4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/module.h>
48 #include <linux/utsname.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/sunrpc/msg_prot.h>
51 #include <linux/sunrpc/gss_api.h>
52 #include <linux/nfs.h>
53 #include <linux/nfs4.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/nfs_idmap.h>
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) + \
142 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
144 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
145 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
147 #define decode_setclientid_maxsz \
148 (op_decode_hdr_maxsz + \
150 1024) /* large value for CLID_INUSE */
151 #define encode_setclientid_confirm_maxsz \
152 (op_encode_hdr_maxsz + \
153 3 + (NFS4_VERIFIER_SIZE >> 2))
154 #define decode_setclientid_confirm_maxsz \
155 (op_decode_hdr_maxsz)
156 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
157 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
158 #define encode_share_access_maxsz \
160 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
161 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
162 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
163 #define encode_open_maxsz (op_encode_hdr_maxsz + \
164 2 + encode_share_access_maxsz + 2 + \
165 open_owner_id_maxsz + \
166 encode_opentype_maxsz + \
167 encode_claim_null_maxsz)
168 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
169 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
171 #define decode_change_info_maxsz (5)
172 #define decode_open_maxsz (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz + \
174 decode_change_info_maxsz + 1 + \
175 nfs4_fattr_bitmap_maxsz + \
176 decode_delegation_maxsz)
177 #define encode_open_confirm_maxsz \
178 (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + 1)
180 #define decode_open_confirm_maxsz \
181 (op_decode_hdr_maxsz + \
182 decode_stateid_maxsz)
183 #define encode_open_downgrade_maxsz \
184 (op_encode_hdr_maxsz + \
185 encode_stateid_maxsz + 1 + \
186 encode_share_access_maxsz)
187 #define decode_open_downgrade_maxsz \
188 (op_decode_hdr_maxsz + \
189 decode_stateid_maxsz)
190 #define encode_close_maxsz (op_encode_hdr_maxsz + \
191 1 + encode_stateid_maxsz)
192 #define decode_close_maxsz (op_decode_hdr_maxsz + \
193 decode_stateid_maxsz)
194 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + \
197 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
198 nfs4_fattr_bitmap_maxsz)
199 #define encode_read_maxsz (op_encode_hdr_maxsz + \
200 encode_stateid_maxsz + 3)
201 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
202 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
203 2 + encode_verifier_maxsz + 5 + \
205 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
206 decode_verifier_maxsz)
207 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
208 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
209 #define encode_write_maxsz (op_encode_hdr_maxsz + \
210 encode_stateid_maxsz + 4)
211 #define decode_write_maxsz (op_decode_hdr_maxsz + \
212 2 + decode_verifier_maxsz)
213 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
214 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
215 decode_verifier_maxsz)
216 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
218 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
219 decode_change_info_maxsz)
220 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
222 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
223 decode_change_info_maxsz + \
224 decode_change_info_maxsz)
225 #define encode_link_maxsz (op_encode_hdr_maxsz + \
227 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
228 #define encode_lockowner_maxsz (7)
229 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
231 1 + encode_stateid_maxsz + 1 + \
232 encode_lockowner_maxsz)
233 #define decode_lock_denied_maxsz \
234 (8 + decode_lockowner_maxsz)
235 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
236 decode_lock_denied_maxsz)
237 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
238 encode_lockowner_maxsz)
239 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
240 decode_lock_denied_maxsz)
241 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
242 encode_stateid_maxsz + \
244 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
245 decode_stateid_maxsz)
246 #define encode_release_lockowner_maxsz \
247 (op_encode_hdr_maxsz + \
248 encode_lockowner_maxsz)
249 #define decode_release_lockowner_maxsz \
250 (op_decode_hdr_maxsz)
251 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
252 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
253 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
254 1 + nfs4_name_maxsz + \
257 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
258 #define encode_create_maxsz (op_encode_hdr_maxsz + \
259 1 + 2 + nfs4_name_maxsz + \
261 #define decode_create_maxsz (op_decode_hdr_maxsz + \
262 decode_change_info_maxsz + \
263 nfs4_fattr_bitmap_maxsz)
264 #define encode_statfs_maxsz (encode_getattr_maxsz)
265 #define decode_statfs_maxsz (decode_getattr_maxsz)
266 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
267 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
268 #define encode_getacl_maxsz (encode_getattr_maxsz)
269 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
270 nfs4_fattr_bitmap_maxsz + 1)
271 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
272 encode_stateid_maxsz + 3)
273 #define decode_setacl_maxsz (decode_setattr_maxsz)
274 #define encode_fs_locations_maxsz \
275 (encode_getattr_maxsz)
276 #define decode_fs_locations_maxsz \
278 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
279 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
281 #if defined(CONFIG_NFS_V4_1)
282 #define NFS4_MAX_MACHINE_NAME_LEN (64)
283 #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
284 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
286 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
287 encode_verifier_maxsz + \
288 1 /* co_ownerid.len */ + \
289 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
292 /* max is SP4_MACH_CRED (for now) */ + \
293 1 + NFS4_OP_MAP_NUM_WORDS + \
294 1 + NFS4_OP_MAP_NUM_WORDS + \
295 1 /* implementation id array of size 1 */ + \
296 1 /* nii_domain */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
299 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
301 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
302 2 /* eir_clientid */ + \
303 1 /* eir_sequenceid */ + \
304 1 /* eir_flags */ + \
306 /* max is SP4_MACH_CRED (for now) */ + \
307 1 + NFS4_OP_MAP_NUM_WORDS + \
308 1 + NFS4_OP_MAP_NUM_WORDS + \
309 2 /* eir_server_owner.so_minor_id */ + \
310 /* eir_server_owner.so_major_id<> */ \
311 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
312 /* eir_server_scope<> */ \
313 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
314 1 /* eir_server_impl_id array length */ + \
315 1 /* nii_domain */ + \
316 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
320 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
321 #define decode_channel_attrs_maxsz (6 + \
322 1 /* ca_rdma_ird.len */ + \
324 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
325 2 /* csa_clientid */ + \
326 1 /* csa_sequence */ + \
327 1 /* csa_flags */ + \
328 encode_channel_attrs_maxsz + \
329 encode_channel_attrs_maxsz + \
330 1 /* csa_cb_program */ + \
331 1 /* csa_sec_parms.len (1) */ + \
332 1 /* cb_secflavor (AUTH_SYS) */ + \
334 1 /* machinename.len */ + \
335 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
338 1 /* gids.len (0) */)
339 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
340 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
341 1 /* csr_sequence */ + \
342 1 /* csr_flags */ + \
343 decode_channel_attrs_maxsz + \
344 decode_channel_attrs_maxsz)
345 #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
347 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
348 1 /* bctsa_dir */ + \
349 1 /* bctsa_use_conn_in_rdma_mode */)
350 #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
352 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
353 1 /* bctsr_dir */ + \
354 1 /* bctsr_use_conn_in_rdma_mode */)
355 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
356 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
357 #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
358 #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
359 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
360 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
361 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
362 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
363 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
364 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
365 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
366 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
367 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
368 1 /* layout type */ + \
369 1 /* opaque devaddr4 length */ + \
370 /* devaddr4 payload is read into page */ \
371 1 /* notification bitmap length */ + \
372 1 /* notification bitmap */)
373 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
374 encode_stateid_maxsz)
375 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
376 decode_stateid_maxsz + \
377 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
378 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
382 encode_stateid_maxsz + \
383 1 /* new offset (true) */ + \
384 2 /* last byte written */ + \
385 1 /* nt_timechanged (false) */ + \
386 1 /* layoutupdate4 layout type */ + \
387 1 /* layoutupdate4 opaqueue len */)
388 /* the actual content of layoutupdate4 should
389 be allocated by drivers and spliced in
390 using xdr_write_pages */
391 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
392 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
393 encode_stateid_maxsz + \
394 1 /* FIXME: opaque lrf_body always empty at the moment */)
395 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
396 1 + decode_stateid_maxsz)
397 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
398 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
399 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
400 XDR_QUADLEN(NFS4_STATEID_SIZE))
401 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
402 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
403 XDR_QUADLEN(NFS4_STATEID_SIZE))
404 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
405 #else /* CONFIG_NFS_V4_1 */
406 #define encode_sequence_maxsz 0
407 #define decode_sequence_maxsz 0
408 #endif /* CONFIG_NFS_V4_1 */
410 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
411 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
412 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
413 encode_sequence_maxsz + \
414 encode_putfh_maxsz + \
416 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
417 decode_sequence_maxsz + \
418 decode_putfh_maxsz + \
420 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
421 encode_sequence_maxsz + \
422 encode_putfh_maxsz + \
423 encode_readlink_maxsz)
424 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
425 decode_sequence_maxsz + \
426 decode_putfh_maxsz + \
427 decode_readlink_maxsz)
428 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
429 encode_sequence_maxsz + \
430 encode_putfh_maxsz + \
431 encode_readdir_maxsz)
432 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
433 decode_sequence_maxsz + \
434 decode_putfh_maxsz + \
435 decode_readdir_maxsz)
436 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
437 encode_sequence_maxsz + \
438 encode_putfh_maxsz + \
439 encode_write_maxsz + \
440 encode_getattr_maxsz)
441 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
442 decode_sequence_maxsz + \
443 decode_putfh_maxsz + \
444 decode_write_maxsz + \
445 decode_getattr_maxsz)
446 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
447 encode_sequence_maxsz + \
448 encode_putfh_maxsz + \
450 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
451 decode_sequence_maxsz + \
452 decode_putfh_maxsz + \
454 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
455 encode_sequence_maxsz + \
456 encode_putfh_maxsz + \
457 encode_open_maxsz + \
458 encode_access_maxsz + \
459 encode_getfh_maxsz + \
460 encode_getattr_maxsz)
461 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
462 decode_sequence_maxsz + \
463 decode_putfh_maxsz + \
464 decode_open_maxsz + \
465 decode_access_maxsz + \
466 decode_getfh_maxsz + \
467 decode_getattr_maxsz)
468 #define NFS4_enc_open_confirm_sz \
469 (compound_encode_hdr_maxsz + \
470 encode_putfh_maxsz + \
471 encode_open_confirm_maxsz)
472 #define NFS4_dec_open_confirm_sz \
473 (compound_decode_hdr_maxsz + \
474 decode_putfh_maxsz + \
475 decode_open_confirm_maxsz)
476 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
477 encode_sequence_maxsz + \
478 encode_putfh_maxsz + \
479 encode_open_maxsz + \
480 encode_access_maxsz + \
481 encode_getattr_maxsz)
482 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
483 decode_sequence_maxsz + \
484 decode_putfh_maxsz + \
485 decode_open_maxsz + \
486 decode_access_maxsz + \
487 decode_getattr_maxsz)
488 #define NFS4_enc_open_downgrade_sz \
489 (compound_encode_hdr_maxsz + \
490 encode_sequence_maxsz + \
491 encode_putfh_maxsz + \
492 encode_open_downgrade_maxsz + \
493 encode_getattr_maxsz)
494 #define NFS4_dec_open_downgrade_sz \
495 (compound_decode_hdr_maxsz + \
496 decode_sequence_maxsz + \
497 decode_putfh_maxsz + \
498 decode_open_downgrade_maxsz + \
499 decode_getattr_maxsz)
500 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
501 encode_sequence_maxsz + \
502 encode_putfh_maxsz + \
503 encode_close_maxsz + \
504 encode_getattr_maxsz)
505 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
506 decode_sequence_maxsz + \
507 decode_putfh_maxsz + \
508 decode_close_maxsz + \
509 decode_getattr_maxsz)
510 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
511 encode_sequence_maxsz + \
512 encode_putfh_maxsz + \
513 encode_setattr_maxsz + \
514 encode_getattr_maxsz)
515 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
516 decode_sequence_maxsz + \
517 decode_putfh_maxsz + \
518 decode_setattr_maxsz + \
519 decode_getattr_maxsz)
520 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
521 encode_sequence_maxsz + \
522 encode_putfh_maxsz + \
524 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
525 decode_sequence_maxsz + \
526 decode_putfh_maxsz + \
528 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
530 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
532 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
533 encode_setclientid_maxsz)
534 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
535 decode_setclientid_maxsz)
536 #define NFS4_enc_setclientid_confirm_sz \
537 (compound_encode_hdr_maxsz + \
538 encode_setclientid_confirm_maxsz)
539 #define NFS4_dec_setclientid_confirm_sz \
540 (compound_decode_hdr_maxsz + \
541 decode_setclientid_confirm_maxsz)
542 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
543 encode_sequence_maxsz + \
544 encode_putfh_maxsz + \
546 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
547 decode_sequence_maxsz + \
548 decode_putfh_maxsz + \
550 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
551 encode_sequence_maxsz + \
552 encode_putfh_maxsz + \
554 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
555 decode_sequence_maxsz + \
556 decode_putfh_maxsz + \
558 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
559 encode_sequence_maxsz + \
560 encode_putfh_maxsz + \
562 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
563 decode_sequence_maxsz + \
564 decode_putfh_maxsz + \
566 #define NFS4_enc_release_lockowner_sz \
567 (compound_encode_hdr_maxsz + \
568 encode_lockowner_maxsz)
569 #define NFS4_dec_release_lockowner_sz \
570 (compound_decode_hdr_maxsz + \
571 decode_lockowner_maxsz)
572 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
573 encode_sequence_maxsz + \
574 encode_putfh_maxsz + \
575 encode_access_maxsz + \
576 encode_getattr_maxsz)
577 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
578 decode_sequence_maxsz + \
579 decode_putfh_maxsz + \
580 decode_access_maxsz + \
581 decode_getattr_maxsz)
582 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
583 encode_sequence_maxsz + \
584 encode_putfh_maxsz + \
585 encode_getattr_maxsz + \
587 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
588 decode_sequence_maxsz + \
589 decode_putfh_maxsz + \
590 decode_getattr_maxsz + \
592 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
593 encode_sequence_maxsz + \
594 encode_putfh_maxsz + \
595 encode_lookup_maxsz + \
596 encode_getattr_maxsz + \
598 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
599 decode_sequence_maxsz + \
600 decode_putfh_maxsz + \
601 decode_lookup_maxsz + \
602 decode_getattr_maxsz + \
604 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
605 encode_sequence_maxsz + \
606 encode_putrootfh_maxsz + \
607 encode_getattr_maxsz + \
609 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
610 decode_sequence_maxsz + \
611 decode_putrootfh_maxsz + \
612 decode_getattr_maxsz + \
614 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
615 encode_sequence_maxsz + \
616 encode_putfh_maxsz + \
618 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
619 decode_sequence_maxsz + \
620 decode_putfh_maxsz + \
622 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
623 encode_sequence_maxsz + \
624 encode_putfh_maxsz + \
625 encode_savefh_maxsz + \
626 encode_putfh_maxsz + \
628 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
629 decode_sequence_maxsz + \
630 decode_putfh_maxsz + \
631 decode_savefh_maxsz + \
632 decode_putfh_maxsz + \
634 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
635 encode_sequence_maxsz + \
636 encode_putfh_maxsz + \
637 encode_savefh_maxsz + \
638 encode_putfh_maxsz + \
639 encode_link_maxsz + \
640 encode_restorefh_maxsz + \
641 encode_getattr_maxsz)
642 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
643 decode_sequence_maxsz + \
644 decode_putfh_maxsz + \
645 decode_savefh_maxsz + \
646 decode_putfh_maxsz + \
647 decode_link_maxsz + \
648 decode_restorefh_maxsz + \
649 decode_getattr_maxsz)
650 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
651 encode_sequence_maxsz + \
652 encode_putfh_maxsz + \
653 encode_symlink_maxsz + \
654 encode_getattr_maxsz + \
656 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
657 decode_sequence_maxsz + \
658 decode_putfh_maxsz + \
659 decode_symlink_maxsz + \
660 decode_getattr_maxsz + \
662 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
663 encode_sequence_maxsz + \
664 encode_putfh_maxsz + \
665 encode_create_maxsz + \
666 encode_getfh_maxsz + \
667 encode_getattr_maxsz)
668 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
669 decode_sequence_maxsz + \
670 decode_putfh_maxsz + \
671 decode_create_maxsz + \
672 decode_getfh_maxsz + \
673 decode_getattr_maxsz)
674 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
675 encode_sequence_maxsz + \
676 encode_putfh_maxsz + \
677 encode_getattr_maxsz)
678 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
679 decode_sequence_maxsz + \
680 decode_putfh_maxsz + \
681 decode_getattr_maxsz)
682 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
683 encode_sequence_maxsz + \
684 encode_putfh_maxsz + \
686 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
687 decode_sequence_maxsz + \
688 decode_putfh_maxsz + \
690 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
691 encode_sequence_maxsz + \
692 encode_putfh_maxsz + \
693 encode_getattr_maxsz)
694 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
695 decode_sequence_maxsz + \
696 decode_putfh_maxsz + \
697 decode_getattr_maxsz)
698 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
699 encode_sequence_maxsz + \
700 encode_putfh_maxsz + \
701 encode_delegreturn_maxsz + \
702 encode_getattr_maxsz)
703 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
704 decode_sequence_maxsz + \
705 decode_delegreturn_maxsz + \
706 decode_getattr_maxsz)
707 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
708 encode_sequence_maxsz + \
709 encode_putfh_maxsz + \
711 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
712 decode_sequence_maxsz + \
713 decode_putfh_maxsz + \
715 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
716 encode_sequence_maxsz + \
717 encode_putfh_maxsz + \
719 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
720 decode_sequence_maxsz + \
721 decode_putfh_maxsz + \
723 #define NFS4_enc_fs_locations_sz \
724 (compound_encode_hdr_maxsz + \
725 encode_sequence_maxsz + \
726 encode_putfh_maxsz + \
727 encode_lookup_maxsz + \
728 encode_fs_locations_maxsz + \
730 #define NFS4_dec_fs_locations_sz \
731 (compound_decode_hdr_maxsz + \
732 decode_sequence_maxsz + \
733 decode_putfh_maxsz + \
734 decode_lookup_maxsz + \
735 decode_fs_locations_maxsz + \
737 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
738 encode_sequence_maxsz + \
739 encode_putfh_maxsz + \
740 encode_secinfo_maxsz)
741 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
742 decode_sequence_maxsz + \
743 decode_putfh_maxsz + \
744 decode_secinfo_maxsz)
745 #define NFS4_enc_fsid_present_sz \
746 (compound_encode_hdr_maxsz + \
747 encode_sequence_maxsz + \
748 encode_putfh_maxsz + \
749 encode_getfh_maxsz + \
751 #define NFS4_dec_fsid_present_sz \
752 (compound_decode_hdr_maxsz + \
753 decode_sequence_maxsz + \
754 decode_putfh_maxsz + \
755 decode_getfh_maxsz + \
757 #if defined(CONFIG_NFS_V4_1)
758 #define NFS4_enc_bind_conn_to_session_sz \
759 (compound_encode_hdr_maxsz + \
760 encode_bind_conn_to_session_maxsz)
761 #define NFS4_dec_bind_conn_to_session_sz \
762 (compound_decode_hdr_maxsz + \
763 decode_bind_conn_to_session_maxsz)
764 #define NFS4_enc_exchange_id_sz \
765 (compound_encode_hdr_maxsz + \
766 encode_exchange_id_maxsz)
767 #define NFS4_dec_exchange_id_sz \
768 (compound_decode_hdr_maxsz + \
769 decode_exchange_id_maxsz)
770 #define NFS4_enc_create_session_sz \
771 (compound_encode_hdr_maxsz + \
772 encode_create_session_maxsz)
773 #define NFS4_dec_create_session_sz \
774 (compound_decode_hdr_maxsz + \
775 decode_create_session_maxsz)
776 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
777 encode_destroy_session_maxsz)
778 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
779 decode_destroy_session_maxsz)
780 #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
781 encode_destroy_clientid_maxsz)
782 #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
783 decode_destroy_clientid_maxsz)
784 #define NFS4_enc_sequence_sz \
785 (compound_decode_hdr_maxsz + \
786 encode_sequence_maxsz)
787 #define NFS4_dec_sequence_sz \
788 (compound_decode_hdr_maxsz + \
789 decode_sequence_maxsz)
790 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
791 encode_sequence_maxsz + \
792 encode_putrootfh_maxsz + \
794 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_putrootfh_maxsz + \
798 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
799 encode_sequence_maxsz + \
800 encode_reclaim_complete_maxsz)
801 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_reclaim_complete_maxsz)
804 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
805 encode_sequence_maxsz +\
806 encode_getdeviceinfo_maxsz)
807 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
808 decode_sequence_maxsz + \
809 decode_getdeviceinfo_maxsz)
810 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
811 encode_sequence_maxsz + \
812 encode_putfh_maxsz + \
813 encode_layoutget_maxsz)
814 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_putfh_maxsz + \
817 decode_layoutget_maxsz)
818 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
819 encode_sequence_maxsz +\
820 encode_putfh_maxsz + \
821 encode_layoutcommit_maxsz + \
822 encode_getattr_maxsz)
823 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_putfh_maxsz + \
826 decode_layoutcommit_maxsz + \
827 decode_getattr_maxsz)
828 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
829 encode_sequence_maxsz + \
830 encode_putfh_maxsz + \
831 encode_layoutreturn_maxsz)
832 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
833 decode_sequence_maxsz + \
834 decode_putfh_maxsz + \
835 decode_layoutreturn_maxsz)
836 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
837 encode_sequence_maxsz + \
838 encode_putrootfh_maxsz +\
839 encode_secinfo_no_name_maxsz)
840 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
841 decode_sequence_maxsz + \
842 decode_putrootfh_maxsz + \
843 decode_secinfo_no_name_maxsz)
844 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
845 encode_sequence_maxsz + \
846 encode_test_stateid_maxsz)
847 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_test_stateid_maxsz)
850 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
851 encode_sequence_maxsz + \
852 encode_free_stateid_maxsz)
853 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
854 decode_sequence_maxsz + \
855 decode_free_stateid_maxsz)
857 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
858 compound_encode_hdr_maxsz +
859 encode_sequence_maxsz +
861 encode_getattr_maxsz) *
864 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
865 compound_decode_hdr_maxsz +
866 decode_sequence_maxsz +
867 decode_putfh_maxsz) *
870 const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
871 compound_decode_hdr_maxsz +
872 decode_sequence_maxsz) *
874 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
875 #endif /* CONFIG_NFS_V4_1 */
877 static const umode_t nfs_type2fmt[] = {
884 [NF4SOCK] = S_IFSOCK,
890 struct compound_hdr {
896 uint32_t replen; /* expected reply words */
900 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
902 __be32 *p = xdr_reserve_space(xdr, nbytes);
907 static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
911 p = xdr_reserve_space(xdr, len);
912 xdr_encode_opaque_fixed(p, buf, len);
915 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
919 p = reserve_space(xdr, 4 + len);
920 xdr_encode_opaque(p, str, len);
923 static void encode_uint32(struct xdr_stream *xdr, u32 n)
927 p = reserve_space(xdr, 4);
931 static void encode_uint64(struct xdr_stream *xdr, u64 n)
935 p = reserve_space(xdr, 8);
936 xdr_encode_hyper(p, n);
939 static void encode_nfs4_seqid(struct xdr_stream *xdr,
940 const struct nfs_seqid *seqid)
942 encode_uint32(xdr, seqid->sequence->counter);
945 static void encode_compound_hdr(struct xdr_stream *xdr,
946 struct rpc_rqst *req,
947 struct compound_hdr *hdr)
950 struct rpc_auth *auth = req->rq_cred->cr_auth;
952 /* initialize running count of expected bytes in reply.
953 * NOTE: the replied tag SHOULD be the same is the one sent,
954 * but this is not required as a MUST for the server to do so. */
955 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
957 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
958 encode_string(xdr, hdr->taglen, hdr->tag);
959 p = reserve_space(xdr, 8);
960 *p++ = cpu_to_be32(hdr->minorversion);
962 *p = cpu_to_be32(hdr->nops);
965 static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
967 struct compound_hdr *hdr)
969 encode_uint32(xdr, op);
971 hdr->replen += replen;
974 static void encode_nops(struct compound_hdr *hdr)
976 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
977 *hdr->nops_p = htonl(hdr->nops);
980 static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
982 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
985 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
987 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
990 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
991 const struct nfs4_label *label,
992 const struct nfs_server *server)
994 char owner_name[IDMAP_NAMESZ];
995 char owner_group[IDMAP_NAMESZ];
996 int owner_namelen = 0;
997 int owner_grouplen = 0;
1002 uint32_t bmval[3] = { 0 };
1005 * We reserve enough space to write the entire attribute buffer at once.
1006 * In the worst-case, this would be
1007 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1008 * = 40 bytes, plus any contribution from variable-length fields
1009 * such as owner/group.
1011 if (iap->ia_valid & ATTR_SIZE) {
1012 bmval[0] |= FATTR4_WORD0_SIZE;
1015 if (iap->ia_valid & ATTR_MODE) {
1016 bmval[1] |= FATTR4_WORD1_MODE;
1019 if (iap->ia_valid & ATTR_UID) {
1020 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1021 if (owner_namelen < 0) {
1022 dprintk("nfs: couldn't resolve uid %d to string\n",
1023 from_kuid(&init_user_ns, iap->ia_uid));
1025 strcpy(owner_name, "nobody");
1026 owner_namelen = sizeof("nobody") - 1;
1029 bmval[1] |= FATTR4_WORD1_OWNER;
1030 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1032 if (iap->ia_valid & ATTR_GID) {
1033 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1034 if (owner_grouplen < 0) {
1035 dprintk("nfs: couldn't resolve gid %d to string\n",
1036 from_kgid(&init_user_ns, iap->ia_gid));
1037 strcpy(owner_group, "nobody");
1038 owner_grouplen = sizeof("nobody") - 1;
1041 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1042 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1044 if (iap->ia_valid & ATTR_ATIME_SET) {
1045 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1047 } else if (iap->ia_valid & ATTR_ATIME) {
1048 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1051 if (iap->ia_valid & ATTR_MTIME_SET) {
1052 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1054 } else if (iap->ia_valid & ATTR_MTIME) {
1055 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1059 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1060 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1065 else if (bmval[1] != 0)
1070 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1072 *p++ = cpu_to_be32(bmval_len);
1073 for (i = 0; i < bmval_len; i++)
1074 *p++ = cpu_to_be32(bmval[i]);
1075 *p++ = cpu_to_be32(len);
1077 if (bmval[0] & FATTR4_WORD0_SIZE)
1078 p = xdr_encode_hyper(p, iap->ia_size);
1079 if (bmval[1] & FATTR4_WORD1_MODE)
1080 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1081 if (bmval[1] & FATTR4_WORD1_OWNER)
1082 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1083 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1084 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1085 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1086 if (iap->ia_valid & ATTR_ATIME_SET) {
1087 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1088 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1089 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1091 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1093 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1094 if (iap->ia_valid & ATTR_MTIME_SET) {
1095 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1096 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1097 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1099 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1101 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1102 *p++ = cpu_to_be32(label->lfs);
1103 *p++ = cpu_to_be32(label->pi);
1104 *p++ = cpu_to_be32(label->len);
1105 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1111 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1113 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1114 encode_uint32(xdr, access);
1117 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1119 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1120 encode_nfs4_seqid(xdr, arg->seqid);
1121 encode_nfs4_stateid(xdr, arg->stateid);
1124 static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1128 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1129 p = reserve_space(xdr, 12);
1130 p = xdr_encode_hyper(p, args->offset);
1131 *p = cpu_to_be32(args->count);
1134 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1138 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1139 encode_uint32(xdr, create->ftype);
1141 switch (create->ftype) {
1143 p = reserve_space(xdr, 4);
1144 *p = cpu_to_be32(create->u.symlink.len);
1145 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1148 case NF4BLK: case NF4CHR:
1149 p = reserve_space(xdr, 8);
1150 *p++ = cpu_to_be32(create->u.device.specdata1);
1151 *p = cpu_to_be32(create->u.device.specdata2);
1158 encode_string(xdr, create->name->len, create->name->name);
1159 encode_attrs(xdr, create->attrs, create->label, create->server);
1162 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1166 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1167 p = reserve_space(xdr, 8);
1168 *p++ = cpu_to_be32(1);
1169 *p = cpu_to_be32(bitmap);
1172 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1176 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1177 p = reserve_space(xdr, 12);
1178 *p++ = cpu_to_be32(2);
1179 *p++ = cpu_to_be32(bm0);
1180 *p = cpu_to_be32(bm1);
1184 encode_getattr_three(struct xdr_stream *xdr,
1185 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1186 struct compound_hdr *hdr)
1190 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1192 p = reserve_space(xdr, 16);
1193 *p++ = cpu_to_be32(3);
1194 *p++ = cpu_to_be32(bm0);
1195 *p++ = cpu_to_be32(bm1);
1196 *p = cpu_to_be32(bm2);
1198 p = reserve_space(xdr, 12);
1199 *p++ = cpu_to_be32(2);
1200 *p++ = cpu_to_be32(bm0);
1201 *p = cpu_to_be32(bm1);
1203 p = reserve_space(xdr, 8);
1204 *p++ = cpu_to_be32(1);
1205 *p = cpu_to_be32(bm0);
1209 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1211 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1212 bitmask[1] & nfs4_fattr_bitmap[1],
1213 bitmask[2] & nfs4_fattr_bitmap[2],
1217 static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1218 const u32 *open_bitmap,
1219 struct compound_hdr *hdr)
1221 encode_getattr_three(xdr,
1222 bitmask[0] & open_bitmap[0],
1223 bitmask[1] & open_bitmap[1],
1224 bitmask[2] & open_bitmap[2],
1228 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1230 encode_getattr_three(xdr,
1231 bitmask[0] & nfs4_fsinfo_bitmap[0],
1232 bitmask[1] & nfs4_fsinfo_bitmap[1],
1233 bitmask[2] & nfs4_fsinfo_bitmap[2],
1237 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1239 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1240 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1243 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1245 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1248 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1250 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1251 encode_string(xdr, name->len, name->name);
1254 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1256 if (fl->fl_type == F_RDLCK)
1257 return block ? NFS4_READW_LT : NFS4_READ_LT;
1258 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1261 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1263 if (fl->fl_end == OFFSET_MAX)
1264 return ~(uint64_t)0;
1265 return fl->fl_end - fl->fl_start + 1;
1268 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1272 p = reserve_space(xdr, 32);
1273 p = xdr_encode_hyper(p, lowner->clientid);
1274 *p++ = cpu_to_be32(20);
1275 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1276 *p++ = cpu_to_be32(lowner->s_dev);
1277 xdr_encode_hyper(p, lowner->id);
1281 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1282 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1284 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1288 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1289 p = reserve_space(xdr, 28);
1290 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1291 *p++ = cpu_to_be32(args->reclaim);
1292 p = xdr_encode_hyper(p, args->fl->fl_start);
1293 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1294 *p = cpu_to_be32(args->new_lock_owner);
1295 if (args->new_lock_owner){
1296 encode_nfs4_seqid(xdr, args->open_seqid);
1297 encode_nfs4_stateid(xdr, args->open_stateid);
1298 encode_nfs4_seqid(xdr, args->lock_seqid);
1299 encode_lockowner(xdr, &args->lock_owner);
1302 encode_nfs4_stateid(xdr, args->lock_stateid);
1303 encode_nfs4_seqid(xdr, args->lock_seqid);
1307 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1311 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1312 p = reserve_space(xdr, 20);
1313 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1314 p = xdr_encode_hyper(p, args->fl->fl_start);
1315 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1316 encode_lockowner(xdr, &args->lock_owner);
1319 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1323 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1324 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1325 encode_nfs4_seqid(xdr, args->seqid);
1326 encode_nfs4_stateid(xdr, args->stateid);
1327 p = reserve_space(xdr, 16);
1328 p = xdr_encode_hyper(p, args->fl->fl_start);
1329 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1332 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1334 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1335 encode_lockowner(xdr, lowner);
1338 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1340 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1341 encode_string(xdr, name->len, name->name);
1344 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1348 p = reserve_space(xdr, 8);
1349 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1351 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1354 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1356 case FMODE_READ|FMODE_WRITE:
1357 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1360 *p++ = cpu_to_be32(0);
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->fmode);
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->fmode);
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, setclientid->sc_name_len, setclientid->sc_name);
1673 p = reserve_space(xdr, 4);
1674 *p = cpu_to_be32(setclientid->sc_prog);
1675 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1676 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1677 p = reserve_space(xdr, 4);
1678 *p = cpu_to_be32(setclientid->sc_cb_ident);
1681 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1683 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1684 decode_setclientid_confirm_maxsz, hdr);
1685 encode_uint64(xdr, arg->clientid);
1686 encode_nfs4_verifier(xdr, &arg->confirm);
1689 static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1690 struct compound_hdr *hdr)
1694 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1695 encode_nfs4_stateid(xdr, &args->stateid);
1697 p = reserve_space(xdr, 16);
1698 p = xdr_encode_hyper(p, args->offset);
1699 *p++ = cpu_to_be32(args->stable);
1700 *p = cpu_to_be32(args->count);
1702 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1705 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1707 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1708 encode_nfs4_stateid(xdr, stateid);
1711 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1713 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1714 encode_string(xdr, name->len, name->name);
1717 #if defined(CONFIG_NFS_V4_1)
1718 /* NFSv4.1 operations */
1719 static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1720 struct nfs4_session *session,
1721 struct compound_hdr *hdr)
1725 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1726 decode_bind_conn_to_session_maxsz, hdr);
1727 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1728 p = xdr_reserve_space(xdr, 8);
1729 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1730 *p = 0; /* use_conn_in_rdma_mode = False */
1733 static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1736 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1737 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1738 encode_uint32(xdr, op_map->u.words[i]);
1741 static void encode_exchange_id(struct xdr_stream *xdr,
1742 struct nfs41_exchange_id_args *args,
1743 struct compound_hdr *hdr)
1746 char impl_name[IMPL_NAME_LIMIT];
1749 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1750 encode_nfs4_verifier(xdr, args->verifier);
1752 encode_string(xdr, args->id_len, args->id);
1754 encode_uint32(xdr, args->flags);
1755 encode_uint32(xdr, args->state_protect.how);
1757 switch (args->state_protect.how) {
1761 encode_op_map(xdr, &args->state_protect.enforce);
1762 encode_op_map(xdr, &args->state_protect.allow);
1769 if (send_implementation_id &&
1770 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1771 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1772 <= sizeof(impl_name) + 1)
1773 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1774 utsname()->sysname, utsname()->release,
1775 utsname()->version, utsname()->machine);
1778 encode_uint32(xdr, 1); /* implementation id array length=1 */
1781 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1782 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1783 encode_string(xdr, len, impl_name);
1784 /* just send zeros for nii_date - the date is in nii_name */
1785 p = reserve_space(xdr, 12);
1786 p = xdr_encode_hyper(p, 0);
1787 *p = cpu_to_be32(0);
1789 encode_uint32(xdr, 0); /* implementation id array length=0 */
1792 static void encode_create_session(struct xdr_stream *xdr,
1793 struct nfs41_create_session_args *args,
1794 struct compound_hdr *hdr)
1797 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1799 struct nfs_client *clp = args->client;
1800 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1801 u32 max_resp_sz_cached;
1804 * Assumes OPEN is the biggest non-idempotent compound.
1805 * 2 is the verifier.
1807 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1808 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1810 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1813 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1814 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
1815 p = xdr_encode_hyper(p, clp->cl_clientid);
1816 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1817 *p++ = cpu_to_be32(args->flags); /*flags */
1820 *p++ = cpu_to_be32(0); /* header padding size */
1821 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1822 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1823 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1824 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1825 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1826 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1829 *p++ = cpu_to_be32(0); /* header padding size */
1830 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1831 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1832 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1833 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1834 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1835 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1837 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1838 *p++ = cpu_to_be32(1);
1839 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1841 /* authsys_parms rfc1831 */
1842 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
1843 p = xdr_encode_opaque(p, machine_name, len);
1844 *p++ = cpu_to_be32(0); /* UID */
1845 *p++ = cpu_to_be32(0); /* GID */
1846 *p = cpu_to_be32(0); /* No more gids */
1849 static void encode_destroy_session(struct xdr_stream *xdr,
1850 struct nfs4_session *session,
1851 struct compound_hdr *hdr)
1853 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1854 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1857 static void encode_destroy_clientid(struct xdr_stream *xdr,
1859 struct compound_hdr *hdr)
1861 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1862 encode_uint64(xdr, clientid);
1865 static void encode_reclaim_complete(struct xdr_stream *xdr,
1866 struct nfs41_reclaim_complete_args *args,
1867 struct compound_hdr *hdr)
1869 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1870 encode_uint32(xdr, args->one_fs);
1872 #endif /* CONFIG_NFS_V4_1 */
1874 static void encode_sequence(struct xdr_stream *xdr,
1875 const struct nfs4_sequence_args *args,
1876 struct compound_hdr *hdr)
1878 #if defined(CONFIG_NFS_V4_1)
1879 struct nfs4_session *session;
1880 struct nfs4_slot_table *tp;
1881 struct nfs4_slot *slot = args->sa_slot;
1885 session = tp->session;
1889 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1892 * Sessionid + seqid + slotid + max slotid + cache_this
1894 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1895 "max_slotid=%d cache_this=%d\n",
1897 ((u32 *)session->sess_id.data)[0],
1898 ((u32 *)session->sess_id.data)[1],
1899 ((u32 *)session->sess_id.data)[2],
1900 ((u32 *)session->sess_id.data)[3],
1901 slot->seq_nr, slot->slot_nr,
1902 tp->highest_used_slotid, args->sa_cache_this);
1903 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1904 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1905 *p++ = cpu_to_be32(slot->seq_nr);
1906 *p++ = cpu_to_be32(slot->slot_nr);
1907 *p++ = cpu_to_be32(tp->highest_used_slotid);
1908 *p = cpu_to_be32(args->sa_cache_this);
1909 #endif /* CONFIG_NFS_V4_1 */
1912 #ifdef CONFIG_NFS_V4_1
1914 encode_getdeviceinfo(struct xdr_stream *xdr,
1915 const struct nfs4_getdeviceinfo_args *args,
1916 struct compound_hdr *hdr)
1920 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1921 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
1922 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1923 NFS4_DEVICEID4_SIZE);
1924 *p++ = cpu_to_be32(args->pdev->layout_type);
1925 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
1926 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1930 encode_layoutget(struct xdr_stream *xdr,
1931 const struct nfs4_layoutget_args *args,
1932 struct compound_hdr *hdr)
1936 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1937 p = reserve_space(xdr, 36);
1938 *p++ = cpu_to_be32(0); /* Signal layout available */
1939 *p++ = cpu_to_be32(args->type);
1940 *p++ = cpu_to_be32(args->range.iomode);
1941 p = xdr_encode_hyper(p, args->range.offset);
1942 p = xdr_encode_hyper(p, args->range.length);
1943 p = xdr_encode_hyper(p, args->minlength);
1944 encode_nfs4_stateid(xdr, &args->stateid);
1945 encode_uint32(xdr, args->maxcount);
1947 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1951 (unsigned long)args->range.offset,
1952 (unsigned long)args->range.length,
1957 encode_layoutcommit(struct xdr_stream *xdr,
1958 struct inode *inode,
1959 struct nfs4_layoutcommit_args *args,
1960 struct compound_hdr *hdr)
1964 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1965 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1967 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1968 p = reserve_space(xdr, 20);
1969 /* Only whole file layouts */
1970 p = xdr_encode_hyper(p, 0); /* offset */
1971 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1972 *p = cpu_to_be32(0); /* reclaim */
1973 encode_nfs4_stateid(xdr, &args->stateid);
1974 p = reserve_space(xdr, 20);
1975 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1976 p = xdr_encode_hyper(p, args->lastbytewritten);
1977 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1978 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1980 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
1981 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1982 NFS_I(inode)->layout, xdr, args);
1984 encode_uint32(xdr, args->layoutupdate_len);
1985 if (args->layoutupdate_pages) {
1986 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1987 args->layoutupdate_len);
1995 encode_layoutreturn(struct xdr_stream *xdr,
1996 const struct nfs4_layoutreturn_args *args,
1997 struct compound_hdr *hdr)
2001 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2002 p = reserve_space(xdr, 16);
2003 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2004 *p++ = cpu_to_be32(args->layout_type);
2005 *p++ = cpu_to_be32(IOMODE_ANY);
2006 *p = cpu_to_be32(RETURN_FILE);
2007 p = reserve_space(xdr, 16);
2008 p = xdr_encode_hyper(p, 0);
2009 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2010 spin_lock(&args->inode->i_lock);
2011 encode_nfs4_stateid(xdr, &args->stateid);
2012 spin_unlock(&args->inode->i_lock);
2013 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2014 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2015 NFS_I(args->inode)->layout, xdr, args);
2017 encode_uint32(xdr, 0);
2021 encode_secinfo_no_name(struct xdr_stream *xdr,
2022 const struct nfs41_secinfo_no_name_args *args,
2023 struct compound_hdr *hdr)
2025 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2026 encode_uint32(xdr, args->style);
2030 static void encode_test_stateid(struct xdr_stream *xdr,
2031 struct nfs41_test_stateid_args *args,
2032 struct compound_hdr *hdr)
2034 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2035 encode_uint32(xdr, 1);
2036 encode_nfs4_stateid(xdr, args->stateid);
2039 static void encode_free_stateid(struct xdr_stream *xdr,
2040 struct nfs41_free_stateid_args *args,
2041 struct compound_hdr *hdr)
2043 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2044 encode_nfs4_stateid(xdr, &args->stateid);
2046 #endif /* CONFIG_NFS_V4_1 */
2049 * END OF "GENERIC" ENCODE ROUTINES.
2052 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2054 #if defined(CONFIG_NFS_V4_1)
2055 struct nfs4_session *session = args->sa_slot->table->session;
2057 return session->clp->cl_mvops->minor_version;
2058 #endif /* CONFIG_NFS_V4_1 */
2063 * Encode an ACCESS request
2065 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2066 const struct nfs4_accessargs *args)
2068 struct compound_hdr hdr = {
2069 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2072 encode_compound_hdr(xdr, req, &hdr);
2073 encode_sequence(xdr, &args->seq_args, &hdr);
2074 encode_putfh(xdr, args->fh, &hdr);
2075 encode_access(xdr, args->access, &hdr);
2076 encode_getfattr(xdr, args->bitmask, &hdr);
2081 * Encode LOOKUP request
2083 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2084 const struct nfs4_lookup_arg *args)
2086 struct compound_hdr hdr = {
2087 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2090 encode_compound_hdr(xdr, req, &hdr);
2091 encode_sequence(xdr, &args->seq_args, &hdr);
2092 encode_putfh(xdr, args->dir_fh, &hdr);
2093 encode_lookup(xdr, args->name, &hdr);
2094 encode_getfh(xdr, &hdr);
2095 encode_getfattr(xdr, args->bitmask, &hdr);
2100 * Encode LOOKUP_ROOT request
2102 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2103 struct xdr_stream *xdr,
2104 const struct nfs4_lookup_root_arg *args)
2106 struct compound_hdr hdr = {
2107 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2110 encode_compound_hdr(xdr, req, &hdr);
2111 encode_sequence(xdr, &args->seq_args, &hdr);
2112 encode_putrootfh(xdr, &hdr);
2113 encode_getfh(xdr, &hdr);
2114 encode_getfattr(xdr, args->bitmask, &hdr);
2119 * Encode REMOVE request
2121 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2122 const struct nfs_removeargs *args)
2124 struct compound_hdr hdr = {
2125 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2128 encode_compound_hdr(xdr, req, &hdr);
2129 encode_sequence(xdr, &args->seq_args, &hdr);
2130 encode_putfh(xdr, args->fh, &hdr);
2131 encode_remove(xdr, &args->name, &hdr);
2136 * Encode RENAME request
2138 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2139 const struct nfs_renameargs *args)
2141 struct compound_hdr hdr = {
2142 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2145 encode_compound_hdr(xdr, req, &hdr);
2146 encode_sequence(xdr, &args->seq_args, &hdr);
2147 encode_putfh(xdr, args->old_dir, &hdr);
2148 encode_savefh(xdr, &hdr);
2149 encode_putfh(xdr, args->new_dir, &hdr);
2150 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2155 * Encode LINK request
2157 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2158 const struct nfs4_link_arg *args)
2160 struct compound_hdr hdr = {
2161 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2164 encode_compound_hdr(xdr, req, &hdr);
2165 encode_sequence(xdr, &args->seq_args, &hdr);
2166 encode_putfh(xdr, args->fh, &hdr);
2167 encode_savefh(xdr, &hdr);
2168 encode_putfh(xdr, args->dir_fh, &hdr);
2169 encode_link(xdr, args->name, &hdr);
2170 encode_restorefh(xdr, &hdr);
2171 encode_getfattr(xdr, args->bitmask, &hdr);
2176 * Encode CREATE request
2178 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2179 const struct nfs4_create_arg *args)
2181 struct compound_hdr hdr = {
2182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2185 encode_compound_hdr(xdr, req, &hdr);
2186 encode_sequence(xdr, &args->seq_args, &hdr);
2187 encode_putfh(xdr, args->dir_fh, &hdr);
2188 encode_create(xdr, args, &hdr);
2189 encode_getfh(xdr, &hdr);
2190 encode_getfattr(xdr, args->bitmask, &hdr);
2195 * Encode SYMLINK request
2197 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2198 const struct nfs4_create_arg *args)
2200 nfs4_xdr_enc_create(req, xdr, args);
2204 * Encode GETATTR request
2206 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2207 const struct nfs4_getattr_arg *args)
2209 struct compound_hdr hdr = {
2210 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2213 encode_compound_hdr(xdr, req, &hdr);
2214 encode_sequence(xdr, &args->seq_args, &hdr);
2215 encode_putfh(xdr, args->fh, &hdr);
2216 encode_getfattr(xdr, args->bitmask, &hdr);
2221 * Encode a CLOSE request
2223 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2224 struct nfs_closeargs *args)
2226 struct compound_hdr hdr = {
2227 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2230 encode_compound_hdr(xdr, req, &hdr);
2231 encode_sequence(xdr, &args->seq_args, &hdr);
2232 encode_putfh(xdr, args->fh, &hdr);
2233 encode_close(xdr, args, &hdr);
2234 encode_getfattr(xdr, args->bitmask, &hdr);
2239 * Encode an OPEN request
2241 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2242 struct nfs_openargs *args)
2244 struct compound_hdr hdr = {
2245 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2248 encode_compound_hdr(xdr, req, &hdr);
2249 encode_sequence(xdr, &args->seq_args, &hdr);
2250 encode_putfh(xdr, args->fh, &hdr);
2251 encode_open(xdr, args, &hdr);
2252 encode_getfh(xdr, &hdr);
2254 encode_access(xdr, args->access, &hdr);
2255 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2260 * Encode an OPEN_CONFIRM request
2262 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2263 struct xdr_stream *xdr,
2264 struct nfs_open_confirmargs *args)
2266 struct compound_hdr hdr = {
2270 encode_compound_hdr(xdr, req, &hdr);
2271 encode_putfh(xdr, args->fh, &hdr);
2272 encode_open_confirm(xdr, args, &hdr);
2277 * Encode an OPEN request with no attributes.
2279 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2280 struct xdr_stream *xdr,
2281 struct nfs_openargs *args)
2283 struct compound_hdr hdr = {
2284 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2287 encode_compound_hdr(xdr, req, &hdr);
2288 encode_sequence(xdr, &args->seq_args, &hdr);
2289 encode_putfh(xdr, args->fh, &hdr);
2290 encode_open(xdr, args, &hdr);
2292 encode_access(xdr, args->access, &hdr);
2293 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2298 * Encode an OPEN_DOWNGRADE request
2300 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2301 struct xdr_stream *xdr,
2302 struct nfs_closeargs *args)
2304 struct compound_hdr hdr = {
2305 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2308 encode_compound_hdr(xdr, req, &hdr);
2309 encode_sequence(xdr, &args->seq_args, &hdr);
2310 encode_putfh(xdr, args->fh, &hdr);
2311 encode_open_downgrade(xdr, args, &hdr);
2312 encode_getfattr(xdr, args->bitmask, &hdr);
2317 * Encode a LOCK request
2319 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2320 struct nfs_lock_args *args)
2322 struct compound_hdr hdr = {
2323 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2326 encode_compound_hdr(xdr, req, &hdr);
2327 encode_sequence(xdr, &args->seq_args, &hdr);
2328 encode_putfh(xdr, args->fh, &hdr);
2329 encode_lock(xdr, args, &hdr);
2334 * Encode a LOCKT request
2336 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2337 struct nfs_lockt_args *args)
2339 struct compound_hdr hdr = {
2340 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2343 encode_compound_hdr(xdr, req, &hdr);
2344 encode_sequence(xdr, &args->seq_args, &hdr);
2345 encode_putfh(xdr, args->fh, &hdr);
2346 encode_lockt(xdr, args, &hdr);
2351 * Encode a LOCKU request
2353 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2354 struct nfs_locku_args *args)
2356 struct compound_hdr hdr = {
2357 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2360 encode_compound_hdr(xdr, req, &hdr);
2361 encode_sequence(xdr, &args->seq_args, &hdr);
2362 encode_putfh(xdr, args->fh, &hdr);
2363 encode_locku(xdr, args, &hdr);
2367 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2368 struct xdr_stream *xdr,
2369 struct nfs_release_lockowner_args *args)
2371 struct compound_hdr hdr = {
2375 encode_compound_hdr(xdr, req, &hdr);
2376 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2381 * Encode a READLINK request
2383 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2384 const struct nfs4_readlink *args)
2386 struct compound_hdr hdr = {
2387 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2390 encode_compound_hdr(xdr, req, &hdr);
2391 encode_sequence(xdr, &args->seq_args, &hdr);
2392 encode_putfh(xdr, args->fh, &hdr);
2393 encode_readlink(xdr, args, req, &hdr);
2395 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2396 args->pgbase, args->pglen);
2401 * Encode a READDIR request
2403 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2404 const struct nfs4_readdir_arg *args)
2406 struct compound_hdr hdr = {
2407 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2410 encode_compound_hdr(xdr, req, &hdr);
2411 encode_sequence(xdr, &args->seq_args, &hdr);
2412 encode_putfh(xdr, args->fh, &hdr);
2413 encode_readdir(xdr, args, req, &hdr);
2415 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2416 args->pgbase, args->count);
2417 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2418 __func__, hdr.replen << 2, args->pages,
2419 args->pgbase, args->count);
2424 * Encode a READ request
2426 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2427 struct nfs_pgio_args *args)
2429 struct compound_hdr hdr = {
2430 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2433 encode_compound_hdr(xdr, req, &hdr);
2434 encode_sequence(xdr, &args->seq_args, &hdr);
2435 encode_putfh(xdr, args->fh, &hdr);
2436 encode_read(xdr, args, &hdr);
2438 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2439 args->pages, args->pgbase, args->count);
2440 req->rq_rcv_buf.flags |= XDRBUF_READ;
2445 * Encode an SETATTR request
2447 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2448 struct nfs_setattrargs *args)
2450 struct compound_hdr hdr = {
2451 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2454 encode_compound_hdr(xdr, req, &hdr);
2455 encode_sequence(xdr, &args->seq_args, &hdr);
2456 encode_putfh(xdr, args->fh, &hdr);
2457 encode_setattr(xdr, args, args->server, &hdr);
2458 encode_getfattr(xdr, args->bitmask, &hdr);
2463 * Encode a GETACL request
2465 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2466 struct nfs_getaclargs *args)
2468 struct compound_hdr hdr = {
2469 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2473 encode_compound_hdr(xdr, req, &hdr);
2474 encode_sequence(xdr, &args->seq_args, &hdr);
2475 encode_putfh(xdr, args->fh, &hdr);
2476 replen = hdr.replen + op_decode_hdr_maxsz + 1;
2477 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2479 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2480 args->acl_pages, args->acl_pgbase, args->acl_len);
2486 * Encode a WRITE request
2488 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2489 struct nfs_pgio_args *args)
2491 struct compound_hdr hdr = {
2492 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2495 encode_compound_hdr(xdr, req, &hdr);
2496 encode_sequence(xdr, &args->seq_args, &hdr);
2497 encode_putfh(xdr, args->fh, &hdr);
2498 encode_write(xdr, args, &hdr);
2499 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2501 encode_getfattr(xdr, args->bitmask, &hdr);
2508 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2509 struct nfs_commitargs *args)
2511 struct compound_hdr hdr = {
2512 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2515 encode_compound_hdr(xdr, req, &hdr);
2516 encode_sequence(xdr, &args->seq_args, &hdr);
2517 encode_putfh(xdr, args->fh, &hdr);
2518 encode_commit(xdr, args, &hdr);
2525 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2526 struct nfs4_fsinfo_arg *args)
2528 struct compound_hdr hdr = {
2529 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2532 encode_compound_hdr(xdr, req, &hdr);
2533 encode_sequence(xdr, &args->seq_args, &hdr);
2534 encode_putfh(xdr, args->fh, &hdr);
2535 encode_fsinfo(xdr, args->bitmask, &hdr);
2540 * a PATHCONF request
2542 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2543 const struct nfs4_pathconf_arg *args)
2545 struct compound_hdr hdr = {
2546 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2549 encode_compound_hdr(xdr, req, &hdr);
2550 encode_sequence(xdr, &args->seq_args, &hdr);
2551 encode_putfh(xdr, args->fh, &hdr);
2552 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2560 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2561 const struct nfs4_statfs_arg *args)
2563 struct compound_hdr hdr = {
2564 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2567 encode_compound_hdr(xdr, req, &hdr);
2568 encode_sequence(xdr, &args->seq_args, &hdr);
2569 encode_putfh(xdr, args->fh, &hdr);
2570 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2571 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2576 * GETATTR_BITMAP request
2578 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2579 struct xdr_stream *xdr,
2580 struct nfs4_server_caps_arg *args)
2582 struct compound_hdr hdr = {
2583 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2586 encode_compound_hdr(xdr, req, &hdr);
2587 encode_sequence(xdr, &args->seq_args, &hdr);
2588 encode_putfh(xdr, args->fhandle, &hdr);
2589 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2590 FATTR4_WORD0_FH_EXPIRE_TYPE|
2591 FATTR4_WORD0_LINK_SUPPORT|
2592 FATTR4_WORD0_SYMLINK_SUPPORT|
2593 FATTR4_WORD0_ACLSUPPORT, &hdr);
2600 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2601 struct nfs_client *clp)
2603 struct compound_hdr hdr = {
2607 encode_compound_hdr(xdr, req, &hdr);
2608 encode_renew(xdr, clp->cl_clientid, &hdr);
2613 * a SETCLIENTID request
2615 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2616 struct xdr_stream *xdr,
2617 struct nfs4_setclientid *sc)
2619 struct compound_hdr hdr = {
2623 encode_compound_hdr(xdr, req, &hdr);
2624 encode_setclientid(xdr, sc, &hdr);
2629 * a SETCLIENTID_CONFIRM request
2631 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2632 struct xdr_stream *xdr,
2633 struct nfs4_setclientid_res *arg)
2635 struct compound_hdr hdr = {
2639 encode_compound_hdr(xdr, req, &hdr);
2640 encode_setclientid_confirm(xdr, arg, &hdr);
2645 * DELEGRETURN request
2647 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2648 struct xdr_stream *xdr,
2649 const struct nfs4_delegreturnargs *args)
2651 struct compound_hdr hdr = {
2652 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_sequence(xdr, &args->seq_args, &hdr);
2657 encode_putfh(xdr, args->fhandle, &hdr);
2658 encode_getfattr(xdr, args->bitmask, &hdr);
2659 encode_delegreturn(xdr, args->stateid, &hdr);
2664 * Encode FS_LOCATIONS request
2666 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2667 struct xdr_stream *xdr,
2668 struct nfs4_fs_locations_arg *args)
2670 struct compound_hdr hdr = {
2671 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2675 encode_compound_hdr(xdr, req, &hdr);
2676 encode_sequence(xdr, &args->seq_args, &hdr);
2677 if (args->migration) {
2678 encode_putfh(xdr, args->fh, &hdr);
2679 replen = hdr.replen;
2680 encode_fs_locations(xdr, args->bitmask, &hdr);
2682 encode_renew(xdr, args->clientid, &hdr);
2684 encode_putfh(xdr, args->dir_fh, &hdr);
2685 encode_lookup(xdr, args->name, &hdr);
2686 replen = hdr.replen;
2687 encode_fs_locations(xdr, args->bitmask, &hdr);
2690 /* Set up reply kvec to capture returned fs_locations array. */
2691 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2697 * Encode SECINFO request
2699 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2700 struct xdr_stream *xdr,
2701 struct nfs4_secinfo_arg *args)
2703 struct compound_hdr hdr = {
2704 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2707 encode_compound_hdr(xdr, req, &hdr);
2708 encode_sequence(xdr, &args->seq_args, &hdr);
2709 encode_putfh(xdr, args->dir_fh, &hdr);
2710 encode_secinfo(xdr, args->name, &hdr);
2715 * Encode FSID_PRESENT request
2717 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2718 struct xdr_stream *xdr,
2719 struct nfs4_fsid_present_arg *args)
2721 struct compound_hdr hdr = {
2722 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2725 encode_compound_hdr(xdr, req, &hdr);
2726 encode_sequence(xdr, &args->seq_args, &hdr);
2727 encode_putfh(xdr, args->fh, &hdr);
2728 encode_getfh(xdr, &hdr);
2730 encode_renew(xdr, args->clientid, &hdr);
2734 #if defined(CONFIG_NFS_V4_1)
2736 * BIND_CONN_TO_SESSION request
2738 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2739 struct xdr_stream *xdr,
2740 struct nfs_client *clp)
2742 struct compound_hdr hdr = {
2743 .minorversion = clp->cl_mvops->minor_version,
2746 encode_compound_hdr(xdr, req, &hdr);
2747 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2752 * EXCHANGE_ID request
2754 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2755 struct xdr_stream *xdr,
2756 struct nfs41_exchange_id_args *args)
2758 struct compound_hdr hdr = {
2759 .minorversion = args->client->cl_mvops->minor_version,
2762 encode_compound_hdr(xdr, req, &hdr);
2763 encode_exchange_id(xdr, args, &hdr);
2768 * a CREATE_SESSION request
2770 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2771 struct xdr_stream *xdr,
2772 struct nfs41_create_session_args *args)
2774 struct compound_hdr hdr = {
2775 .minorversion = args->client->cl_mvops->minor_version,
2778 encode_compound_hdr(xdr, req, &hdr);
2779 encode_create_session(xdr, args, &hdr);
2784 * a DESTROY_SESSION request
2786 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2787 struct xdr_stream *xdr,
2788 struct nfs4_session *session)
2790 struct compound_hdr hdr = {
2791 .minorversion = session->clp->cl_mvops->minor_version,
2794 encode_compound_hdr(xdr, req, &hdr);
2795 encode_destroy_session(xdr, session, &hdr);
2800 * a DESTROY_CLIENTID request
2802 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2803 struct xdr_stream *xdr,
2804 struct nfs_client *clp)
2806 struct compound_hdr hdr = {
2807 .minorversion = clp->cl_mvops->minor_version,
2810 encode_compound_hdr(xdr, req, &hdr);
2811 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2816 * a SEQUENCE request
2818 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2819 struct nfs4_sequence_args *args)
2821 struct compound_hdr hdr = {
2822 .minorversion = nfs4_xdr_minorversion(args),
2825 encode_compound_hdr(xdr, req, &hdr);
2826 encode_sequence(xdr, args, &hdr);
2831 * a GET_LEASE_TIME request
2833 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2834 struct xdr_stream *xdr,
2835 struct nfs4_get_lease_time_args *args)
2837 struct compound_hdr hdr = {
2838 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2840 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2842 encode_compound_hdr(xdr, req, &hdr);
2843 encode_sequence(xdr, &args->la_seq_args, &hdr);
2844 encode_putrootfh(xdr, &hdr);
2845 encode_fsinfo(xdr, lease_bitmap, &hdr);
2850 * a RECLAIM_COMPLETE request
2852 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2853 struct xdr_stream *xdr,
2854 struct nfs41_reclaim_complete_args *args)
2856 struct compound_hdr hdr = {
2857 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2860 encode_compound_hdr(xdr, req, &hdr);
2861 encode_sequence(xdr, &args->seq_args, &hdr);
2862 encode_reclaim_complete(xdr, args, &hdr);
2867 * Encode GETDEVICEINFO request
2869 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2870 struct xdr_stream *xdr,
2871 struct nfs4_getdeviceinfo_args *args)
2873 struct compound_hdr hdr = {
2874 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2877 encode_compound_hdr(xdr, req, &hdr);
2878 encode_sequence(xdr, &args->seq_args, &hdr);
2879 encode_getdeviceinfo(xdr, args, &hdr);
2881 /* set up reply kvec. Subtract notification bitmap max size (2)
2882 * so that notification bitmap is put in xdr_buf tail */
2883 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2884 args->pdev->pages, args->pdev->pgbase,
2891 * Encode LAYOUTGET request
2893 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2894 struct xdr_stream *xdr,
2895 struct nfs4_layoutget_args *args)
2897 struct compound_hdr hdr = {
2898 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2901 encode_compound_hdr(xdr, req, &hdr);
2902 encode_sequence(xdr, &args->seq_args, &hdr);
2903 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2904 encode_layoutget(xdr, args, &hdr);
2906 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2907 args->layout.pages, 0, args->layout.pglen);
2913 * Encode LAYOUTCOMMIT request
2915 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2916 struct xdr_stream *xdr,
2917 struct nfs4_layoutcommit_args *args)
2919 struct nfs4_layoutcommit_data *data =
2920 container_of(args, struct nfs4_layoutcommit_data, args);
2921 struct compound_hdr hdr = {
2922 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2925 encode_compound_hdr(xdr, req, &hdr);
2926 encode_sequence(xdr, &args->seq_args, &hdr);
2927 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2928 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2929 encode_getfattr(xdr, args->bitmask, &hdr);
2934 * Encode LAYOUTRETURN request
2936 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2937 struct xdr_stream *xdr,
2938 struct nfs4_layoutreturn_args *args)
2940 struct compound_hdr hdr = {
2941 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2944 encode_compound_hdr(xdr, req, &hdr);
2945 encode_sequence(xdr, &args->seq_args, &hdr);
2946 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2947 encode_layoutreturn(xdr, args, &hdr);
2952 * Encode SECINFO_NO_NAME request
2954 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2955 struct xdr_stream *xdr,
2956 struct nfs41_secinfo_no_name_args *args)
2958 struct compound_hdr hdr = {
2959 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2962 encode_compound_hdr(xdr, req, &hdr);
2963 encode_sequence(xdr, &args->seq_args, &hdr);
2964 encode_putrootfh(xdr, &hdr);
2965 encode_secinfo_no_name(xdr, args, &hdr);
2971 * Encode TEST_STATEID request
2973 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2974 struct xdr_stream *xdr,
2975 struct nfs41_test_stateid_args *args)
2977 struct compound_hdr hdr = {
2978 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2981 encode_compound_hdr(xdr, req, &hdr);
2982 encode_sequence(xdr, &args->seq_args, &hdr);
2983 encode_test_stateid(xdr, args, &hdr);
2988 * Encode FREE_STATEID request
2990 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2991 struct xdr_stream *xdr,
2992 struct nfs41_free_stateid_args *args)
2994 struct compound_hdr hdr = {
2995 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2998 encode_compound_hdr(xdr, req, &hdr);
2999 encode_sequence(xdr, &args->seq_args, &hdr);
3000 encode_free_stateid(xdr, args, &hdr);
3003 #endif /* CONFIG_NFS_V4_1 */
3005 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3007 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3008 "Remaining buffer length is %tu words.\n",
3009 func, xdr->end - xdr->p);
3012 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3016 p = xdr_inline_decode(xdr, 4);
3019 *len = be32_to_cpup(p);
3020 p = xdr_inline_decode(xdr, *len);
3023 *string = (char *)p;
3026 print_overflow_msg(__func__, xdr);
3030 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3034 p = xdr_inline_decode(xdr, 8);
3037 hdr->status = be32_to_cpup(p++);
3038 hdr->taglen = be32_to_cpup(p);
3040 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3043 hdr->tag = (char *)p;
3044 p += XDR_QUADLEN(hdr->taglen);
3045 hdr->nops = be32_to_cpup(p);
3046 if (unlikely(hdr->nops < 1))
3047 return nfs4_stat_to_errno(hdr->status);
3050 print_overflow_msg(__func__, xdr);
3054 static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3061 p = xdr_inline_decode(xdr, 8);
3064 opnum = be32_to_cpup(p++);
3065 if (unlikely(opnum != expected))
3066 goto out_bad_operation;
3067 nfserr = be32_to_cpup(p);
3068 if (nfserr == NFS_OK)
3071 *nfs_retval = nfs4_stat_to_errno(nfserr);
3074 dprintk("nfs: Server returned operation"
3075 " %d but we issued a request for %d\n",
3077 *nfs_retval = -EREMOTEIO;
3080 print_overflow_msg(__func__, xdr);
3085 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3089 __decode_op_hdr(xdr, expected, &retval);
3094 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
3097 unsigned int strlen;
3100 p = xdr_inline_decode(xdr, 12);
3102 return decode_opaque_inline(xdr, &strlen, &str);
3103 print_overflow_msg(__func__, xdr);
3107 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3112 p = xdr_inline_decode(xdr, 4);
3115 bmlen = be32_to_cpup(p);
3117 bitmap[0] = bitmap[1] = bitmap[2] = 0;
3118 p = xdr_inline_decode(xdr, (bmlen << 2));
3122 bitmap[0] = be32_to_cpup(p++);
3124 bitmap[1] = be32_to_cpup(p++);
3126 bitmap[2] = be32_to_cpup(p);
3131 print_overflow_msg(__func__, xdr);
3135 static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
3139 p = xdr_inline_decode(xdr, 4);
3142 *attrlen = be32_to_cpup(p);
3143 *savep = xdr_stream_pos(xdr);
3146 print_overflow_msg(__func__, xdr);
3150 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3152 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3154 ret = decode_attr_bitmap(xdr, bitmask);
3155 if (unlikely(ret < 0))
3157 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3159 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3160 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3161 bitmask[0], bitmask[1], bitmask[2]);
3165 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3171 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3173 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3174 p = xdr_inline_decode(xdr, 4);
3177 *type = be32_to_cpup(p);
3178 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3179 dprintk("%s: bad type %d\n", __func__, *type);
3182 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3183 ret = NFS_ATTR_FATTR_TYPE;
3185 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3188 print_overflow_msg(__func__, xdr);
3192 static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3193 uint32_t *bitmap, uint32_t *type)
3198 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3200 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3201 p = xdr_inline_decode(xdr, 4);
3204 *type = be32_to_cpup(p);
3205 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3207 dprintk("%s: expire type=0x%x\n", __func__, *type);
3210 print_overflow_msg(__func__, xdr);
3214 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3220 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3222 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3223 p = xdr_inline_decode(xdr, 8);
3226 xdr_decode_hyper(p, change);
3227 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3228 ret = NFS_ATTR_FATTR_CHANGE;
3230 dprintk("%s: change attribute=%Lu\n", __func__,
3231 (unsigned long long)*change);
3234 print_overflow_msg(__func__, xdr);
3238 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3244 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3246 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3247 p = xdr_inline_decode(xdr, 8);
3250 xdr_decode_hyper(p, size);
3251 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3252 ret = NFS_ATTR_FATTR_SIZE;
3254 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3257 print_overflow_msg(__func__, xdr);
3261 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3266 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3268 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3269 p = xdr_inline_decode(xdr, 4);
3272 *res = be32_to_cpup(p);
3273 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3275 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3278 print_overflow_msg(__func__, xdr);
3282 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3287 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3289 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3290 p = xdr_inline_decode(xdr, 4);
3293 *res = be32_to_cpup(p);
3294 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3296 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3299 print_overflow_msg(__func__, xdr);
3303 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3310 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3312 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3313 p = xdr_inline_decode(xdr, 16);
3316 p = xdr_decode_hyper(p, &fsid->major);
3317 xdr_decode_hyper(p, &fsid->minor);
3318 bitmap[0] &= ~FATTR4_WORD0_FSID;
3319 ret = NFS_ATTR_FATTR_FSID;
3321 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3322 (unsigned long long)fsid->major,
3323 (unsigned long long)fsid->minor);
3326 print_overflow_msg(__func__, xdr);
3330 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3335 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3337 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3338 p = xdr_inline_decode(xdr, 4);
3341 *res = be32_to_cpup(p);
3342 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3344 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3347 print_overflow_msg(__func__, xdr);
3351 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3355 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3357 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3358 p = xdr_inline_decode(xdr, 4);
3361 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3362 *res = -be32_to_cpup(p);
3366 print_overflow_msg(__func__, xdr);
3370 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3376 memset(fh, 0, sizeof(*fh));
3378 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3380 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3381 p = xdr_inline_decode(xdr, 4);
3384 len = be32_to_cpup(p);
3385 if (len > NFS4_FHSIZE)
3387 p = xdr_inline_decode(xdr, len);
3391 memcpy(fh->data, p, len);
3394 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3398 print_overflow_msg(__func__, xdr);
3402 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3407 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3409 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3410 p = xdr_inline_decode(xdr, 4);
3413 *res = be32_to_cpup(p);
3414 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3416 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3419 print_overflow_msg(__func__, xdr);
3423 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3429 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3431 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3432 p = xdr_inline_decode(xdr, 8);
3435 xdr_decode_hyper(p, fileid);
3436 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3437 ret = NFS_ATTR_FATTR_FILEID;
3439 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3442 print_overflow_msg(__func__, xdr);
3446 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3452 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3454 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3455 p = xdr_inline_decode(xdr, 8);
3458 xdr_decode_hyper(p, fileid);
3459 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3460 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3462 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3465 print_overflow_msg(__func__, xdr);
3469 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3475 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3477 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3478 p = xdr_inline_decode(xdr, 8);
3481 xdr_decode_hyper(p, res);
3482 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3484 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3487 print_overflow_msg(__func__, xdr);
3491 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3497 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3499 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3500 p = xdr_inline_decode(xdr, 8);
3503 xdr_decode_hyper(p, res);
3504 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3506 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3509 print_overflow_msg(__func__, xdr);
3513 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3519 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3521 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3522 p = xdr_inline_decode(xdr, 8);
3525 xdr_decode_hyper(p, res);
3526 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3528 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3531 print_overflow_msg(__func__, xdr);
3535 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3541 p = xdr_inline_decode(xdr, 4);
3544 n = be32_to_cpup(p);
3547 dprintk("pathname4: ");
3548 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3549 dprintk("cannot parse %d components in path\n", n);
3552 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
3553 struct nfs4_string *component = &path->components[path->ncomponents];
3554 status = decode_opaque_inline(xdr, &component->len, &component->data);
3555 if (unlikely(status != 0))
3559 (path->ncomponents != n ? "/ " : ""),
3560 component->len, component->data);
3565 /* a root pathname is sent as a zero component4 */
3566 path->ncomponents = 1;
3567 path->components[0].len=0;
3568 path->components[0].data=NULL;
3569 dprintk("pathname4: /\n");
3572 dprintk(" status %d", status);
3576 print_overflow_msg(__func__, xdr);
3580 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3586 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3589 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3592 /* Ignore borken servers that return unrequested attrs */
3593 if (unlikely(res == NULL))
3595 dprintk("%s: fsroot:\n", __func__);
3596 status = decode_pathname(xdr, &res->fs_path);
3597 if (unlikely(status != 0))
3599 p = xdr_inline_decode(xdr, 4);
3602 n = be32_to_cpup(p);
3605 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3607 struct nfs4_fs_location *loc;
3609 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3611 loc = &res->locations[res->nlocations];
3612 p = xdr_inline_decode(xdr, 4);
3615 m = be32_to_cpup(p);
3617 dprintk("%s: servers:\n", __func__);
3618 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3619 struct nfs4_string *server;
3621 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3623 dprintk("%s: using first %u of %u servers "
3624 "returned for location %u\n",
3626 NFS4_FS_LOCATION_MAXSERVERS,
3627 m, res->nlocations);
3628 for (i = loc->nservers; i < m; i++) {
3631 status = decode_opaque_inline(xdr, &len, &data);
3632 if (unlikely(status != 0))
3637 server = &loc->servers[loc->nservers];
3638 status = decode_opaque_inline(xdr, &server->len, &server->data);
3639 if (unlikely(status != 0))
3641 dprintk("%s ", server->data);
3643 status = decode_pathname(xdr, &loc->rootpath);
3644 if (unlikely(status != 0))
3647 if (res->nlocations != 0)
3648 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3650 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3653 print_overflow_msg(__func__, xdr);
3659 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3665 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3667 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3668 p = xdr_inline_decode(xdr, 8);
3671 xdr_decode_hyper(p, res);
3672 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3674 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3677 print_overflow_msg(__func__, xdr);
3681 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3687 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3689 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3690 p = xdr_inline_decode(xdr, 4);
3693 *maxlink = be32_to_cpup(p);
3694 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3696 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3699 print_overflow_msg(__func__, xdr);
3703 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3709 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3711 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3712 p = xdr_inline_decode(xdr, 4);
3715 *maxname = be32_to_cpup(p);
3716 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3718 dprintk("%s: maxname=%u\n", __func__, *maxname);
3721 print_overflow_msg(__func__, xdr);
3725 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3731 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3733 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3735 p = xdr_inline_decode(xdr, 8);
3738 xdr_decode_hyper(p, &maxread);
3739 if (maxread > 0x7FFFFFFF)
3740 maxread = 0x7FFFFFFF;
3741 *res = (uint32_t)maxread;
3742 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3744 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3747 print_overflow_msg(__func__, xdr);
3751 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3757 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3759 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3761 p = xdr_inline_decode(xdr, 8);
3764 xdr_decode_hyper(p, &maxwrite);
3765 if (maxwrite > 0x7FFFFFFF)
3766 maxwrite = 0x7FFFFFFF;
3767 *res = (uint32_t)maxwrite;
3768 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3770 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3773 print_overflow_msg(__func__, xdr);
3777 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3784 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3786 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3787 p = xdr_inline_decode(xdr, 4);
3790 tmp = be32_to_cpup(p);
3791 *mode = tmp & ~S_IFMT;
3792 bitmap[1] &= ~FATTR4_WORD1_MODE;
3793 ret = NFS_ATTR_FATTR_MODE;
3795 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3798 print_overflow_msg(__func__, xdr);
3802 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3808 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3810 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3811 p = xdr_inline_decode(xdr, 4);
3814 *nlink = be32_to_cpup(p);
3815 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3816 ret = NFS_ATTR_FATTR_NLINK;
3818 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3821 print_overflow_msg(__func__, xdr);
3825 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3826 const struct nfs_server *server, kuid_t *uid,
3827 struct nfs4_string *owner_name)
3833 *uid = make_kuid(&init_user_ns, -2);
3834 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3836 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3837 p = xdr_inline_decode(xdr, 4);
3840 len = be32_to_cpup(p);
3841 p = xdr_inline_decode(xdr, len);
3844 if (owner_name != NULL) {
3845 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3846 if (owner_name->data != NULL) {
3847 owner_name->len = len;
3848 ret = NFS_ATTR_FATTR_OWNER_NAME;
3850 } else if (len < XDR_MAX_NETOBJ) {
3851 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3852 ret = NFS_ATTR_FATTR_OWNER;
3854 dprintk("%s: nfs_map_name_to_uid failed!\n",
3857 dprintk("%s: name too long (%u)!\n",
3859 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3861 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3864 print_overflow_msg(__func__, xdr);
3868 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3869 const struct nfs_server *server, kgid_t *gid,
3870 struct nfs4_string *group_name)
3876 *gid = make_kgid(&init_user_ns, -2);
3877 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3879 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3880 p = xdr_inline_decode(xdr, 4);
3883 len = be32_to_cpup(p);
3884 p = xdr_inline_decode(xdr, len);
3887 if (group_name != NULL) {
3888 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3889 if (group_name->data != NULL) {
3890 group_name->len = len;
3891 ret = NFS_ATTR_FATTR_GROUP_NAME;
3893 } else if (len < XDR_MAX_NETOBJ) {
3894 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3895 ret = NFS_ATTR_FATTR_GROUP;
3897 dprintk("%s: nfs_map_group_to_gid failed!\n",
3900 dprintk("%s: name too long (%u)!\n",
3902 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3904 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3907 print_overflow_msg(__func__, xdr);
3911 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3913 uint32_t major = 0, minor = 0;
3918 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3920 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3923 p = xdr_inline_decode(xdr, 8);
3926 major = be32_to_cpup(p++);
3927 minor = be32_to_cpup(p);
3928 tmp = MKDEV(major, minor);
3929 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3931 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3932 ret = NFS_ATTR_FATTR_RDEV;
3934 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3937 print_overflow_msg(__func__, xdr);
3941 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3947 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3949 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3950 p = xdr_inline_decode(xdr, 8);
3953 xdr_decode_hyper(p, res);
3954 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3956 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3959 print_overflow_msg(__func__, xdr);
3963 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3969 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3971 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3972 p = xdr_inline_decode(xdr, 8);
3975 xdr_decode_hyper(p, res);
3976 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3978 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3981 print_overflow_msg(__func__, xdr);
3985 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3991 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3993 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3994 p = xdr_inline_decode(xdr, 8);
3997 xdr_decode_hyper(p, res);
3998 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4000 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
4003 print_overflow_msg(__func__, xdr);
4007 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4013 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4015 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4016 p = xdr_inline_decode(xdr, 8);
4019 xdr_decode_hyper(p, used);
4020 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4021 ret = NFS_ATTR_FATTR_SPACE_USED;
4023 dprintk("%s: space used=%Lu\n", __func__,
4024 (unsigned long long)*used);
4027 print_overflow_msg(__func__, xdr);
4031 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4037 p = xdr_inline_decode(xdr, 12);
4040 p = xdr_decode_hyper(p, &sec);
4041 nsec = be32_to_cpup(p);
4042 time->tv_sec = (time_t)sec;
4043 time->tv_nsec = (long)nsec;
4046 print_overflow_msg(__func__, xdr);
4050 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4056 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4058 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4059 status = decode_attr_time(xdr, time);
4061 status = NFS_ATTR_FATTR_ATIME;
4062 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4064 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
4068 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4074 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4076 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4077 status = decode_attr_time(xdr, time);
4079 status = NFS_ATTR_FATTR_CTIME;
4080 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4082 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
4086 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4087 struct timespec *time)
4093 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4095 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4096 status = decode_attr_time(xdr, time);
4097 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4099 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4100 (long)time->tv_nsec);
4104 static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4105 struct nfs4_label *label)
4113 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4115 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4116 p = xdr_inline_decode(xdr, 4);
4119 lfs = be32_to_cpup(p++);
4120 p = xdr_inline_decode(xdr, 4);
4123 pi = be32_to_cpup(p++);
4124 p = xdr_inline_decode(xdr, 4);
4127 len = be32_to_cpup(p++);
4128 p = xdr_inline_decode(xdr, len);
4131 if (len < NFS4_MAXLABELLEN) {
4133 memcpy(label->label, p, len);
4137 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4139 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4141 printk(KERN_WARNING "%s: label too long (%u)!\n",
4144 if (label && label->label)
4145 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4146 (char *)label->label, label->len, label->pi, label->lfs);
4150 print_overflow_msg(__func__, xdr);
4154 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4160 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4162 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4163 status = decode_attr_time(xdr, time);
4165 status = NFS_ATTR_FATTR_MTIME;
4166 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4168 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
4172 static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
4174 unsigned int attrwords = XDR_QUADLEN(attrlen);
4175 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
4177 if (unlikely(attrwords != nwords)) {
4178 dprintk("%s: server returned incorrect attribute length: "
4182 (attrwords < nwords) ? '<' : '>',
4189 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4193 p = xdr_inline_decode(xdr, 20);
4196 cinfo->atomic = be32_to_cpup(p++);
4197 p = xdr_decode_hyper(p, &cinfo->before);
4198 xdr_decode_hyper(p, &cinfo->after);
4201 print_overflow_msg(__func__, xdr);
4205 static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
4211 status = decode_op_hdr(xdr, OP_ACCESS);
4214 p = xdr_inline_decode(xdr, 8);
4217 supp = be32_to_cpup(p++);
4218 acc = be32_to_cpup(p);
4223 print_overflow_msg(__func__, xdr);
4227 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4231 p = xdr_inline_decode(xdr, len);
4233 memcpy(buf, p, len);
4236 print_overflow_msg(__func__, xdr);
4240 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4242 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4245 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4249 status = decode_op_hdr(xdr, OP_CLOSE);
4251 nfs_increment_open_seqid(status, res->seqid);
4253 status = decode_stateid(xdr, &res->stateid);
4257 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4259 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4262 static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4264 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4267 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4271 status = decode_op_hdr(xdr, OP_COMMIT);
4273 status = decode_write_verifier(xdr, &res->verf->verifier);
4277 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4283 status = decode_op_hdr(xdr, OP_CREATE);
4286 if ((status = decode_change_info(xdr, cinfo)))
4288 p = xdr_inline_decode(xdr, 4);
4291 bmlen = be32_to_cpup(p);
4292 p = xdr_inline_decode(xdr, bmlen << 2);
4296 print_overflow_msg(__func__, xdr);
4300 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4303 uint32_t attrlen, bitmap[3] = {0};
4306 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4308 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4310 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4312 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4314 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4315 &res->fh_expire_type)) != 0)
4317 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4319 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4321 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4323 status = verify_attr_len(xdr, savep, attrlen);
4325 dprintk("%s: xdr returned %d!\n", __func__, -status);
4329 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4332 uint32_t attrlen, bitmap[3] = {0};
4335 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4337 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4339 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4342 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4344 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4346 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4348 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4350 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4352 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4355 status = verify_attr_len(xdr, savep, attrlen);
4357 dprintk("%s: xdr returned %d!\n", __func__, -status);
4361 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4364 uint32_t attrlen, bitmap[3] = {0};
4367 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4369 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4371 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4374 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4376 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4379 status = verify_attr_len(xdr, savep, attrlen);
4381 dprintk("%s: xdr returned %d!\n", __func__, -status);
4385 static int decode_threshold_hint(struct xdr_stream *xdr,
4393 if (likely(bitmap[0] & hint_bit)) {
4394 p = xdr_inline_decode(xdr, 8);
4397 xdr_decode_hyper(p, res);
4401 print_overflow_msg(__func__, xdr);
4405 static int decode_first_threshold_item4(struct xdr_stream *xdr,
4406 struct nfs4_threshold *res)
4410 uint32_t bitmap[3] = {0,}, attrlen;
4414 p = xdr_inline_decode(xdr, 4);
4416 print_overflow_msg(__func__, xdr);
4419 res->l_type = be32_to_cpup(p);
4421 /* thi_hintset bitmap */
4422 status = decode_attr_bitmap(xdr, bitmap);
4426 /* thi_hintlist length */
4427 status = decode_attr_length(xdr, &attrlen, &savep);
4431 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4434 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4437 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4441 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4446 status = verify_attr_len(xdr, savep, attrlen);
4447 res->bm = bitmap[0];
4449 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4450 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4453 dprintk("%s ret=%d!\n", __func__, status);
4458 * Thresholds on pNFS direct I/O vrs MDS I/O
4460 static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4462 struct nfs4_threshold *res)
4468 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4470 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
4471 /* Did the server return an unrequested attribute? */
4472 if (unlikely(res == NULL))
4474 p = xdr_inline_decode(xdr, 4);
4477 num = be32_to_cpup(p);
4481 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4482 "drivers per filesystem not supported\n",
4485 status = decode_first_threshold_item4(xdr, res);
4486 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
4490 print_overflow_msg(__func__, xdr);
4494 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4495 struct nfs_fattr *fattr, struct nfs_fh *fh,
4496 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
4497 const struct nfs_server *server)
4504 status = decode_attr_type(xdr, bitmap, &type);
4509 fattr->mode |= nfs_type2fmt[type];
4510 fattr->valid |= status;
4513 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4516 fattr->valid |= status;
4518 status = decode_attr_size(xdr, bitmap, &fattr->size);
4521 fattr->valid |= status;
4523 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4526 fattr->valid |= status;
4529 status = decode_attr_error(xdr, bitmap, &err);
4533 status = decode_attr_filehandle(xdr, bitmap, fh);
4537 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4540 fattr->valid |= status;
4542 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4545 fattr->valid |= status;
4547 status = decode_attr_mode(xdr, bitmap, &fmode);
4551 fattr->mode |= fmode;
4552 fattr->valid |= status;
4555 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4558 fattr->valid |= status;
4560 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4563 fattr->valid |= status;
4565 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4568 fattr->valid |= status;
4570 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4573 fattr->valid |= status;
4575 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4578 fattr->valid |= status;
4580 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4583 fattr->valid |= status;
4585 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4588 fattr->valid |= status;
4590 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4593 fattr->valid |= status;
4595 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4598 fattr->valid |= status;
4600 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4605 status = decode_attr_security_label(xdr, bitmap, label);
4608 fattr->valid |= status;
4612 dprintk("%s: xdr returned %d\n", __func__, -status);
4616 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4617 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4618 struct nfs4_label *label, const struct nfs_server *server)
4625 status = decode_op_hdr(xdr, OP_GETATTR);
4629 status = decode_attr_bitmap(xdr, bitmap);
4633 status = decode_attr_length(xdr, &attrlen, &savep);
4637 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4642 status = verify_attr_len(xdr, savep, attrlen);
4644 dprintk("%s: xdr returned %d\n", __func__, -status);
4648 static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4649 struct nfs4_label *label, const struct nfs_server *server)
4651 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4654 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4655 const struct nfs_server *server)
4657 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4661 * Decode potentially multiple layout types. Currently we only support
4662 * one layout driver per file system.
4664 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4665 uint32_t *layouttype)
4670 p = xdr_inline_decode(xdr, 4);
4673 num = be32_to_cpup(p);
4675 /* pNFS is not supported by the underlying file system */
4681 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4682 "drivers per filesystem not supported\n", __func__);
4684 /* Decode and set first layout type, move xdr->p past unused types */
4685 p = xdr_inline_decode(xdr, num * 4);
4688 *layouttype = be32_to_cpup(p);
4691 print_overflow_msg(__func__, xdr);
4696 * The type of file system exported.
4697 * Note we must ensure that layouttype is set in any non-error case.
4699 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4700 uint32_t *layouttype)
4704 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4705 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4707 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4708 status = decode_first_pnfs_layout_type(xdr, layouttype);
4709 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4716 * The prefered block size for layout directed io
4718 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4723 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4725 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4726 p = xdr_inline_decode(xdr, 4);
4728 print_overflow_msg(__func__, xdr);
4731 *res = be32_to_cpup(p);
4732 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4737 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4740 uint32_t attrlen, bitmap[3];
4743 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4745 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4747 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4750 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4752 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4754 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4756 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4758 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4759 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4761 fsinfo->wtpref = fsinfo->wtmax;
4762 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4765 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4768 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4772 status = verify_attr_len(xdr, savep, attrlen);
4774 dprintk("%s: xdr returned %d!\n", __func__, -status);
4778 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4784 /* Zero handle first to allow comparisons */
4785 memset(fh, 0, sizeof(*fh));
4787 status = decode_op_hdr(xdr, OP_GETFH);
4791 p = xdr_inline_decode(xdr, 4);
4794 len = be32_to_cpup(p);
4795 if (len > NFS4_FHSIZE)
4798 p = xdr_inline_decode(xdr, len);
4801 memcpy(fh->data, p, len);
4804 print_overflow_msg(__func__, xdr);
4808 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4812 status = decode_op_hdr(xdr, OP_LINK);
4815 return decode_change_info(xdr, cinfo);
4819 * We create the owner, so we know a proper owner.id length is 4.
4821 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4823 uint64_t offset, length, clientid;
4825 uint32_t namelen, type;
4827 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4830 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4831 p = xdr_decode_hyper(p, &length);
4832 type = be32_to_cpup(p++); /* 4 byte read */
4833 if (fl != NULL) { /* manipulate file lock */
4834 fl->fl_start = (loff_t)offset;
4835 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4836 if (length == ~(uint64_t)0)
4837 fl->fl_end = OFFSET_MAX;
4838 fl->fl_type = F_WRLCK;
4840 fl->fl_type = F_RDLCK;
4843 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4844 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4845 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4847 return -NFS4ERR_DENIED;
4849 print_overflow_msg(__func__, xdr);
4853 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4857 status = decode_op_hdr(xdr, OP_LOCK);
4861 status = decode_stateid(xdr, &res->stateid);
4862 if (unlikely(status))
4864 } else if (status == -NFS4ERR_DENIED)
4865 status = decode_lock_denied(xdr, NULL);
4866 if (res->open_seqid != NULL)
4867 nfs_increment_open_seqid(status, res->open_seqid);
4868 nfs_increment_lock_seqid(status, res->lock_seqid);
4873 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4876 status = decode_op_hdr(xdr, OP_LOCKT);
4877 if (status == -NFS4ERR_DENIED)
4878 return decode_lock_denied(xdr, res->denied);
4882 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4886 status = decode_op_hdr(xdr, OP_LOCKU);
4888 nfs_increment_lock_seqid(status, res->seqid);
4890 status = decode_stateid(xdr, &res->stateid);
4894 static int decode_release_lockowner(struct xdr_stream *xdr)
4896 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4899 static int decode_lookup(struct xdr_stream *xdr)
4901 return decode_op_hdr(xdr, OP_LOOKUP);
4904 /* This is too sick! */
4905 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4908 uint32_t limit_type, nblocks, blocksize;
4910 p = xdr_inline_decode(xdr, 12);
4913 limit_type = be32_to_cpup(p++);
4914 switch (limit_type) {
4916 xdr_decode_hyper(p, maxsize);
4919 nblocks = be32_to_cpup(p++);
4920 blocksize = be32_to_cpup(p);
4921 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4925 print_overflow_msg(__func__, xdr);
4929 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4932 uint32_t delegation_type;
4935 p = xdr_inline_decode(xdr, 4);
4938 delegation_type = be32_to_cpup(p);
4939 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4940 res->delegation_type = 0;
4943 status = decode_stateid(xdr, &res->delegation);
4944 if (unlikely(status))
4946 p = xdr_inline_decode(xdr, 4);
4949 res->do_recall = be32_to_cpup(p);
4951 switch (delegation_type) {
4952 case NFS4_OPEN_DELEGATE_READ:
4953 res->delegation_type = FMODE_READ;
4955 case NFS4_OPEN_DELEGATE_WRITE:
4956 res->delegation_type = FMODE_WRITE|FMODE_READ;
4957 if (decode_space_limit(xdr, &res->maxsize) < 0)
4960 return decode_ace(xdr, NULL, res->server->nfs_client);
4962 print_overflow_msg(__func__, xdr);
4966 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4969 uint32_t savewords, bmlen, i;
4972 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
4974 nfs_increment_open_seqid(status, res->seqid);
4977 status = decode_stateid(xdr, &res->stateid);
4978 if (unlikely(status))
4981 decode_change_info(xdr, &res->cinfo);
4983 p = xdr_inline_decode(xdr, 8);
4986 res->rflags = be32_to_cpup(p++);
4987 bmlen = be32_to_cpup(p);
4991 p = xdr_inline_decode(xdr, bmlen << 2);
4994 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4995 for (i = 0; i < savewords; ++i)
4996 res->attrset[i] = be32_to_cpup(p++);
4997 for (; i < NFS4_BITMAP_SIZE; i++)
4998 res->attrset[i] = 0;
5000 return decode_delegation(xdr, res);
5002 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
5005 print_overflow_msg(__func__, xdr);
5009 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5013 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5015 nfs_increment_open_seqid(status, res->seqid);
5017 status = decode_stateid(xdr, &res->stateid);
5021 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5025 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5027 nfs_increment_open_seqid(status, res->seqid);
5029 status = decode_stateid(xdr, &res->stateid);
5033 static int decode_putfh(struct xdr_stream *xdr)
5035 return decode_op_hdr(xdr, OP_PUTFH);
5038 static int decode_putrootfh(struct xdr_stream *xdr)
5040 return decode_op_hdr(xdr, OP_PUTROOTFH);
5043 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5044 struct nfs_pgio_res *res)
5047 uint32_t count, eof, recvd;
5050 status = decode_op_hdr(xdr, OP_READ);
5053 p = xdr_inline_decode(xdr, 8);
5056 eof = be32_to_cpup(p++);
5057 count = be32_to_cpup(p);
5058 recvd = xdr_read_pages(xdr, count);
5059 if (count > recvd) {
5060 dprintk("NFS: server cheating in read reply: "
5061 "count %u > recvd %u\n", count, recvd);
5069 print_overflow_msg(__func__, xdr);
5073 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5078 status = decode_op_hdr(xdr, OP_READDIR);
5080 status = decode_verifier(xdr, readdir->verifier.data);
5081 if (unlikely(status))
5083 memcpy(verf, readdir->verifier.data, sizeof(verf));
5084 dprintk("%s: verifier = %08x:%08x\n",
5085 __func__, verf[0], verf[1]);
5086 return xdr_read_pages(xdr, xdr->buf->page_len);
5089 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5091 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5096 status = decode_op_hdr(xdr, OP_READLINK);
5100 /* Convert length of symlink */
5101 p = xdr_inline_decode(xdr, 4);
5104 len = be32_to_cpup(p);
5105 if (len >= rcvbuf->page_len || len <= 0) {
5106 dprintk("nfs: server returned giant symlink!\n");
5107 return -ENAMETOOLONG;
5109 recvd = xdr_read_pages(xdr, len);
5111 dprintk("NFS: server cheating in readlink reply: "
5112 "count %u > recvd %u\n", len, recvd);
5116 * The XDR encode routine has set things up so that
5117 * the link text will be copied directly into the
5118 * buffer. We just have to do overflow-checking,
5119 * and and null-terminate the text (the VFS expects
5120 * null-termination).
5122 xdr_terminate_string(rcvbuf, len);
5125 print_overflow_msg(__func__, xdr);
5129 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5133 status = decode_op_hdr(xdr, OP_REMOVE);
5136 status = decode_change_info(xdr, cinfo);
5141 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5142 struct nfs4_change_info *new_cinfo)
5146 status = decode_op_hdr(xdr, OP_RENAME);
5149 if ((status = decode_change_info(xdr, old_cinfo)))
5151 status = decode_change_info(xdr, new_cinfo);
5156 static int decode_renew(struct xdr_stream *xdr)
5158 return decode_op_hdr(xdr, OP_RENEW);
5162 decode_restorefh(struct xdr_stream *xdr)
5164 return decode_op_hdr(xdr, OP_RESTOREFH);
5167 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5168 struct nfs_getaclres *res)
5174 unsigned int pg_offset;
5177 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5180 xdr_enter_page(xdr, xdr->buf->page_len);
5182 /* Calculate the offset of the page data */
5183 pg_offset = xdr->buf->head[0].iov_len;
5185 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5187 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5190 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5192 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5194 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5195 * are stored with the acl data to handle the problem of
5196 * variable length bitmaps.*/
5197 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5198 res->acl_len = attrlen;
5200 /* Check for receive buffer overflow */
5201 if (res->acl_len > (xdr->nwords << 2) ||
5202 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5203 res->acl_flags |= NFS4_ACL_TRUNC;
5204 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5205 attrlen, xdr->nwords << 2);
5208 status = -EOPNOTSUPP;
5215 decode_savefh(struct xdr_stream *xdr)
5217 return decode_op_hdr(xdr, OP_SAVEFH);
5220 static int decode_setattr(struct xdr_stream *xdr)
5226 status = decode_op_hdr(xdr, OP_SETATTR);
5229 p = xdr_inline_decode(xdr, 4);
5232 bmlen = be32_to_cpup(p);
5233 p = xdr_inline_decode(xdr, bmlen << 2);
5237 print_overflow_msg(__func__, xdr);
5241 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5247 p = xdr_inline_decode(xdr, 8);
5250 opnum = be32_to_cpup(p++);
5251 if (opnum != OP_SETCLIENTID) {
5252 dprintk("nfs: decode_setclientid: Server returned operation"
5256 nfserr = be32_to_cpup(p);
5257 if (nfserr == NFS_OK) {
5258 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5261 p = xdr_decode_hyper(p, &res->clientid);
5262 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5263 } else if (nfserr == NFSERR_CLID_INUSE) {
5266 /* skip netid string */
5267 p = xdr_inline_decode(xdr, 4);
5270 len = be32_to_cpup(p);
5271 p = xdr_inline_decode(xdr, len);
5275 /* skip uaddr string */
5276 p = xdr_inline_decode(xdr, 4);
5279 len = be32_to_cpup(p);
5280 p = xdr_inline_decode(xdr, len);
5283 return -NFSERR_CLID_INUSE;
5285 return nfs4_stat_to_errno(nfserr);
5289 print_overflow_msg(__func__, xdr);
5293 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5295 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5298 static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
5303 status = decode_op_hdr(xdr, OP_WRITE);
5307 p = xdr_inline_decode(xdr, 8);
5310 res->count = be32_to_cpup(p++);
5311 res->verf->committed = be32_to_cpup(p++);
5312 return decode_write_verifier(xdr, &res->verf->verifier);
5314 print_overflow_msg(__func__, xdr);
5318 static int decode_delegreturn(struct xdr_stream *xdr)
5320 return decode_op_hdr(xdr, OP_DELEGRETURN);
5323 static int decode_secinfo_gss(struct xdr_stream *xdr,
5324 struct nfs4_secinfo4 *flavor)
5329 p = xdr_inline_decode(xdr, 4);
5332 oid_len = be32_to_cpup(p);
5333 if (oid_len > GSS_OID_MAX_LEN)
5336 p = xdr_inline_decode(xdr, oid_len);
5339 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5340 flavor->flavor_info.oid.len = oid_len;
5342 p = xdr_inline_decode(xdr, 8);
5345 flavor->flavor_info.qop = be32_to_cpup(p++);
5346 flavor->flavor_info.service = be32_to_cpup(p);
5351 print_overflow_msg(__func__, xdr);
5357 static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5359 struct nfs4_secinfo4 *sec_flavor;
5360 unsigned int i, num_flavors;
5364 p = xdr_inline_decode(xdr, 4);
5368 res->flavors->num_flavors = 0;
5369 num_flavors = be32_to_cpup(p);
5371 for (i = 0; i < num_flavors; i++) {
5372 sec_flavor = &res->flavors->flavors[i];
5373 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5376 p = xdr_inline_decode(xdr, 4);
5379 sec_flavor->flavor = be32_to_cpup(p);
5381 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5382 status = decode_secinfo_gss(xdr, sec_flavor);
5386 res->flavors->num_flavors++;
5393 print_overflow_msg(__func__, xdr);
5397 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5399 int status = decode_op_hdr(xdr, OP_SECINFO);
5402 return decode_secinfo_common(xdr, res);
5405 #if defined(CONFIG_NFS_V4_1)
5406 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5408 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5411 return decode_secinfo_common(xdr, res);
5414 static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5417 uint32_t bitmap_words;
5420 p = xdr_inline_decode(xdr, 4);
5421 bitmap_words = be32_to_cpup(p++);
5422 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5424 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5425 for (i = 0; i < bitmap_words; i++)
5426 op_map->u.words[i] = be32_to_cpup(p++);
5431 static int decode_exchange_id(struct xdr_stream *xdr,
5432 struct nfs41_exchange_id_res *res)
5438 uint32_t impl_id_count;
5440 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5444 p = xdr_inline_decode(xdr, 8);
5447 xdr_decode_hyper(p, &res->clientid);
5448 p = xdr_inline_decode(xdr, 12);
5451 res->seqid = be32_to_cpup(p++);
5452 res->flags = be32_to_cpup(p++);
5454 res->state_protect.how = be32_to_cpup(p);
5455 switch (res->state_protect.how) {
5459 status = decode_op_map(xdr, &res->state_protect.enforce);
5462 status = decode_op_map(xdr, &res->state_protect.allow);
5471 /* server_owner4.so_minor_id */
5472 p = xdr_inline_decode(xdr, 8);
5475 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5477 /* server_owner4.so_major_id */
5478 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5479 if (unlikely(status))
5481 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5483 memcpy(res->server_owner->major_id, dummy_str, dummy);
5484 res->server_owner->major_id_sz = dummy;
5487 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5488 if (unlikely(status))
5490 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5492 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5493 res->server_scope->server_scope_sz = dummy;
5495 /* Implementation Id */
5496 p = xdr_inline_decode(xdr, 4);
5499 impl_id_count = be32_to_cpup(p++);
5501 if (impl_id_count) {
5503 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5504 if (unlikely(status))
5506 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5508 memcpy(res->impl_id->domain, dummy_str, dummy);
5511 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5512 if (unlikely(status))
5514 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5516 memcpy(res->impl_id->name, dummy_str, dummy);
5519 p = xdr_inline_decode(xdr, 12);
5522 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5523 res->impl_id->date.nseconds = be32_to_cpup(p);
5525 /* if there's more than one entry, ignore the rest */
5529 print_overflow_msg(__func__, xdr);
5533 static int decode_chan_attrs(struct xdr_stream *xdr,
5534 struct nfs4_channel_attrs *attrs)
5539 p = xdr_inline_decode(xdr, 28);
5542 val = be32_to_cpup(p++); /* headerpadsz */
5544 return -EINVAL; /* no support for header padding yet */
5545 attrs->max_rqst_sz = be32_to_cpup(p++);
5546 attrs->max_resp_sz = be32_to_cpup(p++);
5547 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5548 attrs->max_ops = be32_to_cpup(p++);
5549 attrs->max_reqs = be32_to_cpup(p++);
5550 nr_attrs = be32_to_cpup(p);
5551 if (unlikely(nr_attrs > 1)) {
5552 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5553 "count %u\n", __func__, nr_attrs);
5556 if (nr_attrs == 1) {
5557 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5563 print_overflow_msg(__func__, xdr);
5567 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5569 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5572 static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5573 struct nfs41_bind_conn_to_session_res *res)
5578 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5580 status = decode_sessionid(xdr, &res->session->sess_id);
5581 if (unlikely(status))
5584 /* dir flags, rdma mode bool */
5585 p = xdr_inline_decode(xdr, 8);
5589 res->dir = be32_to_cpup(p++);
5590 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5592 if (be32_to_cpup(p) == 0)
5593 res->use_conn_in_rdma_mode = false;
5595 res->use_conn_in_rdma_mode = true;
5599 print_overflow_msg(__func__, xdr);
5603 static int decode_create_session(struct xdr_stream *xdr,
5604 struct nfs41_create_session_res *res)
5608 struct nfs_client *clp = res->client;
5609 struct nfs4_session *session = clp->cl_session;
5611 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5613 status = decode_sessionid(xdr, &session->sess_id);
5614 if (unlikely(status))
5618 p = xdr_inline_decode(xdr, 8);
5621 clp->cl_seqid = be32_to_cpup(p++);
5622 session->flags = be32_to_cpup(p);
5624 /* Channel attributes */
5625 status = decode_chan_attrs(xdr, &session->fc_attrs);
5627 status = decode_chan_attrs(xdr, &session->bc_attrs);
5630 print_overflow_msg(__func__, xdr);
5634 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5636 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5639 static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5641 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5644 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5646 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5648 #endif /* CONFIG_NFS_V4_1 */
5650 static int decode_sequence(struct xdr_stream *xdr,
5651 struct nfs4_sequence_res *res,
5652 struct rpc_rqst *rqstp)
5654 #if defined(CONFIG_NFS_V4_1)
5655 struct nfs4_session *session;
5656 struct nfs4_sessionid id;
5661 if (res->sr_slot == NULL)
5663 if (!res->sr_slot->table->session)
5666 status = decode_op_hdr(xdr, OP_SEQUENCE);
5668 status = decode_sessionid(xdr, &id);
5669 if (unlikely(status))
5673 * If the server returns different values for sessionID, slotID or
5674 * sequence number, the server is looney tunes.
5676 status = -EREMOTEIO;
5677 session = res->sr_slot->table->session;
5679 if (memcmp(id.data, session->sess_id.data,
5680 NFS4_MAX_SESSIONID_LEN)) {
5681 dprintk("%s Invalid session id\n", __func__);
5685 p = xdr_inline_decode(xdr, 20);
5690 dummy = be32_to_cpup(p++);
5691 if (dummy != res->sr_slot->seq_nr) {
5692 dprintk("%s Invalid sequence number\n", __func__);
5696 dummy = be32_to_cpup(p++);
5697 if (dummy != res->sr_slot->slot_nr) {
5698 dprintk("%s Invalid slot id\n", __func__);
5701 /* highest slot id */
5702 res->sr_highest_slotid = be32_to_cpup(p++);
5703 /* target highest slot id */
5704 res->sr_target_highest_slotid = be32_to_cpup(p++);
5706 res->sr_status_flags = be32_to_cpup(p);
5709 res->sr_status = status;
5712 print_overflow_msg(__func__, xdr);
5715 #else /* CONFIG_NFS_V4_1 */
5717 #endif /* CONFIG_NFS_V4_1 */
5720 #if defined(CONFIG_NFS_V4_1)
5721 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5722 struct pnfs_device *pdev)
5728 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5730 if (status == -ETOOSMALL) {
5731 p = xdr_inline_decode(xdr, 4);
5734 pdev->mincount = be32_to_cpup(p);
5735 dprintk("%s: Min count too small. mincnt = %u\n",
5736 __func__, pdev->mincount);
5741 p = xdr_inline_decode(xdr, 8);
5744 type = be32_to_cpup(p++);
5745 if (type != pdev->layout_type) {
5746 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5747 __func__, pdev->layout_type, type);
5751 * Get the length of the opaque device_addr4. xdr_read_pages places
5752 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5753 * and places the remaining xdr data in xdr_buf->tail
5755 pdev->mincount = be32_to_cpup(p);
5756 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5759 /* Parse notification bitmap, verifying that it is zero. */
5760 p = xdr_inline_decode(xdr, 4);
5763 len = be32_to_cpup(p);
5767 p = xdr_inline_decode(xdr, 4 * len);
5770 for (i = 0; i < len; i++, p++) {
5771 if (be32_to_cpup(p)) {
5772 dprintk("%s: notifications not supported\n",
5780 print_overflow_msg(__func__, xdr);
5784 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5785 struct nfs4_layoutget_res *res)
5792 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5795 p = xdr_inline_decode(xdr, 4);
5798 res->return_on_close = be32_to_cpup(p);
5799 decode_stateid(xdr, &res->stateid);
5800 p = xdr_inline_decode(xdr, 4);
5803 layout_count = be32_to_cpup(p);
5804 if (!layout_count) {
5805 dprintk("%s: server responded with empty layout array\n",
5810 p = xdr_inline_decode(xdr, 28);
5813 p = xdr_decode_hyper(p, &res->range.offset);
5814 p = xdr_decode_hyper(p, &res->range.length);
5815 res->range.iomode = be32_to_cpup(p++);
5816 res->type = be32_to_cpup(p++);
5817 res->layoutp->len = be32_to_cpup(p);
5819 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5821 (unsigned long)res->range.offset,
5822 (unsigned long)res->range.length,
5827 recvd = xdr_read_pages(xdr, res->layoutp->len);
5828 if (res->layoutp->len > recvd) {
5829 dprintk("NFS: server cheating in layoutget reply: "
5830 "layout len %u > recvd %u\n",
5831 res->layoutp->len, recvd);
5835 if (layout_count > 1) {
5836 /* We only handle a length one array at the moment. Any
5837 * further entries are just ignored. Note that this means
5838 * the client may see a response that is less than the
5839 * minimum it requested.
5841 dprintk("%s: server responded with %d layouts, dropping tail\n",
5842 __func__, layout_count);
5847 print_overflow_msg(__func__, xdr);
5851 static int decode_layoutreturn(struct xdr_stream *xdr,
5852 struct nfs4_layoutreturn_res *res)
5857 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5860 p = xdr_inline_decode(xdr, 4);
5863 res->lrs_present = be32_to_cpup(p);
5864 if (res->lrs_present)
5865 status = decode_stateid(xdr, &res->stateid);
5868 print_overflow_msg(__func__, xdr);
5872 static int decode_layoutcommit(struct xdr_stream *xdr,
5873 struct rpc_rqst *req,
5874 struct nfs4_layoutcommit_res *res)
5880 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5881 res->status = status;
5885 p = xdr_inline_decode(xdr, 4);
5888 sizechanged = be32_to_cpup(p);
5891 /* throw away new size */
5892 p = xdr_inline_decode(xdr, 8);
5898 print_overflow_msg(__func__, xdr);
5902 static int decode_test_stateid(struct xdr_stream *xdr,
5903 struct nfs41_test_stateid_res *res)
5909 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5913 p = xdr_inline_decode(xdr, 4);
5916 num_res = be32_to_cpup(p++);
5920 p = xdr_inline_decode(xdr, 4);
5923 res->status = be32_to_cpup(p++);
5927 print_overflow_msg(__func__, xdr);
5932 static int decode_free_stateid(struct xdr_stream *xdr,
5933 struct nfs41_free_stateid_res *res)
5935 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
5938 #endif /* CONFIG_NFS_V4_1 */
5941 * END OF "GENERIC" DECODE ROUTINES.
5945 * Decode OPEN_DOWNGRADE response
5947 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5948 struct xdr_stream *xdr,
5949 struct nfs_closeres *res)
5951 struct compound_hdr hdr;
5954 status = decode_compound_hdr(xdr, &hdr);
5957 status = decode_sequence(xdr, &res->seq_res, rqstp);
5960 status = decode_putfh(xdr);
5963 status = decode_open_downgrade(xdr, res);
5966 decode_getfattr(xdr, res->fattr, res->server);
5972 * Decode ACCESS response
5974 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5975 struct nfs4_accessres *res)
5977 struct compound_hdr hdr;
5980 status = decode_compound_hdr(xdr, &hdr);
5983 status = decode_sequence(xdr, &res->seq_res, rqstp);
5986 status = decode_putfh(xdr);
5989 status = decode_access(xdr, &res->supported, &res->access);
5992 decode_getfattr(xdr, res->fattr, res->server);
5998 * Decode LOOKUP response
6000 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6001 struct nfs4_lookup_res *res)
6003 struct compound_hdr hdr;
6006 status = decode_compound_hdr(xdr, &hdr);
6009 status = decode_sequence(xdr, &res->seq_res, rqstp);
6012 status = decode_putfh(xdr);
6015 status = decode_lookup(xdr);
6018 status = decode_getfh(xdr, res->fh);
6021 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6027 * Decode LOOKUP_ROOT response
6029 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6030 struct xdr_stream *xdr,
6031 struct nfs4_lookup_res *res)
6033 struct compound_hdr hdr;
6036 status = decode_compound_hdr(xdr, &hdr);
6039 status = decode_sequence(xdr, &res->seq_res, rqstp);
6042 status = decode_putrootfh(xdr);
6045 status = decode_getfh(xdr, res->fh);
6047 status = decode_getfattr_label(xdr, res->fattr,
6048 res->label, res->server);
6054 * Decode REMOVE response
6056 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6057 struct nfs_removeres *res)
6059 struct compound_hdr hdr;
6062 status = decode_compound_hdr(xdr, &hdr);
6065 status = decode_sequence(xdr, &res->seq_res, rqstp);
6068 status = decode_putfh(xdr);
6071 status = decode_remove(xdr, &res->cinfo);
6077 * Decode RENAME response
6079 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6080 struct nfs_renameres *res)
6082 struct compound_hdr hdr;
6085 status = decode_compound_hdr(xdr, &hdr);
6088 status = decode_sequence(xdr, &res->seq_res, rqstp);
6091 status = decode_putfh(xdr);
6094 status = decode_savefh(xdr);
6097 status = decode_putfh(xdr);
6100 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
6106 * Decode LINK response
6108 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6109 struct nfs4_link_res *res)
6111 struct compound_hdr hdr;
6114 status = decode_compound_hdr(xdr, &hdr);
6117 status = decode_sequence(xdr, &res->seq_res, rqstp);
6120 status = decode_putfh(xdr);
6123 status = decode_savefh(xdr);
6126 status = decode_putfh(xdr);
6129 status = decode_link(xdr, &res->cinfo);
6133 * Note order: OP_LINK leaves the directory as the current
6136 status = decode_restorefh(xdr);
6139 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6145 * Decode CREATE response
6147 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6148 struct nfs4_create_res *res)
6150 struct compound_hdr hdr;
6153 status = decode_compound_hdr(xdr, &hdr);
6156 status = decode_sequence(xdr, &res->seq_res, rqstp);
6159 status = decode_putfh(xdr);
6162 status = decode_create(xdr, &res->dir_cinfo);
6165 status = decode_getfh(xdr, res->fh);
6168 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6174 * Decode SYMLINK response
6176 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6177 struct nfs4_create_res *res)
6179 return nfs4_xdr_dec_create(rqstp, xdr, res);
6183 * Decode GETATTR response
6185 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6186 struct nfs4_getattr_res *res)
6188 struct compound_hdr hdr;
6191 status = decode_compound_hdr(xdr, &hdr);
6194 status = decode_sequence(xdr, &res->seq_res, rqstp);
6197 status = decode_putfh(xdr);
6200 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6206 * Encode an SETACL request
6208 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6209 struct nfs_setaclargs *args)
6211 struct compound_hdr hdr = {
6212 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6215 encode_compound_hdr(xdr, req, &hdr);
6216 encode_sequence(xdr, &args->seq_args, &hdr);
6217 encode_putfh(xdr, args->fh, &hdr);
6218 encode_setacl(xdr, args, &hdr);
6223 * Decode SETACL response
6226 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6227 struct nfs_setaclres *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_setattr(xdr);
6247 * Decode GETACL response
6250 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6251 struct nfs_getaclres *res)
6253 struct compound_hdr hdr;
6256 if (res->acl_scratch != NULL) {
6257 void *p = page_address(res->acl_scratch);
6258 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6260 status = decode_compound_hdr(xdr, &hdr);
6263 status = decode_sequence(xdr, &res->seq_res, rqstp);
6266 status = decode_putfh(xdr);
6269 status = decode_getacl(xdr, rqstp, res);
6276 * Decode CLOSE response
6278 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6279 struct nfs_closeres *res)
6281 struct compound_hdr hdr;
6284 status = decode_compound_hdr(xdr, &hdr);
6287 status = decode_sequence(xdr, &res->seq_res, rqstp);
6290 status = decode_putfh(xdr);
6293 status = decode_close(xdr, res);
6297 * Note: Server may do delete on close for this file
6298 * in which case the getattr call will fail with
6299 * an ESTALE error. Shouldn't be a problem,
6300 * though, since fattr->valid will remain unset.
6302 decode_getfattr(xdr, res->fattr, res->server);
6308 * Decode OPEN response
6310 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6311 struct nfs_openres *res)
6313 struct compound_hdr hdr;
6316 status = decode_compound_hdr(xdr, &hdr);
6319 status = decode_sequence(xdr, &res->seq_res, rqstp);
6322 status = decode_putfh(xdr);
6325 status = decode_open(xdr, res);
6328 status = decode_getfh(xdr, &res->fh);
6331 if (res->access_request)
6332 decode_access(xdr, &res->access_supported, &res->access_result);
6333 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
6339 * Decode OPEN_CONFIRM response
6341 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6342 struct xdr_stream *xdr,
6343 struct nfs_open_confirmres *res)
6345 struct compound_hdr hdr;
6348 status = decode_compound_hdr(xdr, &hdr);
6351 status = decode_putfh(xdr);
6354 status = decode_open_confirm(xdr, res);
6360 * Decode OPEN response
6362 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6363 struct xdr_stream *xdr,
6364 struct nfs_openres *res)
6366 struct compound_hdr hdr;
6369 status = decode_compound_hdr(xdr, &hdr);
6372 status = decode_sequence(xdr, &res->seq_res, rqstp);
6375 status = decode_putfh(xdr);
6378 status = decode_open(xdr, res);
6381 if (res->access_request)
6382 decode_access(xdr, &res->access_supported, &res->access_result);
6383 decode_getfattr(xdr, res->f_attr, res->server);
6389 * Decode SETATTR response
6391 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6392 struct xdr_stream *xdr,
6393 struct nfs_setattrres *res)
6395 struct compound_hdr hdr;
6398 status = decode_compound_hdr(xdr, &hdr);
6401 status = decode_sequence(xdr, &res->seq_res, rqstp);
6404 status = decode_putfh(xdr);
6407 status = decode_setattr(xdr);
6410 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6416 * Decode LOCK response
6418 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6419 struct nfs_lock_res *res)
6421 struct compound_hdr hdr;
6424 status = decode_compound_hdr(xdr, &hdr);
6427 status = decode_sequence(xdr, &res->seq_res, rqstp);
6430 status = decode_putfh(xdr);
6433 status = decode_lock(xdr, res);
6439 * Decode LOCKT response
6441 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6442 struct nfs_lockt_res *res)
6444 struct compound_hdr hdr;
6447 status = decode_compound_hdr(xdr, &hdr);
6450 status = decode_sequence(xdr, &res->seq_res, rqstp);
6453 status = decode_putfh(xdr);
6456 status = decode_lockt(xdr, res);
6462 * Decode LOCKU response
6464 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6465 struct nfs_locku_res *res)
6467 struct compound_hdr hdr;
6470 status = decode_compound_hdr(xdr, &hdr);
6473 status = decode_sequence(xdr, &res->seq_res, rqstp);
6476 status = decode_putfh(xdr);
6479 status = decode_locku(xdr, res);
6484 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6485 struct xdr_stream *xdr, void *dummy)
6487 struct compound_hdr hdr;
6490 status = decode_compound_hdr(xdr, &hdr);
6492 status = decode_release_lockowner(xdr);
6497 * Decode READLINK response
6499 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6500 struct xdr_stream *xdr,
6501 struct nfs4_readlink_res *res)
6503 struct compound_hdr hdr;
6506 status = decode_compound_hdr(xdr, &hdr);
6509 status = decode_sequence(xdr, &res->seq_res, rqstp);
6512 status = decode_putfh(xdr);
6515 status = decode_readlink(xdr, rqstp);
6521 * Decode READDIR response
6523 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6524 struct nfs4_readdir_res *res)
6526 struct compound_hdr hdr;
6529 status = decode_compound_hdr(xdr, &hdr);
6532 status = decode_sequence(xdr, &res->seq_res, rqstp);
6535 status = decode_putfh(xdr);
6538 status = decode_readdir(xdr, rqstp, res);
6544 * Decode Read response
6546 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6547 struct nfs_pgio_res *res)
6549 struct compound_hdr hdr;
6552 status = decode_compound_hdr(xdr, &hdr);
6555 status = decode_sequence(xdr, &res->seq_res, rqstp);
6558 status = decode_putfh(xdr);
6561 status = decode_read(xdr, rqstp, res);
6563 status = res->count;
6569 * Decode WRITE response
6571 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6572 struct nfs_pgio_res *res)
6574 struct compound_hdr hdr;
6577 status = decode_compound_hdr(xdr, &hdr);
6580 status = decode_sequence(xdr, &res->seq_res, rqstp);
6583 status = decode_putfh(xdr);
6586 status = decode_write(xdr, res);
6590 decode_getfattr(xdr, res->fattr, res->server);
6592 status = res->count;
6598 * Decode COMMIT response
6600 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6601 struct nfs_commitres *res)
6603 struct compound_hdr hdr;
6606 status = decode_compound_hdr(xdr, &hdr);
6609 status = decode_sequence(xdr, &res->seq_res, rqstp);
6612 status = decode_putfh(xdr);
6615 status = decode_commit(xdr, res);
6621 * Decode FSINFO response
6623 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6624 struct nfs4_fsinfo_res *res)
6626 struct compound_hdr hdr;
6629 status = decode_compound_hdr(xdr, &hdr);
6631 status = decode_sequence(xdr, &res->seq_res, req);
6633 status = decode_putfh(xdr);
6635 status = decode_fsinfo(xdr, res->fsinfo);
6640 * Decode PATHCONF response
6642 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6643 struct nfs4_pathconf_res *res)
6645 struct compound_hdr hdr;
6648 status = decode_compound_hdr(xdr, &hdr);
6650 status = decode_sequence(xdr, &res->seq_res, req);
6652 status = decode_putfh(xdr);
6654 status = decode_pathconf(xdr, res->pathconf);
6659 * Decode STATFS response
6661 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6662 struct nfs4_statfs_res *res)
6664 struct compound_hdr hdr;
6667 status = decode_compound_hdr(xdr, &hdr);
6669 status = decode_sequence(xdr, &res->seq_res, req);
6671 status = decode_putfh(xdr);
6673 status = decode_statfs(xdr, res->fsstat);
6678 * Decode GETATTR_BITMAP response
6680 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6681 struct xdr_stream *xdr,
6682 struct nfs4_server_caps_res *res)
6684 struct compound_hdr hdr;
6687 status = decode_compound_hdr(xdr, &hdr);
6690 status = decode_sequence(xdr, &res->seq_res, req);
6693 status = decode_putfh(xdr);
6696 status = decode_server_caps(xdr, res);
6702 * Decode RENEW response
6704 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6707 struct compound_hdr hdr;
6710 status = decode_compound_hdr(xdr, &hdr);
6712 status = decode_renew(xdr);
6717 * Decode SETCLIENTID response
6719 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6720 struct xdr_stream *xdr,
6721 struct nfs4_setclientid_res *res)
6723 struct compound_hdr hdr;
6726 status = decode_compound_hdr(xdr, &hdr);
6728 status = decode_setclientid(xdr, res);
6733 * Decode SETCLIENTID_CONFIRM response
6735 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6736 struct xdr_stream *xdr)
6738 struct compound_hdr hdr;
6741 status = decode_compound_hdr(xdr, &hdr);
6743 status = decode_setclientid_confirm(xdr);
6748 * Decode DELEGRETURN response
6750 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6751 struct xdr_stream *xdr,
6752 struct nfs4_delegreturnres *res)
6754 struct compound_hdr hdr;
6757 status = decode_compound_hdr(xdr, &hdr);
6760 status = decode_sequence(xdr, &res->seq_res, rqstp);
6763 status = decode_putfh(xdr);
6766 status = decode_getfattr(xdr, res->fattr, res->server);
6769 status = decode_delegreturn(xdr);
6775 * Decode FS_LOCATIONS response
6777 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6778 struct xdr_stream *xdr,
6779 struct nfs4_fs_locations_res *res)
6781 struct compound_hdr hdr;
6784 status = decode_compound_hdr(xdr, &hdr);
6787 status = decode_sequence(xdr, &res->seq_res, req);
6790 status = decode_putfh(xdr);
6793 if (res->migration) {
6794 xdr_enter_page(xdr, PAGE_SIZE);
6795 status = decode_getfattr_generic(xdr,
6796 &res->fs_locations->fattr,
6797 NULL, res->fs_locations,
6798 NULL, res->fs_locations->server);
6802 status = decode_renew(xdr);
6804 status = decode_lookup(xdr);
6807 xdr_enter_page(xdr, PAGE_SIZE);
6808 status = decode_getfattr_generic(xdr,
6809 &res->fs_locations->fattr,
6810 NULL, res->fs_locations,
6811 NULL, res->fs_locations->server);
6818 * Decode SECINFO response
6820 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6821 struct xdr_stream *xdr,
6822 struct nfs4_secinfo_res *res)
6824 struct compound_hdr hdr;
6827 status = decode_compound_hdr(xdr, &hdr);
6830 status = decode_sequence(xdr, &res->seq_res, rqstp);
6833 status = decode_putfh(xdr);
6836 status = decode_secinfo(xdr, res);
6842 * Decode FSID_PRESENT response
6844 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6845 struct xdr_stream *xdr,
6846 struct nfs4_fsid_present_res *res)
6848 struct compound_hdr hdr;
6851 status = decode_compound_hdr(xdr, &hdr);
6854 status = decode_sequence(xdr, &res->seq_res, rqstp);
6857 status = decode_putfh(xdr);
6860 status = decode_getfh(xdr, res->fh);
6864 status = decode_renew(xdr);
6869 #if defined(CONFIG_NFS_V4_1)
6871 * Decode BIND_CONN_TO_SESSION response
6873 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6874 struct xdr_stream *xdr,
6877 struct compound_hdr hdr;
6880 status = decode_compound_hdr(xdr, &hdr);
6882 status = decode_bind_conn_to_session(xdr, res);
6887 * Decode EXCHANGE_ID response
6889 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6890 struct xdr_stream *xdr,
6893 struct compound_hdr hdr;
6896 status = decode_compound_hdr(xdr, &hdr);
6898 status = decode_exchange_id(xdr, res);
6903 * Decode CREATE_SESSION response
6905 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6906 struct xdr_stream *xdr,
6907 struct nfs41_create_session_res *res)
6909 struct compound_hdr hdr;
6912 status = decode_compound_hdr(xdr, &hdr);
6914 status = decode_create_session(xdr, res);
6919 * Decode DESTROY_SESSION response
6921 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6922 struct xdr_stream *xdr,
6925 struct compound_hdr hdr;
6928 status = decode_compound_hdr(xdr, &hdr);
6930 status = decode_destroy_session(xdr, res);
6935 * Decode DESTROY_CLIENTID response
6937 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6938 struct xdr_stream *xdr,
6941 struct compound_hdr hdr;
6944 status = decode_compound_hdr(xdr, &hdr);
6946 status = decode_destroy_clientid(xdr, res);
6951 * Decode SEQUENCE response
6953 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6954 struct xdr_stream *xdr,
6955 struct nfs4_sequence_res *res)
6957 struct compound_hdr hdr;
6960 status = decode_compound_hdr(xdr, &hdr);
6962 status = decode_sequence(xdr, res, rqstp);
6967 * Decode GET_LEASE_TIME response
6969 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6970 struct xdr_stream *xdr,
6971 struct nfs4_get_lease_time_res *res)
6973 struct compound_hdr hdr;
6976 status = decode_compound_hdr(xdr, &hdr);
6978 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
6980 status = decode_putrootfh(xdr);
6982 status = decode_fsinfo(xdr, res->lr_fsinfo);
6987 * Decode RECLAIM_COMPLETE response
6989 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6990 struct xdr_stream *xdr,
6991 struct nfs41_reclaim_complete_res *res)
6993 struct compound_hdr hdr;
6996 status = decode_compound_hdr(xdr, &hdr);
6998 status = decode_sequence(xdr, &res->seq_res, rqstp);
7000 status = decode_reclaim_complete(xdr, NULL);
7005 * Decode GETDEVINFO response
7007 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7008 struct xdr_stream *xdr,
7009 struct nfs4_getdeviceinfo_res *res)
7011 struct compound_hdr hdr;
7014 status = decode_compound_hdr(xdr, &hdr);
7017 status = decode_sequence(xdr, &res->seq_res, rqstp);
7020 status = decode_getdeviceinfo(xdr, res->pdev);
7026 * Decode LAYOUTGET response
7028 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7029 struct xdr_stream *xdr,
7030 struct nfs4_layoutget_res *res)
7032 struct compound_hdr hdr;
7035 status = decode_compound_hdr(xdr, &hdr);
7038 status = decode_sequence(xdr, &res->seq_res, rqstp);
7041 status = decode_putfh(xdr);
7044 status = decode_layoutget(xdr, rqstp, res);
7050 * Decode LAYOUTRETURN response
7052 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7053 struct xdr_stream *xdr,
7054 struct nfs4_layoutreturn_res *res)
7056 struct compound_hdr hdr;
7059 status = decode_compound_hdr(xdr, &hdr);
7062 status = decode_sequence(xdr, &res->seq_res, rqstp);
7065 status = decode_putfh(xdr);
7068 status = decode_layoutreturn(xdr, res);
7074 * Decode LAYOUTCOMMIT response
7076 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7077 struct xdr_stream *xdr,
7078 struct nfs4_layoutcommit_res *res)
7080 struct compound_hdr hdr;
7083 status = decode_compound_hdr(xdr, &hdr);
7086 status = decode_sequence(xdr, &res->seq_res, rqstp);
7089 status = decode_putfh(xdr);
7092 status = decode_layoutcommit(xdr, rqstp, res);
7095 decode_getfattr(xdr, res->fattr, res->server);
7101 * Decode SECINFO_NO_NAME response
7103 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7104 struct xdr_stream *xdr,
7105 struct nfs4_secinfo_res *res)
7107 struct compound_hdr hdr;
7110 status = decode_compound_hdr(xdr, &hdr);
7113 status = decode_sequence(xdr, &res->seq_res, rqstp);
7116 status = decode_putrootfh(xdr);
7119 status = decode_secinfo_no_name(xdr, res);
7125 * Decode TEST_STATEID response
7127 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7128 struct xdr_stream *xdr,
7129 struct nfs41_test_stateid_res *res)
7131 struct compound_hdr hdr;
7134 status = decode_compound_hdr(xdr, &hdr);
7137 status = decode_sequence(xdr, &res->seq_res, rqstp);
7140 status = decode_test_stateid(xdr, res);
7146 * Decode FREE_STATEID response
7148 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7149 struct xdr_stream *xdr,
7150 struct nfs41_free_stateid_res *res)
7152 struct compound_hdr hdr;
7155 status = decode_compound_hdr(xdr, &hdr);
7158 status = decode_sequence(xdr, &res->seq_res, rqstp);
7161 status = decode_free_stateid(xdr, res);
7165 #endif /* CONFIG_NFS_V4_1 */
7168 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7169 * the local page cache.
7170 * @xdr: XDR stream where entry resides
7171 * @entry: buffer to fill in with entry data
7172 * @plus: boolean indicating whether this should be a readdirplus entry
7174 * Returns zero if successful, otherwise a negative errno value is
7177 * This function is not invoked during READDIR reply decoding, but
7178 * rather whenever an application invokes the getdents(2) system call
7179 * on a directory already in our cache.
7181 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7185 uint32_t bitmap[3] = {0};
7187 __be32 *p = xdr_inline_decode(xdr, 4);
7190 if (*p == xdr_zero) {
7191 p = xdr_inline_decode(xdr, 4);
7200 p = xdr_inline_decode(xdr, 12);
7203 entry->prev_cookie = entry->cookie;
7204 p = xdr_decode_hyper(p, &entry->cookie);
7205 entry->len = be32_to_cpup(p);
7207 p = xdr_inline_decode(xdr, entry->len);
7210 entry->name = (const char *) p;
7213 * In case the server doesn't return an inode number,
7214 * we fake one here. (We don't use inode number 0,
7215 * since glibc seems to choke on it...)
7218 entry->fattr->valid = 0;
7220 if (decode_attr_bitmap(xdr, bitmap) < 0)
7223 if (decode_attr_length(xdr, &len, &savep) < 0)
7226 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7227 NULL, entry->label, entry->server) < 0)
7229 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7230 entry->ino = entry->fattr->mounted_on_fileid;
7231 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7232 entry->ino = entry->fattr->fileid;
7234 entry->d_type = DT_UNKNOWN;
7235 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7236 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7241 print_overflow_msg(__func__, xdr);
7246 * We need to translate between nfs status return values and
7247 * the local errno values which may not be the same.
7254 { NFS4ERR_PERM, -EPERM },
7255 { NFS4ERR_NOENT, -ENOENT },
7256 { NFS4ERR_IO, -errno_NFSERR_IO},
7257 { NFS4ERR_NXIO, -ENXIO },
7258 { NFS4ERR_ACCESS, -EACCES },
7259 { NFS4ERR_EXIST, -EEXIST },
7260 { NFS4ERR_XDEV, -EXDEV },
7261 { NFS4ERR_NOTDIR, -ENOTDIR },
7262 { NFS4ERR_ISDIR, -EISDIR },
7263 { NFS4ERR_INVAL, -EINVAL },
7264 { NFS4ERR_FBIG, -EFBIG },
7265 { NFS4ERR_NOSPC, -ENOSPC },
7266 { NFS4ERR_ROFS, -EROFS },
7267 { NFS4ERR_MLINK, -EMLINK },
7268 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7269 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7270 { NFS4ERR_DQUOT, -EDQUOT },
7271 { NFS4ERR_STALE, -ESTALE },
7272 { NFS4ERR_BADHANDLE, -EBADHANDLE },
7273 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7274 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7275 { NFS4ERR_TOOSMALL, -ETOOSMALL },
7276 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7277 { NFS4ERR_BADTYPE, -EBADTYPE },
7278 { NFS4ERR_LOCKED, -EAGAIN },
7279 { NFS4ERR_SYMLINK, -ELOOP },
7280 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7281 { NFS4ERR_DEADLOCK, -EDEADLK },
7286 * Convert an NFS error code to a local one.
7287 * This one is used jointly by NFSv2 and NFSv3.
7290 nfs4_stat_to_errno(int stat)
7293 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7294 if (nfs_errtbl[i].stat == stat)
7295 return nfs_errtbl[i].errno;
7297 if (stat <= 10000 || stat > 10100) {
7298 /* The server is looney tunes. */
7301 /* If we cannot translate the error, the recovery routines should
7303 * Note: remaining NFSv4 error codes have values > 10000, so should
7304 * not conflict with native Linux error codes.
7309 #define PROC(proc, argtype, restype) \
7310 [NFSPROC4_CLNT_##proc] = { \
7311 .p_proc = NFSPROC4_COMPOUND, \
7312 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7313 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7314 .p_arglen = NFS4_##argtype##_sz, \
7315 .p_replen = NFS4_##restype##_sz, \
7316 .p_statidx = NFSPROC4_CLNT_##proc, \
7320 struct rpc_procinfo nfs4_procedures[] = {
7321 PROC(READ, enc_read, dec_read),
7322 PROC(WRITE, enc_write, dec_write),
7323 PROC(COMMIT, enc_commit, dec_commit),
7324 PROC(OPEN, enc_open, dec_open),
7325 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7326 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7327 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7328 PROC(CLOSE, enc_close, dec_close),
7329 PROC(SETATTR, enc_setattr, dec_setattr),
7330 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7331 PROC(RENEW, enc_renew, dec_renew),
7332 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7333 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7334 PROC(LOCK, enc_lock, dec_lock),
7335 PROC(LOCKT, enc_lockt, dec_lockt),
7336 PROC(LOCKU, enc_locku, dec_locku),
7337 PROC(ACCESS, enc_access, dec_access),
7338 PROC(GETATTR, enc_getattr, dec_getattr),
7339 PROC(LOOKUP, enc_lookup, dec_lookup),
7340 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7341 PROC(REMOVE, enc_remove, dec_remove),
7342 PROC(RENAME, enc_rename, dec_rename),
7343 PROC(LINK, enc_link, dec_link),
7344 PROC(SYMLINK, enc_symlink, dec_symlink),
7345 PROC(CREATE, enc_create, dec_create),
7346 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7347 PROC(STATFS, enc_statfs, dec_statfs),
7348 PROC(READLINK, enc_readlink, dec_readlink),
7349 PROC(READDIR, enc_readdir, dec_readdir),
7350 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7351 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7352 PROC(GETACL, enc_getacl, dec_getacl),
7353 PROC(SETACL, enc_setacl, dec_setacl),
7354 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7355 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7356 PROC(SECINFO, enc_secinfo, dec_secinfo),
7357 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
7358 #if defined(CONFIG_NFS_V4_1)
7359 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7360 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7361 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7362 PROC(SEQUENCE, enc_sequence, dec_sequence),
7363 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7364 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7365 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7366 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7367 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7368 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7369 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7370 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7371 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7372 PROC(BIND_CONN_TO_SESSION,
7373 enc_bind_conn_to_session, dec_bind_conn_to_session),
7374 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
7375 #endif /* CONFIG_NFS_V4_1 */
7378 const struct rpc_version nfs_version4 = {
7380 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7381 .procs = nfs4_procedures