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>
58 #include "nfs4idmap.h"
59 #include "nfs4session.h"
63 #define NFSDBG_FACILITY NFSDBG_XDR
65 /* Mapping from NFS error code to "errno" error code. */
66 #define errno_NFSERR_IO EIO
68 static int nfs4_stat_to_errno(int);
70 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
72 #define NFS4_MAXTAGLEN 20
74 #define NFS4_MAXTAGLEN 0
77 /* lock,open owner id:
78 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
80 #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
81 #define lock_owner_id_maxsz (1 + 1 + 4)
82 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
83 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85 #define op_encode_hdr_maxsz (1)
86 #define op_decode_hdr_maxsz (2)
87 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
91 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
93 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
94 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
97 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
99 #define nfs4_fattr_bitmap_maxsz 4
100 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
101 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
103 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
106 /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107 #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
109 #define nfs4_label_maxsz 0
111 /* We support only one layout type per file system */
112 #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
113 /* This is based on getfattr, which uses the most attributes: */
114 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
115 3 + 3 + 3 + nfs4_owner_maxsz + \
116 nfs4_group_maxsz + nfs4_label_maxsz + \
117 decode_mdsthreshold_maxsz))
118 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 nfs4_fattr_value_maxsz)
120 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
121 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
127 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
128 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
129 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
131 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
132 /* The 5 accounts for the PNFS attributes, and assumes that at most three
133 * layout types will be returned.
135 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
137 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138 #define decode_renew_maxsz (op_decode_hdr_maxsz)
139 #define encode_setclientid_maxsz \
140 (op_encode_hdr_maxsz + \
141 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
143 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
145 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
146 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
148 #define decode_setclientid_maxsz \
149 (op_decode_hdr_maxsz + \
151 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
152 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
154 #define encode_setclientid_confirm_maxsz \
155 (op_encode_hdr_maxsz + \
156 3 + (NFS4_VERIFIER_SIZE >> 2))
157 #define decode_setclientid_confirm_maxsz \
158 (op_decode_hdr_maxsz)
159 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
160 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
161 #define encode_share_access_maxsz \
163 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
164 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
165 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
166 #define encode_open_maxsz (op_encode_hdr_maxsz + \
167 2 + encode_share_access_maxsz + 2 + \
168 open_owner_id_maxsz + \
169 encode_opentype_maxsz + \
170 encode_claim_null_maxsz)
171 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
172 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
174 #define decode_change_info_maxsz (5)
175 #define decode_open_maxsz (op_decode_hdr_maxsz + \
176 decode_stateid_maxsz + \
177 decode_change_info_maxsz + 1 + \
178 nfs4_fattr_bitmap_maxsz + \
179 decode_delegation_maxsz)
180 #define encode_open_confirm_maxsz \
181 (op_encode_hdr_maxsz + \
182 encode_stateid_maxsz + 1)
183 #define decode_open_confirm_maxsz \
184 (op_decode_hdr_maxsz + \
185 decode_stateid_maxsz)
186 #define encode_open_downgrade_maxsz \
187 (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 1 + \
189 encode_share_access_maxsz)
190 #define decode_open_downgrade_maxsz \
191 (op_decode_hdr_maxsz + \
192 decode_stateid_maxsz)
193 #define encode_close_maxsz (op_encode_hdr_maxsz + \
194 1 + encode_stateid_maxsz)
195 #define decode_close_maxsz (op_decode_hdr_maxsz + \
196 decode_stateid_maxsz)
197 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
198 encode_stateid_maxsz + \
200 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
201 nfs4_fattr_bitmap_maxsz)
202 #define encode_read_maxsz (op_encode_hdr_maxsz + \
203 encode_stateid_maxsz + 3)
204 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
205 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
206 2 + encode_verifier_maxsz + 5 + \
208 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
209 decode_verifier_maxsz)
210 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
211 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
212 #define encode_write_maxsz (op_encode_hdr_maxsz + \
213 encode_stateid_maxsz + 4)
214 #define decode_write_maxsz (op_decode_hdr_maxsz + \
215 2 + decode_verifier_maxsz)
216 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
217 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
218 decode_verifier_maxsz)
219 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
221 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
222 decode_change_info_maxsz)
223 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
225 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
226 decode_change_info_maxsz + \
227 decode_change_info_maxsz)
228 #define encode_link_maxsz (op_encode_hdr_maxsz + \
230 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
231 #define encode_lockowner_maxsz (7)
232 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
234 1 + encode_stateid_maxsz + 1 + \
235 encode_lockowner_maxsz)
236 #define decode_lock_denied_maxsz \
237 (8 + decode_lockowner_maxsz)
238 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
239 decode_lock_denied_maxsz)
240 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
241 encode_lockowner_maxsz)
242 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
243 decode_lock_denied_maxsz)
244 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
245 encode_stateid_maxsz + \
247 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
248 decode_stateid_maxsz)
249 #define encode_release_lockowner_maxsz \
250 (op_encode_hdr_maxsz + \
251 encode_lockowner_maxsz)
252 #define decode_release_lockowner_maxsz \
253 (op_decode_hdr_maxsz)
254 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
255 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
256 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
257 1 + nfs4_name_maxsz + \
260 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
261 #define encode_create_maxsz (op_encode_hdr_maxsz + \
262 1 + 2 + nfs4_name_maxsz + \
264 #define decode_create_maxsz (op_decode_hdr_maxsz + \
265 decode_change_info_maxsz + \
266 nfs4_fattr_bitmap_maxsz)
267 #define encode_statfs_maxsz (encode_getattr_maxsz)
268 #define decode_statfs_maxsz (decode_getattr_maxsz)
269 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
270 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
271 #define encode_getacl_maxsz (encode_getattr_maxsz)
272 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
273 nfs4_fattr_bitmap_maxsz + 1)
274 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
275 encode_stateid_maxsz + 3)
276 #define decode_setacl_maxsz (decode_setattr_maxsz)
277 #define encode_fs_locations_maxsz \
278 (encode_getattr_maxsz)
279 #define decode_fs_locations_maxsz \
281 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
282 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
284 #if defined(CONFIG_NFS_V4_1)
285 #define NFS4_MAX_MACHINE_NAME_LEN (64)
286 #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
287 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
289 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
290 encode_verifier_maxsz + \
291 1 /* co_ownerid.len */ + \
292 /* eia_clientowner */ \
293 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 /* max is SP4_MACH_CRED (for now) */ + \
297 1 + NFS4_OP_MAP_NUM_WORDS + \
298 1 + NFS4_OP_MAP_NUM_WORDS + \
299 1 /* implementation id array of size 1 */ + \
300 1 /* nii_domain */ + \
301 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
303 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
305 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
306 2 /* eir_clientid */ + \
307 1 /* eir_sequenceid */ + \
308 1 /* eir_flags */ + \
310 /* max is SP4_MACH_CRED (for now) */ + \
311 1 + NFS4_OP_MAP_NUM_WORDS + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
313 2 /* eir_server_owner.so_minor_id */ + \
314 /* eir_server_owner.so_major_id<> */ \
315 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
316 /* eir_server_scope<> */ \
317 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
318 1 /* eir_server_impl_id array length */ + \
319 1 /* nii_domain */ + \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
322 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
324 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
325 #define decode_channel_attrs_maxsz (6 + \
326 1 /* ca_rdma_ird.len */ + \
328 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
329 2 /* csa_clientid */ + \
330 1 /* csa_sequence */ + \
331 1 /* csa_flags */ + \
332 encode_channel_attrs_maxsz + \
333 encode_channel_attrs_maxsz + \
334 1 /* csa_cb_program */ + \
335 1 /* csa_sec_parms.len (1) */ + \
336 1 /* cb_secflavor (AUTH_SYS) */ + \
338 1 /* machinename.len */ + \
339 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
342 1 /* gids.len (0) */)
343 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
344 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
345 1 /* csr_sequence */ + \
346 1 /* csr_flags */ + \
347 decode_channel_attrs_maxsz + \
348 decode_channel_attrs_maxsz)
349 #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
351 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
352 1 /* bctsa_dir */ + \
353 1 /* bctsa_use_conn_in_rdma_mode */)
354 #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
356 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
357 1 /* bctsr_dir */ + \
358 1 /* bctsr_use_conn_in_rdma_mode */)
359 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
360 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
361 #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
362 #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
363 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
364 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
365 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
366 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
367 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
368 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
369 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
370 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
371 1 /* layout type */ + \
373 1 /* bitmap size */ + \
374 1 /* notification bitmap length */ + \
375 1 /* notification bitmap, word 0 */)
376 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
377 1 /* layout type */ + \
378 1 /* opaque devaddr4 length */ + \
379 /* devaddr4 payload is read into page */ \
380 1 /* notification bitmap length */ + \
381 1 /* notification bitmap, word 0 */)
382 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
383 encode_stateid_maxsz)
384 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
385 decode_stateid_maxsz + \
386 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
387 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
391 encode_stateid_maxsz + \
392 1 /* new offset (true) */ + \
393 2 /* last byte written */ + \
394 1 /* nt_timechanged (false) */ + \
395 1 /* layoutupdate4 layout type */ + \
396 1 /* layoutupdate4 opaqueue len */)
397 /* the actual content of layoutupdate4 should
398 be allocated by drivers and spliced in
399 using xdr_write_pages */
400 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
401 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
402 encode_stateid_maxsz + \
403 1 /* FIXME: opaque lrf_body always empty at the moment */)
404 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
405 1 + decode_stateid_maxsz)
406 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
407 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
408 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
409 XDR_QUADLEN(NFS4_STATEID_SIZE))
410 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
411 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
412 XDR_QUADLEN(NFS4_STATEID_SIZE))
413 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
414 #else /* CONFIG_NFS_V4_1 */
415 #define encode_sequence_maxsz 0
416 #define decode_sequence_maxsz 0
417 #endif /* CONFIG_NFS_V4_1 */
419 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
420 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
421 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
422 encode_sequence_maxsz + \
423 encode_putfh_maxsz + \
425 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
426 decode_sequence_maxsz + \
427 decode_putfh_maxsz + \
429 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
430 encode_sequence_maxsz + \
431 encode_putfh_maxsz + \
432 encode_readlink_maxsz)
433 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
434 decode_sequence_maxsz + \
435 decode_putfh_maxsz + \
436 decode_readlink_maxsz)
437 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
438 encode_sequence_maxsz + \
439 encode_putfh_maxsz + \
440 encode_readdir_maxsz)
441 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
442 decode_sequence_maxsz + \
443 decode_putfh_maxsz + \
444 decode_readdir_maxsz)
445 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
446 encode_sequence_maxsz + \
447 encode_putfh_maxsz + \
448 encode_write_maxsz + \
449 encode_getattr_maxsz)
450 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
451 decode_sequence_maxsz + \
452 decode_putfh_maxsz + \
453 decode_write_maxsz + \
454 decode_getattr_maxsz)
455 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
456 encode_sequence_maxsz + \
457 encode_putfh_maxsz + \
459 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
460 decode_sequence_maxsz + \
461 decode_putfh_maxsz + \
463 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
464 encode_sequence_maxsz + \
465 encode_putfh_maxsz + \
466 encode_open_maxsz + \
467 encode_access_maxsz + \
468 encode_getfh_maxsz + \
469 encode_getattr_maxsz)
470 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
471 decode_sequence_maxsz + \
472 decode_putfh_maxsz + \
473 decode_open_maxsz + \
474 decode_access_maxsz + \
475 decode_getfh_maxsz + \
476 decode_getattr_maxsz)
477 #define NFS4_enc_open_confirm_sz \
478 (compound_encode_hdr_maxsz + \
479 encode_putfh_maxsz + \
480 encode_open_confirm_maxsz)
481 #define NFS4_dec_open_confirm_sz \
482 (compound_decode_hdr_maxsz + \
483 decode_putfh_maxsz + \
484 decode_open_confirm_maxsz)
485 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
486 encode_sequence_maxsz + \
487 encode_putfh_maxsz + \
488 encode_open_maxsz + \
489 encode_access_maxsz + \
490 encode_getattr_maxsz)
491 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
492 decode_sequence_maxsz + \
493 decode_putfh_maxsz + \
494 decode_open_maxsz + \
495 decode_access_maxsz + \
496 decode_getattr_maxsz)
497 #define NFS4_enc_open_downgrade_sz \
498 (compound_encode_hdr_maxsz + \
499 encode_sequence_maxsz + \
500 encode_putfh_maxsz + \
501 encode_open_downgrade_maxsz + \
502 encode_getattr_maxsz)
503 #define NFS4_dec_open_downgrade_sz \
504 (compound_decode_hdr_maxsz + \
505 decode_sequence_maxsz + \
506 decode_putfh_maxsz + \
507 decode_open_downgrade_maxsz + \
508 decode_getattr_maxsz)
509 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
510 encode_sequence_maxsz + \
511 encode_putfh_maxsz + \
512 encode_close_maxsz + \
513 encode_getattr_maxsz)
514 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
515 decode_sequence_maxsz + \
516 decode_putfh_maxsz + \
517 decode_close_maxsz + \
518 decode_getattr_maxsz)
519 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
520 encode_sequence_maxsz + \
521 encode_putfh_maxsz + \
522 encode_setattr_maxsz + \
523 encode_getattr_maxsz)
524 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
525 decode_sequence_maxsz + \
526 decode_putfh_maxsz + \
527 decode_setattr_maxsz + \
528 decode_getattr_maxsz)
529 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
530 encode_sequence_maxsz + \
531 encode_putfh_maxsz + \
533 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
534 decode_sequence_maxsz + \
535 decode_putfh_maxsz + \
537 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
539 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
541 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
542 encode_setclientid_maxsz)
543 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
544 decode_setclientid_maxsz)
545 #define NFS4_enc_setclientid_confirm_sz \
546 (compound_encode_hdr_maxsz + \
547 encode_setclientid_confirm_maxsz)
548 #define NFS4_dec_setclientid_confirm_sz \
549 (compound_decode_hdr_maxsz + \
550 decode_setclientid_confirm_maxsz)
551 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
552 encode_sequence_maxsz + \
553 encode_putfh_maxsz + \
555 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
556 decode_sequence_maxsz + \
557 decode_putfh_maxsz + \
559 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
560 encode_sequence_maxsz + \
561 encode_putfh_maxsz + \
563 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
564 decode_sequence_maxsz + \
565 decode_putfh_maxsz + \
567 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
568 encode_sequence_maxsz + \
569 encode_putfh_maxsz + \
571 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
572 decode_sequence_maxsz + \
573 decode_putfh_maxsz + \
575 #define NFS4_enc_release_lockowner_sz \
576 (compound_encode_hdr_maxsz + \
577 encode_lockowner_maxsz)
578 #define NFS4_dec_release_lockowner_sz \
579 (compound_decode_hdr_maxsz + \
580 decode_lockowner_maxsz)
581 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
582 encode_sequence_maxsz + \
583 encode_putfh_maxsz + \
584 encode_access_maxsz + \
585 encode_getattr_maxsz)
586 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
587 decode_sequence_maxsz + \
588 decode_putfh_maxsz + \
589 decode_access_maxsz + \
590 decode_getattr_maxsz)
591 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
592 encode_sequence_maxsz + \
593 encode_putfh_maxsz + \
594 encode_getattr_maxsz + \
596 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
597 decode_sequence_maxsz + \
598 decode_putfh_maxsz + \
599 decode_getattr_maxsz + \
601 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
602 encode_sequence_maxsz + \
603 encode_putfh_maxsz + \
604 encode_lookup_maxsz + \
605 encode_getattr_maxsz + \
607 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
608 decode_sequence_maxsz + \
609 decode_putfh_maxsz + \
610 decode_lookup_maxsz + \
611 decode_getattr_maxsz + \
613 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
614 encode_sequence_maxsz + \
615 encode_putrootfh_maxsz + \
616 encode_getattr_maxsz + \
618 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
619 decode_sequence_maxsz + \
620 decode_putrootfh_maxsz + \
621 decode_getattr_maxsz + \
623 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
624 encode_sequence_maxsz + \
625 encode_putfh_maxsz + \
627 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
628 decode_sequence_maxsz + \
629 decode_putfh_maxsz + \
631 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
632 encode_sequence_maxsz + \
633 encode_putfh_maxsz + \
634 encode_savefh_maxsz + \
635 encode_putfh_maxsz + \
637 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
638 decode_sequence_maxsz + \
639 decode_putfh_maxsz + \
640 decode_savefh_maxsz + \
641 decode_putfh_maxsz + \
643 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
644 encode_sequence_maxsz + \
645 encode_putfh_maxsz + \
646 encode_savefh_maxsz + \
647 encode_putfh_maxsz + \
648 encode_link_maxsz + \
649 encode_restorefh_maxsz + \
650 encode_getattr_maxsz)
651 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
652 decode_sequence_maxsz + \
653 decode_putfh_maxsz + \
654 decode_savefh_maxsz + \
655 decode_putfh_maxsz + \
656 decode_link_maxsz + \
657 decode_restorefh_maxsz + \
658 decode_getattr_maxsz)
659 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
660 encode_sequence_maxsz + \
661 encode_putfh_maxsz + \
662 encode_symlink_maxsz + \
663 encode_getattr_maxsz + \
665 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
666 decode_sequence_maxsz + \
667 decode_putfh_maxsz + \
668 decode_symlink_maxsz + \
669 decode_getattr_maxsz + \
671 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
672 encode_sequence_maxsz + \
673 encode_putfh_maxsz + \
674 encode_create_maxsz + \
675 encode_getfh_maxsz + \
676 encode_getattr_maxsz)
677 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
678 decode_sequence_maxsz + \
679 decode_putfh_maxsz + \
680 decode_create_maxsz + \
681 decode_getfh_maxsz + \
682 decode_getattr_maxsz)
683 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
684 encode_sequence_maxsz + \
685 encode_putfh_maxsz + \
686 encode_getattr_maxsz)
687 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
688 decode_sequence_maxsz + \
689 decode_putfh_maxsz + \
690 decode_getattr_maxsz)
691 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
692 encode_sequence_maxsz + \
693 encode_putfh_maxsz + \
695 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
696 decode_sequence_maxsz + \
697 decode_putfh_maxsz + \
699 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
700 encode_sequence_maxsz + \
701 encode_putfh_maxsz + \
702 encode_getattr_maxsz)
703 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
704 decode_sequence_maxsz + \
705 decode_putfh_maxsz + \
706 decode_getattr_maxsz)
707 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
708 encode_sequence_maxsz + \
709 encode_putfh_maxsz + \
710 encode_delegreturn_maxsz + \
711 encode_getattr_maxsz)
712 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
713 decode_sequence_maxsz + \
714 decode_delegreturn_maxsz + \
715 decode_getattr_maxsz)
716 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
717 encode_sequence_maxsz + \
718 encode_putfh_maxsz + \
720 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
721 decode_sequence_maxsz + \
722 decode_putfh_maxsz + \
724 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
725 encode_sequence_maxsz + \
726 encode_putfh_maxsz + \
728 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
729 decode_sequence_maxsz + \
730 decode_putfh_maxsz + \
732 #define NFS4_enc_fs_locations_sz \
733 (compound_encode_hdr_maxsz + \
734 encode_sequence_maxsz + \
735 encode_putfh_maxsz + \
736 encode_lookup_maxsz + \
737 encode_fs_locations_maxsz + \
739 #define NFS4_dec_fs_locations_sz \
740 (compound_decode_hdr_maxsz + \
741 decode_sequence_maxsz + \
742 decode_putfh_maxsz + \
743 decode_lookup_maxsz + \
744 decode_fs_locations_maxsz + \
746 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
747 encode_sequence_maxsz + \
748 encode_putfh_maxsz + \
749 encode_secinfo_maxsz)
750 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
751 decode_sequence_maxsz + \
752 decode_putfh_maxsz + \
753 decode_secinfo_maxsz)
754 #define NFS4_enc_fsid_present_sz \
755 (compound_encode_hdr_maxsz + \
756 encode_sequence_maxsz + \
757 encode_putfh_maxsz + \
758 encode_getfh_maxsz + \
760 #define NFS4_dec_fsid_present_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz + \
763 decode_putfh_maxsz + \
764 decode_getfh_maxsz + \
766 #if defined(CONFIG_NFS_V4_1)
767 #define NFS4_enc_bind_conn_to_session_sz \
768 (compound_encode_hdr_maxsz + \
769 encode_bind_conn_to_session_maxsz)
770 #define NFS4_dec_bind_conn_to_session_sz \
771 (compound_decode_hdr_maxsz + \
772 decode_bind_conn_to_session_maxsz)
773 #define NFS4_enc_exchange_id_sz \
774 (compound_encode_hdr_maxsz + \
775 encode_exchange_id_maxsz)
776 #define NFS4_dec_exchange_id_sz \
777 (compound_decode_hdr_maxsz + \
778 decode_exchange_id_maxsz)
779 #define NFS4_enc_create_session_sz \
780 (compound_encode_hdr_maxsz + \
781 encode_create_session_maxsz)
782 #define NFS4_dec_create_session_sz \
783 (compound_decode_hdr_maxsz + \
784 decode_create_session_maxsz)
785 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
786 encode_destroy_session_maxsz)
787 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
788 decode_destroy_session_maxsz)
789 #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
790 encode_destroy_clientid_maxsz)
791 #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
792 decode_destroy_clientid_maxsz)
793 #define NFS4_enc_sequence_sz \
794 (compound_decode_hdr_maxsz + \
795 encode_sequence_maxsz)
796 #define NFS4_dec_sequence_sz \
797 (compound_decode_hdr_maxsz + \
798 decode_sequence_maxsz)
799 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz + \
801 encode_putrootfh_maxsz + \
803 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
804 decode_sequence_maxsz + \
805 decode_putrootfh_maxsz + \
807 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
808 encode_sequence_maxsz + \
809 encode_reclaim_complete_maxsz)
810 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_reclaim_complete_maxsz)
813 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
814 encode_sequence_maxsz +\
815 encode_getdeviceinfo_maxsz)
816 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
817 decode_sequence_maxsz + \
818 decode_getdeviceinfo_maxsz)
819 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz + \
821 encode_putfh_maxsz + \
822 encode_layoutget_maxsz)
823 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_putfh_maxsz + \
826 decode_layoutget_maxsz)
827 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
828 encode_sequence_maxsz +\
829 encode_putfh_maxsz + \
830 encode_layoutcommit_maxsz + \
831 encode_getattr_maxsz)
832 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
833 decode_sequence_maxsz + \
834 decode_putfh_maxsz + \
835 decode_layoutcommit_maxsz + \
836 decode_getattr_maxsz)
837 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz + \
839 encode_putfh_maxsz + \
840 encode_layoutreturn_maxsz)
841 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_putfh_maxsz + \
844 decode_layoutreturn_maxsz)
845 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
846 encode_sequence_maxsz + \
847 encode_putrootfh_maxsz +\
848 encode_secinfo_no_name_maxsz)
849 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
850 decode_sequence_maxsz + \
851 decode_putrootfh_maxsz + \
852 decode_secinfo_no_name_maxsz)
853 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
854 encode_sequence_maxsz + \
855 encode_test_stateid_maxsz)
856 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
857 decode_sequence_maxsz + \
858 decode_test_stateid_maxsz)
859 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
860 encode_sequence_maxsz + \
861 encode_free_stateid_maxsz)
862 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
863 decode_sequence_maxsz + \
864 decode_free_stateid_maxsz)
866 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
867 compound_encode_hdr_maxsz +
868 encode_sequence_maxsz +
870 encode_getattr_maxsz) *
873 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
874 compound_decode_hdr_maxsz +
875 decode_sequence_maxsz +
876 decode_putfh_maxsz) *
879 const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
880 compound_decode_hdr_maxsz +
881 decode_sequence_maxsz) *
883 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
884 #endif /* CONFIG_NFS_V4_1 */
886 static const umode_t nfs_type2fmt[] = {
893 [NF4SOCK] = S_IFSOCK,
899 struct compound_hdr {
905 uint32_t replen; /* expected reply words */
909 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
911 __be32 *p = xdr_reserve_space(xdr, nbytes);
916 static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
920 p = xdr_reserve_space(xdr, len);
921 xdr_encode_opaque_fixed(p, buf, len);
924 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
928 p = reserve_space(xdr, 4 + len);
929 xdr_encode_opaque(p, str, len);
932 static void encode_uint32(struct xdr_stream *xdr, u32 n)
936 p = reserve_space(xdr, 4);
940 static void encode_uint64(struct xdr_stream *xdr, u64 n)
944 p = reserve_space(xdr, 8);
945 xdr_encode_hyper(p, n);
948 static void encode_nfs4_seqid(struct xdr_stream *xdr,
949 const struct nfs_seqid *seqid)
952 encode_uint32(xdr, seqid->sequence->counter);
954 encode_uint32(xdr, 0);
957 static void encode_compound_hdr(struct xdr_stream *xdr,
958 struct rpc_rqst *req,
959 struct compound_hdr *hdr)
962 struct rpc_auth *auth = req->rq_cred->cr_auth;
964 /* initialize running count of expected bytes in reply.
965 * NOTE: the replied tag SHOULD be the same is the one sent,
966 * but this is not required as a MUST for the server to do so. */
967 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
969 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
970 encode_string(xdr, hdr->taglen, hdr->tag);
971 p = reserve_space(xdr, 8);
972 *p++ = cpu_to_be32(hdr->minorversion);
974 *p = cpu_to_be32(hdr->nops);
977 static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
979 struct compound_hdr *hdr)
981 encode_uint32(xdr, op);
983 hdr->replen += replen;
986 static void encode_nops(struct compound_hdr *hdr)
988 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
989 *hdr->nops_p = htonl(hdr->nops);
992 static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
994 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
997 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
999 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
1002 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1003 const struct nfs4_label *label,
1004 const struct nfs_server *server)
1006 char owner_name[IDMAP_NAMESZ];
1007 char owner_group[IDMAP_NAMESZ];
1008 int owner_namelen = 0;
1009 int owner_grouplen = 0;
1014 uint32_t bmval[3] = { 0 };
1017 * We reserve enough space to write the entire attribute buffer at once.
1018 * In the worst-case, this would be
1019 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1020 * = 40 bytes, plus any contribution from variable-length fields
1021 * such as owner/group.
1023 if (iap->ia_valid & ATTR_SIZE) {
1024 bmval[0] |= FATTR4_WORD0_SIZE;
1027 if (iap->ia_valid & ATTR_MODE) {
1028 bmval[1] |= FATTR4_WORD1_MODE;
1031 if (iap->ia_valid & ATTR_UID) {
1032 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1033 if (owner_namelen < 0) {
1034 dprintk("nfs: couldn't resolve uid %d to string\n",
1035 from_kuid(&init_user_ns, iap->ia_uid));
1037 strcpy(owner_name, "nobody");
1038 owner_namelen = sizeof("nobody") - 1;
1041 bmval[1] |= FATTR4_WORD1_OWNER;
1042 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1044 if (iap->ia_valid & ATTR_GID) {
1045 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1046 if (owner_grouplen < 0) {
1047 dprintk("nfs: couldn't resolve gid %d to string\n",
1048 from_kgid(&init_user_ns, iap->ia_gid));
1049 strcpy(owner_group, "nobody");
1050 owner_grouplen = sizeof("nobody") - 1;
1053 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1054 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1056 if (iap->ia_valid & ATTR_ATIME_SET) {
1057 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1059 } else if (iap->ia_valid & ATTR_ATIME) {
1060 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1063 if (iap->ia_valid & ATTR_MTIME_SET) {
1064 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1066 } else if (iap->ia_valid & ATTR_MTIME) {
1067 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1071 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1072 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1077 else if (bmval[1] != 0)
1082 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1084 *p++ = cpu_to_be32(bmval_len);
1085 for (i = 0; i < bmval_len; i++)
1086 *p++ = cpu_to_be32(bmval[i]);
1087 *p++ = cpu_to_be32(len);
1089 if (bmval[0] & FATTR4_WORD0_SIZE)
1090 p = xdr_encode_hyper(p, iap->ia_size);
1091 if (bmval[1] & FATTR4_WORD1_MODE)
1092 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1093 if (bmval[1] & FATTR4_WORD1_OWNER)
1094 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1095 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1096 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1097 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1098 if (iap->ia_valid & ATTR_ATIME_SET) {
1099 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1100 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1101 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1103 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1105 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1106 if (iap->ia_valid & ATTR_MTIME_SET) {
1107 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1108 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1109 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1111 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1113 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1114 *p++ = cpu_to_be32(label->lfs);
1115 *p++ = cpu_to_be32(label->pi);
1116 *p++ = cpu_to_be32(label->len);
1117 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1123 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1125 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1126 encode_uint32(xdr, access);
1129 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1131 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1132 encode_nfs4_seqid(xdr, arg->seqid);
1133 encode_nfs4_stateid(xdr, &arg->stateid);
1136 static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1140 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1141 p = reserve_space(xdr, 12);
1142 p = xdr_encode_hyper(p, args->offset);
1143 *p = cpu_to_be32(args->count);
1146 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1150 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1151 encode_uint32(xdr, create->ftype);
1153 switch (create->ftype) {
1155 p = reserve_space(xdr, 4);
1156 *p = cpu_to_be32(create->u.symlink.len);
1157 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1160 case NF4BLK: case NF4CHR:
1161 p = reserve_space(xdr, 8);
1162 *p++ = cpu_to_be32(create->u.device.specdata1);
1163 *p = cpu_to_be32(create->u.device.specdata2);
1170 encode_string(xdr, create->name->len, create->name->name);
1171 encode_attrs(xdr, create->attrs, create->label, create->server);
1174 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1178 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1179 p = reserve_space(xdr, 8);
1180 *p++ = cpu_to_be32(1);
1181 *p = cpu_to_be32(bitmap);
1184 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1188 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1189 p = reserve_space(xdr, 12);
1190 *p++ = cpu_to_be32(2);
1191 *p++ = cpu_to_be32(bm0);
1192 *p = cpu_to_be32(bm1);
1196 encode_getattr_three(struct xdr_stream *xdr,
1197 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1198 struct compound_hdr *hdr)
1202 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1204 p = reserve_space(xdr, 16);
1205 *p++ = cpu_to_be32(3);
1206 *p++ = cpu_to_be32(bm0);
1207 *p++ = cpu_to_be32(bm1);
1208 *p = cpu_to_be32(bm2);
1210 p = reserve_space(xdr, 12);
1211 *p++ = cpu_to_be32(2);
1212 *p++ = cpu_to_be32(bm0);
1213 *p = cpu_to_be32(bm1);
1215 p = reserve_space(xdr, 8);
1216 *p++ = cpu_to_be32(1);
1217 *p = cpu_to_be32(bm0);
1221 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1223 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1224 bitmask[1] & nfs4_fattr_bitmap[1],
1225 bitmask[2] & nfs4_fattr_bitmap[2],
1229 static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1230 const u32 *open_bitmap,
1231 struct compound_hdr *hdr)
1233 encode_getattr_three(xdr,
1234 bitmask[0] & open_bitmap[0],
1235 bitmask[1] & open_bitmap[1],
1236 bitmask[2] & open_bitmap[2],
1240 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1242 encode_getattr_three(xdr,
1243 bitmask[0] & nfs4_fsinfo_bitmap[0],
1244 bitmask[1] & nfs4_fsinfo_bitmap[1],
1245 bitmask[2] & nfs4_fsinfo_bitmap[2],
1249 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1251 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1252 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1255 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1257 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1260 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1262 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1263 encode_string(xdr, name->len, name->name);
1266 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1268 if (fl->fl_type == F_RDLCK)
1269 return block ? NFS4_READW_LT : NFS4_READ_LT;
1270 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1273 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1275 if (fl->fl_end == OFFSET_MAX)
1276 return ~(uint64_t)0;
1277 return fl->fl_end - fl->fl_start + 1;
1280 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1284 p = reserve_space(xdr, 32);
1285 p = xdr_encode_hyper(p, lowner->clientid);
1286 *p++ = cpu_to_be32(20);
1287 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1288 *p++ = cpu_to_be32(lowner->s_dev);
1289 xdr_encode_hyper(p, lowner->id);
1293 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1294 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1296 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1300 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1301 p = reserve_space(xdr, 28);
1302 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1303 *p++ = cpu_to_be32(args->reclaim);
1304 p = xdr_encode_hyper(p, args->fl->fl_start);
1305 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1306 *p = cpu_to_be32(args->new_lock_owner);
1307 if (args->new_lock_owner){
1308 encode_nfs4_seqid(xdr, args->open_seqid);
1309 encode_nfs4_stateid(xdr, &args->open_stateid);
1310 encode_nfs4_seqid(xdr, args->lock_seqid);
1311 encode_lockowner(xdr, &args->lock_owner);
1314 encode_nfs4_stateid(xdr, &args->lock_stateid);
1315 encode_nfs4_seqid(xdr, args->lock_seqid);
1319 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1323 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1324 p = reserve_space(xdr, 20);
1325 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1326 p = xdr_encode_hyper(p, args->fl->fl_start);
1327 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1328 encode_lockowner(xdr, &args->lock_owner);
1331 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1335 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1336 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1337 encode_nfs4_seqid(xdr, args->seqid);
1338 encode_nfs4_stateid(xdr, &args->stateid);
1339 p = reserve_space(xdr, 16);
1340 p = xdr_encode_hyper(p, args->fl->fl_start);
1341 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1344 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1346 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1347 encode_lockowner(xdr, lowner);
1350 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1352 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1353 encode_string(xdr, name->len, name->name);
1356 static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
1360 p = reserve_space(xdr, 8);
1361 *p++ = cpu_to_be32(share_access);
1362 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1365 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1369 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1372 encode_nfs4_seqid(xdr, arg->seqid);
1373 encode_share_access(xdr, arg->share_access);
1374 p = reserve_space(xdr, 36);
1375 p = xdr_encode_hyper(p, arg->clientid);
1376 *p++ = cpu_to_be32(24);
1377 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1378 *p++ = cpu_to_be32(arg->server->s_dev);
1379 *p++ = cpu_to_be32(arg->id.uniquifier);
1380 xdr_encode_hyper(p, arg->id.create_time);
1383 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1388 p = reserve_space(xdr, 4);
1389 switch(arg->createmode) {
1390 case NFS4_CREATE_UNCHECKED:
1391 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1392 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
1394 case NFS4_CREATE_GUARDED:
1395 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1396 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
1398 case NFS4_CREATE_EXCLUSIVE:
1399 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1400 encode_nfs4_verifier(xdr, &arg->u.verifier);
1402 case NFS4_CREATE_EXCLUSIVE4_1:
1403 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1404 encode_nfs4_verifier(xdr, &arg->u.verifier);
1406 encode_attrs(xdr, &dummy, arg->label, arg->server);
1410 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1414 p = reserve_space(xdr, 4);
1415 switch (arg->open_flags & O_CREAT) {
1417 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1420 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1421 encode_createmode(xdr, arg);
1425 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1429 p = reserve_space(xdr, 4);
1430 switch (delegation_type) {
1432 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1435 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1437 case FMODE_WRITE|FMODE_READ:
1438 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1445 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1449 p = reserve_space(xdr, 4);
1450 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1451 encode_string(xdr, name->len, name->name);
1454 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1458 p = reserve_space(xdr, 4);
1459 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1460 encode_delegation_type(xdr, type);
1463 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1467 p = reserve_space(xdr, 4);
1468 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1469 encode_nfs4_stateid(xdr, stateid);
1470 encode_string(xdr, name->len, name->name);
1473 static inline void encode_claim_fh(struct xdr_stream *xdr)
1477 p = reserve_space(xdr, 4);
1478 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1481 static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1485 p = reserve_space(xdr, 4);
1486 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1487 encode_nfs4_stateid(xdr, stateid);
1490 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1492 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1493 encode_openhdr(xdr, arg);
1494 encode_opentype(xdr, arg);
1495 switch (arg->claim) {
1496 case NFS4_OPEN_CLAIM_NULL:
1497 encode_claim_null(xdr, arg->name);
1499 case NFS4_OPEN_CLAIM_PREVIOUS:
1500 encode_claim_previous(xdr, arg->u.delegation_type);
1502 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1503 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1505 case NFS4_OPEN_CLAIM_FH:
1506 encode_claim_fh(xdr);
1508 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1509 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1516 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1518 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1519 encode_nfs4_stateid(xdr, arg->stateid);
1520 encode_nfs4_seqid(xdr, arg->seqid);
1523 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1525 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1526 encode_nfs4_stateid(xdr, &arg->stateid);
1527 encode_nfs4_seqid(xdr, arg->seqid);
1528 encode_share_access(xdr, arg->share_access);
1532 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1534 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1535 encode_string(xdr, fh->size, fh->data);
1538 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1540 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1543 static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1544 struct compound_hdr *hdr)
1548 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1549 encode_nfs4_stateid(xdr, &args->stateid);
1551 p = reserve_space(xdr, 12);
1552 p = xdr_encode_hyper(p, args->offset);
1553 *p = cpu_to_be32(args->count);
1556 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1558 uint32_t attrs[3] = {
1559 FATTR4_WORD0_RDATTR_ERROR,
1560 FATTR4_WORD1_MOUNTED_ON_FILEID,
1562 uint32_t dircount = readdir->count >> 1;
1564 uint32_t attrlen = 0;
1567 if (readdir->plus) {
1568 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1569 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1570 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1571 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1572 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1573 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1574 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1577 /* Use mounted_on_fileid only if the server supports it */
1578 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1579 attrs[0] |= FATTR4_WORD0_FILEID;
1580 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1581 attrs[i] &= readdir->bitmask[i];
1586 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1587 encode_uint64(xdr, readdir->cookie);
1588 encode_nfs4_verifier(xdr, &readdir->verifier);
1589 p = reserve_space(xdr, 12 + (attrlen << 2));
1590 *p++ = cpu_to_be32(dircount);
1591 *p++ = cpu_to_be32(readdir->count);
1592 *p++ = cpu_to_be32(attrlen);
1593 for (i = 0; i < attrlen; i++)
1594 *p++ = cpu_to_be32(attrs[i]);
1595 memcpy(verf, readdir->verifier.data, sizeof(verf));
1597 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1599 (unsigned long long)readdir->cookie,
1601 attrs[0] & readdir->bitmask[0],
1602 attrs[1] & readdir->bitmask[1],
1603 attrs[2] & readdir->bitmask[2]);
1606 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1608 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1611 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1613 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1614 encode_string(xdr, name->len, name->name);
1617 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1619 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1620 encode_string(xdr, oldname->len, oldname->name);
1621 encode_string(xdr, newname->len, newname->name);
1624 static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1625 struct compound_hdr *hdr)
1627 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1628 encode_uint64(xdr, clid);
1632 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1634 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1638 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1642 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1643 encode_nfs4_stateid(xdr, &zero_stateid);
1644 p = reserve_space(xdr, 2*4);
1645 *p++ = cpu_to_be32(1);
1646 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1647 p = reserve_space(xdr, 4);
1648 *p = cpu_to_be32(arg->acl_len);
1649 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1653 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1655 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1658 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1660 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1661 encode_nfs4_stateid(xdr, &arg->stateid);
1662 encode_attrs(xdr, arg->iap, arg->label, server);
1665 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1669 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1670 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1672 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1673 setclientid->sc_clnt->cl_owner_id);
1674 p = reserve_space(xdr, 4);
1675 *p = cpu_to_be32(setclientid->sc_prog);
1676 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1677 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1678 p = reserve_space(xdr, 4);
1679 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
1682 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1684 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1685 decode_setclientid_confirm_maxsz, hdr);
1686 encode_uint64(xdr, arg->clientid);
1687 encode_nfs4_verifier(xdr, &arg->confirm);
1690 static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1691 struct compound_hdr *hdr)
1695 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1696 encode_nfs4_stateid(xdr, &args->stateid);
1698 p = reserve_space(xdr, 16);
1699 p = xdr_encode_hyper(p, args->offset);
1700 *p++ = cpu_to_be32(args->stable);
1701 *p = cpu_to_be32(args->count);
1703 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1706 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1708 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1709 encode_nfs4_stateid(xdr, stateid);
1712 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1714 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1715 encode_string(xdr, name->len, name->name);
1718 #if defined(CONFIG_NFS_V4_1)
1719 /* NFSv4.1 operations */
1720 static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1721 struct nfs41_bind_conn_to_session_args *args,
1722 struct compound_hdr *hdr)
1726 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1727 decode_bind_conn_to_session_maxsz, hdr);
1728 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1729 p = xdr_reserve_space(xdr, 8);
1730 *p++ = cpu_to_be32(args->dir);
1731 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
1734 static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1737 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1738 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1739 encode_uint32(xdr, op_map->u.words[i]);
1742 static void encode_exchange_id(struct xdr_stream *xdr,
1743 struct nfs41_exchange_id_args *args,
1744 struct compound_hdr *hdr)
1747 char impl_name[IMPL_NAME_LIMIT];
1750 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1751 encode_nfs4_verifier(xdr, args->verifier);
1753 encode_string(xdr, strlen(args->client->cl_owner_id),
1754 args->client->cl_owner_id);
1756 encode_uint32(xdr, args->flags);
1757 encode_uint32(xdr, args->state_protect.how);
1759 switch (args->state_protect.how) {
1763 encode_op_map(xdr, &args->state_protect.enforce);
1764 encode_op_map(xdr, &args->state_protect.allow);
1771 if (send_implementation_id &&
1772 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1773 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1774 <= sizeof(impl_name) + 1)
1775 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1776 utsname()->sysname, utsname()->release,
1777 utsname()->version, utsname()->machine);
1780 encode_uint32(xdr, 1); /* implementation id array length=1 */
1783 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1784 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1785 encode_string(xdr, len, impl_name);
1786 /* just send zeros for nii_date - the date is in nii_name */
1787 p = reserve_space(xdr, 12);
1788 p = xdr_encode_hyper(p, 0);
1789 *p = cpu_to_be32(0);
1791 encode_uint32(xdr, 0); /* implementation id array length=0 */
1794 static void encode_create_session(struct xdr_stream *xdr,
1795 struct nfs41_create_session_args *args,
1796 struct compound_hdr *hdr)
1799 struct nfs_client *clp = args->client;
1800 struct rpc_clnt *clnt = clp->cl_rpcclient;
1801 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1802 u32 max_resp_sz_cached;
1805 * Assumes OPEN is the biggest non-idempotent compound.
1806 * 2 is the verifier.
1808 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1809 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1811 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1812 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
1813 p = xdr_encode_hyper(p, args->clientid);
1814 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
1815 *p++ = cpu_to_be32(args->flags); /*flags */
1818 *p++ = cpu_to_be32(0); /* header padding size */
1819 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1820 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1821 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1822 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1823 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1824 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1827 *p++ = cpu_to_be32(0); /* header padding size */
1828 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1829 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1830 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1831 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1832 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1833 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1835 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1836 *p++ = cpu_to_be32(1);
1837 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1839 /* authsys_parms rfc1831 */
1840 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
1841 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1842 *p++ = cpu_to_be32(0); /* UID */
1843 *p++ = cpu_to_be32(0); /* GID */
1844 *p = cpu_to_be32(0); /* No more gids */
1847 static void encode_destroy_session(struct xdr_stream *xdr,
1848 struct nfs4_session *session,
1849 struct compound_hdr *hdr)
1851 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1852 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1855 static void encode_destroy_clientid(struct xdr_stream *xdr,
1857 struct compound_hdr *hdr)
1859 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1860 encode_uint64(xdr, clientid);
1863 static void encode_reclaim_complete(struct xdr_stream *xdr,
1864 struct nfs41_reclaim_complete_args *args,
1865 struct compound_hdr *hdr)
1867 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1868 encode_uint32(xdr, args->one_fs);
1870 #endif /* CONFIG_NFS_V4_1 */
1872 static void encode_sequence(struct xdr_stream *xdr,
1873 const struct nfs4_sequence_args *args,
1874 struct compound_hdr *hdr)
1876 #if defined(CONFIG_NFS_V4_1)
1877 struct nfs4_session *session;
1878 struct nfs4_slot_table *tp;
1879 struct nfs4_slot *slot = args->sa_slot;
1883 session = tp->session;
1887 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1890 * Sessionid + seqid + slotid + max slotid + cache_this
1892 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1893 "max_slotid=%d cache_this=%d\n",
1895 ((u32 *)session->sess_id.data)[0],
1896 ((u32 *)session->sess_id.data)[1],
1897 ((u32 *)session->sess_id.data)[2],
1898 ((u32 *)session->sess_id.data)[3],
1899 slot->seq_nr, slot->slot_nr,
1900 tp->highest_used_slotid, args->sa_cache_this);
1901 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1902 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1903 *p++ = cpu_to_be32(slot->seq_nr);
1904 *p++ = cpu_to_be32(slot->slot_nr);
1905 *p++ = cpu_to_be32(tp->highest_used_slotid);
1906 *p = cpu_to_be32(args->sa_cache_this);
1907 #endif /* CONFIG_NFS_V4_1 */
1910 #ifdef CONFIG_NFS_V4_1
1912 encode_getdeviceinfo(struct xdr_stream *xdr,
1913 const struct nfs4_getdeviceinfo_args *args,
1914 struct compound_hdr *hdr)
1918 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1919 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1920 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1921 NFS4_DEVICEID4_SIZE);
1922 *p++ = cpu_to_be32(args->pdev->layout_type);
1923 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
1925 p = reserve_space(xdr, 4 + 4);
1926 *p++ = cpu_to_be32(1); /* bitmap length */
1927 *p++ = cpu_to_be32(args->notify_types);
1931 encode_layoutget(struct xdr_stream *xdr,
1932 const struct nfs4_layoutget_args *args,
1933 struct compound_hdr *hdr)
1937 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1938 p = reserve_space(xdr, 36);
1939 *p++ = cpu_to_be32(0); /* Signal layout available */
1940 *p++ = cpu_to_be32(args->type);
1941 *p++ = cpu_to_be32(args->range.iomode);
1942 p = xdr_encode_hyper(p, args->range.offset);
1943 p = xdr_encode_hyper(p, args->range.length);
1944 p = xdr_encode_hyper(p, args->minlength);
1945 encode_nfs4_stateid(xdr, &args->stateid);
1946 encode_uint32(xdr, args->maxcount);
1948 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1952 (unsigned long)args->range.offset,
1953 (unsigned long)args->range.length,
1958 encode_layoutcommit(struct xdr_stream *xdr,
1959 struct inode *inode,
1960 struct nfs4_layoutcommit_args *args,
1961 struct compound_hdr *hdr)
1965 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1966 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1968 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1969 p = reserve_space(xdr, 20);
1970 /* Only whole file layouts */
1971 p = xdr_encode_hyper(p, 0); /* offset */
1972 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1973 *p = cpu_to_be32(0); /* reclaim */
1974 encode_nfs4_stateid(xdr, &args->stateid);
1975 p = reserve_space(xdr, 20);
1976 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1977 p = xdr_encode_hyper(p, args->lastbytewritten);
1978 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1979 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1981 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
1982 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1983 NFS_I(inode)->layout, xdr, args);
1985 encode_uint32(xdr, args->layoutupdate_len);
1986 if (args->layoutupdate_pages) {
1987 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1988 args->layoutupdate_len);
1996 encode_layoutreturn(struct xdr_stream *xdr,
1997 const struct nfs4_layoutreturn_args *args,
1998 struct compound_hdr *hdr)
2002 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2003 p = reserve_space(xdr, 16);
2004 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2005 *p++ = cpu_to_be32(args->layout_type);
2006 *p++ = cpu_to_be32(args->range.iomode);
2007 *p = cpu_to_be32(RETURN_FILE);
2008 p = reserve_space(xdr, 16);
2009 p = xdr_encode_hyper(p, args->range.offset);
2010 p = xdr_encode_hyper(p, args->range.length);
2011 spin_lock(&args->inode->i_lock);
2012 encode_nfs4_stateid(xdr, &args->stateid);
2013 spin_unlock(&args->inode->i_lock);
2014 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2015 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2016 NFS_I(args->inode)->layout, xdr, args);
2018 encode_uint32(xdr, 0);
2022 encode_secinfo_no_name(struct xdr_stream *xdr,
2023 const struct nfs41_secinfo_no_name_args *args,
2024 struct compound_hdr *hdr)
2026 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2027 encode_uint32(xdr, args->style);
2031 static void encode_test_stateid(struct xdr_stream *xdr,
2032 struct nfs41_test_stateid_args *args,
2033 struct compound_hdr *hdr)
2035 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2036 encode_uint32(xdr, 1);
2037 encode_nfs4_stateid(xdr, args->stateid);
2040 static void encode_free_stateid(struct xdr_stream *xdr,
2041 struct nfs41_free_stateid_args *args,
2042 struct compound_hdr *hdr)
2044 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2045 encode_nfs4_stateid(xdr, &args->stateid);
2047 #endif /* CONFIG_NFS_V4_1 */
2050 * END OF "GENERIC" ENCODE ROUTINES.
2053 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2055 #if defined(CONFIG_NFS_V4_1)
2056 struct nfs4_session *session = args->sa_slot->table->session;
2058 return session->clp->cl_mvops->minor_version;
2059 #endif /* CONFIG_NFS_V4_1 */
2064 * Encode an ACCESS request
2066 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2067 const struct nfs4_accessargs *args)
2069 struct compound_hdr hdr = {
2070 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2073 encode_compound_hdr(xdr, req, &hdr);
2074 encode_sequence(xdr, &args->seq_args, &hdr);
2075 encode_putfh(xdr, args->fh, &hdr);
2076 encode_access(xdr, args->access, &hdr);
2077 encode_getfattr(xdr, args->bitmask, &hdr);
2082 * Encode LOOKUP request
2084 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2085 const struct nfs4_lookup_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->dir_fh, &hdr);
2094 encode_lookup(xdr, args->name, &hdr);
2095 encode_getfh(xdr, &hdr);
2096 encode_getfattr(xdr, args->bitmask, &hdr);
2101 * Encode LOOKUP_ROOT request
2103 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2104 struct xdr_stream *xdr,
2105 const struct nfs4_lookup_root_arg *args)
2107 struct compound_hdr hdr = {
2108 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2111 encode_compound_hdr(xdr, req, &hdr);
2112 encode_sequence(xdr, &args->seq_args, &hdr);
2113 encode_putrootfh(xdr, &hdr);
2114 encode_getfh(xdr, &hdr);
2115 encode_getfattr(xdr, args->bitmask, &hdr);
2120 * Encode REMOVE request
2122 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2123 const struct nfs_removeargs *args)
2125 struct compound_hdr hdr = {
2126 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2129 encode_compound_hdr(xdr, req, &hdr);
2130 encode_sequence(xdr, &args->seq_args, &hdr);
2131 encode_putfh(xdr, args->fh, &hdr);
2132 encode_remove(xdr, &args->name, &hdr);
2137 * Encode RENAME request
2139 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2140 const struct nfs_renameargs *args)
2142 struct compound_hdr hdr = {
2143 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2146 encode_compound_hdr(xdr, req, &hdr);
2147 encode_sequence(xdr, &args->seq_args, &hdr);
2148 encode_putfh(xdr, args->old_dir, &hdr);
2149 encode_savefh(xdr, &hdr);
2150 encode_putfh(xdr, args->new_dir, &hdr);
2151 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2156 * Encode LINK request
2158 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2159 const struct nfs4_link_arg *args)
2161 struct compound_hdr hdr = {
2162 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_sequence(xdr, &args->seq_args, &hdr);
2167 encode_putfh(xdr, args->fh, &hdr);
2168 encode_savefh(xdr, &hdr);
2169 encode_putfh(xdr, args->dir_fh, &hdr);
2170 encode_link(xdr, args->name, &hdr);
2171 encode_restorefh(xdr, &hdr);
2172 encode_getfattr(xdr, args->bitmask, &hdr);
2177 * Encode CREATE request
2179 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2180 const struct nfs4_create_arg *args)
2182 struct compound_hdr hdr = {
2183 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2186 encode_compound_hdr(xdr, req, &hdr);
2187 encode_sequence(xdr, &args->seq_args, &hdr);
2188 encode_putfh(xdr, args->dir_fh, &hdr);
2189 encode_create(xdr, args, &hdr);
2190 encode_getfh(xdr, &hdr);
2191 encode_getfattr(xdr, args->bitmask, &hdr);
2196 * Encode SYMLINK request
2198 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2199 const struct nfs4_create_arg *args)
2201 nfs4_xdr_enc_create(req, xdr, args);
2205 * Encode GETATTR request
2207 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2208 const struct nfs4_getattr_arg *args)
2210 struct compound_hdr hdr = {
2211 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2214 encode_compound_hdr(xdr, req, &hdr);
2215 encode_sequence(xdr, &args->seq_args, &hdr);
2216 encode_putfh(xdr, args->fh, &hdr);
2217 encode_getfattr(xdr, args->bitmask, &hdr);
2222 * Encode a CLOSE request
2224 static void nfs4_xdr_enc_close(struct rpc_rqst *req, 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_close(xdr, args, &hdr);
2235 encode_getfattr(xdr, args->bitmask, &hdr);
2240 * Encode an OPEN request
2242 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2243 struct nfs_openargs *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_open(xdr, args, &hdr);
2253 encode_getfh(xdr, &hdr);
2255 encode_access(xdr, args->access, &hdr);
2256 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2261 * Encode an OPEN_CONFIRM request
2263 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2264 struct xdr_stream *xdr,
2265 struct nfs_open_confirmargs *args)
2267 struct compound_hdr hdr = {
2271 encode_compound_hdr(xdr, req, &hdr);
2272 encode_putfh(xdr, args->fh, &hdr);
2273 encode_open_confirm(xdr, args, &hdr);
2278 * Encode an OPEN request with no attributes.
2280 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2281 struct xdr_stream *xdr,
2282 struct nfs_openargs *args)
2284 struct compound_hdr hdr = {
2285 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2288 encode_compound_hdr(xdr, req, &hdr);
2289 encode_sequence(xdr, &args->seq_args, &hdr);
2290 encode_putfh(xdr, args->fh, &hdr);
2291 encode_open(xdr, args, &hdr);
2293 encode_access(xdr, args->access, &hdr);
2294 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2299 * Encode an OPEN_DOWNGRADE request
2301 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2302 struct xdr_stream *xdr,
2303 struct nfs_closeargs *args)
2305 struct compound_hdr hdr = {
2306 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2309 encode_compound_hdr(xdr, req, &hdr);
2310 encode_sequence(xdr, &args->seq_args, &hdr);
2311 encode_putfh(xdr, args->fh, &hdr);
2312 encode_open_downgrade(xdr, args, &hdr);
2313 encode_getfattr(xdr, args->bitmask, &hdr);
2318 * Encode a LOCK request
2320 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2321 struct nfs_lock_args *args)
2323 struct compound_hdr hdr = {
2324 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2327 encode_compound_hdr(xdr, req, &hdr);
2328 encode_sequence(xdr, &args->seq_args, &hdr);
2329 encode_putfh(xdr, args->fh, &hdr);
2330 encode_lock(xdr, args, &hdr);
2335 * Encode a LOCKT request
2337 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2338 struct nfs_lockt_args *args)
2340 struct compound_hdr hdr = {
2341 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2344 encode_compound_hdr(xdr, req, &hdr);
2345 encode_sequence(xdr, &args->seq_args, &hdr);
2346 encode_putfh(xdr, args->fh, &hdr);
2347 encode_lockt(xdr, args, &hdr);
2352 * Encode a LOCKU request
2354 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2355 struct nfs_locku_args *args)
2357 struct compound_hdr hdr = {
2358 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2361 encode_compound_hdr(xdr, req, &hdr);
2362 encode_sequence(xdr, &args->seq_args, &hdr);
2363 encode_putfh(xdr, args->fh, &hdr);
2364 encode_locku(xdr, args, &hdr);
2368 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2369 struct xdr_stream *xdr,
2370 struct nfs_release_lockowner_args *args)
2372 struct compound_hdr hdr = {
2376 encode_compound_hdr(xdr, req, &hdr);
2377 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2382 * Encode a READLINK request
2384 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2385 const struct nfs4_readlink *args)
2387 struct compound_hdr hdr = {
2388 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2391 encode_compound_hdr(xdr, req, &hdr);
2392 encode_sequence(xdr, &args->seq_args, &hdr);
2393 encode_putfh(xdr, args->fh, &hdr);
2394 encode_readlink(xdr, args, req, &hdr);
2396 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2397 args->pgbase, args->pglen);
2402 * Encode a READDIR request
2404 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2405 const struct nfs4_readdir_arg *args)
2407 struct compound_hdr hdr = {
2408 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2411 encode_compound_hdr(xdr, req, &hdr);
2412 encode_sequence(xdr, &args->seq_args, &hdr);
2413 encode_putfh(xdr, args->fh, &hdr);
2414 encode_readdir(xdr, args, req, &hdr);
2416 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2417 args->pgbase, args->count);
2418 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2419 __func__, hdr.replen << 2, args->pages,
2420 args->pgbase, args->count);
2425 * Encode a READ request
2427 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2428 struct nfs_pgio_args *args)
2430 struct compound_hdr hdr = {
2431 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2434 encode_compound_hdr(xdr, req, &hdr);
2435 encode_sequence(xdr, &args->seq_args, &hdr);
2436 encode_putfh(xdr, args->fh, &hdr);
2437 encode_read(xdr, args, &hdr);
2439 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2440 args->pages, args->pgbase, args->count);
2441 req->rq_rcv_buf.flags |= XDRBUF_READ;
2446 * Encode an SETATTR request
2448 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2449 struct nfs_setattrargs *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_setattr(xdr, args, args->server, &hdr);
2459 encode_getfattr(xdr, args->bitmask, &hdr);
2464 * Encode a GETACL request
2466 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2467 struct nfs_getaclargs *args)
2469 struct compound_hdr hdr = {
2470 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2474 encode_compound_hdr(xdr, req, &hdr);
2475 encode_sequence(xdr, &args->seq_args, &hdr);
2476 encode_putfh(xdr, args->fh, &hdr);
2477 replen = hdr.replen + op_decode_hdr_maxsz + 1;
2478 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2480 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2481 args->acl_pages, args->acl_pgbase, args->acl_len);
2487 * Encode a WRITE request
2489 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2490 struct nfs_pgio_args *args)
2492 struct compound_hdr hdr = {
2493 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2496 encode_compound_hdr(xdr, req, &hdr);
2497 encode_sequence(xdr, &args->seq_args, &hdr);
2498 encode_putfh(xdr, args->fh, &hdr);
2499 encode_write(xdr, args, &hdr);
2500 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2502 encode_getfattr(xdr, args->bitmask, &hdr);
2509 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2510 struct nfs_commitargs *args)
2512 struct compound_hdr hdr = {
2513 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2516 encode_compound_hdr(xdr, req, &hdr);
2517 encode_sequence(xdr, &args->seq_args, &hdr);
2518 encode_putfh(xdr, args->fh, &hdr);
2519 encode_commit(xdr, args, &hdr);
2526 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2527 struct nfs4_fsinfo_arg *args)
2529 struct compound_hdr hdr = {
2530 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2533 encode_compound_hdr(xdr, req, &hdr);
2534 encode_sequence(xdr, &args->seq_args, &hdr);
2535 encode_putfh(xdr, args->fh, &hdr);
2536 encode_fsinfo(xdr, args->bitmask, &hdr);
2541 * a PATHCONF request
2543 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2544 const struct nfs4_pathconf_arg *args)
2546 struct compound_hdr hdr = {
2547 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2550 encode_compound_hdr(xdr, req, &hdr);
2551 encode_sequence(xdr, &args->seq_args, &hdr);
2552 encode_putfh(xdr, args->fh, &hdr);
2553 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2561 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2562 const struct nfs4_statfs_arg *args)
2564 struct compound_hdr hdr = {
2565 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2568 encode_compound_hdr(xdr, req, &hdr);
2569 encode_sequence(xdr, &args->seq_args, &hdr);
2570 encode_putfh(xdr, args->fh, &hdr);
2571 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2572 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2577 * GETATTR_BITMAP request
2579 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2580 struct xdr_stream *xdr,
2581 struct nfs4_server_caps_arg *args)
2583 struct compound_hdr hdr = {
2584 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2587 encode_compound_hdr(xdr, req, &hdr);
2588 encode_sequence(xdr, &args->seq_args, &hdr);
2589 encode_putfh(xdr, args->fhandle, &hdr);
2590 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2591 FATTR4_WORD0_FH_EXPIRE_TYPE|
2592 FATTR4_WORD0_LINK_SUPPORT|
2593 FATTR4_WORD0_SYMLINK_SUPPORT|
2594 FATTR4_WORD0_ACLSUPPORT, &hdr);
2601 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2602 struct nfs_client *clp)
2604 struct compound_hdr hdr = {
2608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_renew(xdr, clp->cl_clientid, &hdr);
2614 * a SETCLIENTID request
2616 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2617 struct xdr_stream *xdr,
2618 struct nfs4_setclientid *sc)
2620 struct compound_hdr hdr = {
2624 encode_compound_hdr(xdr, req, &hdr);
2625 encode_setclientid(xdr, sc, &hdr);
2630 * a SETCLIENTID_CONFIRM request
2632 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2633 struct xdr_stream *xdr,
2634 struct nfs4_setclientid_res *arg)
2636 struct compound_hdr hdr = {
2640 encode_compound_hdr(xdr, req, &hdr);
2641 encode_setclientid_confirm(xdr, arg, &hdr);
2646 * DELEGRETURN request
2648 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2649 struct xdr_stream *xdr,
2650 const struct nfs4_delegreturnargs *args)
2652 struct compound_hdr hdr = {
2653 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2656 encode_compound_hdr(xdr, req, &hdr);
2657 encode_sequence(xdr, &args->seq_args, &hdr);
2658 encode_putfh(xdr, args->fhandle, &hdr);
2659 encode_getfattr(xdr, args->bitmask, &hdr);
2660 encode_delegreturn(xdr, args->stateid, &hdr);
2665 * Encode FS_LOCATIONS request
2667 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2668 struct xdr_stream *xdr,
2669 struct nfs4_fs_locations_arg *args)
2671 struct compound_hdr hdr = {
2672 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2676 encode_compound_hdr(xdr, req, &hdr);
2677 encode_sequence(xdr, &args->seq_args, &hdr);
2678 if (args->migration) {
2679 encode_putfh(xdr, args->fh, &hdr);
2680 replen = hdr.replen;
2681 encode_fs_locations(xdr, args->bitmask, &hdr);
2683 encode_renew(xdr, args->clientid, &hdr);
2685 encode_putfh(xdr, args->dir_fh, &hdr);
2686 encode_lookup(xdr, args->name, &hdr);
2687 replen = hdr.replen;
2688 encode_fs_locations(xdr, args->bitmask, &hdr);
2691 /* Set up reply kvec to capture returned fs_locations array. */
2692 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2698 * Encode SECINFO request
2700 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2701 struct xdr_stream *xdr,
2702 struct nfs4_secinfo_arg *args)
2704 struct compound_hdr hdr = {
2705 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2708 encode_compound_hdr(xdr, req, &hdr);
2709 encode_sequence(xdr, &args->seq_args, &hdr);
2710 encode_putfh(xdr, args->dir_fh, &hdr);
2711 encode_secinfo(xdr, args->name, &hdr);
2716 * Encode FSID_PRESENT request
2718 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2719 struct xdr_stream *xdr,
2720 struct nfs4_fsid_present_arg *args)
2722 struct compound_hdr hdr = {
2723 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2726 encode_compound_hdr(xdr, req, &hdr);
2727 encode_sequence(xdr, &args->seq_args, &hdr);
2728 encode_putfh(xdr, args->fh, &hdr);
2729 encode_getfh(xdr, &hdr);
2731 encode_renew(xdr, args->clientid, &hdr);
2735 #if defined(CONFIG_NFS_V4_1)
2737 * BIND_CONN_TO_SESSION request
2739 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2740 struct xdr_stream *xdr,
2741 struct nfs41_bind_conn_to_session_args *args)
2743 struct compound_hdr hdr = {
2744 .minorversion = args->client->cl_mvops->minor_version,
2747 encode_compound_hdr(xdr, req, &hdr);
2748 encode_bind_conn_to_session(xdr, args, &hdr);
2753 * EXCHANGE_ID request
2755 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2756 struct xdr_stream *xdr,
2757 struct nfs41_exchange_id_args *args)
2759 struct compound_hdr hdr = {
2760 .minorversion = args->client->cl_mvops->minor_version,
2763 encode_compound_hdr(xdr, req, &hdr);
2764 encode_exchange_id(xdr, args, &hdr);
2769 * a CREATE_SESSION request
2771 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2772 struct xdr_stream *xdr,
2773 struct nfs41_create_session_args *args)
2775 struct compound_hdr hdr = {
2776 .minorversion = args->client->cl_mvops->minor_version,
2779 encode_compound_hdr(xdr, req, &hdr);
2780 encode_create_session(xdr, args, &hdr);
2785 * a DESTROY_SESSION request
2787 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2788 struct xdr_stream *xdr,
2789 struct nfs4_session *session)
2791 struct compound_hdr hdr = {
2792 .minorversion = session->clp->cl_mvops->minor_version,
2795 encode_compound_hdr(xdr, req, &hdr);
2796 encode_destroy_session(xdr, session, &hdr);
2801 * a DESTROY_CLIENTID request
2803 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2804 struct xdr_stream *xdr,
2805 struct nfs_client *clp)
2807 struct compound_hdr hdr = {
2808 .minorversion = clp->cl_mvops->minor_version,
2811 encode_compound_hdr(xdr, req, &hdr);
2812 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2817 * a SEQUENCE request
2819 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2820 struct nfs4_sequence_args *args)
2822 struct compound_hdr hdr = {
2823 .minorversion = nfs4_xdr_minorversion(args),
2826 encode_compound_hdr(xdr, req, &hdr);
2827 encode_sequence(xdr, args, &hdr);
2832 * a GET_LEASE_TIME request
2834 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2835 struct xdr_stream *xdr,
2836 struct nfs4_get_lease_time_args *args)
2838 struct compound_hdr hdr = {
2839 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2841 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2843 encode_compound_hdr(xdr, req, &hdr);
2844 encode_sequence(xdr, &args->la_seq_args, &hdr);
2845 encode_putrootfh(xdr, &hdr);
2846 encode_fsinfo(xdr, lease_bitmap, &hdr);
2851 * a RECLAIM_COMPLETE request
2853 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2854 struct xdr_stream *xdr,
2855 struct nfs41_reclaim_complete_args *args)
2857 struct compound_hdr hdr = {
2858 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2861 encode_compound_hdr(xdr, req, &hdr);
2862 encode_sequence(xdr, &args->seq_args, &hdr);
2863 encode_reclaim_complete(xdr, args, &hdr);
2868 * Encode GETDEVICEINFO request
2870 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2871 struct xdr_stream *xdr,
2872 struct nfs4_getdeviceinfo_args *args)
2874 struct compound_hdr hdr = {
2875 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2878 encode_compound_hdr(xdr, req, &hdr);
2879 encode_sequence(xdr, &args->seq_args, &hdr);
2880 encode_getdeviceinfo(xdr, args, &hdr);
2882 /* set up reply kvec. Subtract notification bitmap max size (2)
2883 * so that notification bitmap is put in xdr_buf tail */
2884 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2885 args->pdev->pages, args->pdev->pgbase,
2892 * Encode LAYOUTGET request
2894 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2895 struct xdr_stream *xdr,
2896 struct nfs4_layoutget_args *args)
2898 struct compound_hdr hdr = {
2899 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2902 encode_compound_hdr(xdr, req, &hdr);
2903 encode_sequence(xdr, &args->seq_args, &hdr);
2904 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2905 encode_layoutget(xdr, args, &hdr);
2907 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2908 args->layout.pages, 0, args->layout.pglen);
2914 * Encode LAYOUTCOMMIT request
2916 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2917 struct xdr_stream *xdr,
2918 struct nfs4_layoutcommit_args *args)
2920 struct nfs4_layoutcommit_data *data =
2921 container_of(args, struct nfs4_layoutcommit_data, args);
2922 struct compound_hdr hdr = {
2923 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2926 encode_compound_hdr(xdr, req, &hdr);
2927 encode_sequence(xdr, &args->seq_args, &hdr);
2928 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2929 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2930 encode_getfattr(xdr, args->bitmask, &hdr);
2935 * Encode LAYOUTRETURN request
2937 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2938 struct xdr_stream *xdr,
2939 struct nfs4_layoutreturn_args *args)
2941 struct compound_hdr hdr = {
2942 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2945 encode_compound_hdr(xdr, req, &hdr);
2946 encode_sequence(xdr, &args->seq_args, &hdr);
2947 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2948 encode_layoutreturn(xdr, args, &hdr);
2953 * Encode SECINFO_NO_NAME request
2955 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2956 struct xdr_stream *xdr,
2957 struct nfs41_secinfo_no_name_args *args)
2959 struct compound_hdr hdr = {
2960 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2963 encode_compound_hdr(xdr, req, &hdr);
2964 encode_sequence(xdr, &args->seq_args, &hdr);
2965 encode_putrootfh(xdr, &hdr);
2966 encode_secinfo_no_name(xdr, args, &hdr);
2972 * Encode TEST_STATEID request
2974 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2975 struct xdr_stream *xdr,
2976 struct nfs41_test_stateid_args *args)
2978 struct compound_hdr hdr = {
2979 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2982 encode_compound_hdr(xdr, req, &hdr);
2983 encode_sequence(xdr, &args->seq_args, &hdr);
2984 encode_test_stateid(xdr, args, &hdr);
2989 * Encode FREE_STATEID request
2991 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2992 struct xdr_stream *xdr,
2993 struct nfs41_free_stateid_args *args)
2995 struct compound_hdr hdr = {
2996 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2999 encode_compound_hdr(xdr, req, &hdr);
3000 encode_sequence(xdr, &args->seq_args, &hdr);
3001 encode_free_stateid(xdr, args, &hdr);
3004 #endif /* CONFIG_NFS_V4_1 */
3006 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3008 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3009 "Remaining buffer length is %tu words.\n",
3010 func, xdr->end - xdr->p);
3013 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3017 p = xdr_inline_decode(xdr, 4);
3020 *len = be32_to_cpup(p);
3021 p = xdr_inline_decode(xdr, *len);
3024 *string = (char *)p;
3027 print_overflow_msg(__func__, xdr);
3031 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3035 p = xdr_inline_decode(xdr, 8);
3038 hdr->status = be32_to_cpup(p++);
3039 hdr->taglen = be32_to_cpup(p);
3041 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3044 hdr->tag = (char *)p;
3045 p += XDR_QUADLEN(hdr->taglen);
3046 hdr->nops = be32_to_cpup(p);
3047 if (unlikely(hdr->nops < 1))
3048 return nfs4_stat_to_errno(hdr->status);
3051 print_overflow_msg(__func__, xdr);
3055 static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3062 p = xdr_inline_decode(xdr, 8);
3065 opnum = be32_to_cpup(p++);
3066 if (unlikely(opnum != expected))
3067 goto out_bad_operation;
3068 nfserr = be32_to_cpup(p);
3069 if (nfserr == NFS_OK)
3072 *nfs_retval = nfs4_stat_to_errno(nfserr);
3075 dprintk("nfs: Server returned operation"
3076 " %d but we issued a request for %d\n",
3078 *nfs_retval = -EREMOTEIO;
3081 print_overflow_msg(__func__, xdr);
3086 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3090 __decode_op_hdr(xdr, expected, &retval);
3095 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
3098 unsigned int strlen;
3101 p = xdr_inline_decode(xdr, 12);
3103 return decode_opaque_inline(xdr, &strlen, &str);
3104 print_overflow_msg(__func__, xdr);
3108 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3113 p = xdr_inline_decode(xdr, 4);
3116 bmlen = be32_to_cpup(p);
3118 bitmap[0] = bitmap[1] = bitmap[2] = 0;
3119 p = xdr_inline_decode(xdr, (bmlen << 2));
3123 bitmap[0] = be32_to_cpup(p++);
3125 bitmap[1] = be32_to_cpup(p++);
3127 bitmap[2] = be32_to_cpup(p);
3132 print_overflow_msg(__func__, xdr);
3136 static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
3140 p = xdr_inline_decode(xdr, 4);
3143 *attrlen = be32_to_cpup(p);
3144 *savep = xdr_stream_pos(xdr);
3147 print_overflow_msg(__func__, xdr);
3151 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3153 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3155 ret = decode_attr_bitmap(xdr, bitmask);
3156 if (unlikely(ret < 0))
3158 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3160 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3161 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3162 bitmask[0], bitmask[1], bitmask[2]);
3166 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3172 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3174 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3175 p = xdr_inline_decode(xdr, 4);
3178 *type = be32_to_cpup(p);
3179 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3180 dprintk("%s: bad type %d\n", __func__, *type);
3183 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3184 ret = NFS_ATTR_FATTR_TYPE;
3186 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3189 print_overflow_msg(__func__, xdr);
3193 static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3194 uint32_t *bitmap, uint32_t *type)
3199 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3201 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3202 p = xdr_inline_decode(xdr, 4);
3205 *type = be32_to_cpup(p);
3206 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3208 dprintk("%s: expire type=0x%x\n", __func__, *type);
3211 print_overflow_msg(__func__, xdr);
3215 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3221 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3223 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3224 p = xdr_inline_decode(xdr, 8);
3227 xdr_decode_hyper(p, change);
3228 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3229 ret = NFS_ATTR_FATTR_CHANGE;
3231 dprintk("%s: change attribute=%Lu\n", __func__,
3232 (unsigned long long)*change);
3235 print_overflow_msg(__func__, xdr);
3239 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3245 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3247 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3248 p = xdr_inline_decode(xdr, 8);
3251 xdr_decode_hyper(p, size);
3252 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3253 ret = NFS_ATTR_FATTR_SIZE;
3255 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3258 print_overflow_msg(__func__, xdr);
3262 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3267 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3269 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3270 p = xdr_inline_decode(xdr, 4);
3273 *res = be32_to_cpup(p);
3274 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3276 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3279 print_overflow_msg(__func__, xdr);
3283 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3288 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3290 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3291 p = xdr_inline_decode(xdr, 4);
3294 *res = be32_to_cpup(p);
3295 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3297 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3300 print_overflow_msg(__func__, xdr);
3304 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3311 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3313 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3314 p = xdr_inline_decode(xdr, 16);
3317 p = xdr_decode_hyper(p, &fsid->major);
3318 xdr_decode_hyper(p, &fsid->minor);
3319 bitmap[0] &= ~FATTR4_WORD0_FSID;
3320 ret = NFS_ATTR_FATTR_FSID;
3322 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3323 (unsigned long long)fsid->major,
3324 (unsigned long long)fsid->minor);
3327 print_overflow_msg(__func__, xdr);
3331 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3336 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3338 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3339 p = xdr_inline_decode(xdr, 4);
3342 *res = be32_to_cpup(p);
3343 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3345 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3348 print_overflow_msg(__func__, xdr);
3352 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3356 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3358 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3359 p = xdr_inline_decode(xdr, 4);
3362 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3363 *res = -be32_to_cpup(p);
3367 print_overflow_msg(__func__, xdr);
3371 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3377 memset(fh, 0, sizeof(*fh));
3379 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3381 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3382 p = xdr_inline_decode(xdr, 4);
3385 len = be32_to_cpup(p);
3386 if (len > NFS4_FHSIZE)
3388 p = xdr_inline_decode(xdr, len);
3392 memcpy(fh->data, p, len);
3395 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3399 print_overflow_msg(__func__, xdr);
3403 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3408 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3410 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3411 p = xdr_inline_decode(xdr, 4);
3414 *res = be32_to_cpup(p);
3415 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3417 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3420 print_overflow_msg(__func__, xdr);
3424 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3430 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3432 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3433 p = xdr_inline_decode(xdr, 8);
3436 xdr_decode_hyper(p, fileid);
3437 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3438 ret = NFS_ATTR_FATTR_FILEID;
3440 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3443 print_overflow_msg(__func__, xdr);
3447 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3453 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3455 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3456 p = xdr_inline_decode(xdr, 8);
3459 xdr_decode_hyper(p, fileid);
3460 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3461 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3463 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3466 print_overflow_msg(__func__, xdr);
3470 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3476 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3478 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3479 p = xdr_inline_decode(xdr, 8);
3482 xdr_decode_hyper(p, res);
3483 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3485 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3488 print_overflow_msg(__func__, xdr);
3492 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3498 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3500 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3501 p = xdr_inline_decode(xdr, 8);
3504 xdr_decode_hyper(p, res);
3505 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3507 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3510 print_overflow_msg(__func__, xdr);
3514 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3520 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3522 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3523 p = xdr_inline_decode(xdr, 8);
3526 xdr_decode_hyper(p, res);
3527 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3529 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3532 print_overflow_msg(__func__, xdr);
3536 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3542 p = xdr_inline_decode(xdr, 4);
3545 n = be32_to_cpup(p);
3548 dprintk("pathname4: ");
3549 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3550 dprintk("cannot parse %d components in path\n", n);
3553 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
3554 struct nfs4_string *component = &path->components[path->ncomponents];
3555 status = decode_opaque_inline(xdr, &component->len, &component->data);
3556 if (unlikely(status != 0))
3560 (path->ncomponents != n ? "/ " : ""),
3561 component->len, component->data);
3566 /* a root pathname is sent as a zero component4 */
3567 path->ncomponents = 1;
3568 path->components[0].len=0;
3569 path->components[0].data=NULL;
3570 dprintk("pathname4: /\n");
3573 dprintk(" status %d", status);
3577 print_overflow_msg(__func__, xdr);
3581 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3587 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3590 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3593 /* Ignore borken servers that return unrequested attrs */
3594 if (unlikely(res == NULL))
3596 dprintk("%s: fsroot:\n", __func__);
3597 status = decode_pathname(xdr, &res->fs_path);
3598 if (unlikely(status != 0))
3600 p = xdr_inline_decode(xdr, 4);
3603 n = be32_to_cpup(p);
3606 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3608 struct nfs4_fs_location *loc;
3610 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3612 loc = &res->locations[res->nlocations];
3613 p = xdr_inline_decode(xdr, 4);
3616 m = be32_to_cpup(p);
3618 dprintk("%s: servers:\n", __func__);
3619 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3620 struct nfs4_string *server;
3622 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3624 dprintk("%s: using first %u of %u servers "
3625 "returned for location %u\n",
3627 NFS4_FS_LOCATION_MAXSERVERS,
3628 m, res->nlocations);
3629 for (i = loc->nservers; i < m; i++) {
3632 status = decode_opaque_inline(xdr, &len, &data);
3633 if (unlikely(status != 0))
3638 server = &loc->servers[loc->nservers];
3639 status = decode_opaque_inline(xdr, &server->len, &server->data);
3640 if (unlikely(status != 0))
3642 dprintk("%s ", server->data);
3644 status = decode_pathname(xdr, &loc->rootpath);
3645 if (unlikely(status != 0))
3648 if (res->nlocations != 0)
3649 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3651 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3654 print_overflow_msg(__func__, xdr);
3660 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3666 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3668 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3669 p = xdr_inline_decode(xdr, 8);
3672 xdr_decode_hyper(p, res);
3673 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3675 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3678 print_overflow_msg(__func__, xdr);
3682 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3688 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3690 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3691 p = xdr_inline_decode(xdr, 4);
3694 *maxlink = be32_to_cpup(p);
3695 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3697 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3700 print_overflow_msg(__func__, xdr);
3704 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3710 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3712 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3713 p = xdr_inline_decode(xdr, 4);
3716 *maxname = be32_to_cpup(p);
3717 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3719 dprintk("%s: maxname=%u\n", __func__, *maxname);
3722 print_overflow_msg(__func__, xdr);
3726 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3732 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3734 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3736 p = xdr_inline_decode(xdr, 8);
3739 xdr_decode_hyper(p, &maxread);
3740 if (maxread > 0x7FFFFFFF)
3741 maxread = 0x7FFFFFFF;
3742 *res = (uint32_t)maxread;
3743 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3745 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3748 print_overflow_msg(__func__, xdr);
3752 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3758 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3760 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3762 p = xdr_inline_decode(xdr, 8);
3765 xdr_decode_hyper(p, &maxwrite);
3766 if (maxwrite > 0x7FFFFFFF)
3767 maxwrite = 0x7FFFFFFF;
3768 *res = (uint32_t)maxwrite;
3769 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3771 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3774 print_overflow_msg(__func__, xdr);
3778 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3785 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3787 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3788 p = xdr_inline_decode(xdr, 4);
3791 tmp = be32_to_cpup(p);
3792 *mode = tmp & ~S_IFMT;
3793 bitmap[1] &= ~FATTR4_WORD1_MODE;
3794 ret = NFS_ATTR_FATTR_MODE;
3796 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3799 print_overflow_msg(__func__, xdr);
3803 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3809 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3811 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3812 p = xdr_inline_decode(xdr, 4);
3815 *nlink = be32_to_cpup(p);
3816 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3817 ret = NFS_ATTR_FATTR_NLINK;
3819 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3822 print_overflow_msg(__func__, xdr);
3826 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3827 const struct nfs_server *server, kuid_t *uid,
3828 struct nfs4_string *owner_name)
3834 *uid = make_kuid(&init_user_ns, -2);
3835 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3837 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3838 p = xdr_inline_decode(xdr, 4);
3841 len = be32_to_cpup(p);
3842 p = xdr_inline_decode(xdr, len);
3845 if (owner_name != NULL) {
3846 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3847 if (owner_name->data != NULL) {
3848 owner_name->len = len;
3849 ret = NFS_ATTR_FATTR_OWNER_NAME;
3851 } else if (len < XDR_MAX_NETOBJ) {
3852 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3853 ret = NFS_ATTR_FATTR_OWNER;
3855 dprintk("%s: nfs_map_name_to_uid failed!\n",
3858 dprintk("%s: name too long (%u)!\n",
3860 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3862 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3865 print_overflow_msg(__func__, xdr);
3869 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3870 const struct nfs_server *server, kgid_t *gid,
3871 struct nfs4_string *group_name)
3877 *gid = make_kgid(&init_user_ns, -2);
3878 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3880 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3881 p = xdr_inline_decode(xdr, 4);
3884 len = be32_to_cpup(p);
3885 p = xdr_inline_decode(xdr, len);
3888 if (group_name != NULL) {
3889 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3890 if (group_name->data != NULL) {
3891 group_name->len = len;
3892 ret = NFS_ATTR_FATTR_GROUP_NAME;
3894 } else if (len < XDR_MAX_NETOBJ) {
3895 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3896 ret = NFS_ATTR_FATTR_GROUP;
3898 dprintk("%s: nfs_map_group_to_gid failed!\n",
3901 dprintk("%s: name too long (%u)!\n",
3903 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3905 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3908 print_overflow_msg(__func__, xdr);
3912 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3914 uint32_t major = 0, minor = 0;
3919 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3921 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3924 p = xdr_inline_decode(xdr, 8);
3927 major = be32_to_cpup(p++);
3928 minor = be32_to_cpup(p);
3929 tmp = MKDEV(major, minor);
3930 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3932 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3933 ret = NFS_ATTR_FATTR_RDEV;
3935 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3938 print_overflow_msg(__func__, xdr);
3942 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3948 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3950 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3951 p = xdr_inline_decode(xdr, 8);
3954 xdr_decode_hyper(p, res);
3955 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3957 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3960 print_overflow_msg(__func__, xdr);
3964 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3970 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3972 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3973 p = xdr_inline_decode(xdr, 8);
3976 xdr_decode_hyper(p, res);
3977 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3979 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3982 print_overflow_msg(__func__, xdr);
3986 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3992 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3994 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3995 p = xdr_inline_decode(xdr, 8);
3998 xdr_decode_hyper(p, res);
3999 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4001 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
4004 print_overflow_msg(__func__, xdr);
4008 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4014 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4016 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4017 p = xdr_inline_decode(xdr, 8);
4020 xdr_decode_hyper(p, used);
4021 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4022 ret = NFS_ATTR_FATTR_SPACE_USED;
4024 dprintk("%s: space used=%Lu\n", __func__,
4025 (unsigned long long)*used);
4028 print_overflow_msg(__func__, xdr);
4032 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4038 p = xdr_inline_decode(xdr, 12);
4041 p = xdr_decode_hyper(p, &sec);
4042 nsec = be32_to_cpup(p);
4043 time->tv_sec = (time_t)sec;
4044 time->tv_nsec = (long)nsec;
4047 print_overflow_msg(__func__, xdr);
4051 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4057 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4059 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4060 status = decode_attr_time(xdr, time);
4062 status = NFS_ATTR_FATTR_ATIME;
4063 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4065 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
4069 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4075 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4077 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4078 status = decode_attr_time(xdr, time);
4080 status = NFS_ATTR_FATTR_CTIME;
4081 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4083 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
4087 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4088 struct timespec *time)
4094 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4096 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4097 status = decode_attr_time(xdr, time);
4098 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4100 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4101 (long)time->tv_nsec);
4105 static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4106 struct nfs4_label *label)
4114 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4116 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4117 p = xdr_inline_decode(xdr, 4);
4120 lfs = be32_to_cpup(p++);
4121 p = xdr_inline_decode(xdr, 4);
4124 pi = be32_to_cpup(p++);
4125 p = xdr_inline_decode(xdr, 4);
4128 len = be32_to_cpup(p++);
4129 p = xdr_inline_decode(xdr, len);
4132 if (len < NFS4_MAXLABELLEN) {
4134 memcpy(label->label, p, len);
4138 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4140 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4142 printk(KERN_WARNING "%s: label too long (%u)!\n",
4145 if (label && label->label)
4146 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4147 (char *)label->label, label->len, label->pi, label->lfs);
4151 print_overflow_msg(__func__, xdr);
4155 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4161 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4163 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4164 status = decode_attr_time(xdr, time);
4166 status = NFS_ATTR_FATTR_MTIME;
4167 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4169 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
4173 static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
4175 unsigned int attrwords = XDR_QUADLEN(attrlen);
4176 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
4178 if (unlikely(attrwords != nwords)) {
4179 dprintk("%s: server returned incorrect attribute length: "
4183 (attrwords < nwords) ? '<' : '>',
4190 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4194 p = xdr_inline_decode(xdr, 20);
4197 cinfo->atomic = be32_to_cpup(p++);
4198 p = xdr_decode_hyper(p, &cinfo->before);
4199 xdr_decode_hyper(p, &cinfo->after);
4202 print_overflow_msg(__func__, xdr);
4206 static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
4212 status = decode_op_hdr(xdr, OP_ACCESS);
4215 p = xdr_inline_decode(xdr, 8);
4218 supp = be32_to_cpup(p++);
4219 acc = be32_to_cpup(p);
4224 print_overflow_msg(__func__, xdr);
4228 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4232 p = xdr_inline_decode(xdr, len);
4234 memcpy(buf, p, len);
4237 print_overflow_msg(__func__, xdr);
4241 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4243 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4246 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4250 status = decode_op_hdr(xdr, OP_CLOSE);
4252 nfs_increment_open_seqid(status, res->seqid);
4254 status = decode_stateid(xdr, &res->stateid);
4258 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4260 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4263 static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4265 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4268 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4272 status = decode_op_hdr(xdr, OP_COMMIT);
4274 status = decode_write_verifier(xdr, &res->verf->verifier);
4278 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4284 status = decode_op_hdr(xdr, OP_CREATE);
4287 if ((status = decode_change_info(xdr, cinfo)))
4289 p = xdr_inline_decode(xdr, 4);
4292 bmlen = be32_to_cpup(p);
4293 p = xdr_inline_decode(xdr, bmlen << 2);
4297 print_overflow_msg(__func__, xdr);
4301 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4304 uint32_t attrlen, bitmap[3] = {0};
4307 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4309 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4311 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4313 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4315 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4316 &res->fh_expire_type)) != 0)
4318 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4320 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4322 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4324 status = verify_attr_len(xdr, savep, attrlen);
4326 dprintk("%s: xdr returned %d!\n", __func__, -status);
4330 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4333 uint32_t attrlen, bitmap[3] = {0};
4336 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4338 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4340 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4343 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4345 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4347 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4349 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4351 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4353 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4356 status = verify_attr_len(xdr, savep, attrlen);
4358 dprintk("%s: xdr returned %d!\n", __func__, -status);
4362 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4365 uint32_t attrlen, bitmap[3] = {0};
4368 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4370 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4372 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4375 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4377 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4380 status = verify_attr_len(xdr, savep, attrlen);
4382 dprintk("%s: xdr returned %d!\n", __func__, -status);
4386 static int decode_threshold_hint(struct xdr_stream *xdr,
4394 if (likely(bitmap[0] & hint_bit)) {
4395 p = xdr_inline_decode(xdr, 8);
4398 xdr_decode_hyper(p, res);
4402 print_overflow_msg(__func__, xdr);
4406 static int decode_first_threshold_item4(struct xdr_stream *xdr,
4407 struct nfs4_threshold *res)
4411 uint32_t bitmap[3] = {0,}, attrlen;
4415 p = xdr_inline_decode(xdr, 4);
4417 print_overflow_msg(__func__, xdr);
4420 res->l_type = be32_to_cpup(p);
4422 /* thi_hintset bitmap */
4423 status = decode_attr_bitmap(xdr, bitmap);
4427 /* thi_hintlist length */
4428 status = decode_attr_length(xdr, &attrlen, &savep);
4432 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4435 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4438 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4442 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4447 status = verify_attr_len(xdr, savep, attrlen);
4448 res->bm = bitmap[0];
4450 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4451 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4454 dprintk("%s ret=%d!\n", __func__, status);
4459 * Thresholds on pNFS direct I/O vrs MDS I/O
4461 static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4463 struct nfs4_threshold *res)
4469 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4471 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
4472 /* Did the server return an unrequested attribute? */
4473 if (unlikely(res == NULL))
4475 p = xdr_inline_decode(xdr, 4);
4478 num = be32_to_cpup(p);
4482 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4483 "drivers per filesystem not supported\n",
4486 status = decode_first_threshold_item4(xdr, res);
4487 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
4491 print_overflow_msg(__func__, xdr);
4495 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4496 struct nfs_fattr *fattr, struct nfs_fh *fh,
4497 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
4498 const struct nfs_server *server)
4505 status = decode_attr_type(xdr, bitmap, &type);
4510 fattr->mode |= nfs_type2fmt[type];
4511 fattr->valid |= status;
4514 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4517 fattr->valid |= status;
4519 status = decode_attr_size(xdr, bitmap, &fattr->size);
4522 fattr->valid |= status;
4524 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4527 fattr->valid |= status;
4530 status = decode_attr_error(xdr, bitmap, &err);
4534 status = decode_attr_filehandle(xdr, bitmap, fh);
4538 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4541 fattr->valid |= status;
4543 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4546 fattr->valid |= status;
4548 status = decode_attr_mode(xdr, bitmap, &fmode);
4552 fattr->mode |= fmode;
4553 fattr->valid |= status;
4556 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4559 fattr->valid |= status;
4561 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4564 fattr->valid |= status;
4566 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4569 fattr->valid |= status;
4571 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4574 fattr->valid |= status;
4576 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4579 fattr->valid |= status;
4581 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4584 fattr->valid |= status;
4586 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4589 fattr->valid |= status;
4591 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4594 fattr->valid |= status;
4596 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4599 fattr->valid |= status;
4601 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4606 status = decode_attr_security_label(xdr, bitmap, label);
4609 fattr->valid |= status;
4613 dprintk("%s: xdr returned %d\n", __func__, -status);
4617 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4618 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4619 struct nfs4_label *label, const struct nfs_server *server)
4626 status = decode_op_hdr(xdr, OP_GETATTR);
4630 status = decode_attr_bitmap(xdr, bitmap);
4634 status = decode_attr_length(xdr, &attrlen, &savep);
4638 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4643 status = verify_attr_len(xdr, savep, attrlen);
4645 dprintk("%s: xdr returned %d\n", __func__, -status);
4649 static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4650 struct nfs4_label *label, const struct nfs_server *server)
4652 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4655 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4656 const struct nfs_server *server)
4658 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4662 * Decode potentially multiple layout types. Currently we only support
4663 * one layout driver per file system.
4665 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4666 uint32_t *layouttype)
4671 p = xdr_inline_decode(xdr, 4);
4674 num = be32_to_cpup(p);
4676 /* pNFS is not supported by the underlying file system */
4682 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4683 "drivers per filesystem not supported\n", __func__);
4685 /* Decode and set first layout type, move xdr->p past unused types */
4686 p = xdr_inline_decode(xdr, num * 4);
4689 *layouttype = be32_to_cpup(p);
4692 print_overflow_msg(__func__, xdr);
4697 * The type of file system exported.
4698 * Note we must ensure that layouttype is set in any non-error case.
4700 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4701 uint32_t *layouttype)
4705 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4706 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4708 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4709 status = decode_first_pnfs_layout_type(xdr, layouttype);
4710 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4717 * The prefered block size for layout directed io
4719 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4724 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4726 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4727 p = xdr_inline_decode(xdr, 4);
4729 print_overflow_msg(__func__, xdr);
4732 *res = be32_to_cpup(p);
4733 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4738 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4741 uint32_t attrlen, bitmap[3];
4744 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4746 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4748 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4751 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4753 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4755 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4757 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4759 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4760 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4762 fsinfo->wtpref = fsinfo->wtmax;
4763 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4766 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4769 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4773 status = verify_attr_len(xdr, savep, attrlen);
4775 dprintk("%s: xdr returned %d!\n", __func__, -status);
4779 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4785 /* Zero handle first to allow comparisons */
4786 memset(fh, 0, sizeof(*fh));
4788 status = decode_op_hdr(xdr, OP_GETFH);
4792 p = xdr_inline_decode(xdr, 4);
4795 len = be32_to_cpup(p);
4796 if (len > NFS4_FHSIZE)
4799 p = xdr_inline_decode(xdr, len);
4802 memcpy(fh->data, p, len);
4805 print_overflow_msg(__func__, xdr);
4809 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4813 status = decode_op_hdr(xdr, OP_LINK);
4816 return decode_change_info(xdr, cinfo);
4820 * We create the owner, so we know a proper owner.id length is 4.
4822 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4824 uint64_t offset, length, clientid;
4826 uint32_t namelen, type;
4828 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4831 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4832 p = xdr_decode_hyper(p, &length);
4833 type = be32_to_cpup(p++); /* 4 byte read */
4834 if (fl != NULL) { /* manipulate file lock */
4835 fl->fl_start = (loff_t)offset;
4836 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4837 if (length == ~(uint64_t)0)
4838 fl->fl_end = OFFSET_MAX;
4839 fl->fl_type = F_WRLCK;
4841 fl->fl_type = F_RDLCK;
4844 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4845 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4846 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4848 return -NFS4ERR_DENIED;
4850 print_overflow_msg(__func__, xdr);
4854 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4858 status = decode_op_hdr(xdr, OP_LOCK);
4862 status = decode_stateid(xdr, &res->stateid);
4863 if (unlikely(status))
4865 } else if (status == -NFS4ERR_DENIED)
4866 status = decode_lock_denied(xdr, NULL);
4867 if (res->open_seqid != NULL)
4868 nfs_increment_open_seqid(status, res->open_seqid);
4869 nfs_increment_lock_seqid(status, res->lock_seqid);
4874 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4877 status = decode_op_hdr(xdr, OP_LOCKT);
4878 if (status == -NFS4ERR_DENIED)
4879 return decode_lock_denied(xdr, res->denied);
4883 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4887 status = decode_op_hdr(xdr, OP_LOCKU);
4889 nfs_increment_lock_seqid(status, res->seqid);
4891 status = decode_stateid(xdr, &res->stateid);
4895 static int decode_release_lockowner(struct xdr_stream *xdr)
4897 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4900 static int decode_lookup(struct xdr_stream *xdr)
4902 return decode_op_hdr(xdr, OP_LOOKUP);
4905 /* This is too sick! */
4906 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4909 uint32_t limit_type, nblocks, blocksize;
4911 p = xdr_inline_decode(xdr, 12);
4914 limit_type = be32_to_cpup(p++);
4915 switch (limit_type) {
4917 xdr_decode_hyper(p, maxsize);
4920 nblocks = be32_to_cpup(p++);
4921 blocksize = be32_to_cpup(p);
4922 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4926 print_overflow_msg(__func__, xdr);
4930 static int decode_rw_delegation(struct xdr_stream *xdr,
4931 uint32_t delegation_type,
4932 struct nfs_openres *res)
4937 status = decode_stateid(xdr, &res->delegation);
4938 if (unlikely(status))
4940 p = xdr_inline_decode(xdr, 4);
4943 res->do_recall = be32_to_cpup(p);
4945 switch (delegation_type) {
4946 case NFS4_OPEN_DELEGATE_READ:
4947 res->delegation_type = FMODE_READ;
4949 case NFS4_OPEN_DELEGATE_WRITE:
4950 res->delegation_type = FMODE_WRITE|FMODE_READ;
4951 if (decode_space_limit(xdr, &res->maxsize) < 0)
4954 return decode_ace(xdr, NULL, res->server->nfs_client);
4956 print_overflow_msg(__func__, xdr);
4960 static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4963 uint32_t why_no_delegation;
4965 p = xdr_inline_decode(xdr, 4);
4968 why_no_delegation = be32_to_cpup(p);
4969 switch (why_no_delegation) {
4970 case WND4_CONTENTION:
4972 xdr_inline_decode(xdr, 4);
4973 /* Ignore for now */
4977 print_overflow_msg(__func__, xdr);
4981 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4984 uint32_t delegation_type;
4986 p = xdr_inline_decode(xdr, 4);
4989 delegation_type = be32_to_cpup(p);
4990 res->delegation_type = 0;
4991 switch (delegation_type) {
4992 case NFS4_OPEN_DELEGATE_NONE:
4994 case NFS4_OPEN_DELEGATE_READ:
4995 case NFS4_OPEN_DELEGATE_WRITE:
4996 return decode_rw_delegation(xdr, delegation_type, res);
4997 case NFS4_OPEN_DELEGATE_NONE_EXT:
4998 return decode_no_delegation(xdr, res);
5002 print_overflow_msg(__func__, xdr);
5006 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5009 uint32_t savewords, bmlen, i;
5012 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5014 nfs_increment_open_seqid(status, res->seqid);
5017 status = decode_stateid(xdr, &res->stateid);
5018 if (unlikely(status))
5021 decode_change_info(xdr, &res->cinfo);
5023 p = xdr_inline_decode(xdr, 8);
5026 res->rflags = be32_to_cpup(p++);
5027 bmlen = be32_to_cpup(p);
5031 p = xdr_inline_decode(xdr, bmlen << 2);
5034 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5035 for (i = 0; i < savewords; ++i)
5036 res->attrset[i] = be32_to_cpup(p++);
5037 for (; i < NFS4_BITMAP_SIZE; i++)
5038 res->attrset[i] = 0;
5040 return decode_delegation(xdr, res);
5042 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
5045 print_overflow_msg(__func__, xdr);
5049 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5053 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5055 nfs_increment_open_seqid(status, res->seqid);
5057 status = decode_stateid(xdr, &res->stateid);
5061 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5065 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5067 nfs_increment_open_seqid(status, res->seqid);
5069 status = decode_stateid(xdr, &res->stateid);
5073 static int decode_putfh(struct xdr_stream *xdr)
5075 return decode_op_hdr(xdr, OP_PUTFH);
5078 static int decode_putrootfh(struct xdr_stream *xdr)
5080 return decode_op_hdr(xdr, OP_PUTROOTFH);
5083 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5084 struct nfs_pgio_res *res)
5087 uint32_t count, eof, recvd;
5090 status = decode_op_hdr(xdr, OP_READ);
5093 p = xdr_inline_decode(xdr, 8);
5096 eof = be32_to_cpup(p++);
5097 count = be32_to_cpup(p);
5098 recvd = xdr_read_pages(xdr, count);
5099 if (count > recvd) {
5100 dprintk("NFS: server cheating in read reply: "
5101 "count %u > recvd %u\n", count, recvd);
5109 print_overflow_msg(__func__, xdr);
5113 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5118 status = decode_op_hdr(xdr, OP_READDIR);
5120 status = decode_verifier(xdr, readdir->verifier.data);
5121 if (unlikely(status))
5123 memcpy(verf, readdir->verifier.data, sizeof(verf));
5124 dprintk("%s: verifier = %08x:%08x\n",
5125 __func__, verf[0], verf[1]);
5126 return xdr_read_pages(xdr, xdr->buf->page_len);
5129 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5131 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5136 status = decode_op_hdr(xdr, OP_READLINK);
5140 /* Convert length of symlink */
5141 p = xdr_inline_decode(xdr, 4);
5144 len = be32_to_cpup(p);
5145 if (len >= rcvbuf->page_len || len <= 0) {
5146 dprintk("nfs: server returned giant symlink!\n");
5147 return -ENAMETOOLONG;
5149 recvd = xdr_read_pages(xdr, len);
5151 dprintk("NFS: server cheating in readlink reply: "
5152 "count %u > recvd %u\n", len, recvd);
5156 * The XDR encode routine has set things up so that
5157 * the link text will be copied directly into the
5158 * buffer. We just have to do overflow-checking,
5159 * and and null-terminate the text (the VFS expects
5160 * null-termination).
5162 xdr_terminate_string(rcvbuf, len);
5165 print_overflow_msg(__func__, xdr);
5169 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5173 status = decode_op_hdr(xdr, OP_REMOVE);
5176 status = decode_change_info(xdr, cinfo);
5181 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5182 struct nfs4_change_info *new_cinfo)
5186 status = decode_op_hdr(xdr, OP_RENAME);
5189 if ((status = decode_change_info(xdr, old_cinfo)))
5191 status = decode_change_info(xdr, new_cinfo);
5196 static int decode_renew(struct xdr_stream *xdr)
5198 return decode_op_hdr(xdr, OP_RENEW);
5202 decode_restorefh(struct xdr_stream *xdr)
5204 return decode_op_hdr(xdr, OP_RESTOREFH);
5207 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5208 struct nfs_getaclres *res)
5214 unsigned int pg_offset;
5217 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5220 xdr_enter_page(xdr, xdr->buf->page_len);
5222 /* Calculate the offset of the page data */
5223 pg_offset = xdr->buf->head[0].iov_len;
5225 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5227 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5230 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5232 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5234 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5235 * are stored with the acl data to handle the problem of
5236 * variable length bitmaps.*/
5237 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5238 res->acl_len = attrlen;
5240 /* Check for receive buffer overflow */
5241 if (res->acl_len > (xdr->nwords << 2) ||
5242 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5243 res->acl_flags |= NFS4_ACL_TRUNC;
5244 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5245 attrlen, xdr->nwords << 2);
5248 status = -EOPNOTSUPP;
5255 decode_savefh(struct xdr_stream *xdr)
5257 return decode_op_hdr(xdr, OP_SAVEFH);
5260 static int decode_setattr(struct xdr_stream *xdr)
5266 status = decode_op_hdr(xdr, OP_SETATTR);
5269 p = xdr_inline_decode(xdr, 4);
5272 bmlen = be32_to_cpup(p);
5273 p = xdr_inline_decode(xdr, bmlen << 2);
5277 print_overflow_msg(__func__, xdr);
5281 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5287 p = xdr_inline_decode(xdr, 8);
5290 opnum = be32_to_cpup(p++);
5291 if (opnum != OP_SETCLIENTID) {
5292 dprintk("nfs: decode_setclientid: Server returned operation"
5296 nfserr = be32_to_cpup(p);
5297 if (nfserr == NFS_OK) {
5298 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5301 p = xdr_decode_hyper(p, &res->clientid);
5302 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5303 } else if (nfserr == NFSERR_CLID_INUSE) {
5306 /* skip netid string */
5307 p = xdr_inline_decode(xdr, 4);
5310 len = be32_to_cpup(p);
5311 p = xdr_inline_decode(xdr, len);
5315 /* skip uaddr string */
5316 p = xdr_inline_decode(xdr, 4);
5319 len = be32_to_cpup(p);
5320 p = xdr_inline_decode(xdr, len);
5323 return -NFSERR_CLID_INUSE;
5325 return nfs4_stat_to_errno(nfserr);
5329 print_overflow_msg(__func__, xdr);
5333 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5335 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5338 static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
5343 status = decode_op_hdr(xdr, OP_WRITE);
5347 p = xdr_inline_decode(xdr, 8);
5350 res->count = be32_to_cpup(p++);
5351 res->verf->committed = be32_to_cpup(p++);
5352 return decode_write_verifier(xdr, &res->verf->verifier);
5354 print_overflow_msg(__func__, xdr);
5358 static int decode_delegreturn(struct xdr_stream *xdr)
5360 return decode_op_hdr(xdr, OP_DELEGRETURN);
5363 static int decode_secinfo_gss(struct xdr_stream *xdr,
5364 struct nfs4_secinfo4 *flavor)
5369 p = xdr_inline_decode(xdr, 4);
5372 oid_len = be32_to_cpup(p);
5373 if (oid_len > GSS_OID_MAX_LEN)
5376 p = xdr_inline_decode(xdr, oid_len);
5379 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5380 flavor->flavor_info.oid.len = oid_len;
5382 p = xdr_inline_decode(xdr, 8);
5385 flavor->flavor_info.qop = be32_to_cpup(p++);
5386 flavor->flavor_info.service = be32_to_cpup(p);
5391 print_overflow_msg(__func__, xdr);
5397 static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5399 struct nfs4_secinfo4 *sec_flavor;
5400 unsigned int i, num_flavors;
5404 p = xdr_inline_decode(xdr, 4);
5408 res->flavors->num_flavors = 0;
5409 num_flavors = be32_to_cpup(p);
5411 for (i = 0; i < num_flavors; i++) {
5412 sec_flavor = &res->flavors->flavors[i];
5413 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5416 p = xdr_inline_decode(xdr, 4);
5419 sec_flavor->flavor = be32_to_cpup(p);
5421 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5422 status = decode_secinfo_gss(xdr, sec_flavor);
5426 res->flavors->num_flavors++;
5433 print_overflow_msg(__func__, xdr);
5437 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5439 int status = decode_op_hdr(xdr, OP_SECINFO);
5442 return decode_secinfo_common(xdr, res);
5445 #if defined(CONFIG_NFS_V4_1)
5446 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5448 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5451 return decode_secinfo_common(xdr, res);
5454 static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5457 uint32_t bitmap_words;
5460 p = xdr_inline_decode(xdr, 4);
5461 bitmap_words = be32_to_cpup(p++);
5462 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5464 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5465 for (i = 0; i < bitmap_words; i++)
5466 op_map->u.words[i] = be32_to_cpup(p++);
5471 static int decode_exchange_id(struct xdr_stream *xdr,
5472 struct nfs41_exchange_id_res *res)
5478 uint32_t impl_id_count;
5480 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5484 p = xdr_inline_decode(xdr, 8);
5487 xdr_decode_hyper(p, &res->clientid);
5488 p = xdr_inline_decode(xdr, 12);
5491 res->seqid = be32_to_cpup(p++);
5492 res->flags = be32_to_cpup(p++);
5494 res->state_protect.how = be32_to_cpup(p);
5495 switch (res->state_protect.how) {
5499 status = decode_op_map(xdr, &res->state_protect.enforce);
5502 status = decode_op_map(xdr, &res->state_protect.allow);
5511 /* server_owner4.so_minor_id */
5512 p = xdr_inline_decode(xdr, 8);
5515 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5517 /* server_owner4.so_major_id */
5518 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5519 if (unlikely(status))
5521 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5523 memcpy(res->server_owner->major_id, dummy_str, dummy);
5524 res->server_owner->major_id_sz = dummy;
5527 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5528 if (unlikely(status))
5530 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5532 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5533 res->server_scope->server_scope_sz = dummy;
5535 /* Implementation Id */
5536 p = xdr_inline_decode(xdr, 4);
5539 impl_id_count = be32_to_cpup(p++);
5541 if (impl_id_count) {
5543 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5544 if (unlikely(status))
5546 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5548 memcpy(res->impl_id->domain, dummy_str, dummy);
5551 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5552 if (unlikely(status))
5554 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5556 memcpy(res->impl_id->name, dummy_str, dummy);
5559 p = xdr_inline_decode(xdr, 12);
5562 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5563 res->impl_id->date.nseconds = be32_to_cpup(p);
5565 /* if there's more than one entry, ignore the rest */
5569 print_overflow_msg(__func__, xdr);
5573 static int decode_chan_attrs(struct xdr_stream *xdr,
5574 struct nfs4_channel_attrs *attrs)
5579 p = xdr_inline_decode(xdr, 28);
5582 val = be32_to_cpup(p++); /* headerpadsz */
5584 return -EINVAL; /* no support for header padding yet */
5585 attrs->max_rqst_sz = be32_to_cpup(p++);
5586 attrs->max_resp_sz = be32_to_cpup(p++);
5587 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5588 attrs->max_ops = be32_to_cpup(p++);
5589 attrs->max_reqs = be32_to_cpup(p++);
5590 nr_attrs = be32_to_cpup(p);
5591 if (unlikely(nr_attrs > 1)) {
5592 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5593 "count %u\n", __func__, nr_attrs);
5596 if (nr_attrs == 1) {
5597 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5603 print_overflow_msg(__func__, xdr);
5607 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5609 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5612 static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5613 struct nfs41_bind_conn_to_session_res *res)
5618 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5620 status = decode_sessionid(xdr, &res->sessionid);
5621 if (unlikely(status))
5624 /* dir flags, rdma mode bool */
5625 p = xdr_inline_decode(xdr, 8);
5629 res->dir = be32_to_cpup(p++);
5630 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5632 if (be32_to_cpup(p) == 0)
5633 res->use_conn_in_rdma_mode = false;
5635 res->use_conn_in_rdma_mode = true;
5639 print_overflow_msg(__func__, xdr);
5643 static int decode_create_session(struct xdr_stream *xdr,
5644 struct nfs41_create_session_res *res)
5649 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5651 status = decode_sessionid(xdr, &res->sessionid);
5652 if (unlikely(status))
5656 p = xdr_inline_decode(xdr, 8);
5659 res->seqid = be32_to_cpup(p++);
5660 res->flags = be32_to_cpup(p);
5662 /* Channel attributes */
5663 status = decode_chan_attrs(xdr, &res->fc_attrs);
5665 status = decode_chan_attrs(xdr, &res->bc_attrs);
5668 print_overflow_msg(__func__, xdr);
5672 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5674 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5677 static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5679 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5682 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5684 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5686 #endif /* CONFIG_NFS_V4_1 */
5688 static int decode_sequence(struct xdr_stream *xdr,
5689 struct nfs4_sequence_res *res,
5690 struct rpc_rqst *rqstp)
5692 #if defined(CONFIG_NFS_V4_1)
5693 struct nfs4_session *session;
5694 struct nfs4_sessionid id;
5699 if (res->sr_slot == NULL)
5701 if (!res->sr_slot->table->session)
5704 status = decode_op_hdr(xdr, OP_SEQUENCE);
5706 status = decode_sessionid(xdr, &id);
5707 if (unlikely(status))
5711 * If the server returns different values for sessionID, slotID or
5712 * sequence number, the server is looney tunes.
5714 status = -EREMOTEIO;
5715 session = res->sr_slot->table->session;
5717 if (memcmp(id.data, session->sess_id.data,
5718 NFS4_MAX_SESSIONID_LEN)) {
5719 dprintk("%s Invalid session id\n", __func__);
5723 p = xdr_inline_decode(xdr, 20);
5728 dummy = be32_to_cpup(p++);
5729 if (dummy != res->sr_slot->seq_nr) {
5730 dprintk("%s Invalid sequence number\n", __func__);
5734 dummy = be32_to_cpup(p++);
5735 if (dummy != res->sr_slot->slot_nr) {
5736 dprintk("%s Invalid slot id\n", __func__);
5739 /* highest slot id */
5740 res->sr_highest_slotid = be32_to_cpup(p++);
5741 /* target highest slot id */
5742 res->sr_target_highest_slotid = be32_to_cpup(p++);
5744 res->sr_status_flags = be32_to_cpup(p);
5747 res->sr_status = status;
5750 print_overflow_msg(__func__, xdr);
5753 #else /* CONFIG_NFS_V4_1 */
5755 #endif /* CONFIG_NFS_V4_1 */
5758 #if defined(CONFIG_NFS_V4_1)
5759 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5760 struct nfs4_getdeviceinfo_res *res)
5762 struct pnfs_device *pdev = res->pdev;
5767 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5769 if (status == -ETOOSMALL) {
5770 p = xdr_inline_decode(xdr, 4);
5773 pdev->mincount = be32_to_cpup(p);
5774 dprintk("%s: Min count too small. mincnt = %u\n",
5775 __func__, pdev->mincount);
5780 p = xdr_inline_decode(xdr, 8);
5783 type = be32_to_cpup(p++);
5784 if (type != pdev->layout_type) {
5785 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5786 __func__, pdev->layout_type, type);
5790 * Get the length of the opaque device_addr4. xdr_read_pages places
5791 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5792 * and places the remaining xdr data in xdr_buf->tail
5794 pdev->mincount = be32_to_cpup(p);
5795 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5798 /* Parse notification bitmap, verifying that it is zero. */
5799 p = xdr_inline_decode(xdr, 4);
5802 len = be32_to_cpup(p);
5806 p = xdr_inline_decode(xdr, 4 * len);
5810 res->notification = be32_to_cpup(p++);
5811 for (i = 1; i < len; i++) {
5812 if (be32_to_cpup(p++)) {
5813 dprintk("%s: unsupported notification\n",
5821 print_overflow_msg(__func__, xdr);
5825 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5826 struct nfs4_layoutget_res *res)
5833 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5836 p = xdr_inline_decode(xdr, 4);
5839 res->return_on_close = be32_to_cpup(p);
5840 decode_stateid(xdr, &res->stateid);
5841 p = xdr_inline_decode(xdr, 4);
5844 layout_count = be32_to_cpup(p);
5845 if (!layout_count) {
5846 dprintk("%s: server responded with empty layout array\n",
5851 p = xdr_inline_decode(xdr, 28);
5854 p = xdr_decode_hyper(p, &res->range.offset);
5855 p = xdr_decode_hyper(p, &res->range.length);
5856 res->range.iomode = be32_to_cpup(p++);
5857 res->type = be32_to_cpup(p++);
5858 res->layoutp->len = be32_to_cpup(p);
5860 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5862 (unsigned long)res->range.offset,
5863 (unsigned long)res->range.length,
5868 recvd = xdr_read_pages(xdr, res->layoutp->len);
5869 if (res->layoutp->len > recvd) {
5870 dprintk("NFS: server cheating in layoutget reply: "
5871 "layout len %u > recvd %u\n",
5872 res->layoutp->len, recvd);
5876 if (layout_count > 1) {
5877 /* We only handle a length one array at the moment. Any
5878 * further entries are just ignored. Note that this means
5879 * the client may see a response that is less than the
5880 * minimum it requested.
5882 dprintk("%s: server responded with %d layouts, dropping tail\n",
5883 __func__, layout_count);
5888 print_overflow_msg(__func__, xdr);
5892 static int decode_layoutreturn(struct xdr_stream *xdr,
5893 struct nfs4_layoutreturn_res *res)
5898 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5901 p = xdr_inline_decode(xdr, 4);
5904 res->lrs_present = be32_to_cpup(p);
5905 if (res->lrs_present)
5906 status = decode_stateid(xdr, &res->stateid);
5909 print_overflow_msg(__func__, xdr);
5913 static int decode_layoutcommit(struct xdr_stream *xdr,
5914 struct rpc_rqst *req,
5915 struct nfs4_layoutcommit_res *res)
5921 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5922 res->status = status;
5926 p = xdr_inline_decode(xdr, 4);
5929 sizechanged = be32_to_cpup(p);
5932 /* throw away new size */
5933 p = xdr_inline_decode(xdr, 8);
5939 print_overflow_msg(__func__, xdr);
5943 static int decode_test_stateid(struct xdr_stream *xdr,
5944 struct nfs41_test_stateid_res *res)
5950 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5954 p = xdr_inline_decode(xdr, 4);
5957 num_res = be32_to_cpup(p++);
5961 p = xdr_inline_decode(xdr, 4);
5964 res->status = be32_to_cpup(p++);
5968 print_overflow_msg(__func__, xdr);
5973 static int decode_free_stateid(struct xdr_stream *xdr,
5974 struct nfs41_free_stateid_res *res)
5976 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
5979 #endif /* CONFIG_NFS_V4_1 */
5982 * END OF "GENERIC" DECODE ROUTINES.
5986 * Decode OPEN_DOWNGRADE response
5988 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5989 struct xdr_stream *xdr,
5990 struct nfs_closeres *res)
5992 struct compound_hdr hdr;
5995 status = decode_compound_hdr(xdr, &hdr);
5998 status = decode_sequence(xdr, &res->seq_res, rqstp);
6001 status = decode_putfh(xdr);
6004 status = decode_open_downgrade(xdr, res);
6007 decode_getfattr(xdr, res->fattr, res->server);
6013 * Decode ACCESS response
6015 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6016 struct nfs4_accessres *res)
6018 struct compound_hdr hdr;
6021 status = decode_compound_hdr(xdr, &hdr);
6024 status = decode_sequence(xdr, &res->seq_res, rqstp);
6027 status = decode_putfh(xdr);
6030 status = decode_access(xdr, &res->supported, &res->access);
6033 decode_getfattr(xdr, res->fattr, res->server);
6039 * Decode LOOKUP response
6041 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6042 struct nfs4_lookup_res *res)
6044 struct compound_hdr hdr;
6047 status = decode_compound_hdr(xdr, &hdr);
6050 status = decode_sequence(xdr, &res->seq_res, rqstp);
6053 status = decode_putfh(xdr);
6056 status = decode_lookup(xdr);
6059 status = decode_getfh(xdr, res->fh);
6062 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6068 * Decode LOOKUP_ROOT response
6070 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6071 struct xdr_stream *xdr,
6072 struct nfs4_lookup_res *res)
6074 struct compound_hdr hdr;
6077 status = decode_compound_hdr(xdr, &hdr);
6080 status = decode_sequence(xdr, &res->seq_res, rqstp);
6083 status = decode_putrootfh(xdr);
6086 status = decode_getfh(xdr, res->fh);
6088 status = decode_getfattr_label(xdr, res->fattr,
6089 res->label, res->server);
6095 * Decode REMOVE response
6097 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6098 struct nfs_removeres *res)
6100 struct compound_hdr hdr;
6103 status = decode_compound_hdr(xdr, &hdr);
6106 status = decode_sequence(xdr, &res->seq_res, rqstp);
6109 status = decode_putfh(xdr);
6112 status = decode_remove(xdr, &res->cinfo);
6118 * Decode RENAME response
6120 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6121 struct nfs_renameres *res)
6123 struct compound_hdr hdr;
6126 status = decode_compound_hdr(xdr, &hdr);
6129 status = decode_sequence(xdr, &res->seq_res, rqstp);
6132 status = decode_putfh(xdr);
6135 status = decode_savefh(xdr);
6138 status = decode_putfh(xdr);
6141 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
6147 * Decode LINK response
6149 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6150 struct nfs4_link_res *res)
6152 struct compound_hdr hdr;
6155 status = decode_compound_hdr(xdr, &hdr);
6158 status = decode_sequence(xdr, &res->seq_res, rqstp);
6161 status = decode_putfh(xdr);
6164 status = decode_savefh(xdr);
6167 status = decode_putfh(xdr);
6170 status = decode_link(xdr, &res->cinfo);
6174 * Note order: OP_LINK leaves the directory as the current
6177 status = decode_restorefh(xdr);
6180 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6186 * Decode CREATE response
6188 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6189 struct nfs4_create_res *res)
6191 struct compound_hdr hdr;
6194 status = decode_compound_hdr(xdr, &hdr);
6197 status = decode_sequence(xdr, &res->seq_res, rqstp);
6200 status = decode_putfh(xdr);
6203 status = decode_create(xdr, &res->dir_cinfo);
6206 status = decode_getfh(xdr, res->fh);
6209 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6215 * Decode SYMLINK response
6217 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6218 struct nfs4_create_res *res)
6220 return nfs4_xdr_dec_create(rqstp, xdr, res);
6224 * Decode GETATTR response
6226 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6227 struct nfs4_getattr_res *res)
6229 struct compound_hdr hdr;
6232 status = decode_compound_hdr(xdr, &hdr);
6235 status = decode_sequence(xdr, &res->seq_res, rqstp);
6238 status = decode_putfh(xdr);
6241 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6247 * Encode an SETACL request
6249 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6250 struct nfs_setaclargs *args)
6252 struct compound_hdr hdr = {
6253 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6256 encode_compound_hdr(xdr, req, &hdr);
6257 encode_sequence(xdr, &args->seq_args, &hdr);
6258 encode_putfh(xdr, args->fh, &hdr);
6259 encode_setacl(xdr, args, &hdr);
6264 * Decode SETACL response
6267 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6268 struct nfs_setaclres *res)
6270 struct compound_hdr hdr;
6273 status = decode_compound_hdr(xdr, &hdr);
6276 status = decode_sequence(xdr, &res->seq_res, rqstp);
6279 status = decode_putfh(xdr);
6282 status = decode_setattr(xdr);
6288 * Decode GETACL response
6291 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6292 struct nfs_getaclres *res)
6294 struct compound_hdr hdr;
6297 if (res->acl_scratch != NULL) {
6298 void *p = page_address(res->acl_scratch);
6299 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6301 status = decode_compound_hdr(xdr, &hdr);
6304 status = decode_sequence(xdr, &res->seq_res, rqstp);
6307 status = decode_putfh(xdr);
6310 status = decode_getacl(xdr, rqstp, res);
6317 * Decode CLOSE response
6319 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6320 struct nfs_closeres *res)
6322 struct compound_hdr hdr;
6325 status = decode_compound_hdr(xdr, &hdr);
6328 status = decode_sequence(xdr, &res->seq_res, rqstp);
6331 status = decode_putfh(xdr);
6334 status = decode_close(xdr, res);
6338 * Note: Server may do delete on close for this file
6339 * in which case the getattr call will fail with
6340 * an ESTALE error. Shouldn't be a problem,
6341 * though, since fattr->valid will remain unset.
6343 decode_getfattr(xdr, res->fattr, res->server);
6349 * Decode OPEN response
6351 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6352 struct nfs_openres *res)
6354 struct compound_hdr hdr;
6357 status = decode_compound_hdr(xdr, &hdr);
6360 status = decode_sequence(xdr, &res->seq_res, rqstp);
6363 status = decode_putfh(xdr);
6366 status = decode_open(xdr, res);
6369 status = decode_getfh(xdr, &res->fh);
6372 if (res->access_request)
6373 decode_access(xdr, &res->access_supported, &res->access_result);
6374 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
6380 * Decode OPEN_CONFIRM response
6382 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6383 struct xdr_stream *xdr,
6384 struct nfs_open_confirmres *res)
6386 struct compound_hdr hdr;
6389 status = decode_compound_hdr(xdr, &hdr);
6392 status = decode_putfh(xdr);
6395 status = decode_open_confirm(xdr, res);
6401 * Decode OPEN response
6403 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6404 struct xdr_stream *xdr,
6405 struct nfs_openres *res)
6407 struct compound_hdr hdr;
6410 status = decode_compound_hdr(xdr, &hdr);
6413 status = decode_sequence(xdr, &res->seq_res, rqstp);
6416 status = decode_putfh(xdr);
6419 status = decode_open(xdr, res);
6422 if (res->access_request)
6423 decode_access(xdr, &res->access_supported, &res->access_result);
6424 decode_getfattr(xdr, res->f_attr, res->server);
6430 * Decode SETATTR response
6432 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6433 struct xdr_stream *xdr,
6434 struct nfs_setattrres *res)
6436 struct compound_hdr hdr;
6439 status = decode_compound_hdr(xdr, &hdr);
6442 status = decode_sequence(xdr, &res->seq_res, rqstp);
6445 status = decode_putfh(xdr);
6448 status = decode_setattr(xdr);
6451 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6457 * Decode LOCK response
6459 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6460 struct nfs_lock_res *res)
6462 struct compound_hdr hdr;
6465 status = decode_compound_hdr(xdr, &hdr);
6468 status = decode_sequence(xdr, &res->seq_res, rqstp);
6471 status = decode_putfh(xdr);
6474 status = decode_lock(xdr, res);
6480 * Decode LOCKT response
6482 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6483 struct nfs_lockt_res *res)
6485 struct compound_hdr hdr;
6488 status = decode_compound_hdr(xdr, &hdr);
6491 status = decode_sequence(xdr, &res->seq_res, rqstp);
6494 status = decode_putfh(xdr);
6497 status = decode_lockt(xdr, res);
6503 * Decode LOCKU response
6505 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6506 struct nfs_locku_res *res)
6508 struct compound_hdr hdr;
6511 status = decode_compound_hdr(xdr, &hdr);
6514 status = decode_sequence(xdr, &res->seq_res, rqstp);
6517 status = decode_putfh(xdr);
6520 status = decode_locku(xdr, res);
6525 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6526 struct xdr_stream *xdr, void *dummy)
6528 struct compound_hdr hdr;
6531 status = decode_compound_hdr(xdr, &hdr);
6533 status = decode_release_lockowner(xdr);
6538 * Decode READLINK response
6540 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6541 struct xdr_stream *xdr,
6542 struct nfs4_readlink_res *res)
6544 struct compound_hdr hdr;
6547 status = decode_compound_hdr(xdr, &hdr);
6550 status = decode_sequence(xdr, &res->seq_res, rqstp);
6553 status = decode_putfh(xdr);
6556 status = decode_readlink(xdr, rqstp);
6562 * Decode READDIR response
6564 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6565 struct nfs4_readdir_res *res)
6567 struct compound_hdr hdr;
6570 status = decode_compound_hdr(xdr, &hdr);
6573 status = decode_sequence(xdr, &res->seq_res, rqstp);
6576 status = decode_putfh(xdr);
6579 status = decode_readdir(xdr, rqstp, res);
6585 * Decode Read response
6587 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6588 struct nfs_pgio_res *res)
6590 struct compound_hdr hdr;
6593 status = decode_compound_hdr(xdr, &hdr);
6594 res->op_status = hdr.status;
6597 status = decode_sequence(xdr, &res->seq_res, rqstp);
6600 status = decode_putfh(xdr);
6603 status = decode_read(xdr, rqstp, res);
6605 status = res->count;
6611 * Decode WRITE response
6613 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6614 struct nfs_pgio_res *res)
6616 struct compound_hdr hdr;
6619 status = decode_compound_hdr(xdr, &hdr);
6620 res->op_status = hdr.status;
6623 status = decode_sequence(xdr, &res->seq_res, rqstp);
6626 status = decode_putfh(xdr);
6629 status = decode_write(xdr, res);
6633 decode_getfattr(xdr, res->fattr, res->server);
6635 status = res->count;
6641 * Decode COMMIT response
6643 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6644 struct nfs_commitres *res)
6646 struct compound_hdr hdr;
6649 status = decode_compound_hdr(xdr, &hdr);
6650 res->op_status = hdr.status;
6653 status = decode_sequence(xdr, &res->seq_res, rqstp);
6656 status = decode_putfh(xdr);
6659 status = decode_commit(xdr, res);
6665 * Decode FSINFO response
6667 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6668 struct nfs4_fsinfo_res *res)
6670 struct compound_hdr hdr;
6673 status = decode_compound_hdr(xdr, &hdr);
6675 status = decode_sequence(xdr, &res->seq_res, req);
6677 status = decode_putfh(xdr);
6679 status = decode_fsinfo(xdr, res->fsinfo);
6684 * Decode PATHCONF response
6686 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6687 struct nfs4_pathconf_res *res)
6689 struct compound_hdr hdr;
6692 status = decode_compound_hdr(xdr, &hdr);
6694 status = decode_sequence(xdr, &res->seq_res, req);
6696 status = decode_putfh(xdr);
6698 status = decode_pathconf(xdr, res->pathconf);
6703 * Decode STATFS response
6705 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6706 struct nfs4_statfs_res *res)
6708 struct compound_hdr hdr;
6711 status = decode_compound_hdr(xdr, &hdr);
6713 status = decode_sequence(xdr, &res->seq_res, req);
6715 status = decode_putfh(xdr);
6717 status = decode_statfs(xdr, res->fsstat);
6722 * Decode GETATTR_BITMAP response
6724 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6725 struct xdr_stream *xdr,
6726 struct nfs4_server_caps_res *res)
6728 struct compound_hdr hdr;
6731 status = decode_compound_hdr(xdr, &hdr);
6734 status = decode_sequence(xdr, &res->seq_res, req);
6737 status = decode_putfh(xdr);
6740 status = decode_server_caps(xdr, res);
6746 * Decode RENEW response
6748 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6751 struct compound_hdr hdr;
6754 status = decode_compound_hdr(xdr, &hdr);
6756 status = decode_renew(xdr);
6761 * Decode SETCLIENTID response
6763 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6764 struct xdr_stream *xdr,
6765 struct nfs4_setclientid_res *res)
6767 struct compound_hdr hdr;
6770 status = decode_compound_hdr(xdr, &hdr);
6772 status = decode_setclientid(xdr, res);
6777 * Decode SETCLIENTID_CONFIRM response
6779 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6780 struct xdr_stream *xdr)
6782 struct compound_hdr hdr;
6785 status = decode_compound_hdr(xdr, &hdr);
6787 status = decode_setclientid_confirm(xdr);
6792 * Decode DELEGRETURN response
6794 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6795 struct xdr_stream *xdr,
6796 struct nfs4_delegreturnres *res)
6798 struct compound_hdr hdr;
6801 status = decode_compound_hdr(xdr, &hdr);
6804 status = decode_sequence(xdr, &res->seq_res, rqstp);
6807 status = decode_putfh(xdr);
6810 status = decode_getfattr(xdr, res->fattr, res->server);
6813 status = decode_delegreturn(xdr);
6819 * Decode FS_LOCATIONS response
6821 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6822 struct xdr_stream *xdr,
6823 struct nfs4_fs_locations_res *res)
6825 struct compound_hdr hdr;
6828 status = decode_compound_hdr(xdr, &hdr);
6831 status = decode_sequence(xdr, &res->seq_res, req);
6834 status = decode_putfh(xdr);
6837 if (res->migration) {
6838 xdr_enter_page(xdr, PAGE_SIZE);
6839 status = decode_getfattr_generic(xdr,
6840 &res->fs_locations->fattr,
6841 NULL, res->fs_locations,
6842 NULL, res->fs_locations->server);
6846 status = decode_renew(xdr);
6848 status = decode_lookup(xdr);
6851 xdr_enter_page(xdr, PAGE_SIZE);
6852 status = decode_getfattr_generic(xdr,
6853 &res->fs_locations->fattr,
6854 NULL, res->fs_locations,
6855 NULL, res->fs_locations->server);
6862 * Decode SECINFO response
6864 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6865 struct xdr_stream *xdr,
6866 struct nfs4_secinfo_res *res)
6868 struct compound_hdr hdr;
6871 status = decode_compound_hdr(xdr, &hdr);
6874 status = decode_sequence(xdr, &res->seq_res, rqstp);
6877 status = decode_putfh(xdr);
6880 status = decode_secinfo(xdr, res);
6886 * Decode FSID_PRESENT response
6888 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6889 struct xdr_stream *xdr,
6890 struct nfs4_fsid_present_res *res)
6892 struct compound_hdr hdr;
6895 status = decode_compound_hdr(xdr, &hdr);
6898 status = decode_sequence(xdr, &res->seq_res, rqstp);
6901 status = decode_putfh(xdr);
6904 status = decode_getfh(xdr, res->fh);
6908 status = decode_renew(xdr);
6913 #if defined(CONFIG_NFS_V4_1)
6915 * Decode BIND_CONN_TO_SESSION response
6917 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6918 struct xdr_stream *xdr,
6921 struct compound_hdr hdr;
6924 status = decode_compound_hdr(xdr, &hdr);
6926 status = decode_bind_conn_to_session(xdr, res);
6931 * Decode EXCHANGE_ID response
6933 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6934 struct xdr_stream *xdr,
6937 struct compound_hdr hdr;
6940 status = decode_compound_hdr(xdr, &hdr);
6942 status = decode_exchange_id(xdr, res);
6947 * Decode CREATE_SESSION response
6949 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6950 struct xdr_stream *xdr,
6951 struct nfs41_create_session_res *res)
6953 struct compound_hdr hdr;
6956 status = decode_compound_hdr(xdr, &hdr);
6958 status = decode_create_session(xdr, res);
6963 * Decode DESTROY_SESSION response
6965 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6966 struct xdr_stream *xdr,
6969 struct compound_hdr hdr;
6972 status = decode_compound_hdr(xdr, &hdr);
6974 status = decode_destroy_session(xdr, res);
6979 * Decode DESTROY_CLIENTID response
6981 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6982 struct xdr_stream *xdr,
6985 struct compound_hdr hdr;
6988 status = decode_compound_hdr(xdr, &hdr);
6990 status = decode_destroy_clientid(xdr, res);
6995 * Decode SEQUENCE response
6997 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6998 struct xdr_stream *xdr,
6999 struct nfs4_sequence_res *res)
7001 struct compound_hdr hdr;
7004 status = decode_compound_hdr(xdr, &hdr);
7006 status = decode_sequence(xdr, res, rqstp);
7011 * Decode GET_LEASE_TIME response
7013 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7014 struct xdr_stream *xdr,
7015 struct nfs4_get_lease_time_res *res)
7017 struct compound_hdr hdr;
7020 status = decode_compound_hdr(xdr, &hdr);
7022 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
7024 status = decode_putrootfh(xdr);
7026 status = decode_fsinfo(xdr, res->lr_fsinfo);
7031 * Decode RECLAIM_COMPLETE response
7033 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7034 struct xdr_stream *xdr,
7035 struct nfs41_reclaim_complete_res *res)
7037 struct compound_hdr hdr;
7040 status = decode_compound_hdr(xdr, &hdr);
7042 status = decode_sequence(xdr, &res->seq_res, rqstp);
7044 status = decode_reclaim_complete(xdr, NULL);
7049 * Decode GETDEVINFO response
7051 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7052 struct xdr_stream *xdr,
7053 struct nfs4_getdeviceinfo_res *res)
7055 struct compound_hdr hdr;
7058 status = decode_compound_hdr(xdr, &hdr);
7061 status = decode_sequence(xdr, &res->seq_res, rqstp);
7064 status = decode_getdeviceinfo(xdr, res);
7070 * Decode LAYOUTGET response
7072 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7073 struct xdr_stream *xdr,
7074 struct nfs4_layoutget_res *res)
7076 struct compound_hdr hdr;
7079 status = decode_compound_hdr(xdr, &hdr);
7082 status = decode_sequence(xdr, &res->seq_res, rqstp);
7085 status = decode_putfh(xdr);
7088 status = decode_layoutget(xdr, rqstp, res);
7094 * Decode LAYOUTRETURN response
7096 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7097 struct xdr_stream *xdr,
7098 struct nfs4_layoutreturn_res *res)
7100 struct compound_hdr hdr;
7103 status = decode_compound_hdr(xdr, &hdr);
7106 status = decode_sequence(xdr, &res->seq_res, rqstp);
7109 status = decode_putfh(xdr);
7112 status = decode_layoutreturn(xdr, res);
7118 * Decode LAYOUTCOMMIT response
7120 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7121 struct xdr_stream *xdr,
7122 struct nfs4_layoutcommit_res *res)
7124 struct compound_hdr hdr;
7127 status = decode_compound_hdr(xdr, &hdr);
7130 status = decode_sequence(xdr, &res->seq_res, rqstp);
7133 status = decode_putfh(xdr);
7136 status = decode_layoutcommit(xdr, rqstp, res);
7139 decode_getfattr(xdr, res->fattr, res->server);
7145 * Decode SECINFO_NO_NAME response
7147 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7148 struct xdr_stream *xdr,
7149 struct nfs4_secinfo_res *res)
7151 struct compound_hdr hdr;
7154 status = decode_compound_hdr(xdr, &hdr);
7157 status = decode_sequence(xdr, &res->seq_res, rqstp);
7160 status = decode_putrootfh(xdr);
7163 status = decode_secinfo_no_name(xdr, res);
7169 * Decode TEST_STATEID response
7171 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7172 struct xdr_stream *xdr,
7173 struct nfs41_test_stateid_res *res)
7175 struct compound_hdr hdr;
7178 status = decode_compound_hdr(xdr, &hdr);
7181 status = decode_sequence(xdr, &res->seq_res, rqstp);
7184 status = decode_test_stateid(xdr, res);
7190 * Decode FREE_STATEID response
7192 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7193 struct xdr_stream *xdr,
7194 struct nfs41_free_stateid_res *res)
7196 struct compound_hdr hdr;
7199 status = decode_compound_hdr(xdr, &hdr);
7202 status = decode_sequence(xdr, &res->seq_res, rqstp);
7205 status = decode_free_stateid(xdr, res);
7209 #endif /* CONFIG_NFS_V4_1 */
7212 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7213 * the local page cache.
7214 * @xdr: XDR stream where entry resides
7215 * @entry: buffer to fill in with entry data
7216 * @plus: boolean indicating whether this should be a readdirplus entry
7218 * Returns zero if successful, otherwise a negative errno value is
7221 * This function is not invoked during READDIR reply decoding, but
7222 * rather whenever an application invokes the getdents(2) system call
7223 * on a directory already in our cache.
7225 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7229 uint32_t bitmap[3] = {0};
7231 __be32 *p = xdr_inline_decode(xdr, 4);
7234 if (*p == xdr_zero) {
7235 p = xdr_inline_decode(xdr, 4);
7244 p = xdr_inline_decode(xdr, 12);
7247 entry->prev_cookie = entry->cookie;
7248 p = xdr_decode_hyper(p, &entry->cookie);
7249 entry->len = be32_to_cpup(p);
7251 p = xdr_inline_decode(xdr, entry->len);
7254 entry->name = (const char *) p;
7257 * In case the server doesn't return an inode number,
7258 * we fake one here. (We don't use inode number 0,
7259 * since glibc seems to choke on it...)
7262 entry->fattr->valid = 0;
7264 if (decode_attr_bitmap(xdr, bitmap) < 0)
7267 if (decode_attr_length(xdr, &len, &savep) < 0)
7270 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7271 NULL, entry->label, entry->server) < 0)
7273 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7274 entry->ino = entry->fattr->mounted_on_fileid;
7275 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7276 entry->ino = entry->fattr->fileid;
7278 entry->d_type = DT_UNKNOWN;
7279 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7280 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7285 print_overflow_msg(__func__, xdr);
7290 * We need to translate between nfs status return values and
7291 * the local errno values which may not be the same.
7298 { NFS4ERR_PERM, -EPERM },
7299 { NFS4ERR_NOENT, -ENOENT },
7300 { NFS4ERR_IO, -errno_NFSERR_IO},
7301 { NFS4ERR_NXIO, -ENXIO },
7302 { NFS4ERR_ACCESS, -EACCES },
7303 { NFS4ERR_EXIST, -EEXIST },
7304 { NFS4ERR_XDEV, -EXDEV },
7305 { NFS4ERR_NOTDIR, -ENOTDIR },
7306 { NFS4ERR_ISDIR, -EISDIR },
7307 { NFS4ERR_INVAL, -EINVAL },
7308 { NFS4ERR_FBIG, -EFBIG },
7309 { NFS4ERR_NOSPC, -ENOSPC },
7310 { NFS4ERR_ROFS, -EROFS },
7311 { NFS4ERR_MLINK, -EMLINK },
7312 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7313 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7314 { NFS4ERR_DQUOT, -EDQUOT },
7315 { NFS4ERR_STALE, -ESTALE },
7316 { NFS4ERR_BADHANDLE, -EBADHANDLE },
7317 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7318 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7319 { NFS4ERR_TOOSMALL, -ETOOSMALL },
7320 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7321 { NFS4ERR_BADTYPE, -EBADTYPE },
7322 { NFS4ERR_LOCKED, -EAGAIN },
7323 { NFS4ERR_SYMLINK, -ELOOP },
7324 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7325 { NFS4ERR_DEADLOCK, -EDEADLK },
7330 * Convert an NFS error code to a local one.
7331 * This one is used jointly by NFSv2 and NFSv3.
7334 nfs4_stat_to_errno(int stat)
7337 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7338 if (nfs_errtbl[i].stat == stat)
7339 return nfs_errtbl[i].errno;
7341 if (stat <= 10000 || stat > 10100) {
7342 /* The server is looney tunes. */
7345 /* If we cannot translate the error, the recovery routines should
7347 * Note: remaining NFSv4 error codes have values > 10000, so should
7348 * not conflict with native Linux error codes.
7353 #ifdef CONFIG_NFS_V4_2
7354 #include "nfs42xdr.c"
7355 #endif /* CONFIG_NFS_V4_2 */
7357 #define PROC(proc, argtype, restype) \
7358 [NFSPROC4_CLNT_##proc] = { \
7359 .p_proc = NFSPROC4_COMPOUND, \
7360 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7361 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7362 .p_arglen = NFS4_##argtype##_sz, \
7363 .p_replen = NFS4_##restype##_sz, \
7364 .p_statidx = NFSPROC4_CLNT_##proc, \
7368 #define STUB(proc) \
7369 [NFSPROC4_CLNT_##proc] = { \
7373 struct rpc_procinfo nfs4_procedures[] = {
7374 PROC(READ, enc_read, dec_read),
7375 PROC(WRITE, enc_write, dec_write),
7376 PROC(COMMIT, enc_commit, dec_commit),
7377 PROC(OPEN, enc_open, dec_open),
7378 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7379 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7380 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7381 PROC(CLOSE, enc_close, dec_close),
7382 PROC(SETATTR, enc_setattr, dec_setattr),
7383 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7384 PROC(RENEW, enc_renew, dec_renew),
7385 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7386 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7387 PROC(LOCK, enc_lock, dec_lock),
7388 PROC(LOCKT, enc_lockt, dec_lockt),
7389 PROC(LOCKU, enc_locku, dec_locku),
7390 PROC(ACCESS, enc_access, dec_access),
7391 PROC(GETATTR, enc_getattr, dec_getattr),
7392 PROC(LOOKUP, enc_lookup, dec_lookup),
7393 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7394 PROC(REMOVE, enc_remove, dec_remove),
7395 PROC(RENAME, enc_rename, dec_rename),
7396 PROC(LINK, enc_link, dec_link),
7397 PROC(SYMLINK, enc_symlink, dec_symlink),
7398 PROC(CREATE, enc_create, dec_create),
7399 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7400 PROC(STATFS, enc_statfs, dec_statfs),
7401 PROC(READLINK, enc_readlink, dec_readlink),
7402 PROC(READDIR, enc_readdir, dec_readdir),
7403 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7404 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7405 PROC(GETACL, enc_getacl, dec_getacl),
7406 PROC(SETACL, enc_setacl, dec_setacl),
7407 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7408 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7409 PROC(SECINFO, enc_secinfo, dec_secinfo),
7410 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
7411 #if defined(CONFIG_NFS_V4_1)
7412 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7413 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7414 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7415 PROC(SEQUENCE, enc_sequence, dec_sequence),
7416 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7417 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7418 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7419 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7420 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7421 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7422 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7423 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7424 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7425 STUB(GETDEVICELIST),
7426 PROC(BIND_CONN_TO_SESSION,
7427 enc_bind_conn_to_session, dec_bind_conn_to_session),
7428 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
7429 #endif /* CONFIG_NFS_V4_1 */
7430 #ifdef CONFIG_NFS_V4_2
7431 PROC(SEEK, enc_seek, dec_seek),
7432 PROC(ALLOCATE, enc_allocate, dec_allocate),
7433 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
7434 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7435 #endif /* CONFIG_NFS_V4_2 */
7438 const struct rpc_version nfs_version4 = {
7440 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7441 .procs = nfs4_procedures