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 + \
366 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
367 1 /* layout type */ + \
369 1 /* bitmap size */ + \
370 1 /* notification bitmap length */ + \
371 1 /* notification bitmap, word 0 */)
372 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
373 1 /* layout type */ + \
374 1 /* opaque devaddr4 length */ + \
375 /* devaddr4 payload is read into page */ \
376 1 /* notification bitmap length */ + \
377 1 /* notification bitmap, word 0 */)
378 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
379 encode_stateid_maxsz)
380 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
381 decode_stateid_maxsz + \
382 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
383 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
387 encode_stateid_maxsz + \
388 1 /* new offset (true) */ + \
389 2 /* last byte written */ + \
390 1 /* nt_timechanged (false) */ + \
391 1 /* layoutupdate4 layout type */ + \
392 1 /* layoutupdate4 opaqueue len */)
393 /* the actual content of layoutupdate4 should
394 be allocated by drivers and spliced in
395 using xdr_write_pages */
396 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
397 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
398 encode_stateid_maxsz + \
399 1 /* FIXME: opaque lrf_body always empty at the moment */)
400 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
401 1 + decode_stateid_maxsz)
402 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
403 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
404 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
405 XDR_QUADLEN(NFS4_STATEID_SIZE))
406 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
407 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
408 XDR_QUADLEN(NFS4_STATEID_SIZE))
409 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
410 #else /* CONFIG_NFS_V4_1 */
411 #define encode_sequence_maxsz 0
412 #define decode_sequence_maxsz 0
413 #endif /* CONFIG_NFS_V4_1 */
415 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
416 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
417 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
418 encode_sequence_maxsz + \
419 encode_putfh_maxsz + \
421 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
422 decode_sequence_maxsz + \
423 decode_putfh_maxsz + \
425 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
426 encode_sequence_maxsz + \
427 encode_putfh_maxsz + \
428 encode_readlink_maxsz)
429 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
430 decode_sequence_maxsz + \
431 decode_putfh_maxsz + \
432 decode_readlink_maxsz)
433 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
434 encode_sequence_maxsz + \
435 encode_putfh_maxsz + \
436 encode_readdir_maxsz)
437 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
438 decode_sequence_maxsz + \
439 decode_putfh_maxsz + \
440 decode_readdir_maxsz)
441 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
442 encode_sequence_maxsz + \
443 encode_putfh_maxsz + \
444 encode_write_maxsz + \
445 encode_getattr_maxsz)
446 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
447 decode_sequence_maxsz + \
448 decode_putfh_maxsz + \
449 decode_write_maxsz + \
450 decode_getattr_maxsz)
451 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
452 encode_sequence_maxsz + \
453 encode_putfh_maxsz + \
455 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
456 decode_sequence_maxsz + \
457 decode_putfh_maxsz + \
459 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
460 encode_sequence_maxsz + \
461 encode_putfh_maxsz + \
462 encode_open_maxsz + \
463 encode_access_maxsz + \
464 encode_getfh_maxsz + \
465 encode_getattr_maxsz)
466 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
467 decode_sequence_maxsz + \
468 decode_putfh_maxsz + \
469 decode_open_maxsz + \
470 decode_access_maxsz + \
471 decode_getfh_maxsz + \
472 decode_getattr_maxsz)
473 #define NFS4_enc_open_confirm_sz \
474 (compound_encode_hdr_maxsz + \
475 encode_putfh_maxsz + \
476 encode_open_confirm_maxsz)
477 #define NFS4_dec_open_confirm_sz \
478 (compound_decode_hdr_maxsz + \
479 decode_putfh_maxsz + \
480 decode_open_confirm_maxsz)
481 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
482 encode_sequence_maxsz + \
483 encode_putfh_maxsz + \
484 encode_open_maxsz + \
485 encode_access_maxsz + \
486 encode_getattr_maxsz)
487 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
488 decode_sequence_maxsz + \
489 decode_putfh_maxsz + \
490 decode_open_maxsz + \
491 decode_access_maxsz + \
492 decode_getattr_maxsz)
493 #define NFS4_enc_open_downgrade_sz \
494 (compound_encode_hdr_maxsz + \
495 encode_sequence_maxsz + \
496 encode_putfh_maxsz + \
497 encode_open_downgrade_maxsz + \
498 encode_getattr_maxsz)
499 #define NFS4_dec_open_downgrade_sz \
500 (compound_decode_hdr_maxsz + \
501 decode_sequence_maxsz + \
502 decode_putfh_maxsz + \
503 decode_open_downgrade_maxsz + \
504 decode_getattr_maxsz)
505 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
506 encode_sequence_maxsz + \
507 encode_putfh_maxsz + \
508 encode_close_maxsz + \
509 encode_getattr_maxsz)
510 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
511 decode_sequence_maxsz + \
512 decode_putfh_maxsz + \
513 decode_close_maxsz + \
514 decode_getattr_maxsz)
515 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
516 encode_sequence_maxsz + \
517 encode_putfh_maxsz + \
518 encode_setattr_maxsz + \
519 encode_getattr_maxsz)
520 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
521 decode_sequence_maxsz + \
522 decode_putfh_maxsz + \
523 decode_setattr_maxsz + \
524 decode_getattr_maxsz)
525 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
526 encode_sequence_maxsz + \
527 encode_putfh_maxsz + \
529 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
530 decode_sequence_maxsz + \
531 decode_putfh_maxsz + \
533 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
535 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
537 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
538 encode_setclientid_maxsz)
539 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
540 decode_setclientid_maxsz)
541 #define NFS4_enc_setclientid_confirm_sz \
542 (compound_encode_hdr_maxsz + \
543 encode_setclientid_confirm_maxsz)
544 #define NFS4_dec_setclientid_confirm_sz \
545 (compound_decode_hdr_maxsz + \
546 decode_setclientid_confirm_maxsz)
547 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
548 encode_sequence_maxsz + \
549 encode_putfh_maxsz + \
551 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
552 decode_sequence_maxsz + \
553 decode_putfh_maxsz + \
555 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
556 encode_sequence_maxsz + \
557 encode_putfh_maxsz + \
559 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
560 decode_sequence_maxsz + \
561 decode_putfh_maxsz + \
563 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
564 encode_sequence_maxsz + \
565 encode_putfh_maxsz + \
567 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
568 decode_sequence_maxsz + \
569 decode_putfh_maxsz + \
571 #define NFS4_enc_release_lockowner_sz \
572 (compound_encode_hdr_maxsz + \
573 encode_lockowner_maxsz)
574 #define NFS4_dec_release_lockowner_sz \
575 (compound_decode_hdr_maxsz + \
576 decode_lockowner_maxsz)
577 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
578 encode_sequence_maxsz + \
579 encode_putfh_maxsz + \
580 encode_access_maxsz + \
581 encode_getattr_maxsz)
582 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
583 decode_sequence_maxsz + \
584 decode_putfh_maxsz + \
585 decode_access_maxsz + \
586 decode_getattr_maxsz)
587 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
588 encode_sequence_maxsz + \
589 encode_putfh_maxsz + \
590 encode_getattr_maxsz + \
592 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
593 decode_sequence_maxsz + \
594 decode_putfh_maxsz + \
595 decode_getattr_maxsz + \
597 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
598 encode_sequence_maxsz + \
599 encode_putfh_maxsz + \
600 encode_lookup_maxsz + \
601 encode_getattr_maxsz + \
603 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
604 decode_sequence_maxsz + \
605 decode_putfh_maxsz + \
606 decode_lookup_maxsz + \
607 decode_getattr_maxsz + \
609 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
610 encode_sequence_maxsz + \
611 encode_putrootfh_maxsz + \
612 encode_getattr_maxsz + \
614 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
615 decode_sequence_maxsz + \
616 decode_putrootfh_maxsz + \
617 decode_getattr_maxsz + \
619 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
620 encode_sequence_maxsz + \
621 encode_putfh_maxsz + \
623 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
624 decode_sequence_maxsz + \
625 decode_putfh_maxsz + \
627 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
628 encode_sequence_maxsz + \
629 encode_putfh_maxsz + \
630 encode_savefh_maxsz + \
631 encode_putfh_maxsz + \
633 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
634 decode_sequence_maxsz + \
635 decode_putfh_maxsz + \
636 decode_savefh_maxsz + \
637 decode_putfh_maxsz + \
639 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
640 encode_sequence_maxsz + \
641 encode_putfh_maxsz + \
642 encode_savefh_maxsz + \
643 encode_putfh_maxsz + \
644 encode_link_maxsz + \
645 encode_restorefh_maxsz + \
646 encode_getattr_maxsz)
647 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
648 decode_sequence_maxsz + \
649 decode_putfh_maxsz + \
650 decode_savefh_maxsz + \
651 decode_putfh_maxsz + \
652 decode_link_maxsz + \
653 decode_restorefh_maxsz + \
654 decode_getattr_maxsz)
655 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
656 encode_sequence_maxsz + \
657 encode_putfh_maxsz + \
658 encode_symlink_maxsz + \
659 encode_getattr_maxsz + \
661 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
662 decode_sequence_maxsz + \
663 decode_putfh_maxsz + \
664 decode_symlink_maxsz + \
665 decode_getattr_maxsz + \
667 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
668 encode_sequence_maxsz + \
669 encode_putfh_maxsz + \
670 encode_create_maxsz + \
671 encode_getfh_maxsz + \
672 encode_getattr_maxsz)
673 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
674 decode_sequence_maxsz + \
675 decode_putfh_maxsz + \
676 decode_create_maxsz + \
677 decode_getfh_maxsz + \
678 decode_getattr_maxsz)
679 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
680 encode_sequence_maxsz + \
681 encode_putfh_maxsz + \
682 encode_getattr_maxsz)
683 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
684 decode_sequence_maxsz + \
685 decode_putfh_maxsz + \
686 decode_getattr_maxsz)
687 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
688 encode_sequence_maxsz + \
689 encode_putfh_maxsz + \
691 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
692 decode_sequence_maxsz + \
693 decode_putfh_maxsz + \
695 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
696 encode_sequence_maxsz + \
697 encode_putfh_maxsz + \
698 encode_getattr_maxsz)
699 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
700 decode_sequence_maxsz + \
701 decode_putfh_maxsz + \
702 decode_getattr_maxsz)
703 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
704 encode_sequence_maxsz + \
705 encode_putfh_maxsz + \
706 encode_delegreturn_maxsz + \
707 encode_getattr_maxsz)
708 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
709 decode_sequence_maxsz + \
710 decode_delegreturn_maxsz + \
711 decode_getattr_maxsz)
712 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
713 encode_sequence_maxsz + \
714 encode_putfh_maxsz + \
716 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
717 decode_sequence_maxsz + \
718 decode_putfh_maxsz + \
720 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
721 encode_sequence_maxsz + \
722 encode_putfh_maxsz + \
724 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
725 decode_sequence_maxsz + \
726 decode_putfh_maxsz + \
728 #define NFS4_enc_fs_locations_sz \
729 (compound_encode_hdr_maxsz + \
730 encode_sequence_maxsz + \
731 encode_putfh_maxsz + \
732 encode_lookup_maxsz + \
733 encode_fs_locations_maxsz + \
735 #define NFS4_dec_fs_locations_sz \
736 (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_putfh_maxsz + \
739 decode_lookup_maxsz + \
740 decode_fs_locations_maxsz + \
742 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
743 encode_sequence_maxsz + \
744 encode_putfh_maxsz + \
745 encode_secinfo_maxsz)
746 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
747 decode_sequence_maxsz + \
748 decode_putfh_maxsz + \
749 decode_secinfo_maxsz)
750 #define NFS4_enc_fsid_present_sz \
751 (compound_encode_hdr_maxsz + \
752 encode_sequence_maxsz + \
753 encode_putfh_maxsz + \
754 encode_getfh_maxsz + \
756 #define NFS4_dec_fsid_present_sz \
757 (compound_decode_hdr_maxsz + \
758 decode_sequence_maxsz + \
759 decode_putfh_maxsz + \
760 decode_getfh_maxsz + \
762 #if defined(CONFIG_NFS_V4_1)
763 #define NFS4_enc_bind_conn_to_session_sz \
764 (compound_encode_hdr_maxsz + \
765 encode_bind_conn_to_session_maxsz)
766 #define NFS4_dec_bind_conn_to_session_sz \
767 (compound_decode_hdr_maxsz + \
768 decode_bind_conn_to_session_maxsz)
769 #define NFS4_enc_exchange_id_sz \
770 (compound_encode_hdr_maxsz + \
771 encode_exchange_id_maxsz)
772 #define NFS4_dec_exchange_id_sz \
773 (compound_decode_hdr_maxsz + \
774 decode_exchange_id_maxsz)
775 #define NFS4_enc_create_session_sz \
776 (compound_encode_hdr_maxsz + \
777 encode_create_session_maxsz)
778 #define NFS4_dec_create_session_sz \
779 (compound_decode_hdr_maxsz + \
780 decode_create_session_maxsz)
781 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
782 encode_destroy_session_maxsz)
783 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
784 decode_destroy_session_maxsz)
785 #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
786 encode_destroy_clientid_maxsz)
787 #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
788 decode_destroy_clientid_maxsz)
789 #define NFS4_enc_sequence_sz \
790 (compound_decode_hdr_maxsz + \
791 encode_sequence_maxsz)
792 #define NFS4_dec_sequence_sz \
793 (compound_decode_hdr_maxsz + \
794 decode_sequence_maxsz)
795 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
796 encode_sequence_maxsz + \
797 encode_putrootfh_maxsz + \
799 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
800 decode_sequence_maxsz + \
801 decode_putrootfh_maxsz + \
803 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
804 encode_sequence_maxsz + \
805 encode_reclaim_complete_maxsz)
806 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
807 decode_sequence_maxsz + \
808 decode_reclaim_complete_maxsz)
809 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz +\
811 encode_getdeviceinfo_maxsz)
812 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
813 decode_sequence_maxsz + \
814 decode_getdeviceinfo_maxsz)
815 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
816 encode_sequence_maxsz + \
817 encode_putfh_maxsz + \
818 encode_layoutget_maxsz)
819 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
820 decode_sequence_maxsz + \
821 decode_putfh_maxsz + \
822 decode_layoutget_maxsz)
823 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
824 encode_sequence_maxsz +\
825 encode_putfh_maxsz + \
826 encode_layoutcommit_maxsz + \
827 encode_getattr_maxsz)
828 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_putfh_maxsz + \
831 decode_layoutcommit_maxsz + \
832 decode_getattr_maxsz)
833 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
834 encode_sequence_maxsz + \
835 encode_putfh_maxsz + \
836 encode_layoutreturn_maxsz)
837 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
838 decode_sequence_maxsz + \
839 decode_putfh_maxsz + \
840 decode_layoutreturn_maxsz)
841 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
842 encode_sequence_maxsz + \
843 encode_putrootfh_maxsz +\
844 encode_secinfo_no_name_maxsz)
845 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
846 decode_sequence_maxsz + \
847 decode_putrootfh_maxsz + \
848 decode_secinfo_no_name_maxsz)
849 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
850 encode_sequence_maxsz + \
851 encode_test_stateid_maxsz)
852 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
853 decode_sequence_maxsz + \
854 decode_test_stateid_maxsz)
855 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
856 encode_sequence_maxsz + \
857 encode_free_stateid_maxsz)
858 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
859 decode_sequence_maxsz + \
860 decode_free_stateid_maxsz)
862 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
863 compound_encode_hdr_maxsz +
864 encode_sequence_maxsz +
866 encode_getattr_maxsz) *
869 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
870 compound_decode_hdr_maxsz +
871 decode_sequence_maxsz +
872 decode_putfh_maxsz) *
875 const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
876 compound_decode_hdr_maxsz +
877 decode_sequence_maxsz) *
879 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
880 #endif /* CONFIG_NFS_V4_1 */
882 static const umode_t nfs_type2fmt[] = {
889 [NF4SOCK] = S_IFSOCK,
895 struct compound_hdr {
901 uint32_t replen; /* expected reply words */
905 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
907 __be32 *p = xdr_reserve_space(xdr, nbytes);
912 static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
916 p = xdr_reserve_space(xdr, len);
917 xdr_encode_opaque_fixed(p, buf, len);
920 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
924 p = reserve_space(xdr, 4 + len);
925 xdr_encode_opaque(p, str, len);
928 static void encode_uint32(struct xdr_stream *xdr, u32 n)
932 p = reserve_space(xdr, 4);
936 static void encode_uint64(struct xdr_stream *xdr, u64 n)
940 p = reserve_space(xdr, 8);
941 xdr_encode_hyper(p, n);
944 static void encode_nfs4_seqid(struct xdr_stream *xdr,
945 const struct nfs_seqid *seqid)
947 encode_uint32(xdr, seqid->sequence->counter);
950 static void encode_compound_hdr(struct xdr_stream *xdr,
951 struct rpc_rqst *req,
952 struct compound_hdr *hdr)
955 struct rpc_auth *auth = req->rq_cred->cr_auth;
957 /* initialize running count of expected bytes in reply.
958 * NOTE: the replied tag SHOULD be the same is the one sent,
959 * but this is not required as a MUST for the server to do so. */
960 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
962 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
963 encode_string(xdr, hdr->taglen, hdr->tag);
964 p = reserve_space(xdr, 8);
965 *p++ = cpu_to_be32(hdr->minorversion);
967 *p = cpu_to_be32(hdr->nops);
970 static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
972 struct compound_hdr *hdr)
974 encode_uint32(xdr, op);
976 hdr->replen += replen;
979 static void encode_nops(struct compound_hdr *hdr)
981 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
982 *hdr->nops_p = htonl(hdr->nops);
985 static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
987 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
990 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
992 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
995 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
996 const struct nfs4_label *label,
997 const struct nfs_server *server)
999 char owner_name[IDMAP_NAMESZ];
1000 char owner_group[IDMAP_NAMESZ];
1001 int owner_namelen = 0;
1002 int owner_grouplen = 0;
1007 uint32_t bmval[3] = { 0 };
1010 * We reserve enough space to write the entire attribute buffer at once.
1011 * In the worst-case, this would be
1012 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1013 * = 40 bytes, plus any contribution from variable-length fields
1014 * such as owner/group.
1016 if (iap->ia_valid & ATTR_SIZE) {
1017 bmval[0] |= FATTR4_WORD0_SIZE;
1020 if (iap->ia_valid & ATTR_MODE) {
1021 bmval[1] |= FATTR4_WORD1_MODE;
1024 if (iap->ia_valid & ATTR_UID) {
1025 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1026 if (owner_namelen < 0) {
1027 dprintk("nfs: couldn't resolve uid %d to string\n",
1028 from_kuid(&init_user_ns, iap->ia_uid));
1030 strcpy(owner_name, "nobody");
1031 owner_namelen = sizeof("nobody") - 1;
1034 bmval[1] |= FATTR4_WORD1_OWNER;
1035 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1037 if (iap->ia_valid & ATTR_GID) {
1038 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1039 if (owner_grouplen < 0) {
1040 dprintk("nfs: couldn't resolve gid %d to string\n",
1041 from_kgid(&init_user_ns, iap->ia_gid));
1042 strcpy(owner_group, "nobody");
1043 owner_grouplen = sizeof("nobody") - 1;
1046 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1047 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1049 if (iap->ia_valid & ATTR_ATIME_SET) {
1050 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1052 } else if (iap->ia_valid & ATTR_ATIME) {
1053 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1056 if (iap->ia_valid & ATTR_MTIME_SET) {
1057 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1059 } else if (iap->ia_valid & ATTR_MTIME) {
1060 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1064 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1065 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1070 else if (bmval[1] != 0)
1075 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1077 *p++ = cpu_to_be32(bmval_len);
1078 for (i = 0; i < bmval_len; i++)
1079 *p++ = cpu_to_be32(bmval[i]);
1080 *p++ = cpu_to_be32(len);
1082 if (bmval[0] & FATTR4_WORD0_SIZE)
1083 p = xdr_encode_hyper(p, iap->ia_size);
1084 if (bmval[1] & FATTR4_WORD1_MODE)
1085 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1086 if (bmval[1] & FATTR4_WORD1_OWNER)
1087 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1088 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1089 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1090 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1091 if (iap->ia_valid & ATTR_ATIME_SET) {
1092 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1093 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1094 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1096 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1098 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1099 if (iap->ia_valid & ATTR_MTIME_SET) {
1100 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1101 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1102 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1104 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1106 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1107 *p++ = cpu_to_be32(label->lfs);
1108 *p++ = cpu_to_be32(label->pi);
1109 *p++ = cpu_to_be32(label->len);
1110 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1116 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1118 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1119 encode_uint32(xdr, access);
1122 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1124 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1125 encode_nfs4_seqid(xdr, arg->seqid);
1126 encode_nfs4_stateid(xdr, arg->stateid);
1129 static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1133 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1134 p = reserve_space(xdr, 12);
1135 p = xdr_encode_hyper(p, args->offset);
1136 *p = cpu_to_be32(args->count);
1139 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1143 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1144 encode_uint32(xdr, create->ftype);
1146 switch (create->ftype) {
1148 p = reserve_space(xdr, 4);
1149 *p = cpu_to_be32(create->u.symlink.len);
1150 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1153 case NF4BLK: case NF4CHR:
1154 p = reserve_space(xdr, 8);
1155 *p++ = cpu_to_be32(create->u.device.specdata1);
1156 *p = cpu_to_be32(create->u.device.specdata2);
1163 encode_string(xdr, create->name->len, create->name->name);
1164 encode_attrs(xdr, create->attrs, create->label, create->server);
1167 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1171 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1172 p = reserve_space(xdr, 8);
1173 *p++ = cpu_to_be32(1);
1174 *p = cpu_to_be32(bitmap);
1177 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1181 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1182 p = reserve_space(xdr, 12);
1183 *p++ = cpu_to_be32(2);
1184 *p++ = cpu_to_be32(bm0);
1185 *p = cpu_to_be32(bm1);
1189 encode_getattr_three(struct xdr_stream *xdr,
1190 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1191 struct compound_hdr *hdr)
1195 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1197 p = reserve_space(xdr, 16);
1198 *p++ = cpu_to_be32(3);
1199 *p++ = cpu_to_be32(bm0);
1200 *p++ = cpu_to_be32(bm1);
1201 *p = cpu_to_be32(bm2);
1203 p = reserve_space(xdr, 12);
1204 *p++ = cpu_to_be32(2);
1205 *p++ = cpu_to_be32(bm0);
1206 *p = cpu_to_be32(bm1);
1208 p = reserve_space(xdr, 8);
1209 *p++ = cpu_to_be32(1);
1210 *p = cpu_to_be32(bm0);
1214 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1216 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1217 bitmask[1] & nfs4_fattr_bitmap[1],
1218 bitmask[2] & nfs4_fattr_bitmap[2],
1222 static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1223 const u32 *open_bitmap,
1224 struct compound_hdr *hdr)
1226 encode_getattr_three(xdr,
1227 bitmask[0] & open_bitmap[0],
1228 bitmask[1] & open_bitmap[1],
1229 bitmask[2] & open_bitmap[2],
1233 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1235 encode_getattr_three(xdr,
1236 bitmask[0] & nfs4_fsinfo_bitmap[0],
1237 bitmask[1] & nfs4_fsinfo_bitmap[1],
1238 bitmask[2] & nfs4_fsinfo_bitmap[2],
1242 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1244 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1245 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1248 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1250 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1253 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1255 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1256 encode_string(xdr, name->len, name->name);
1259 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1261 if (fl->fl_type == F_RDLCK)
1262 return block ? NFS4_READW_LT : NFS4_READ_LT;
1263 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1266 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1268 if (fl->fl_end == OFFSET_MAX)
1269 return ~(uint64_t)0;
1270 return fl->fl_end - fl->fl_start + 1;
1273 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1277 p = reserve_space(xdr, 32);
1278 p = xdr_encode_hyper(p, lowner->clientid);
1279 *p++ = cpu_to_be32(20);
1280 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1281 *p++ = cpu_to_be32(lowner->s_dev);
1282 xdr_encode_hyper(p, lowner->id);
1286 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1287 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1289 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1293 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1294 p = reserve_space(xdr, 28);
1295 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1296 *p++ = cpu_to_be32(args->reclaim);
1297 p = xdr_encode_hyper(p, args->fl->fl_start);
1298 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1299 *p = cpu_to_be32(args->new_lock_owner);
1300 if (args->new_lock_owner){
1301 encode_nfs4_seqid(xdr, args->open_seqid);
1302 encode_nfs4_stateid(xdr, args->open_stateid);
1303 encode_nfs4_seqid(xdr, args->lock_seqid);
1304 encode_lockowner(xdr, &args->lock_owner);
1307 encode_nfs4_stateid(xdr, args->lock_stateid);
1308 encode_nfs4_seqid(xdr, args->lock_seqid);
1312 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1316 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1317 p = reserve_space(xdr, 20);
1318 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1319 p = xdr_encode_hyper(p, args->fl->fl_start);
1320 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1321 encode_lockowner(xdr, &args->lock_owner);
1324 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1328 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1329 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1330 encode_nfs4_seqid(xdr, args->seqid);
1331 encode_nfs4_stateid(xdr, args->stateid);
1332 p = reserve_space(xdr, 16);
1333 p = xdr_encode_hyper(p, args->fl->fl_start);
1334 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1337 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1339 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1340 encode_lockowner(xdr, lowner);
1343 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1345 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1346 encode_string(xdr, name->len, name->name);
1349 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1353 p = reserve_space(xdr, 8);
1354 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1356 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1359 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1361 case FMODE_READ|FMODE_WRITE:
1362 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1365 *p++ = cpu_to_be32(0);
1367 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1370 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1374 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1377 encode_nfs4_seqid(xdr, arg->seqid);
1378 encode_share_access(xdr, arg->fmode);
1379 p = reserve_space(xdr, 36);
1380 p = xdr_encode_hyper(p, arg->clientid);
1381 *p++ = cpu_to_be32(24);
1382 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1383 *p++ = cpu_to_be32(arg->server->s_dev);
1384 *p++ = cpu_to_be32(arg->id.uniquifier);
1385 xdr_encode_hyper(p, arg->id.create_time);
1388 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1393 p = reserve_space(xdr, 4);
1394 switch(arg->createmode) {
1395 case NFS4_CREATE_UNCHECKED:
1396 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1397 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
1399 case NFS4_CREATE_GUARDED:
1400 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1401 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
1403 case NFS4_CREATE_EXCLUSIVE:
1404 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1405 encode_nfs4_verifier(xdr, &arg->u.verifier);
1407 case NFS4_CREATE_EXCLUSIVE4_1:
1408 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1409 encode_nfs4_verifier(xdr, &arg->u.verifier);
1411 encode_attrs(xdr, &dummy, arg->label, arg->server);
1415 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1419 p = reserve_space(xdr, 4);
1420 switch (arg->open_flags & O_CREAT) {
1422 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1425 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1426 encode_createmode(xdr, arg);
1430 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1434 p = reserve_space(xdr, 4);
1435 switch (delegation_type) {
1437 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1440 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1442 case FMODE_WRITE|FMODE_READ:
1443 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1450 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1454 p = reserve_space(xdr, 4);
1455 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1456 encode_string(xdr, name->len, name->name);
1459 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1463 p = reserve_space(xdr, 4);
1464 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1465 encode_delegation_type(xdr, type);
1468 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1472 p = reserve_space(xdr, 4);
1473 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1474 encode_nfs4_stateid(xdr, stateid);
1475 encode_string(xdr, name->len, name->name);
1478 static inline void encode_claim_fh(struct xdr_stream *xdr)
1482 p = reserve_space(xdr, 4);
1483 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1486 static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1490 p = reserve_space(xdr, 4);
1491 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1492 encode_nfs4_stateid(xdr, stateid);
1495 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1497 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1498 encode_openhdr(xdr, arg);
1499 encode_opentype(xdr, arg);
1500 switch (arg->claim) {
1501 case NFS4_OPEN_CLAIM_NULL:
1502 encode_claim_null(xdr, arg->name);
1504 case NFS4_OPEN_CLAIM_PREVIOUS:
1505 encode_claim_previous(xdr, arg->u.delegation_type);
1507 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1508 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1510 case NFS4_OPEN_CLAIM_FH:
1511 encode_claim_fh(xdr);
1513 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1514 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1521 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1523 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1524 encode_nfs4_stateid(xdr, arg->stateid);
1525 encode_nfs4_seqid(xdr, arg->seqid);
1528 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1530 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1531 encode_nfs4_stateid(xdr, arg->stateid);
1532 encode_nfs4_seqid(xdr, arg->seqid);
1533 encode_share_access(xdr, arg->fmode);
1537 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1539 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1540 encode_string(xdr, fh->size, fh->data);
1543 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1545 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1548 static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1549 struct compound_hdr *hdr)
1553 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1554 encode_nfs4_stateid(xdr, &args->stateid);
1556 p = reserve_space(xdr, 12);
1557 p = xdr_encode_hyper(p, args->offset);
1558 *p = cpu_to_be32(args->count);
1561 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1563 uint32_t attrs[3] = {
1564 FATTR4_WORD0_RDATTR_ERROR,
1565 FATTR4_WORD1_MOUNTED_ON_FILEID,
1567 uint32_t dircount = readdir->count >> 1;
1569 uint32_t attrlen = 0;
1572 if (readdir->plus) {
1573 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1574 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1575 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1576 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1577 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1578 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1579 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1582 /* Use mounted_on_fileid only if the server supports it */
1583 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1584 attrs[0] |= FATTR4_WORD0_FILEID;
1585 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1586 attrs[i] &= readdir->bitmask[i];
1591 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1592 encode_uint64(xdr, readdir->cookie);
1593 encode_nfs4_verifier(xdr, &readdir->verifier);
1594 p = reserve_space(xdr, 12 + (attrlen << 2));
1595 *p++ = cpu_to_be32(dircount);
1596 *p++ = cpu_to_be32(readdir->count);
1597 *p++ = cpu_to_be32(attrlen);
1598 for (i = 0; i < attrlen; i++)
1599 *p++ = cpu_to_be32(attrs[i]);
1600 memcpy(verf, readdir->verifier.data, sizeof(verf));
1602 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1604 (unsigned long long)readdir->cookie,
1606 attrs[0] & readdir->bitmask[0],
1607 attrs[1] & readdir->bitmask[1],
1608 attrs[2] & readdir->bitmask[2]);
1611 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1613 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1616 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1618 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1619 encode_string(xdr, name->len, name->name);
1622 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1624 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1625 encode_string(xdr, oldname->len, oldname->name);
1626 encode_string(xdr, newname->len, newname->name);
1629 static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1630 struct compound_hdr *hdr)
1632 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1633 encode_uint64(xdr, clid);
1637 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1639 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1643 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1647 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1648 encode_nfs4_stateid(xdr, &zero_stateid);
1649 p = reserve_space(xdr, 2*4);
1650 *p++ = cpu_to_be32(1);
1651 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1652 p = reserve_space(xdr, 4);
1653 *p = cpu_to_be32(arg->acl_len);
1654 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1658 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1660 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1663 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1665 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1666 encode_nfs4_stateid(xdr, &arg->stateid);
1667 encode_attrs(xdr, arg->iap, arg->label, server);
1670 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1674 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1675 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1677 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1678 p = reserve_space(xdr, 4);
1679 *p = cpu_to_be32(setclientid->sc_prog);
1680 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1681 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1682 p = reserve_space(xdr, 4);
1683 *p = cpu_to_be32(setclientid->sc_cb_ident);
1686 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1688 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1689 decode_setclientid_confirm_maxsz, hdr);
1690 encode_uint64(xdr, arg->clientid);
1691 encode_nfs4_verifier(xdr, &arg->confirm);
1694 static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1695 struct compound_hdr *hdr)
1699 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1700 encode_nfs4_stateid(xdr, &args->stateid);
1702 p = reserve_space(xdr, 16);
1703 p = xdr_encode_hyper(p, args->offset);
1704 *p++ = cpu_to_be32(args->stable);
1705 *p = cpu_to_be32(args->count);
1707 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1710 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1712 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1713 encode_nfs4_stateid(xdr, stateid);
1716 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1718 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1719 encode_string(xdr, name->len, name->name);
1722 #if defined(CONFIG_NFS_V4_1)
1723 /* NFSv4.1 operations */
1724 static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1725 struct nfs4_session *session,
1726 struct compound_hdr *hdr)
1730 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1731 decode_bind_conn_to_session_maxsz, hdr);
1732 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1733 p = xdr_reserve_space(xdr, 8);
1734 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1735 *p = 0; /* use_conn_in_rdma_mode = False */
1738 static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1741 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1742 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1743 encode_uint32(xdr, op_map->u.words[i]);
1746 static void encode_exchange_id(struct xdr_stream *xdr,
1747 struct nfs41_exchange_id_args *args,
1748 struct compound_hdr *hdr)
1751 char impl_name[IMPL_NAME_LIMIT];
1754 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1755 encode_nfs4_verifier(xdr, args->verifier);
1757 encode_string(xdr, args->id_len, args->id);
1759 encode_uint32(xdr, args->flags);
1760 encode_uint32(xdr, args->state_protect.how);
1762 switch (args->state_protect.how) {
1766 encode_op_map(xdr, &args->state_protect.enforce);
1767 encode_op_map(xdr, &args->state_protect.allow);
1774 if (send_implementation_id &&
1775 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1776 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1777 <= sizeof(impl_name) + 1)
1778 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1779 utsname()->sysname, utsname()->release,
1780 utsname()->version, utsname()->machine);
1783 encode_uint32(xdr, 1); /* implementation id array length=1 */
1786 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1787 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1788 encode_string(xdr, len, impl_name);
1789 /* just send zeros for nii_date - the date is in nii_name */
1790 p = reserve_space(xdr, 12);
1791 p = xdr_encode_hyper(p, 0);
1792 *p = cpu_to_be32(0);
1794 encode_uint32(xdr, 0); /* implementation id array length=0 */
1797 static void encode_create_session(struct xdr_stream *xdr,
1798 struct nfs41_create_session_args *args,
1799 struct compound_hdr *hdr)
1802 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1804 struct nfs_client *clp = args->client;
1805 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1806 u32 max_resp_sz_cached;
1809 * Assumes OPEN is the biggest non-idempotent compound.
1810 * 2 is the verifier.
1812 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1813 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1815 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1818 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1819 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
1820 p = xdr_encode_hyper(p, clp->cl_clientid);
1821 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1822 *p++ = cpu_to_be32(args->flags); /*flags */
1825 *p++ = cpu_to_be32(0); /* header padding size */
1826 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1827 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1828 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1829 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1830 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1831 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1834 *p++ = cpu_to_be32(0); /* header padding size */
1835 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1836 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1837 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1838 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1839 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1840 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1842 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1843 *p++ = cpu_to_be32(1);
1844 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1846 /* authsys_parms rfc1831 */
1847 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
1848 p = xdr_encode_opaque(p, machine_name, len);
1849 *p++ = cpu_to_be32(0); /* UID */
1850 *p++ = cpu_to_be32(0); /* GID */
1851 *p = cpu_to_be32(0); /* No more gids */
1854 static void encode_destroy_session(struct xdr_stream *xdr,
1855 struct nfs4_session *session,
1856 struct compound_hdr *hdr)
1858 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1859 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1862 static void encode_destroy_clientid(struct xdr_stream *xdr,
1864 struct compound_hdr *hdr)
1866 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1867 encode_uint64(xdr, clientid);
1870 static void encode_reclaim_complete(struct xdr_stream *xdr,
1871 struct nfs41_reclaim_complete_args *args,
1872 struct compound_hdr *hdr)
1874 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1875 encode_uint32(xdr, args->one_fs);
1877 #endif /* CONFIG_NFS_V4_1 */
1879 static void encode_sequence(struct xdr_stream *xdr,
1880 const struct nfs4_sequence_args *args,
1881 struct compound_hdr *hdr)
1883 #if defined(CONFIG_NFS_V4_1)
1884 struct nfs4_session *session;
1885 struct nfs4_slot_table *tp;
1886 struct nfs4_slot *slot = args->sa_slot;
1890 session = tp->session;
1894 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1897 * Sessionid + seqid + slotid + max slotid + cache_this
1899 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1900 "max_slotid=%d cache_this=%d\n",
1902 ((u32 *)session->sess_id.data)[0],
1903 ((u32 *)session->sess_id.data)[1],
1904 ((u32 *)session->sess_id.data)[2],
1905 ((u32 *)session->sess_id.data)[3],
1906 slot->seq_nr, slot->slot_nr,
1907 tp->highest_used_slotid, args->sa_cache_this);
1908 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1909 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1910 *p++ = cpu_to_be32(slot->seq_nr);
1911 *p++ = cpu_to_be32(slot->slot_nr);
1912 *p++ = cpu_to_be32(tp->highest_used_slotid);
1913 *p = cpu_to_be32(args->sa_cache_this);
1914 #endif /* CONFIG_NFS_V4_1 */
1917 #ifdef CONFIG_NFS_V4_1
1919 encode_getdeviceinfo(struct xdr_stream *xdr,
1920 const struct nfs4_getdeviceinfo_args *args,
1921 struct compound_hdr *hdr)
1925 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1926 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1927 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1928 NFS4_DEVICEID4_SIZE);
1929 *p++ = cpu_to_be32(args->pdev->layout_type);
1930 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
1932 p = reserve_space(xdr, 4 + 4);
1933 *p++ = cpu_to_be32(1); /* bitmap length */
1934 *p++ = cpu_to_be32(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE);
1938 encode_layoutget(struct xdr_stream *xdr,
1939 const struct nfs4_layoutget_args *args,
1940 struct compound_hdr *hdr)
1944 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1945 p = reserve_space(xdr, 36);
1946 *p++ = cpu_to_be32(0); /* Signal layout available */
1947 *p++ = cpu_to_be32(args->type);
1948 *p++ = cpu_to_be32(args->range.iomode);
1949 p = xdr_encode_hyper(p, args->range.offset);
1950 p = xdr_encode_hyper(p, args->range.length);
1951 p = xdr_encode_hyper(p, args->minlength);
1952 encode_nfs4_stateid(xdr, &args->stateid);
1953 encode_uint32(xdr, args->maxcount);
1955 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1959 (unsigned long)args->range.offset,
1960 (unsigned long)args->range.length,
1965 encode_layoutcommit(struct xdr_stream *xdr,
1966 struct inode *inode,
1967 struct nfs4_layoutcommit_args *args,
1968 struct compound_hdr *hdr)
1972 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1973 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1975 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1976 p = reserve_space(xdr, 20);
1977 /* Only whole file layouts */
1978 p = xdr_encode_hyper(p, 0); /* offset */
1979 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1980 *p = cpu_to_be32(0); /* reclaim */
1981 encode_nfs4_stateid(xdr, &args->stateid);
1982 p = reserve_space(xdr, 20);
1983 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1984 p = xdr_encode_hyper(p, args->lastbytewritten);
1985 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1986 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1988 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
1989 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1990 NFS_I(inode)->layout, xdr, args);
1992 encode_uint32(xdr, args->layoutupdate_len);
1993 if (args->layoutupdate_pages) {
1994 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1995 args->layoutupdate_len);
2003 encode_layoutreturn(struct xdr_stream *xdr,
2004 const struct nfs4_layoutreturn_args *args,
2005 struct compound_hdr *hdr)
2009 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2010 p = reserve_space(xdr, 16);
2011 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2012 *p++ = cpu_to_be32(args->layout_type);
2013 *p++ = cpu_to_be32(IOMODE_ANY);
2014 *p = cpu_to_be32(RETURN_FILE);
2015 p = reserve_space(xdr, 16);
2016 p = xdr_encode_hyper(p, 0);
2017 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2018 spin_lock(&args->inode->i_lock);
2019 encode_nfs4_stateid(xdr, &args->stateid);
2020 spin_unlock(&args->inode->i_lock);
2021 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2022 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2023 NFS_I(args->inode)->layout, xdr, args);
2025 encode_uint32(xdr, 0);
2029 encode_secinfo_no_name(struct xdr_stream *xdr,
2030 const struct nfs41_secinfo_no_name_args *args,
2031 struct compound_hdr *hdr)
2033 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2034 encode_uint32(xdr, args->style);
2038 static void encode_test_stateid(struct xdr_stream *xdr,
2039 struct nfs41_test_stateid_args *args,
2040 struct compound_hdr *hdr)
2042 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2043 encode_uint32(xdr, 1);
2044 encode_nfs4_stateid(xdr, args->stateid);
2047 static void encode_free_stateid(struct xdr_stream *xdr,
2048 struct nfs41_free_stateid_args *args,
2049 struct compound_hdr *hdr)
2051 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2052 encode_nfs4_stateid(xdr, &args->stateid);
2054 #endif /* CONFIG_NFS_V4_1 */
2057 * END OF "GENERIC" ENCODE ROUTINES.
2060 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2062 #if defined(CONFIG_NFS_V4_1)
2063 struct nfs4_session *session = args->sa_slot->table->session;
2065 return session->clp->cl_mvops->minor_version;
2066 #endif /* CONFIG_NFS_V4_1 */
2071 * Encode an ACCESS request
2073 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2074 const struct nfs4_accessargs *args)
2076 struct compound_hdr hdr = {
2077 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2080 encode_compound_hdr(xdr, req, &hdr);
2081 encode_sequence(xdr, &args->seq_args, &hdr);
2082 encode_putfh(xdr, args->fh, &hdr);
2083 encode_access(xdr, args->access, &hdr);
2084 encode_getfattr(xdr, args->bitmask, &hdr);
2089 * Encode LOOKUP request
2091 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2092 const struct nfs4_lookup_arg *args)
2094 struct compound_hdr hdr = {
2095 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2098 encode_compound_hdr(xdr, req, &hdr);
2099 encode_sequence(xdr, &args->seq_args, &hdr);
2100 encode_putfh(xdr, args->dir_fh, &hdr);
2101 encode_lookup(xdr, args->name, &hdr);
2102 encode_getfh(xdr, &hdr);
2103 encode_getfattr(xdr, args->bitmask, &hdr);
2108 * Encode LOOKUP_ROOT request
2110 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2111 struct xdr_stream *xdr,
2112 const struct nfs4_lookup_root_arg *args)
2114 struct compound_hdr hdr = {
2115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2118 encode_compound_hdr(xdr, req, &hdr);
2119 encode_sequence(xdr, &args->seq_args, &hdr);
2120 encode_putrootfh(xdr, &hdr);
2121 encode_getfh(xdr, &hdr);
2122 encode_getfattr(xdr, args->bitmask, &hdr);
2127 * Encode REMOVE request
2129 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2130 const struct nfs_removeargs *args)
2132 struct compound_hdr hdr = {
2133 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2136 encode_compound_hdr(xdr, req, &hdr);
2137 encode_sequence(xdr, &args->seq_args, &hdr);
2138 encode_putfh(xdr, args->fh, &hdr);
2139 encode_remove(xdr, &args->name, &hdr);
2144 * Encode RENAME request
2146 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2147 const struct nfs_renameargs *args)
2149 struct compound_hdr hdr = {
2150 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2153 encode_compound_hdr(xdr, req, &hdr);
2154 encode_sequence(xdr, &args->seq_args, &hdr);
2155 encode_putfh(xdr, args->old_dir, &hdr);
2156 encode_savefh(xdr, &hdr);
2157 encode_putfh(xdr, args->new_dir, &hdr);
2158 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2163 * Encode LINK request
2165 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2166 const struct nfs4_link_arg *args)
2168 struct compound_hdr hdr = {
2169 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2172 encode_compound_hdr(xdr, req, &hdr);
2173 encode_sequence(xdr, &args->seq_args, &hdr);
2174 encode_putfh(xdr, args->fh, &hdr);
2175 encode_savefh(xdr, &hdr);
2176 encode_putfh(xdr, args->dir_fh, &hdr);
2177 encode_link(xdr, args->name, &hdr);
2178 encode_restorefh(xdr, &hdr);
2179 encode_getfattr(xdr, args->bitmask, &hdr);
2184 * Encode CREATE request
2186 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2187 const struct nfs4_create_arg *args)
2189 struct compound_hdr hdr = {
2190 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2193 encode_compound_hdr(xdr, req, &hdr);
2194 encode_sequence(xdr, &args->seq_args, &hdr);
2195 encode_putfh(xdr, args->dir_fh, &hdr);
2196 encode_create(xdr, args, &hdr);
2197 encode_getfh(xdr, &hdr);
2198 encode_getfattr(xdr, args->bitmask, &hdr);
2203 * Encode SYMLINK request
2205 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2206 const struct nfs4_create_arg *args)
2208 nfs4_xdr_enc_create(req, xdr, args);
2212 * Encode GETATTR request
2214 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2215 const struct nfs4_getattr_arg *args)
2217 struct compound_hdr hdr = {
2218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2221 encode_compound_hdr(xdr, req, &hdr);
2222 encode_sequence(xdr, &args->seq_args, &hdr);
2223 encode_putfh(xdr, args->fh, &hdr);
2224 encode_getfattr(xdr, args->bitmask, &hdr);
2229 * Encode a CLOSE request
2231 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2232 struct nfs_closeargs *args)
2234 struct compound_hdr hdr = {
2235 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2238 encode_compound_hdr(xdr, req, &hdr);
2239 encode_sequence(xdr, &args->seq_args, &hdr);
2240 encode_putfh(xdr, args->fh, &hdr);
2241 encode_close(xdr, args, &hdr);
2242 encode_getfattr(xdr, args->bitmask, &hdr);
2247 * Encode an OPEN request
2249 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2250 struct nfs_openargs *args)
2252 struct compound_hdr hdr = {
2253 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2256 encode_compound_hdr(xdr, req, &hdr);
2257 encode_sequence(xdr, &args->seq_args, &hdr);
2258 encode_putfh(xdr, args->fh, &hdr);
2259 encode_open(xdr, args, &hdr);
2260 encode_getfh(xdr, &hdr);
2262 encode_access(xdr, args->access, &hdr);
2263 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2268 * Encode an OPEN_CONFIRM request
2270 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2271 struct xdr_stream *xdr,
2272 struct nfs_open_confirmargs *args)
2274 struct compound_hdr hdr = {
2278 encode_compound_hdr(xdr, req, &hdr);
2279 encode_putfh(xdr, args->fh, &hdr);
2280 encode_open_confirm(xdr, args, &hdr);
2285 * Encode an OPEN request with no attributes.
2287 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2288 struct xdr_stream *xdr,
2289 struct nfs_openargs *args)
2291 struct compound_hdr hdr = {
2292 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2295 encode_compound_hdr(xdr, req, &hdr);
2296 encode_sequence(xdr, &args->seq_args, &hdr);
2297 encode_putfh(xdr, args->fh, &hdr);
2298 encode_open(xdr, args, &hdr);
2300 encode_access(xdr, args->access, &hdr);
2301 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2306 * Encode an OPEN_DOWNGRADE request
2308 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2309 struct xdr_stream *xdr,
2310 struct nfs_closeargs *args)
2312 struct compound_hdr hdr = {
2313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_sequence(xdr, &args->seq_args, &hdr);
2318 encode_putfh(xdr, args->fh, &hdr);
2319 encode_open_downgrade(xdr, args, &hdr);
2320 encode_getfattr(xdr, args->bitmask, &hdr);
2325 * Encode a LOCK request
2327 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 struct nfs_lock_args *args)
2330 struct compound_hdr hdr = {
2331 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2334 encode_compound_hdr(xdr, req, &hdr);
2335 encode_sequence(xdr, &args->seq_args, &hdr);
2336 encode_putfh(xdr, args->fh, &hdr);
2337 encode_lock(xdr, args, &hdr);
2342 * Encode a LOCKT request
2344 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2345 struct nfs_lockt_args *args)
2347 struct compound_hdr hdr = {
2348 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2351 encode_compound_hdr(xdr, req, &hdr);
2352 encode_sequence(xdr, &args->seq_args, &hdr);
2353 encode_putfh(xdr, args->fh, &hdr);
2354 encode_lockt(xdr, args, &hdr);
2359 * Encode a LOCKU request
2361 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2362 struct nfs_locku_args *args)
2364 struct compound_hdr hdr = {
2365 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2368 encode_compound_hdr(xdr, req, &hdr);
2369 encode_sequence(xdr, &args->seq_args, &hdr);
2370 encode_putfh(xdr, args->fh, &hdr);
2371 encode_locku(xdr, args, &hdr);
2375 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2376 struct xdr_stream *xdr,
2377 struct nfs_release_lockowner_args *args)
2379 struct compound_hdr hdr = {
2383 encode_compound_hdr(xdr, req, &hdr);
2384 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2389 * Encode a READLINK request
2391 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2392 const struct nfs4_readlink *args)
2394 struct compound_hdr hdr = {
2395 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2398 encode_compound_hdr(xdr, req, &hdr);
2399 encode_sequence(xdr, &args->seq_args, &hdr);
2400 encode_putfh(xdr, args->fh, &hdr);
2401 encode_readlink(xdr, args, req, &hdr);
2403 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2404 args->pgbase, args->pglen);
2409 * Encode a READDIR request
2411 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2412 const struct nfs4_readdir_arg *args)
2414 struct compound_hdr hdr = {
2415 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2418 encode_compound_hdr(xdr, req, &hdr);
2419 encode_sequence(xdr, &args->seq_args, &hdr);
2420 encode_putfh(xdr, args->fh, &hdr);
2421 encode_readdir(xdr, args, req, &hdr);
2423 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2424 args->pgbase, args->count);
2425 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2426 __func__, hdr.replen << 2, args->pages,
2427 args->pgbase, args->count);
2432 * Encode a READ request
2434 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2435 struct nfs_pgio_args *args)
2437 struct compound_hdr hdr = {
2438 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2441 encode_compound_hdr(xdr, req, &hdr);
2442 encode_sequence(xdr, &args->seq_args, &hdr);
2443 encode_putfh(xdr, args->fh, &hdr);
2444 encode_read(xdr, args, &hdr);
2446 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2447 args->pages, args->pgbase, args->count);
2448 req->rq_rcv_buf.flags |= XDRBUF_READ;
2453 * Encode an SETATTR request
2455 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2456 struct nfs_setattrargs *args)
2458 struct compound_hdr hdr = {
2459 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2462 encode_compound_hdr(xdr, req, &hdr);
2463 encode_sequence(xdr, &args->seq_args, &hdr);
2464 encode_putfh(xdr, args->fh, &hdr);
2465 encode_setattr(xdr, args, args->server, &hdr);
2466 encode_getfattr(xdr, args->bitmask, &hdr);
2471 * Encode a GETACL request
2473 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2474 struct nfs_getaclargs *args)
2476 struct compound_hdr hdr = {
2477 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2481 encode_compound_hdr(xdr, req, &hdr);
2482 encode_sequence(xdr, &args->seq_args, &hdr);
2483 encode_putfh(xdr, args->fh, &hdr);
2484 replen = hdr.replen + op_decode_hdr_maxsz + 1;
2485 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2487 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2488 args->acl_pages, args->acl_pgbase, args->acl_len);
2494 * Encode a WRITE request
2496 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2497 struct nfs_pgio_args *args)
2499 struct compound_hdr hdr = {
2500 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2503 encode_compound_hdr(xdr, req, &hdr);
2504 encode_sequence(xdr, &args->seq_args, &hdr);
2505 encode_putfh(xdr, args->fh, &hdr);
2506 encode_write(xdr, args, &hdr);
2507 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2509 encode_getfattr(xdr, args->bitmask, &hdr);
2516 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2517 struct nfs_commitargs *args)
2519 struct compound_hdr hdr = {
2520 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2523 encode_compound_hdr(xdr, req, &hdr);
2524 encode_sequence(xdr, &args->seq_args, &hdr);
2525 encode_putfh(xdr, args->fh, &hdr);
2526 encode_commit(xdr, args, &hdr);
2533 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2534 struct nfs4_fsinfo_arg *args)
2536 struct compound_hdr hdr = {
2537 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2540 encode_compound_hdr(xdr, req, &hdr);
2541 encode_sequence(xdr, &args->seq_args, &hdr);
2542 encode_putfh(xdr, args->fh, &hdr);
2543 encode_fsinfo(xdr, args->bitmask, &hdr);
2548 * a PATHCONF request
2550 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2551 const struct nfs4_pathconf_arg *args)
2553 struct compound_hdr hdr = {
2554 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2557 encode_compound_hdr(xdr, req, &hdr);
2558 encode_sequence(xdr, &args->seq_args, &hdr);
2559 encode_putfh(xdr, args->fh, &hdr);
2560 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2568 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2569 const struct nfs4_statfs_arg *args)
2571 struct compound_hdr hdr = {
2572 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2575 encode_compound_hdr(xdr, req, &hdr);
2576 encode_sequence(xdr, &args->seq_args, &hdr);
2577 encode_putfh(xdr, args->fh, &hdr);
2578 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2579 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2584 * GETATTR_BITMAP request
2586 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2587 struct xdr_stream *xdr,
2588 struct nfs4_server_caps_arg *args)
2590 struct compound_hdr hdr = {
2591 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2594 encode_compound_hdr(xdr, req, &hdr);
2595 encode_sequence(xdr, &args->seq_args, &hdr);
2596 encode_putfh(xdr, args->fhandle, &hdr);
2597 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2598 FATTR4_WORD0_FH_EXPIRE_TYPE|
2599 FATTR4_WORD0_LINK_SUPPORT|
2600 FATTR4_WORD0_SYMLINK_SUPPORT|
2601 FATTR4_WORD0_ACLSUPPORT, &hdr);
2608 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2609 struct nfs_client *clp)
2611 struct compound_hdr hdr = {
2615 encode_compound_hdr(xdr, req, &hdr);
2616 encode_renew(xdr, clp->cl_clientid, &hdr);
2621 * a SETCLIENTID request
2623 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2624 struct xdr_stream *xdr,
2625 struct nfs4_setclientid *sc)
2627 struct compound_hdr hdr = {
2631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_setclientid(xdr, sc, &hdr);
2637 * a SETCLIENTID_CONFIRM request
2639 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2640 struct xdr_stream *xdr,
2641 struct nfs4_setclientid_res *arg)
2643 struct compound_hdr hdr = {
2647 encode_compound_hdr(xdr, req, &hdr);
2648 encode_setclientid_confirm(xdr, arg, &hdr);
2653 * DELEGRETURN request
2655 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2656 struct xdr_stream *xdr,
2657 const struct nfs4_delegreturnargs *args)
2659 struct compound_hdr hdr = {
2660 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2663 encode_compound_hdr(xdr, req, &hdr);
2664 encode_sequence(xdr, &args->seq_args, &hdr);
2665 encode_putfh(xdr, args->fhandle, &hdr);
2666 encode_getfattr(xdr, args->bitmask, &hdr);
2667 encode_delegreturn(xdr, args->stateid, &hdr);
2672 * Encode FS_LOCATIONS request
2674 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2675 struct xdr_stream *xdr,
2676 struct nfs4_fs_locations_arg *args)
2678 struct compound_hdr hdr = {
2679 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2683 encode_compound_hdr(xdr, req, &hdr);
2684 encode_sequence(xdr, &args->seq_args, &hdr);
2685 if (args->migration) {
2686 encode_putfh(xdr, args->fh, &hdr);
2687 replen = hdr.replen;
2688 encode_fs_locations(xdr, args->bitmask, &hdr);
2690 encode_renew(xdr, args->clientid, &hdr);
2692 encode_putfh(xdr, args->dir_fh, &hdr);
2693 encode_lookup(xdr, args->name, &hdr);
2694 replen = hdr.replen;
2695 encode_fs_locations(xdr, args->bitmask, &hdr);
2698 /* Set up reply kvec to capture returned fs_locations array. */
2699 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2705 * Encode SECINFO request
2707 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2708 struct xdr_stream *xdr,
2709 struct nfs4_secinfo_arg *args)
2711 struct compound_hdr hdr = {
2712 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2715 encode_compound_hdr(xdr, req, &hdr);
2716 encode_sequence(xdr, &args->seq_args, &hdr);
2717 encode_putfh(xdr, args->dir_fh, &hdr);
2718 encode_secinfo(xdr, args->name, &hdr);
2723 * Encode FSID_PRESENT request
2725 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2726 struct xdr_stream *xdr,
2727 struct nfs4_fsid_present_arg *args)
2729 struct compound_hdr hdr = {
2730 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2733 encode_compound_hdr(xdr, req, &hdr);
2734 encode_sequence(xdr, &args->seq_args, &hdr);
2735 encode_putfh(xdr, args->fh, &hdr);
2736 encode_getfh(xdr, &hdr);
2738 encode_renew(xdr, args->clientid, &hdr);
2742 #if defined(CONFIG_NFS_V4_1)
2744 * BIND_CONN_TO_SESSION request
2746 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2747 struct xdr_stream *xdr,
2748 struct nfs_client *clp)
2750 struct compound_hdr hdr = {
2751 .minorversion = clp->cl_mvops->minor_version,
2754 encode_compound_hdr(xdr, req, &hdr);
2755 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2760 * EXCHANGE_ID request
2762 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2763 struct xdr_stream *xdr,
2764 struct nfs41_exchange_id_args *args)
2766 struct compound_hdr hdr = {
2767 .minorversion = args->client->cl_mvops->minor_version,
2770 encode_compound_hdr(xdr, req, &hdr);
2771 encode_exchange_id(xdr, args, &hdr);
2776 * a CREATE_SESSION request
2778 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2779 struct xdr_stream *xdr,
2780 struct nfs41_create_session_args *args)
2782 struct compound_hdr hdr = {
2783 .minorversion = args->client->cl_mvops->minor_version,
2786 encode_compound_hdr(xdr, req, &hdr);
2787 encode_create_session(xdr, args, &hdr);
2792 * a DESTROY_SESSION request
2794 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2795 struct xdr_stream *xdr,
2796 struct nfs4_session *session)
2798 struct compound_hdr hdr = {
2799 .minorversion = session->clp->cl_mvops->minor_version,
2802 encode_compound_hdr(xdr, req, &hdr);
2803 encode_destroy_session(xdr, session, &hdr);
2808 * a DESTROY_CLIENTID request
2810 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2811 struct xdr_stream *xdr,
2812 struct nfs_client *clp)
2814 struct compound_hdr hdr = {
2815 .minorversion = clp->cl_mvops->minor_version,
2818 encode_compound_hdr(xdr, req, &hdr);
2819 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2824 * a SEQUENCE request
2826 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2827 struct nfs4_sequence_args *args)
2829 struct compound_hdr hdr = {
2830 .minorversion = nfs4_xdr_minorversion(args),
2833 encode_compound_hdr(xdr, req, &hdr);
2834 encode_sequence(xdr, args, &hdr);
2839 * a GET_LEASE_TIME request
2841 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2842 struct xdr_stream *xdr,
2843 struct nfs4_get_lease_time_args *args)
2845 struct compound_hdr hdr = {
2846 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2848 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2850 encode_compound_hdr(xdr, req, &hdr);
2851 encode_sequence(xdr, &args->la_seq_args, &hdr);
2852 encode_putrootfh(xdr, &hdr);
2853 encode_fsinfo(xdr, lease_bitmap, &hdr);
2858 * a RECLAIM_COMPLETE request
2860 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2861 struct xdr_stream *xdr,
2862 struct nfs41_reclaim_complete_args *args)
2864 struct compound_hdr hdr = {
2865 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2868 encode_compound_hdr(xdr, req, &hdr);
2869 encode_sequence(xdr, &args->seq_args, &hdr);
2870 encode_reclaim_complete(xdr, args, &hdr);
2875 * Encode GETDEVICEINFO request
2877 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2878 struct xdr_stream *xdr,
2879 struct nfs4_getdeviceinfo_args *args)
2881 struct compound_hdr hdr = {
2882 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2885 encode_compound_hdr(xdr, req, &hdr);
2886 encode_sequence(xdr, &args->seq_args, &hdr);
2887 encode_getdeviceinfo(xdr, args, &hdr);
2889 /* set up reply kvec. Subtract notification bitmap max size (2)
2890 * so that notification bitmap is put in xdr_buf tail */
2891 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2892 args->pdev->pages, args->pdev->pgbase,
2899 * Encode LAYOUTGET request
2901 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2902 struct xdr_stream *xdr,
2903 struct nfs4_layoutget_args *args)
2905 struct compound_hdr hdr = {
2906 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2909 encode_compound_hdr(xdr, req, &hdr);
2910 encode_sequence(xdr, &args->seq_args, &hdr);
2911 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2912 encode_layoutget(xdr, args, &hdr);
2914 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2915 args->layout.pages, 0, args->layout.pglen);
2921 * Encode LAYOUTCOMMIT request
2923 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2924 struct xdr_stream *xdr,
2925 struct nfs4_layoutcommit_args *args)
2927 struct nfs4_layoutcommit_data *data =
2928 container_of(args, struct nfs4_layoutcommit_data, args);
2929 struct compound_hdr hdr = {
2930 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2933 encode_compound_hdr(xdr, req, &hdr);
2934 encode_sequence(xdr, &args->seq_args, &hdr);
2935 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2936 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2937 encode_getfattr(xdr, args->bitmask, &hdr);
2942 * Encode LAYOUTRETURN request
2944 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2945 struct xdr_stream *xdr,
2946 struct nfs4_layoutreturn_args *args)
2948 struct compound_hdr hdr = {
2949 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2952 encode_compound_hdr(xdr, req, &hdr);
2953 encode_sequence(xdr, &args->seq_args, &hdr);
2954 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2955 encode_layoutreturn(xdr, args, &hdr);
2960 * Encode SECINFO_NO_NAME request
2962 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2963 struct xdr_stream *xdr,
2964 struct nfs41_secinfo_no_name_args *args)
2966 struct compound_hdr hdr = {
2967 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2970 encode_compound_hdr(xdr, req, &hdr);
2971 encode_sequence(xdr, &args->seq_args, &hdr);
2972 encode_putrootfh(xdr, &hdr);
2973 encode_secinfo_no_name(xdr, args, &hdr);
2979 * Encode TEST_STATEID request
2981 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2982 struct xdr_stream *xdr,
2983 struct nfs41_test_stateid_args *args)
2985 struct compound_hdr hdr = {
2986 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2989 encode_compound_hdr(xdr, req, &hdr);
2990 encode_sequence(xdr, &args->seq_args, &hdr);
2991 encode_test_stateid(xdr, args, &hdr);
2996 * Encode FREE_STATEID request
2998 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2999 struct xdr_stream *xdr,
3000 struct nfs41_free_stateid_args *args)
3002 struct compound_hdr hdr = {
3003 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3006 encode_compound_hdr(xdr, req, &hdr);
3007 encode_sequence(xdr, &args->seq_args, &hdr);
3008 encode_free_stateid(xdr, args, &hdr);
3011 #endif /* CONFIG_NFS_V4_1 */
3013 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3015 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3016 "Remaining buffer length is %tu words.\n",
3017 func, xdr->end - xdr->p);
3020 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3024 p = xdr_inline_decode(xdr, 4);
3027 *len = be32_to_cpup(p);
3028 p = xdr_inline_decode(xdr, *len);
3031 *string = (char *)p;
3034 print_overflow_msg(__func__, xdr);
3038 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3042 p = xdr_inline_decode(xdr, 8);
3045 hdr->status = be32_to_cpup(p++);
3046 hdr->taglen = be32_to_cpup(p);
3048 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3051 hdr->tag = (char *)p;
3052 p += XDR_QUADLEN(hdr->taglen);
3053 hdr->nops = be32_to_cpup(p);
3054 if (unlikely(hdr->nops < 1))
3055 return nfs4_stat_to_errno(hdr->status);
3058 print_overflow_msg(__func__, xdr);
3062 static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3069 p = xdr_inline_decode(xdr, 8);
3072 opnum = be32_to_cpup(p++);
3073 if (unlikely(opnum != expected))
3074 goto out_bad_operation;
3075 nfserr = be32_to_cpup(p);
3076 if (nfserr == NFS_OK)
3079 *nfs_retval = nfs4_stat_to_errno(nfserr);
3082 dprintk("nfs: Server returned operation"
3083 " %d but we issued a request for %d\n",
3085 *nfs_retval = -EREMOTEIO;
3088 print_overflow_msg(__func__, xdr);
3093 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3097 __decode_op_hdr(xdr, expected, &retval);
3102 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
3105 unsigned int strlen;
3108 p = xdr_inline_decode(xdr, 12);
3110 return decode_opaque_inline(xdr, &strlen, &str);
3111 print_overflow_msg(__func__, xdr);
3115 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3120 p = xdr_inline_decode(xdr, 4);
3123 bmlen = be32_to_cpup(p);
3125 bitmap[0] = bitmap[1] = bitmap[2] = 0;
3126 p = xdr_inline_decode(xdr, (bmlen << 2));
3130 bitmap[0] = be32_to_cpup(p++);
3132 bitmap[1] = be32_to_cpup(p++);
3134 bitmap[2] = be32_to_cpup(p);
3139 print_overflow_msg(__func__, xdr);
3143 static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
3147 p = xdr_inline_decode(xdr, 4);
3150 *attrlen = be32_to_cpup(p);
3151 *savep = xdr_stream_pos(xdr);
3154 print_overflow_msg(__func__, xdr);
3158 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3160 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3162 ret = decode_attr_bitmap(xdr, bitmask);
3163 if (unlikely(ret < 0))
3165 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3167 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3168 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3169 bitmask[0], bitmask[1], bitmask[2]);
3173 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3179 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3181 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3182 p = xdr_inline_decode(xdr, 4);
3185 *type = be32_to_cpup(p);
3186 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3187 dprintk("%s: bad type %d\n", __func__, *type);
3190 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3191 ret = NFS_ATTR_FATTR_TYPE;
3193 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3196 print_overflow_msg(__func__, xdr);
3200 static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3201 uint32_t *bitmap, uint32_t *type)
3206 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3208 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3209 p = xdr_inline_decode(xdr, 4);
3212 *type = be32_to_cpup(p);
3213 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3215 dprintk("%s: expire type=0x%x\n", __func__, *type);
3218 print_overflow_msg(__func__, xdr);
3222 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3228 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3230 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3231 p = xdr_inline_decode(xdr, 8);
3234 xdr_decode_hyper(p, change);
3235 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3236 ret = NFS_ATTR_FATTR_CHANGE;
3238 dprintk("%s: change attribute=%Lu\n", __func__,
3239 (unsigned long long)*change);
3242 print_overflow_msg(__func__, xdr);
3246 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3252 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3254 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3255 p = xdr_inline_decode(xdr, 8);
3258 xdr_decode_hyper(p, size);
3259 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3260 ret = NFS_ATTR_FATTR_SIZE;
3262 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3265 print_overflow_msg(__func__, xdr);
3269 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3274 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3276 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3277 p = xdr_inline_decode(xdr, 4);
3280 *res = be32_to_cpup(p);
3281 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3283 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3286 print_overflow_msg(__func__, xdr);
3290 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3295 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3297 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3298 p = xdr_inline_decode(xdr, 4);
3301 *res = be32_to_cpup(p);
3302 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3304 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3307 print_overflow_msg(__func__, xdr);
3311 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3318 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3320 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3321 p = xdr_inline_decode(xdr, 16);
3324 p = xdr_decode_hyper(p, &fsid->major);
3325 xdr_decode_hyper(p, &fsid->minor);
3326 bitmap[0] &= ~FATTR4_WORD0_FSID;
3327 ret = NFS_ATTR_FATTR_FSID;
3329 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3330 (unsigned long long)fsid->major,
3331 (unsigned long long)fsid->minor);
3334 print_overflow_msg(__func__, xdr);
3338 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3343 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3345 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3346 p = xdr_inline_decode(xdr, 4);
3349 *res = be32_to_cpup(p);
3350 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3352 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3355 print_overflow_msg(__func__, xdr);
3359 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3363 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3365 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3366 p = xdr_inline_decode(xdr, 4);
3369 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3370 *res = -be32_to_cpup(p);
3374 print_overflow_msg(__func__, xdr);
3378 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3384 memset(fh, 0, sizeof(*fh));
3386 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3388 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3389 p = xdr_inline_decode(xdr, 4);
3392 len = be32_to_cpup(p);
3393 if (len > NFS4_FHSIZE)
3395 p = xdr_inline_decode(xdr, len);
3399 memcpy(fh->data, p, len);
3402 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3406 print_overflow_msg(__func__, xdr);
3410 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3415 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3417 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3418 p = xdr_inline_decode(xdr, 4);
3421 *res = be32_to_cpup(p);
3422 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3424 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3427 print_overflow_msg(__func__, xdr);
3431 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3437 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3439 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3440 p = xdr_inline_decode(xdr, 8);
3443 xdr_decode_hyper(p, fileid);
3444 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3445 ret = NFS_ATTR_FATTR_FILEID;
3447 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3450 print_overflow_msg(__func__, xdr);
3454 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3460 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3462 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3463 p = xdr_inline_decode(xdr, 8);
3466 xdr_decode_hyper(p, fileid);
3467 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3468 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3470 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3473 print_overflow_msg(__func__, xdr);
3477 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3483 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3485 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3486 p = xdr_inline_decode(xdr, 8);
3489 xdr_decode_hyper(p, res);
3490 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3492 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3495 print_overflow_msg(__func__, xdr);
3499 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3505 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3507 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3508 p = xdr_inline_decode(xdr, 8);
3511 xdr_decode_hyper(p, res);
3512 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3514 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3517 print_overflow_msg(__func__, xdr);
3521 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3527 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3529 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3530 p = xdr_inline_decode(xdr, 8);
3533 xdr_decode_hyper(p, res);
3534 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3536 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3539 print_overflow_msg(__func__, xdr);
3543 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3549 p = xdr_inline_decode(xdr, 4);
3552 n = be32_to_cpup(p);
3555 dprintk("pathname4: ");
3556 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3557 dprintk("cannot parse %d components in path\n", n);
3560 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
3561 struct nfs4_string *component = &path->components[path->ncomponents];
3562 status = decode_opaque_inline(xdr, &component->len, &component->data);
3563 if (unlikely(status != 0))
3567 (path->ncomponents != n ? "/ " : ""),
3568 component->len, component->data);
3573 /* a root pathname is sent as a zero component4 */
3574 path->ncomponents = 1;
3575 path->components[0].len=0;
3576 path->components[0].data=NULL;
3577 dprintk("pathname4: /\n");
3580 dprintk(" status %d", status);
3584 print_overflow_msg(__func__, xdr);
3588 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3594 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3597 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3600 /* Ignore borken servers that return unrequested attrs */
3601 if (unlikely(res == NULL))
3603 dprintk("%s: fsroot:\n", __func__);
3604 status = decode_pathname(xdr, &res->fs_path);
3605 if (unlikely(status != 0))
3607 p = xdr_inline_decode(xdr, 4);
3610 n = be32_to_cpup(p);
3613 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3615 struct nfs4_fs_location *loc;
3617 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3619 loc = &res->locations[res->nlocations];
3620 p = xdr_inline_decode(xdr, 4);
3623 m = be32_to_cpup(p);
3625 dprintk("%s: servers:\n", __func__);
3626 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3627 struct nfs4_string *server;
3629 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3631 dprintk("%s: using first %u of %u servers "
3632 "returned for location %u\n",
3634 NFS4_FS_LOCATION_MAXSERVERS,
3635 m, res->nlocations);
3636 for (i = loc->nservers; i < m; i++) {
3639 status = decode_opaque_inline(xdr, &len, &data);
3640 if (unlikely(status != 0))
3645 server = &loc->servers[loc->nservers];
3646 status = decode_opaque_inline(xdr, &server->len, &server->data);
3647 if (unlikely(status != 0))
3649 dprintk("%s ", server->data);
3651 status = decode_pathname(xdr, &loc->rootpath);
3652 if (unlikely(status != 0))
3655 if (res->nlocations != 0)
3656 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3658 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3661 print_overflow_msg(__func__, xdr);
3667 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3673 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3675 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3676 p = xdr_inline_decode(xdr, 8);
3679 xdr_decode_hyper(p, res);
3680 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3682 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3685 print_overflow_msg(__func__, xdr);
3689 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3695 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3697 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3698 p = xdr_inline_decode(xdr, 4);
3701 *maxlink = be32_to_cpup(p);
3702 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3704 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3707 print_overflow_msg(__func__, xdr);
3711 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3717 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3719 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3720 p = xdr_inline_decode(xdr, 4);
3723 *maxname = be32_to_cpup(p);
3724 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3726 dprintk("%s: maxname=%u\n", __func__, *maxname);
3729 print_overflow_msg(__func__, xdr);
3733 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3739 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3741 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3743 p = xdr_inline_decode(xdr, 8);
3746 xdr_decode_hyper(p, &maxread);
3747 if (maxread > 0x7FFFFFFF)
3748 maxread = 0x7FFFFFFF;
3749 *res = (uint32_t)maxread;
3750 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3752 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3755 print_overflow_msg(__func__, xdr);
3759 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3765 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3767 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3769 p = xdr_inline_decode(xdr, 8);
3772 xdr_decode_hyper(p, &maxwrite);
3773 if (maxwrite > 0x7FFFFFFF)
3774 maxwrite = 0x7FFFFFFF;
3775 *res = (uint32_t)maxwrite;
3776 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3778 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3781 print_overflow_msg(__func__, xdr);
3785 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3792 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3794 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3795 p = xdr_inline_decode(xdr, 4);
3798 tmp = be32_to_cpup(p);
3799 *mode = tmp & ~S_IFMT;
3800 bitmap[1] &= ~FATTR4_WORD1_MODE;
3801 ret = NFS_ATTR_FATTR_MODE;
3803 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3806 print_overflow_msg(__func__, xdr);
3810 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3816 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3818 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3819 p = xdr_inline_decode(xdr, 4);
3822 *nlink = be32_to_cpup(p);
3823 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3824 ret = NFS_ATTR_FATTR_NLINK;
3826 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3829 print_overflow_msg(__func__, xdr);
3833 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3834 const struct nfs_server *server, kuid_t *uid,
3835 struct nfs4_string *owner_name)
3841 *uid = make_kuid(&init_user_ns, -2);
3842 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3844 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3845 p = xdr_inline_decode(xdr, 4);
3848 len = be32_to_cpup(p);
3849 p = xdr_inline_decode(xdr, len);
3852 if (owner_name != NULL) {
3853 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3854 if (owner_name->data != NULL) {
3855 owner_name->len = len;
3856 ret = NFS_ATTR_FATTR_OWNER_NAME;
3858 } else if (len < XDR_MAX_NETOBJ) {
3859 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3860 ret = NFS_ATTR_FATTR_OWNER;
3862 dprintk("%s: nfs_map_name_to_uid failed!\n",
3865 dprintk("%s: name too long (%u)!\n",
3867 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3869 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3872 print_overflow_msg(__func__, xdr);
3876 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3877 const struct nfs_server *server, kgid_t *gid,
3878 struct nfs4_string *group_name)
3884 *gid = make_kgid(&init_user_ns, -2);
3885 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3887 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3888 p = xdr_inline_decode(xdr, 4);
3891 len = be32_to_cpup(p);
3892 p = xdr_inline_decode(xdr, len);
3895 if (group_name != NULL) {
3896 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3897 if (group_name->data != NULL) {
3898 group_name->len = len;
3899 ret = NFS_ATTR_FATTR_GROUP_NAME;
3901 } else if (len < XDR_MAX_NETOBJ) {
3902 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3903 ret = NFS_ATTR_FATTR_GROUP;
3905 dprintk("%s: nfs_map_group_to_gid failed!\n",
3908 dprintk("%s: name too long (%u)!\n",
3910 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3912 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3915 print_overflow_msg(__func__, xdr);
3919 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3921 uint32_t major = 0, minor = 0;
3926 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3928 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3931 p = xdr_inline_decode(xdr, 8);
3934 major = be32_to_cpup(p++);
3935 minor = be32_to_cpup(p);
3936 tmp = MKDEV(major, minor);
3937 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3939 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3940 ret = NFS_ATTR_FATTR_RDEV;
3942 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3945 print_overflow_msg(__func__, xdr);
3949 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3955 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3957 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3958 p = xdr_inline_decode(xdr, 8);
3961 xdr_decode_hyper(p, res);
3962 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3964 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3967 print_overflow_msg(__func__, xdr);
3971 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3977 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3979 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3980 p = xdr_inline_decode(xdr, 8);
3983 xdr_decode_hyper(p, res);
3984 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3986 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3989 print_overflow_msg(__func__, xdr);
3993 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3999 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4001 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4002 p = xdr_inline_decode(xdr, 8);
4005 xdr_decode_hyper(p, res);
4006 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4008 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
4011 print_overflow_msg(__func__, xdr);
4015 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4021 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4023 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4024 p = xdr_inline_decode(xdr, 8);
4027 xdr_decode_hyper(p, used);
4028 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4029 ret = NFS_ATTR_FATTR_SPACE_USED;
4031 dprintk("%s: space used=%Lu\n", __func__,
4032 (unsigned long long)*used);
4035 print_overflow_msg(__func__, xdr);
4039 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4045 p = xdr_inline_decode(xdr, 12);
4048 p = xdr_decode_hyper(p, &sec);
4049 nsec = be32_to_cpup(p);
4050 time->tv_sec = (time_t)sec;
4051 time->tv_nsec = (long)nsec;
4054 print_overflow_msg(__func__, xdr);
4058 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4064 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4066 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4067 status = decode_attr_time(xdr, time);
4069 status = NFS_ATTR_FATTR_ATIME;
4070 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4072 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
4076 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4082 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4084 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4085 status = decode_attr_time(xdr, time);
4087 status = NFS_ATTR_FATTR_CTIME;
4088 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4090 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
4094 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4095 struct timespec *time)
4101 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4103 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4104 status = decode_attr_time(xdr, time);
4105 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4107 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4108 (long)time->tv_nsec);
4112 static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4113 struct nfs4_label *label)
4121 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4123 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4124 p = xdr_inline_decode(xdr, 4);
4127 lfs = be32_to_cpup(p++);
4128 p = xdr_inline_decode(xdr, 4);
4131 pi = be32_to_cpup(p++);
4132 p = xdr_inline_decode(xdr, 4);
4135 len = be32_to_cpup(p++);
4136 p = xdr_inline_decode(xdr, len);
4139 if (len < NFS4_MAXLABELLEN) {
4141 memcpy(label->label, p, len);
4145 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4147 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4149 printk(KERN_WARNING "%s: label too long (%u)!\n",
4152 if (label && label->label)
4153 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4154 (char *)label->label, label->len, label->pi, label->lfs);
4158 print_overflow_msg(__func__, xdr);
4162 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4168 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4170 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4171 status = decode_attr_time(xdr, time);
4173 status = NFS_ATTR_FATTR_MTIME;
4174 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4176 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
4180 static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
4182 unsigned int attrwords = XDR_QUADLEN(attrlen);
4183 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
4185 if (unlikely(attrwords != nwords)) {
4186 dprintk("%s: server returned incorrect attribute length: "
4190 (attrwords < nwords) ? '<' : '>',
4197 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4201 p = xdr_inline_decode(xdr, 20);
4204 cinfo->atomic = be32_to_cpup(p++);
4205 p = xdr_decode_hyper(p, &cinfo->before);
4206 xdr_decode_hyper(p, &cinfo->after);
4209 print_overflow_msg(__func__, xdr);
4213 static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
4219 status = decode_op_hdr(xdr, OP_ACCESS);
4222 p = xdr_inline_decode(xdr, 8);
4225 supp = be32_to_cpup(p++);
4226 acc = be32_to_cpup(p);
4231 print_overflow_msg(__func__, xdr);
4235 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4239 p = xdr_inline_decode(xdr, len);
4241 memcpy(buf, p, len);
4244 print_overflow_msg(__func__, xdr);
4248 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4250 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4253 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4257 status = decode_op_hdr(xdr, OP_CLOSE);
4259 nfs_increment_open_seqid(status, res->seqid);
4261 status = decode_stateid(xdr, &res->stateid);
4265 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4267 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4270 static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4272 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4275 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4279 status = decode_op_hdr(xdr, OP_COMMIT);
4281 status = decode_write_verifier(xdr, &res->verf->verifier);
4285 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4291 status = decode_op_hdr(xdr, OP_CREATE);
4294 if ((status = decode_change_info(xdr, cinfo)))
4296 p = xdr_inline_decode(xdr, 4);
4299 bmlen = be32_to_cpup(p);
4300 p = xdr_inline_decode(xdr, bmlen << 2);
4304 print_overflow_msg(__func__, xdr);
4308 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4311 uint32_t attrlen, bitmap[3] = {0};
4314 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4316 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4318 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4320 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4322 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4323 &res->fh_expire_type)) != 0)
4325 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4327 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4329 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4331 status = verify_attr_len(xdr, savep, attrlen);
4333 dprintk("%s: xdr returned %d!\n", __func__, -status);
4337 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4340 uint32_t attrlen, bitmap[3] = {0};
4343 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4345 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4347 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4350 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4352 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4354 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4356 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4358 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4360 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4363 status = verify_attr_len(xdr, savep, attrlen);
4365 dprintk("%s: xdr returned %d!\n", __func__, -status);
4369 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4372 uint32_t attrlen, bitmap[3] = {0};
4375 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4377 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4379 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4382 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4384 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4387 status = verify_attr_len(xdr, savep, attrlen);
4389 dprintk("%s: xdr returned %d!\n", __func__, -status);
4393 static int decode_threshold_hint(struct xdr_stream *xdr,
4401 if (likely(bitmap[0] & hint_bit)) {
4402 p = xdr_inline_decode(xdr, 8);
4405 xdr_decode_hyper(p, res);
4409 print_overflow_msg(__func__, xdr);
4413 static int decode_first_threshold_item4(struct xdr_stream *xdr,
4414 struct nfs4_threshold *res)
4418 uint32_t bitmap[3] = {0,}, attrlen;
4422 p = xdr_inline_decode(xdr, 4);
4424 print_overflow_msg(__func__, xdr);
4427 res->l_type = be32_to_cpup(p);
4429 /* thi_hintset bitmap */
4430 status = decode_attr_bitmap(xdr, bitmap);
4434 /* thi_hintlist length */
4435 status = decode_attr_length(xdr, &attrlen, &savep);
4439 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4442 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4445 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4449 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4454 status = verify_attr_len(xdr, savep, attrlen);
4455 res->bm = bitmap[0];
4457 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4458 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4461 dprintk("%s ret=%d!\n", __func__, status);
4466 * Thresholds on pNFS direct I/O vrs MDS I/O
4468 static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4470 struct nfs4_threshold *res)
4476 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4478 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
4479 /* Did the server return an unrequested attribute? */
4480 if (unlikely(res == NULL))
4482 p = xdr_inline_decode(xdr, 4);
4485 num = be32_to_cpup(p);
4489 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4490 "drivers per filesystem not supported\n",
4493 status = decode_first_threshold_item4(xdr, res);
4494 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
4498 print_overflow_msg(__func__, xdr);
4502 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4503 struct nfs_fattr *fattr, struct nfs_fh *fh,
4504 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
4505 const struct nfs_server *server)
4512 status = decode_attr_type(xdr, bitmap, &type);
4517 fattr->mode |= nfs_type2fmt[type];
4518 fattr->valid |= status;
4521 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4524 fattr->valid |= status;
4526 status = decode_attr_size(xdr, bitmap, &fattr->size);
4529 fattr->valid |= status;
4531 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4534 fattr->valid |= status;
4537 status = decode_attr_error(xdr, bitmap, &err);
4541 status = decode_attr_filehandle(xdr, bitmap, fh);
4545 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4548 fattr->valid |= status;
4550 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4553 fattr->valid |= status;
4555 status = decode_attr_mode(xdr, bitmap, &fmode);
4559 fattr->mode |= fmode;
4560 fattr->valid |= status;
4563 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4566 fattr->valid |= status;
4568 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4571 fattr->valid |= status;
4573 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4576 fattr->valid |= status;
4578 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4581 fattr->valid |= status;
4583 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4586 fattr->valid |= status;
4588 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4591 fattr->valid |= status;
4593 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4596 fattr->valid |= status;
4598 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4601 fattr->valid |= status;
4603 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4606 fattr->valid |= status;
4608 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4613 status = decode_attr_security_label(xdr, bitmap, label);
4616 fattr->valid |= status;
4620 dprintk("%s: xdr returned %d\n", __func__, -status);
4624 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4625 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4626 struct nfs4_label *label, const struct nfs_server *server)
4633 status = decode_op_hdr(xdr, OP_GETATTR);
4637 status = decode_attr_bitmap(xdr, bitmap);
4641 status = decode_attr_length(xdr, &attrlen, &savep);
4645 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4650 status = verify_attr_len(xdr, savep, attrlen);
4652 dprintk("%s: xdr returned %d\n", __func__, -status);
4656 static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4657 struct nfs4_label *label, const struct nfs_server *server)
4659 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4662 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4663 const struct nfs_server *server)
4665 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4669 * Decode potentially multiple layout types. Currently we only support
4670 * one layout driver per file system.
4672 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4673 uint32_t *layouttype)
4678 p = xdr_inline_decode(xdr, 4);
4681 num = be32_to_cpup(p);
4683 /* pNFS is not supported by the underlying file system */
4689 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4690 "drivers per filesystem not supported\n", __func__);
4692 /* Decode and set first layout type, move xdr->p past unused types */
4693 p = xdr_inline_decode(xdr, num * 4);
4696 *layouttype = be32_to_cpup(p);
4699 print_overflow_msg(__func__, xdr);
4704 * The type of file system exported.
4705 * Note we must ensure that layouttype is set in any non-error case.
4707 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4708 uint32_t *layouttype)
4712 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4713 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4715 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4716 status = decode_first_pnfs_layout_type(xdr, layouttype);
4717 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4724 * The prefered block size for layout directed io
4726 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4731 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4733 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4734 p = xdr_inline_decode(xdr, 4);
4736 print_overflow_msg(__func__, xdr);
4739 *res = be32_to_cpup(p);
4740 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4745 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4748 uint32_t attrlen, bitmap[3];
4751 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4753 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4755 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4758 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4760 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4762 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4764 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4766 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4767 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4769 fsinfo->wtpref = fsinfo->wtmax;
4770 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4773 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4776 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4780 status = verify_attr_len(xdr, savep, attrlen);
4782 dprintk("%s: xdr returned %d!\n", __func__, -status);
4786 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4792 /* Zero handle first to allow comparisons */
4793 memset(fh, 0, sizeof(*fh));
4795 status = decode_op_hdr(xdr, OP_GETFH);
4799 p = xdr_inline_decode(xdr, 4);
4802 len = be32_to_cpup(p);
4803 if (len > NFS4_FHSIZE)
4806 p = xdr_inline_decode(xdr, len);
4809 memcpy(fh->data, p, len);
4812 print_overflow_msg(__func__, xdr);
4816 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4820 status = decode_op_hdr(xdr, OP_LINK);
4823 return decode_change_info(xdr, cinfo);
4827 * We create the owner, so we know a proper owner.id length is 4.
4829 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4831 uint64_t offset, length, clientid;
4833 uint32_t namelen, type;
4835 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4838 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4839 p = xdr_decode_hyper(p, &length);
4840 type = be32_to_cpup(p++); /* 4 byte read */
4841 if (fl != NULL) { /* manipulate file lock */
4842 fl->fl_start = (loff_t)offset;
4843 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4844 if (length == ~(uint64_t)0)
4845 fl->fl_end = OFFSET_MAX;
4846 fl->fl_type = F_WRLCK;
4848 fl->fl_type = F_RDLCK;
4851 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4852 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4853 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4855 return -NFS4ERR_DENIED;
4857 print_overflow_msg(__func__, xdr);
4861 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4865 status = decode_op_hdr(xdr, OP_LOCK);
4869 status = decode_stateid(xdr, &res->stateid);
4870 if (unlikely(status))
4872 } else if (status == -NFS4ERR_DENIED)
4873 status = decode_lock_denied(xdr, NULL);
4874 if (res->open_seqid != NULL)
4875 nfs_increment_open_seqid(status, res->open_seqid);
4876 nfs_increment_lock_seqid(status, res->lock_seqid);
4881 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4884 status = decode_op_hdr(xdr, OP_LOCKT);
4885 if (status == -NFS4ERR_DENIED)
4886 return decode_lock_denied(xdr, res->denied);
4890 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4894 status = decode_op_hdr(xdr, OP_LOCKU);
4896 nfs_increment_lock_seqid(status, res->seqid);
4898 status = decode_stateid(xdr, &res->stateid);
4902 static int decode_release_lockowner(struct xdr_stream *xdr)
4904 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4907 static int decode_lookup(struct xdr_stream *xdr)
4909 return decode_op_hdr(xdr, OP_LOOKUP);
4912 /* This is too sick! */
4913 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4916 uint32_t limit_type, nblocks, blocksize;
4918 p = xdr_inline_decode(xdr, 12);
4921 limit_type = be32_to_cpup(p++);
4922 switch (limit_type) {
4924 xdr_decode_hyper(p, maxsize);
4927 nblocks = be32_to_cpup(p++);
4928 blocksize = be32_to_cpup(p);
4929 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4933 print_overflow_msg(__func__, xdr);
4937 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4940 uint32_t delegation_type;
4943 p = xdr_inline_decode(xdr, 4);
4946 delegation_type = be32_to_cpup(p);
4947 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4948 res->delegation_type = 0;
4951 status = decode_stateid(xdr, &res->delegation);
4952 if (unlikely(status))
4954 p = xdr_inline_decode(xdr, 4);
4957 res->do_recall = be32_to_cpup(p);
4959 switch (delegation_type) {
4960 case NFS4_OPEN_DELEGATE_READ:
4961 res->delegation_type = FMODE_READ;
4963 case NFS4_OPEN_DELEGATE_WRITE:
4964 res->delegation_type = FMODE_WRITE|FMODE_READ;
4965 if (decode_space_limit(xdr, &res->maxsize) < 0)
4968 return decode_ace(xdr, NULL, res->server->nfs_client);
4970 print_overflow_msg(__func__, xdr);
4974 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4977 uint32_t savewords, bmlen, i;
4980 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
4982 nfs_increment_open_seqid(status, res->seqid);
4985 status = decode_stateid(xdr, &res->stateid);
4986 if (unlikely(status))
4989 decode_change_info(xdr, &res->cinfo);
4991 p = xdr_inline_decode(xdr, 8);
4994 res->rflags = be32_to_cpup(p++);
4995 bmlen = be32_to_cpup(p);
4999 p = xdr_inline_decode(xdr, bmlen << 2);
5002 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5003 for (i = 0; i < savewords; ++i)
5004 res->attrset[i] = be32_to_cpup(p++);
5005 for (; i < NFS4_BITMAP_SIZE; i++)
5006 res->attrset[i] = 0;
5008 return decode_delegation(xdr, res);
5010 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
5013 print_overflow_msg(__func__, xdr);
5017 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5021 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5023 nfs_increment_open_seqid(status, res->seqid);
5025 status = decode_stateid(xdr, &res->stateid);
5029 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5033 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5035 nfs_increment_open_seqid(status, res->seqid);
5037 status = decode_stateid(xdr, &res->stateid);
5041 static int decode_putfh(struct xdr_stream *xdr)
5043 return decode_op_hdr(xdr, OP_PUTFH);
5046 static int decode_putrootfh(struct xdr_stream *xdr)
5048 return decode_op_hdr(xdr, OP_PUTROOTFH);
5051 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5052 struct nfs_pgio_res *res)
5055 uint32_t count, eof, recvd;
5058 status = decode_op_hdr(xdr, OP_READ);
5061 p = xdr_inline_decode(xdr, 8);
5064 eof = be32_to_cpup(p++);
5065 count = be32_to_cpup(p);
5066 recvd = xdr_read_pages(xdr, count);
5067 if (count > recvd) {
5068 dprintk("NFS: server cheating in read reply: "
5069 "count %u > recvd %u\n", count, recvd);
5077 print_overflow_msg(__func__, xdr);
5081 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5086 status = decode_op_hdr(xdr, OP_READDIR);
5088 status = decode_verifier(xdr, readdir->verifier.data);
5089 if (unlikely(status))
5091 memcpy(verf, readdir->verifier.data, sizeof(verf));
5092 dprintk("%s: verifier = %08x:%08x\n",
5093 __func__, verf[0], verf[1]);
5094 return xdr_read_pages(xdr, xdr->buf->page_len);
5097 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5099 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5104 status = decode_op_hdr(xdr, OP_READLINK);
5108 /* Convert length of symlink */
5109 p = xdr_inline_decode(xdr, 4);
5112 len = be32_to_cpup(p);
5113 if (len >= rcvbuf->page_len || len <= 0) {
5114 dprintk("nfs: server returned giant symlink!\n");
5115 return -ENAMETOOLONG;
5117 recvd = xdr_read_pages(xdr, len);
5119 dprintk("NFS: server cheating in readlink reply: "
5120 "count %u > recvd %u\n", len, recvd);
5124 * The XDR encode routine has set things up so that
5125 * the link text will be copied directly into the
5126 * buffer. We just have to do overflow-checking,
5127 * and and null-terminate the text (the VFS expects
5128 * null-termination).
5130 xdr_terminate_string(rcvbuf, len);
5133 print_overflow_msg(__func__, xdr);
5137 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5141 status = decode_op_hdr(xdr, OP_REMOVE);
5144 status = decode_change_info(xdr, cinfo);
5149 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5150 struct nfs4_change_info *new_cinfo)
5154 status = decode_op_hdr(xdr, OP_RENAME);
5157 if ((status = decode_change_info(xdr, old_cinfo)))
5159 status = decode_change_info(xdr, new_cinfo);
5164 static int decode_renew(struct xdr_stream *xdr)
5166 return decode_op_hdr(xdr, OP_RENEW);
5170 decode_restorefh(struct xdr_stream *xdr)
5172 return decode_op_hdr(xdr, OP_RESTOREFH);
5175 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5176 struct nfs_getaclres *res)
5182 unsigned int pg_offset;
5185 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5188 xdr_enter_page(xdr, xdr->buf->page_len);
5190 /* Calculate the offset of the page data */
5191 pg_offset = xdr->buf->head[0].iov_len;
5193 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5195 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5198 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5200 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5202 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5203 * are stored with the acl data to handle the problem of
5204 * variable length bitmaps.*/
5205 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5206 res->acl_len = attrlen;
5208 /* Check for receive buffer overflow */
5209 if (res->acl_len > (xdr->nwords << 2) ||
5210 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5211 res->acl_flags |= NFS4_ACL_TRUNC;
5212 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5213 attrlen, xdr->nwords << 2);
5216 status = -EOPNOTSUPP;
5223 decode_savefh(struct xdr_stream *xdr)
5225 return decode_op_hdr(xdr, OP_SAVEFH);
5228 static int decode_setattr(struct xdr_stream *xdr)
5234 status = decode_op_hdr(xdr, OP_SETATTR);
5237 p = xdr_inline_decode(xdr, 4);
5240 bmlen = be32_to_cpup(p);
5241 p = xdr_inline_decode(xdr, bmlen << 2);
5245 print_overflow_msg(__func__, xdr);
5249 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5255 p = xdr_inline_decode(xdr, 8);
5258 opnum = be32_to_cpup(p++);
5259 if (opnum != OP_SETCLIENTID) {
5260 dprintk("nfs: decode_setclientid: Server returned operation"
5264 nfserr = be32_to_cpup(p);
5265 if (nfserr == NFS_OK) {
5266 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5269 p = xdr_decode_hyper(p, &res->clientid);
5270 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5271 } else if (nfserr == NFSERR_CLID_INUSE) {
5274 /* skip netid string */
5275 p = xdr_inline_decode(xdr, 4);
5278 len = be32_to_cpup(p);
5279 p = xdr_inline_decode(xdr, len);
5283 /* skip uaddr string */
5284 p = xdr_inline_decode(xdr, 4);
5287 len = be32_to_cpup(p);
5288 p = xdr_inline_decode(xdr, len);
5291 return -NFSERR_CLID_INUSE;
5293 return nfs4_stat_to_errno(nfserr);
5297 print_overflow_msg(__func__, xdr);
5301 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5303 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5306 static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
5311 status = decode_op_hdr(xdr, OP_WRITE);
5315 p = xdr_inline_decode(xdr, 8);
5318 res->count = be32_to_cpup(p++);
5319 res->verf->committed = be32_to_cpup(p++);
5320 return decode_write_verifier(xdr, &res->verf->verifier);
5322 print_overflow_msg(__func__, xdr);
5326 static int decode_delegreturn(struct xdr_stream *xdr)
5328 return decode_op_hdr(xdr, OP_DELEGRETURN);
5331 static int decode_secinfo_gss(struct xdr_stream *xdr,
5332 struct nfs4_secinfo4 *flavor)
5337 p = xdr_inline_decode(xdr, 4);
5340 oid_len = be32_to_cpup(p);
5341 if (oid_len > GSS_OID_MAX_LEN)
5344 p = xdr_inline_decode(xdr, oid_len);
5347 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5348 flavor->flavor_info.oid.len = oid_len;
5350 p = xdr_inline_decode(xdr, 8);
5353 flavor->flavor_info.qop = be32_to_cpup(p++);
5354 flavor->flavor_info.service = be32_to_cpup(p);
5359 print_overflow_msg(__func__, xdr);
5365 static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5367 struct nfs4_secinfo4 *sec_flavor;
5368 unsigned int i, num_flavors;
5372 p = xdr_inline_decode(xdr, 4);
5376 res->flavors->num_flavors = 0;
5377 num_flavors = be32_to_cpup(p);
5379 for (i = 0; i < num_flavors; i++) {
5380 sec_flavor = &res->flavors->flavors[i];
5381 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5384 p = xdr_inline_decode(xdr, 4);
5387 sec_flavor->flavor = be32_to_cpup(p);
5389 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5390 status = decode_secinfo_gss(xdr, sec_flavor);
5394 res->flavors->num_flavors++;
5401 print_overflow_msg(__func__, xdr);
5405 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5407 int status = decode_op_hdr(xdr, OP_SECINFO);
5410 return decode_secinfo_common(xdr, res);
5413 #if defined(CONFIG_NFS_V4_1)
5414 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5416 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5419 return decode_secinfo_common(xdr, res);
5422 static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5425 uint32_t bitmap_words;
5428 p = xdr_inline_decode(xdr, 4);
5429 bitmap_words = be32_to_cpup(p++);
5430 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5432 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5433 for (i = 0; i < bitmap_words; i++)
5434 op_map->u.words[i] = be32_to_cpup(p++);
5439 static int decode_exchange_id(struct xdr_stream *xdr,
5440 struct nfs41_exchange_id_res *res)
5446 uint32_t impl_id_count;
5448 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5452 p = xdr_inline_decode(xdr, 8);
5455 xdr_decode_hyper(p, &res->clientid);
5456 p = xdr_inline_decode(xdr, 12);
5459 res->seqid = be32_to_cpup(p++);
5460 res->flags = be32_to_cpup(p++);
5462 res->state_protect.how = be32_to_cpup(p);
5463 switch (res->state_protect.how) {
5467 status = decode_op_map(xdr, &res->state_protect.enforce);
5470 status = decode_op_map(xdr, &res->state_protect.allow);
5479 /* server_owner4.so_minor_id */
5480 p = xdr_inline_decode(xdr, 8);
5483 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5485 /* server_owner4.so_major_id */
5486 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5487 if (unlikely(status))
5489 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5491 memcpy(res->server_owner->major_id, dummy_str, dummy);
5492 res->server_owner->major_id_sz = dummy;
5495 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5496 if (unlikely(status))
5498 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5500 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5501 res->server_scope->server_scope_sz = dummy;
5503 /* Implementation Id */
5504 p = xdr_inline_decode(xdr, 4);
5507 impl_id_count = be32_to_cpup(p++);
5509 if (impl_id_count) {
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->domain, dummy_str, dummy);
5519 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5520 if (unlikely(status))
5522 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5524 memcpy(res->impl_id->name, dummy_str, dummy);
5527 p = xdr_inline_decode(xdr, 12);
5530 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5531 res->impl_id->date.nseconds = be32_to_cpup(p);
5533 /* if there's more than one entry, ignore the rest */
5537 print_overflow_msg(__func__, xdr);
5541 static int decode_chan_attrs(struct xdr_stream *xdr,
5542 struct nfs4_channel_attrs *attrs)
5547 p = xdr_inline_decode(xdr, 28);
5550 val = be32_to_cpup(p++); /* headerpadsz */
5552 return -EINVAL; /* no support for header padding yet */
5553 attrs->max_rqst_sz = be32_to_cpup(p++);
5554 attrs->max_resp_sz = be32_to_cpup(p++);
5555 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5556 attrs->max_ops = be32_to_cpup(p++);
5557 attrs->max_reqs = be32_to_cpup(p++);
5558 nr_attrs = be32_to_cpup(p);
5559 if (unlikely(nr_attrs > 1)) {
5560 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5561 "count %u\n", __func__, nr_attrs);
5564 if (nr_attrs == 1) {
5565 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5571 print_overflow_msg(__func__, xdr);
5575 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5577 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5580 static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5581 struct nfs41_bind_conn_to_session_res *res)
5586 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5588 status = decode_sessionid(xdr, &res->session->sess_id);
5589 if (unlikely(status))
5592 /* dir flags, rdma mode bool */
5593 p = xdr_inline_decode(xdr, 8);
5597 res->dir = be32_to_cpup(p++);
5598 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5600 if (be32_to_cpup(p) == 0)
5601 res->use_conn_in_rdma_mode = false;
5603 res->use_conn_in_rdma_mode = true;
5607 print_overflow_msg(__func__, xdr);
5611 static int decode_create_session(struct xdr_stream *xdr,
5612 struct nfs41_create_session_res *res)
5616 struct nfs_client *clp = res->client;
5617 struct nfs4_session *session = clp->cl_session;
5619 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5621 status = decode_sessionid(xdr, &session->sess_id);
5622 if (unlikely(status))
5626 p = xdr_inline_decode(xdr, 8);
5629 clp->cl_seqid = be32_to_cpup(p++);
5630 session->flags = be32_to_cpup(p);
5632 /* Channel attributes */
5633 status = decode_chan_attrs(xdr, &session->fc_attrs);
5635 status = decode_chan_attrs(xdr, &session->bc_attrs);
5638 print_overflow_msg(__func__, xdr);
5642 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5644 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5647 static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5649 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5652 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5654 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5656 #endif /* CONFIG_NFS_V4_1 */
5658 static int decode_sequence(struct xdr_stream *xdr,
5659 struct nfs4_sequence_res *res,
5660 struct rpc_rqst *rqstp)
5662 #if defined(CONFIG_NFS_V4_1)
5663 struct nfs4_session *session;
5664 struct nfs4_sessionid id;
5669 if (res->sr_slot == NULL)
5671 if (!res->sr_slot->table->session)
5674 status = decode_op_hdr(xdr, OP_SEQUENCE);
5676 status = decode_sessionid(xdr, &id);
5677 if (unlikely(status))
5681 * If the server returns different values for sessionID, slotID or
5682 * sequence number, the server is looney tunes.
5684 status = -EREMOTEIO;
5685 session = res->sr_slot->table->session;
5687 if (memcmp(id.data, session->sess_id.data,
5688 NFS4_MAX_SESSIONID_LEN)) {
5689 dprintk("%s Invalid session id\n", __func__);
5693 p = xdr_inline_decode(xdr, 20);
5698 dummy = be32_to_cpup(p++);
5699 if (dummy != res->sr_slot->seq_nr) {
5700 dprintk("%s Invalid sequence number\n", __func__);
5704 dummy = be32_to_cpup(p++);
5705 if (dummy != res->sr_slot->slot_nr) {
5706 dprintk("%s Invalid slot id\n", __func__);
5709 /* highest slot id */
5710 res->sr_highest_slotid = be32_to_cpup(p++);
5711 /* target highest slot id */
5712 res->sr_target_highest_slotid = be32_to_cpup(p++);
5714 res->sr_status_flags = be32_to_cpup(p);
5717 res->sr_status = status;
5720 print_overflow_msg(__func__, xdr);
5723 #else /* CONFIG_NFS_V4_1 */
5725 #endif /* CONFIG_NFS_V4_1 */
5728 #if defined(CONFIG_NFS_V4_1)
5729 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5730 struct pnfs_device *pdev)
5736 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5738 if (status == -ETOOSMALL) {
5739 p = xdr_inline_decode(xdr, 4);
5742 pdev->mincount = be32_to_cpup(p);
5743 dprintk("%s: Min count too small. mincnt = %u\n",
5744 __func__, pdev->mincount);
5749 p = xdr_inline_decode(xdr, 8);
5752 type = be32_to_cpup(p++);
5753 if (type != pdev->layout_type) {
5754 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5755 __func__, pdev->layout_type, type);
5759 * Get the length of the opaque device_addr4. xdr_read_pages places
5760 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5761 * and places the remaining xdr data in xdr_buf->tail
5763 pdev->mincount = be32_to_cpup(p);
5764 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5767 /* Parse notification bitmap, verifying that it is zero. */
5768 p = xdr_inline_decode(xdr, 4);
5771 len = be32_to_cpup(p);
5775 p = xdr_inline_decode(xdr, 4 * len);
5779 if (be32_to_cpup(p++) &
5780 ~(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE)) {
5781 dprintk("%s: unsupported notification\n",
5785 for (i = 1; i < len; i++) {
5786 if (be32_to_cpup(p++)) {
5787 dprintk("%s: unsupported notification\n",
5795 print_overflow_msg(__func__, xdr);
5799 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5800 struct nfs4_layoutget_res *res)
5807 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5810 p = xdr_inline_decode(xdr, 4);
5813 res->return_on_close = be32_to_cpup(p);
5814 decode_stateid(xdr, &res->stateid);
5815 p = xdr_inline_decode(xdr, 4);
5818 layout_count = be32_to_cpup(p);
5819 if (!layout_count) {
5820 dprintk("%s: server responded with empty layout array\n",
5825 p = xdr_inline_decode(xdr, 28);
5828 p = xdr_decode_hyper(p, &res->range.offset);
5829 p = xdr_decode_hyper(p, &res->range.length);
5830 res->range.iomode = be32_to_cpup(p++);
5831 res->type = be32_to_cpup(p++);
5832 res->layoutp->len = be32_to_cpup(p);
5834 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5836 (unsigned long)res->range.offset,
5837 (unsigned long)res->range.length,
5842 recvd = xdr_read_pages(xdr, res->layoutp->len);
5843 if (res->layoutp->len > recvd) {
5844 dprintk("NFS: server cheating in layoutget reply: "
5845 "layout len %u > recvd %u\n",
5846 res->layoutp->len, recvd);
5850 if (layout_count > 1) {
5851 /* We only handle a length one array at the moment. Any
5852 * further entries are just ignored. Note that this means
5853 * the client may see a response that is less than the
5854 * minimum it requested.
5856 dprintk("%s: server responded with %d layouts, dropping tail\n",
5857 __func__, layout_count);
5862 print_overflow_msg(__func__, xdr);
5866 static int decode_layoutreturn(struct xdr_stream *xdr,
5867 struct nfs4_layoutreturn_res *res)
5872 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5875 p = xdr_inline_decode(xdr, 4);
5878 res->lrs_present = be32_to_cpup(p);
5879 if (res->lrs_present)
5880 status = decode_stateid(xdr, &res->stateid);
5883 print_overflow_msg(__func__, xdr);
5887 static int decode_layoutcommit(struct xdr_stream *xdr,
5888 struct rpc_rqst *req,
5889 struct nfs4_layoutcommit_res *res)
5895 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5896 res->status = status;
5900 p = xdr_inline_decode(xdr, 4);
5903 sizechanged = be32_to_cpup(p);
5906 /* throw away new size */
5907 p = xdr_inline_decode(xdr, 8);
5913 print_overflow_msg(__func__, xdr);
5917 static int decode_test_stateid(struct xdr_stream *xdr,
5918 struct nfs41_test_stateid_res *res)
5924 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5928 p = xdr_inline_decode(xdr, 4);
5931 num_res = be32_to_cpup(p++);
5935 p = xdr_inline_decode(xdr, 4);
5938 res->status = be32_to_cpup(p++);
5942 print_overflow_msg(__func__, xdr);
5947 static int decode_free_stateid(struct xdr_stream *xdr,
5948 struct nfs41_free_stateid_res *res)
5950 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
5953 #endif /* CONFIG_NFS_V4_1 */
5956 * END OF "GENERIC" DECODE ROUTINES.
5960 * Decode OPEN_DOWNGRADE response
5962 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5963 struct xdr_stream *xdr,
5964 struct nfs_closeres *res)
5966 struct compound_hdr hdr;
5969 status = decode_compound_hdr(xdr, &hdr);
5972 status = decode_sequence(xdr, &res->seq_res, rqstp);
5975 status = decode_putfh(xdr);
5978 status = decode_open_downgrade(xdr, res);
5981 decode_getfattr(xdr, res->fattr, res->server);
5987 * Decode ACCESS response
5989 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5990 struct nfs4_accessres *res)
5992 struct compound_hdr hdr;
5995 status = decode_compound_hdr(xdr, &hdr);
5998 status = decode_sequence(xdr, &res->seq_res, rqstp);
6001 status = decode_putfh(xdr);
6004 status = decode_access(xdr, &res->supported, &res->access);
6007 decode_getfattr(xdr, res->fattr, res->server);
6013 * Decode LOOKUP response
6015 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6016 struct nfs4_lookup_res *res)
6018 struct compound_hdr hdr;
6021 status = decode_compound_hdr(xdr, &hdr);
6024 status = decode_sequence(xdr, &res->seq_res, rqstp);
6027 status = decode_putfh(xdr);
6030 status = decode_lookup(xdr);
6033 status = decode_getfh(xdr, res->fh);
6036 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6042 * Decode LOOKUP_ROOT response
6044 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6045 struct xdr_stream *xdr,
6046 struct nfs4_lookup_res *res)
6048 struct compound_hdr hdr;
6051 status = decode_compound_hdr(xdr, &hdr);
6054 status = decode_sequence(xdr, &res->seq_res, rqstp);
6057 status = decode_putrootfh(xdr);
6060 status = decode_getfh(xdr, res->fh);
6062 status = decode_getfattr_label(xdr, res->fattr,
6063 res->label, res->server);
6069 * Decode REMOVE response
6071 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6072 struct nfs_removeres *res)
6074 struct compound_hdr hdr;
6077 status = decode_compound_hdr(xdr, &hdr);
6080 status = decode_sequence(xdr, &res->seq_res, rqstp);
6083 status = decode_putfh(xdr);
6086 status = decode_remove(xdr, &res->cinfo);
6092 * Decode RENAME response
6094 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6095 struct nfs_renameres *res)
6097 struct compound_hdr hdr;
6100 status = decode_compound_hdr(xdr, &hdr);
6103 status = decode_sequence(xdr, &res->seq_res, rqstp);
6106 status = decode_putfh(xdr);
6109 status = decode_savefh(xdr);
6112 status = decode_putfh(xdr);
6115 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
6121 * Decode LINK response
6123 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6124 struct nfs4_link_res *res)
6126 struct compound_hdr hdr;
6129 status = decode_compound_hdr(xdr, &hdr);
6132 status = decode_sequence(xdr, &res->seq_res, rqstp);
6135 status = decode_putfh(xdr);
6138 status = decode_savefh(xdr);
6141 status = decode_putfh(xdr);
6144 status = decode_link(xdr, &res->cinfo);
6148 * Note order: OP_LINK leaves the directory as the current
6151 status = decode_restorefh(xdr);
6154 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6160 * Decode CREATE response
6162 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6163 struct nfs4_create_res *res)
6165 struct compound_hdr hdr;
6168 status = decode_compound_hdr(xdr, &hdr);
6171 status = decode_sequence(xdr, &res->seq_res, rqstp);
6174 status = decode_putfh(xdr);
6177 status = decode_create(xdr, &res->dir_cinfo);
6180 status = decode_getfh(xdr, res->fh);
6183 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6189 * Decode SYMLINK response
6191 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6192 struct nfs4_create_res *res)
6194 return nfs4_xdr_dec_create(rqstp, xdr, res);
6198 * Decode GETATTR response
6200 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6201 struct nfs4_getattr_res *res)
6203 struct compound_hdr hdr;
6206 status = decode_compound_hdr(xdr, &hdr);
6209 status = decode_sequence(xdr, &res->seq_res, rqstp);
6212 status = decode_putfh(xdr);
6215 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6221 * Encode an SETACL request
6223 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6224 struct nfs_setaclargs *args)
6226 struct compound_hdr hdr = {
6227 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6230 encode_compound_hdr(xdr, req, &hdr);
6231 encode_sequence(xdr, &args->seq_args, &hdr);
6232 encode_putfh(xdr, args->fh, &hdr);
6233 encode_setacl(xdr, args, &hdr);
6238 * Decode SETACL response
6241 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6242 struct nfs_setaclres *res)
6244 struct compound_hdr hdr;
6247 status = decode_compound_hdr(xdr, &hdr);
6250 status = decode_sequence(xdr, &res->seq_res, rqstp);
6253 status = decode_putfh(xdr);
6256 status = decode_setattr(xdr);
6262 * Decode GETACL response
6265 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6266 struct nfs_getaclres *res)
6268 struct compound_hdr hdr;
6271 if (res->acl_scratch != NULL) {
6272 void *p = page_address(res->acl_scratch);
6273 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6275 status = decode_compound_hdr(xdr, &hdr);
6278 status = decode_sequence(xdr, &res->seq_res, rqstp);
6281 status = decode_putfh(xdr);
6284 status = decode_getacl(xdr, rqstp, res);
6291 * Decode CLOSE response
6293 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6294 struct nfs_closeres *res)
6296 struct compound_hdr hdr;
6299 status = decode_compound_hdr(xdr, &hdr);
6302 status = decode_sequence(xdr, &res->seq_res, rqstp);
6305 status = decode_putfh(xdr);
6308 status = decode_close(xdr, res);
6312 * Note: Server may do delete on close for this file
6313 * in which case the getattr call will fail with
6314 * an ESTALE error. Shouldn't be a problem,
6315 * though, since fattr->valid will remain unset.
6317 decode_getfattr(xdr, res->fattr, res->server);
6323 * Decode OPEN response
6325 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6326 struct nfs_openres *res)
6328 struct compound_hdr hdr;
6331 status = decode_compound_hdr(xdr, &hdr);
6334 status = decode_sequence(xdr, &res->seq_res, rqstp);
6337 status = decode_putfh(xdr);
6340 status = decode_open(xdr, res);
6343 status = decode_getfh(xdr, &res->fh);
6346 if (res->access_request)
6347 decode_access(xdr, &res->access_supported, &res->access_result);
6348 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
6354 * Decode OPEN_CONFIRM response
6356 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6357 struct xdr_stream *xdr,
6358 struct nfs_open_confirmres *res)
6360 struct compound_hdr hdr;
6363 status = decode_compound_hdr(xdr, &hdr);
6366 status = decode_putfh(xdr);
6369 status = decode_open_confirm(xdr, res);
6375 * Decode OPEN response
6377 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6378 struct xdr_stream *xdr,
6379 struct nfs_openres *res)
6381 struct compound_hdr hdr;
6384 status = decode_compound_hdr(xdr, &hdr);
6387 status = decode_sequence(xdr, &res->seq_res, rqstp);
6390 status = decode_putfh(xdr);
6393 status = decode_open(xdr, res);
6396 if (res->access_request)
6397 decode_access(xdr, &res->access_supported, &res->access_result);
6398 decode_getfattr(xdr, res->f_attr, res->server);
6404 * Decode SETATTR response
6406 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6407 struct xdr_stream *xdr,
6408 struct nfs_setattrres *res)
6410 struct compound_hdr hdr;
6413 status = decode_compound_hdr(xdr, &hdr);
6416 status = decode_sequence(xdr, &res->seq_res, rqstp);
6419 status = decode_putfh(xdr);
6422 status = decode_setattr(xdr);
6425 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6431 * Decode LOCK response
6433 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6434 struct nfs_lock_res *res)
6436 struct compound_hdr hdr;
6439 status = decode_compound_hdr(xdr, &hdr);
6442 status = decode_sequence(xdr, &res->seq_res, rqstp);
6445 status = decode_putfh(xdr);
6448 status = decode_lock(xdr, res);
6454 * Decode LOCKT response
6456 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6457 struct nfs_lockt_res *res)
6459 struct compound_hdr hdr;
6462 status = decode_compound_hdr(xdr, &hdr);
6465 status = decode_sequence(xdr, &res->seq_res, rqstp);
6468 status = decode_putfh(xdr);
6471 status = decode_lockt(xdr, res);
6477 * Decode LOCKU response
6479 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6480 struct nfs_locku_res *res)
6482 struct compound_hdr hdr;
6485 status = decode_compound_hdr(xdr, &hdr);
6488 status = decode_sequence(xdr, &res->seq_res, rqstp);
6491 status = decode_putfh(xdr);
6494 status = decode_locku(xdr, res);
6499 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6500 struct xdr_stream *xdr, void *dummy)
6502 struct compound_hdr hdr;
6505 status = decode_compound_hdr(xdr, &hdr);
6507 status = decode_release_lockowner(xdr);
6512 * Decode READLINK response
6514 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6515 struct xdr_stream *xdr,
6516 struct nfs4_readlink_res *res)
6518 struct compound_hdr hdr;
6521 status = decode_compound_hdr(xdr, &hdr);
6524 status = decode_sequence(xdr, &res->seq_res, rqstp);
6527 status = decode_putfh(xdr);
6530 status = decode_readlink(xdr, rqstp);
6536 * Decode READDIR response
6538 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6539 struct nfs4_readdir_res *res)
6541 struct compound_hdr hdr;
6544 status = decode_compound_hdr(xdr, &hdr);
6547 status = decode_sequence(xdr, &res->seq_res, rqstp);
6550 status = decode_putfh(xdr);
6553 status = decode_readdir(xdr, rqstp, res);
6559 * Decode Read response
6561 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6562 struct nfs_pgio_res *res)
6564 struct compound_hdr hdr;
6567 status = decode_compound_hdr(xdr, &hdr);
6570 status = decode_sequence(xdr, &res->seq_res, rqstp);
6573 status = decode_putfh(xdr);
6576 status = decode_read(xdr, rqstp, res);
6578 status = res->count;
6584 * Decode WRITE response
6586 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6587 struct nfs_pgio_res *res)
6589 struct compound_hdr hdr;
6592 status = decode_compound_hdr(xdr, &hdr);
6595 status = decode_sequence(xdr, &res->seq_res, rqstp);
6598 status = decode_putfh(xdr);
6601 status = decode_write(xdr, res);
6605 decode_getfattr(xdr, res->fattr, res->server);
6607 status = res->count;
6613 * Decode COMMIT response
6615 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6616 struct nfs_commitres *res)
6618 struct compound_hdr hdr;
6621 status = decode_compound_hdr(xdr, &hdr);
6624 status = decode_sequence(xdr, &res->seq_res, rqstp);
6627 status = decode_putfh(xdr);
6630 status = decode_commit(xdr, res);
6636 * Decode FSINFO response
6638 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6639 struct nfs4_fsinfo_res *res)
6641 struct compound_hdr hdr;
6644 status = decode_compound_hdr(xdr, &hdr);
6646 status = decode_sequence(xdr, &res->seq_res, req);
6648 status = decode_putfh(xdr);
6650 status = decode_fsinfo(xdr, res->fsinfo);
6655 * Decode PATHCONF response
6657 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6658 struct nfs4_pathconf_res *res)
6660 struct compound_hdr hdr;
6663 status = decode_compound_hdr(xdr, &hdr);
6665 status = decode_sequence(xdr, &res->seq_res, req);
6667 status = decode_putfh(xdr);
6669 status = decode_pathconf(xdr, res->pathconf);
6674 * Decode STATFS response
6676 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6677 struct nfs4_statfs_res *res)
6679 struct compound_hdr hdr;
6682 status = decode_compound_hdr(xdr, &hdr);
6684 status = decode_sequence(xdr, &res->seq_res, req);
6686 status = decode_putfh(xdr);
6688 status = decode_statfs(xdr, res->fsstat);
6693 * Decode GETATTR_BITMAP response
6695 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6696 struct xdr_stream *xdr,
6697 struct nfs4_server_caps_res *res)
6699 struct compound_hdr hdr;
6702 status = decode_compound_hdr(xdr, &hdr);
6705 status = decode_sequence(xdr, &res->seq_res, req);
6708 status = decode_putfh(xdr);
6711 status = decode_server_caps(xdr, res);
6717 * Decode RENEW response
6719 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6722 struct compound_hdr hdr;
6725 status = decode_compound_hdr(xdr, &hdr);
6727 status = decode_renew(xdr);
6732 * Decode SETCLIENTID response
6734 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6735 struct xdr_stream *xdr,
6736 struct nfs4_setclientid_res *res)
6738 struct compound_hdr hdr;
6741 status = decode_compound_hdr(xdr, &hdr);
6743 status = decode_setclientid(xdr, res);
6748 * Decode SETCLIENTID_CONFIRM response
6750 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6751 struct xdr_stream *xdr)
6753 struct compound_hdr hdr;
6756 status = decode_compound_hdr(xdr, &hdr);
6758 status = decode_setclientid_confirm(xdr);
6763 * Decode DELEGRETURN response
6765 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6766 struct xdr_stream *xdr,
6767 struct nfs4_delegreturnres *res)
6769 struct compound_hdr hdr;
6772 status = decode_compound_hdr(xdr, &hdr);
6775 status = decode_sequence(xdr, &res->seq_res, rqstp);
6778 status = decode_putfh(xdr);
6781 status = decode_getfattr(xdr, res->fattr, res->server);
6784 status = decode_delegreturn(xdr);
6790 * Decode FS_LOCATIONS response
6792 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6793 struct xdr_stream *xdr,
6794 struct nfs4_fs_locations_res *res)
6796 struct compound_hdr hdr;
6799 status = decode_compound_hdr(xdr, &hdr);
6802 status = decode_sequence(xdr, &res->seq_res, req);
6805 status = decode_putfh(xdr);
6808 if (res->migration) {
6809 xdr_enter_page(xdr, PAGE_SIZE);
6810 status = decode_getfattr_generic(xdr,
6811 &res->fs_locations->fattr,
6812 NULL, res->fs_locations,
6813 NULL, res->fs_locations->server);
6817 status = decode_renew(xdr);
6819 status = decode_lookup(xdr);
6822 xdr_enter_page(xdr, PAGE_SIZE);
6823 status = decode_getfattr_generic(xdr,
6824 &res->fs_locations->fattr,
6825 NULL, res->fs_locations,
6826 NULL, res->fs_locations->server);
6833 * Decode SECINFO response
6835 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6836 struct xdr_stream *xdr,
6837 struct nfs4_secinfo_res *res)
6839 struct compound_hdr hdr;
6842 status = decode_compound_hdr(xdr, &hdr);
6845 status = decode_sequence(xdr, &res->seq_res, rqstp);
6848 status = decode_putfh(xdr);
6851 status = decode_secinfo(xdr, res);
6857 * Decode FSID_PRESENT response
6859 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6860 struct xdr_stream *xdr,
6861 struct nfs4_fsid_present_res *res)
6863 struct compound_hdr hdr;
6866 status = decode_compound_hdr(xdr, &hdr);
6869 status = decode_sequence(xdr, &res->seq_res, rqstp);
6872 status = decode_putfh(xdr);
6875 status = decode_getfh(xdr, res->fh);
6879 status = decode_renew(xdr);
6884 #if defined(CONFIG_NFS_V4_1)
6886 * Decode BIND_CONN_TO_SESSION response
6888 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6889 struct xdr_stream *xdr,
6892 struct compound_hdr hdr;
6895 status = decode_compound_hdr(xdr, &hdr);
6897 status = decode_bind_conn_to_session(xdr, res);
6902 * Decode EXCHANGE_ID response
6904 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6905 struct xdr_stream *xdr,
6908 struct compound_hdr hdr;
6911 status = decode_compound_hdr(xdr, &hdr);
6913 status = decode_exchange_id(xdr, res);
6918 * Decode CREATE_SESSION response
6920 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6921 struct xdr_stream *xdr,
6922 struct nfs41_create_session_res *res)
6924 struct compound_hdr hdr;
6927 status = decode_compound_hdr(xdr, &hdr);
6929 status = decode_create_session(xdr, res);
6934 * Decode DESTROY_SESSION response
6936 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6937 struct xdr_stream *xdr,
6940 struct compound_hdr hdr;
6943 status = decode_compound_hdr(xdr, &hdr);
6945 status = decode_destroy_session(xdr, res);
6950 * Decode DESTROY_CLIENTID response
6952 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6953 struct xdr_stream *xdr,
6956 struct compound_hdr hdr;
6959 status = decode_compound_hdr(xdr, &hdr);
6961 status = decode_destroy_clientid(xdr, res);
6966 * Decode SEQUENCE response
6968 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6969 struct xdr_stream *xdr,
6970 struct nfs4_sequence_res *res)
6972 struct compound_hdr hdr;
6975 status = decode_compound_hdr(xdr, &hdr);
6977 status = decode_sequence(xdr, res, rqstp);
6982 * Decode GET_LEASE_TIME response
6984 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6985 struct xdr_stream *xdr,
6986 struct nfs4_get_lease_time_res *res)
6988 struct compound_hdr hdr;
6991 status = decode_compound_hdr(xdr, &hdr);
6993 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
6995 status = decode_putrootfh(xdr);
6997 status = decode_fsinfo(xdr, res->lr_fsinfo);
7002 * Decode RECLAIM_COMPLETE response
7004 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7005 struct xdr_stream *xdr,
7006 struct nfs41_reclaim_complete_res *res)
7008 struct compound_hdr hdr;
7011 status = decode_compound_hdr(xdr, &hdr);
7013 status = decode_sequence(xdr, &res->seq_res, rqstp);
7015 status = decode_reclaim_complete(xdr, NULL);
7020 * Decode GETDEVINFO response
7022 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7023 struct xdr_stream *xdr,
7024 struct nfs4_getdeviceinfo_res *res)
7026 struct compound_hdr hdr;
7029 status = decode_compound_hdr(xdr, &hdr);
7032 status = decode_sequence(xdr, &res->seq_res, rqstp);
7035 status = decode_getdeviceinfo(xdr, res->pdev);
7041 * Decode LAYOUTGET response
7043 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7044 struct xdr_stream *xdr,
7045 struct nfs4_layoutget_res *res)
7047 struct compound_hdr hdr;
7050 status = decode_compound_hdr(xdr, &hdr);
7053 status = decode_sequence(xdr, &res->seq_res, rqstp);
7056 status = decode_putfh(xdr);
7059 status = decode_layoutget(xdr, rqstp, res);
7065 * Decode LAYOUTRETURN response
7067 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7068 struct xdr_stream *xdr,
7069 struct nfs4_layoutreturn_res *res)
7071 struct compound_hdr hdr;
7074 status = decode_compound_hdr(xdr, &hdr);
7077 status = decode_sequence(xdr, &res->seq_res, rqstp);
7080 status = decode_putfh(xdr);
7083 status = decode_layoutreturn(xdr, res);
7089 * Decode LAYOUTCOMMIT response
7091 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7092 struct xdr_stream *xdr,
7093 struct nfs4_layoutcommit_res *res)
7095 struct compound_hdr hdr;
7098 status = decode_compound_hdr(xdr, &hdr);
7101 status = decode_sequence(xdr, &res->seq_res, rqstp);
7104 status = decode_putfh(xdr);
7107 status = decode_layoutcommit(xdr, rqstp, res);
7110 decode_getfattr(xdr, res->fattr, res->server);
7116 * Decode SECINFO_NO_NAME response
7118 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7119 struct xdr_stream *xdr,
7120 struct nfs4_secinfo_res *res)
7122 struct compound_hdr hdr;
7125 status = decode_compound_hdr(xdr, &hdr);
7128 status = decode_sequence(xdr, &res->seq_res, rqstp);
7131 status = decode_putrootfh(xdr);
7134 status = decode_secinfo_no_name(xdr, res);
7140 * Decode TEST_STATEID response
7142 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7143 struct xdr_stream *xdr,
7144 struct nfs41_test_stateid_res *res)
7146 struct compound_hdr hdr;
7149 status = decode_compound_hdr(xdr, &hdr);
7152 status = decode_sequence(xdr, &res->seq_res, rqstp);
7155 status = decode_test_stateid(xdr, res);
7161 * Decode FREE_STATEID response
7163 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7164 struct xdr_stream *xdr,
7165 struct nfs41_free_stateid_res *res)
7167 struct compound_hdr hdr;
7170 status = decode_compound_hdr(xdr, &hdr);
7173 status = decode_sequence(xdr, &res->seq_res, rqstp);
7176 status = decode_free_stateid(xdr, res);
7180 #endif /* CONFIG_NFS_V4_1 */
7183 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7184 * the local page cache.
7185 * @xdr: XDR stream where entry resides
7186 * @entry: buffer to fill in with entry data
7187 * @plus: boolean indicating whether this should be a readdirplus entry
7189 * Returns zero if successful, otherwise a negative errno value is
7192 * This function is not invoked during READDIR reply decoding, but
7193 * rather whenever an application invokes the getdents(2) system call
7194 * on a directory already in our cache.
7196 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7200 uint32_t bitmap[3] = {0};
7202 __be32 *p = xdr_inline_decode(xdr, 4);
7205 if (*p == xdr_zero) {
7206 p = xdr_inline_decode(xdr, 4);
7215 p = xdr_inline_decode(xdr, 12);
7218 entry->prev_cookie = entry->cookie;
7219 p = xdr_decode_hyper(p, &entry->cookie);
7220 entry->len = be32_to_cpup(p);
7222 p = xdr_inline_decode(xdr, entry->len);
7225 entry->name = (const char *) p;
7228 * In case the server doesn't return an inode number,
7229 * we fake one here. (We don't use inode number 0,
7230 * since glibc seems to choke on it...)
7233 entry->fattr->valid = 0;
7235 if (decode_attr_bitmap(xdr, bitmap) < 0)
7238 if (decode_attr_length(xdr, &len, &savep) < 0)
7241 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7242 NULL, entry->label, entry->server) < 0)
7244 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7245 entry->ino = entry->fattr->mounted_on_fileid;
7246 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7247 entry->ino = entry->fattr->fileid;
7249 entry->d_type = DT_UNKNOWN;
7250 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7251 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7256 print_overflow_msg(__func__, xdr);
7261 * We need to translate between nfs status return values and
7262 * the local errno values which may not be the same.
7269 { NFS4ERR_PERM, -EPERM },
7270 { NFS4ERR_NOENT, -ENOENT },
7271 { NFS4ERR_IO, -errno_NFSERR_IO},
7272 { NFS4ERR_NXIO, -ENXIO },
7273 { NFS4ERR_ACCESS, -EACCES },
7274 { NFS4ERR_EXIST, -EEXIST },
7275 { NFS4ERR_XDEV, -EXDEV },
7276 { NFS4ERR_NOTDIR, -ENOTDIR },
7277 { NFS4ERR_ISDIR, -EISDIR },
7278 { NFS4ERR_INVAL, -EINVAL },
7279 { NFS4ERR_FBIG, -EFBIG },
7280 { NFS4ERR_NOSPC, -ENOSPC },
7281 { NFS4ERR_ROFS, -EROFS },
7282 { NFS4ERR_MLINK, -EMLINK },
7283 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7284 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7285 { NFS4ERR_DQUOT, -EDQUOT },
7286 { NFS4ERR_STALE, -ESTALE },
7287 { NFS4ERR_BADHANDLE, -EBADHANDLE },
7288 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7289 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7290 { NFS4ERR_TOOSMALL, -ETOOSMALL },
7291 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7292 { NFS4ERR_BADTYPE, -EBADTYPE },
7293 { NFS4ERR_LOCKED, -EAGAIN },
7294 { NFS4ERR_SYMLINK, -ELOOP },
7295 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7296 { NFS4ERR_DEADLOCK, -EDEADLK },
7301 * Convert an NFS error code to a local one.
7302 * This one is used jointly by NFSv2 and NFSv3.
7305 nfs4_stat_to_errno(int stat)
7308 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7309 if (nfs_errtbl[i].stat == stat)
7310 return nfs_errtbl[i].errno;
7312 if (stat <= 10000 || stat > 10100) {
7313 /* The server is looney tunes. */
7316 /* If we cannot translate the error, the recovery routines should
7318 * Note: remaining NFSv4 error codes have values > 10000, so should
7319 * not conflict with native Linux error codes.
7324 #define PROC(proc, argtype, restype) \
7325 [NFSPROC4_CLNT_##proc] = { \
7326 .p_proc = NFSPROC4_COMPOUND, \
7327 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7328 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7329 .p_arglen = NFS4_##argtype##_sz, \
7330 .p_replen = NFS4_##restype##_sz, \
7331 .p_statidx = NFSPROC4_CLNT_##proc, \
7335 struct rpc_procinfo nfs4_procedures[] = {
7336 PROC(READ, enc_read, dec_read),
7337 PROC(WRITE, enc_write, dec_write),
7338 PROC(COMMIT, enc_commit, dec_commit),
7339 PROC(OPEN, enc_open, dec_open),
7340 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7341 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7342 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7343 PROC(CLOSE, enc_close, dec_close),
7344 PROC(SETATTR, enc_setattr, dec_setattr),
7345 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7346 PROC(RENEW, enc_renew, dec_renew),
7347 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7348 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7349 PROC(LOCK, enc_lock, dec_lock),
7350 PROC(LOCKT, enc_lockt, dec_lockt),
7351 PROC(LOCKU, enc_locku, dec_locku),
7352 PROC(ACCESS, enc_access, dec_access),
7353 PROC(GETATTR, enc_getattr, dec_getattr),
7354 PROC(LOOKUP, enc_lookup, dec_lookup),
7355 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7356 PROC(REMOVE, enc_remove, dec_remove),
7357 PROC(RENAME, enc_rename, dec_rename),
7358 PROC(LINK, enc_link, dec_link),
7359 PROC(SYMLINK, enc_symlink, dec_symlink),
7360 PROC(CREATE, enc_create, dec_create),
7361 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7362 PROC(STATFS, enc_statfs, dec_statfs),
7363 PROC(READLINK, enc_readlink, dec_readlink),
7364 PROC(READDIR, enc_readdir, dec_readdir),
7365 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7366 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7367 PROC(GETACL, enc_getacl, dec_getacl),
7368 PROC(SETACL, enc_setacl, dec_setacl),
7369 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7370 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7371 PROC(SECINFO, enc_secinfo, dec_secinfo),
7372 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
7373 #if defined(CONFIG_NFS_V4_1)
7374 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7375 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7376 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7377 PROC(SEQUENCE, enc_sequence, dec_sequence),
7378 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7379 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7380 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7381 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7382 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7383 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7384 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7385 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7386 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7387 PROC(BIND_CONN_TO_SESSION,
7388 enc_bind_conn_to_session, dec_bind_conn_to_session),
7389 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
7390 #endif /* CONFIG_NFS_V4_1 */
7393 const struct rpc_version nfs_version4 = {
7395 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7396 .procs = nfs4_procedures