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/fs_struct.h>
59 #include "nfs4idmap.h"
60 #include "nfs4session.h"
64 #define NFSDBG_FACILITY NFSDBG_XDR
66 /* Mapping from NFS error code to "errno" error code. */
67 #define errno_NFSERR_IO EIO
69 static int nfs4_stat_to_errno(int);
71 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
73 #define NFS4_MAXTAGLEN 20
75 #define NFS4_MAXTAGLEN 0
78 /* lock,open owner id:
79 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
81 #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
82 #define lock_owner_id_maxsz (1 + 1 + 4)
83 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
84 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
86 #define op_encode_hdr_maxsz (1)
87 #define op_decode_hdr_maxsz (2)
88 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
90 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
91 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
92 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
94 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
95 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
96 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
97 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
98 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
99 ((3+NFS4_FHSIZE) >> 2))
100 #define nfs4_fattr_bitmap_maxsz 4
101 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
102 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
103 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
104 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
106 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
107 /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
108 #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
110 #define nfs4_label_maxsz 0
112 /* We support only one layout type per file system */
113 #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
114 /* This is based on getfattr, which uses the most attributes: */
115 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
116 3 + 3 + 3 + nfs4_owner_maxsz + \
117 nfs4_group_maxsz + nfs4_label_maxsz + \
118 decode_mdsthreshold_maxsz))
119 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
120 nfs4_fattr_value_maxsz)
121 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
122 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
128 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
129 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
130 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
131 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
132 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
133 /* The 5 accounts for the PNFS attributes, and assumes that at most three
134 * layout types will be returned.
136 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
137 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
138 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
139 #define decode_renew_maxsz (op_decode_hdr_maxsz)
140 #define encode_setclientid_maxsz \
141 (op_encode_hdr_maxsz + \
142 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
144 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
146 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
147 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
149 #define decode_setclientid_maxsz \
150 (op_decode_hdr_maxsz + \
152 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
154 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
155 #define encode_setclientid_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 3 + (NFS4_VERIFIER_SIZE >> 2))
158 #define decode_setclientid_confirm_maxsz \
159 (op_decode_hdr_maxsz)
160 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
161 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
162 #define encode_share_access_maxsz \
164 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
165 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
166 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
167 #define encode_open_maxsz (op_encode_hdr_maxsz + \
168 2 + encode_share_access_maxsz + 2 + \
169 open_owner_id_maxsz + \
170 encode_opentype_maxsz + \
171 encode_claim_null_maxsz)
172 #define decode_space_limit_maxsz (3)
173 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
174 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
175 decode_space_limit_maxsz + \
177 #define decode_change_info_maxsz (5)
178 #define decode_open_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz + \
180 decode_change_info_maxsz + 1 + \
181 nfs4_fattr_bitmap_maxsz + \
182 decode_delegation_maxsz)
183 #define encode_open_confirm_maxsz \
184 (op_encode_hdr_maxsz + \
185 encode_stateid_maxsz + 1)
186 #define decode_open_confirm_maxsz \
187 (op_decode_hdr_maxsz + \
188 decode_stateid_maxsz)
189 #define encode_open_downgrade_maxsz \
190 (op_encode_hdr_maxsz + \
191 encode_stateid_maxsz + 1 + \
192 encode_share_access_maxsz)
193 #define decode_open_downgrade_maxsz \
194 (op_decode_hdr_maxsz + \
195 decode_stateid_maxsz)
196 #define encode_close_maxsz (op_encode_hdr_maxsz + \
197 1 + encode_stateid_maxsz)
198 #define decode_close_maxsz (op_decode_hdr_maxsz + \
199 decode_stateid_maxsz)
200 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
201 encode_stateid_maxsz + \
203 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
204 nfs4_fattr_bitmap_maxsz)
205 #define encode_read_maxsz (op_encode_hdr_maxsz + \
206 encode_stateid_maxsz + 3)
207 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
208 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
209 2 + encode_verifier_maxsz + 5 + \
211 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
212 decode_verifier_maxsz)
213 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
214 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
215 #define encode_write_maxsz (op_encode_hdr_maxsz + \
216 encode_stateid_maxsz + 4)
217 #define decode_write_maxsz (op_decode_hdr_maxsz + \
218 2 + decode_verifier_maxsz)
219 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
220 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
221 decode_verifier_maxsz)
222 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
224 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
225 decode_change_info_maxsz)
226 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
228 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
229 decode_change_info_maxsz + \
230 decode_change_info_maxsz)
231 #define encode_link_maxsz (op_encode_hdr_maxsz + \
233 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
234 #define encode_lockowner_maxsz (7)
235 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
237 1 + encode_stateid_maxsz + 1 + \
238 encode_lockowner_maxsz)
239 #define decode_lock_denied_maxsz \
240 (8 + decode_lockowner_maxsz)
241 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
242 decode_lock_denied_maxsz)
243 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
244 encode_lockowner_maxsz)
245 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
246 decode_lock_denied_maxsz)
247 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
248 encode_stateid_maxsz + \
250 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
251 decode_stateid_maxsz)
252 #define encode_release_lockowner_maxsz \
253 (op_encode_hdr_maxsz + \
254 encode_lockowner_maxsz)
255 #define decode_release_lockowner_maxsz \
256 (op_decode_hdr_maxsz)
257 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
258 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
259 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
260 1 + nfs4_name_maxsz + \
263 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
264 #define encode_create_maxsz (op_encode_hdr_maxsz + \
265 1 + 2 + nfs4_name_maxsz + \
267 #define decode_create_maxsz (op_decode_hdr_maxsz + \
268 decode_change_info_maxsz + \
269 nfs4_fattr_bitmap_maxsz)
270 #define encode_statfs_maxsz (encode_getattr_maxsz)
271 #define decode_statfs_maxsz (decode_getattr_maxsz)
272 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
273 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
274 #define encode_getacl_maxsz (encode_getattr_maxsz)
275 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
276 nfs4_fattr_bitmap_maxsz + 1)
277 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
278 encode_stateid_maxsz + 3)
279 #define decode_setacl_maxsz (decode_setattr_maxsz)
280 #define encode_fs_locations_maxsz \
281 (encode_getattr_maxsz)
282 #define decode_fs_locations_maxsz \
284 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
285 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
287 #if defined(CONFIG_NFS_V4_1)
288 #define NFS4_MAX_MACHINE_NAME_LEN (64)
289 #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
290 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
292 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
293 encode_verifier_maxsz + \
294 1 /* co_ownerid.len */ + \
295 /* eia_clientowner */ \
296 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
299 /* max is SP4_MACH_CRED (for now) */ + \
300 1 + NFS4_OP_MAP_NUM_WORDS + \
301 1 + NFS4_OP_MAP_NUM_WORDS + \
302 1 /* implementation id array of size 1 */ + \
303 1 /* nii_domain */ + \
304 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
306 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
308 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
309 2 /* eir_clientid */ + \
310 1 /* eir_sequenceid */ + \
311 1 /* eir_flags */ + \
313 /* max is SP4_MACH_CRED (for now) */ + \
314 1 + NFS4_OP_MAP_NUM_WORDS + \
315 1 + NFS4_OP_MAP_NUM_WORDS + \
316 2 /* eir_server_owner.so_minor_id */ + \
317 /* eir_server_owner.so_major_id<> */ \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
319 /* eir_server_scope<> */ \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
321 1 /* eir_server_impl_id array length */ + \
322 1 /* nii_domain */ + \
323 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
325 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
327 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
328 #define decode_channel_attrs_maxsz (6 + \
329 1 /* ca_rdma_ird.len */ + \
331 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
332 2 /* csa_clientid */ + \
333 1 /* csa_sequence */ + \
334 1 /* csa_flags */ + \
335 encode_channel_attrs_maxsz + \
336 encode_channel_attrs_maxsz + \
337 1 /* csa_cb_program */ + \
338 1 /* csa_sec_parms.len (1) */ + \
339 1 /* cb_secflavor (AUTH_SYS) */ + \
341 1 /* machinename.len */ + \
342 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
345 1 /* gids.len (0) */)
346 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
347 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
348 1 /* csr_sequence */ + \
349 1 /* csr_flags */ + \
350 decode_channel_attrs_maxsz + \
351 decode_channel_attrs_maxsz)
352 #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
354 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
355 1 /* bctsa_dir */ + \
356 1 /* bctsa_use_conn_in_rdma_mode */)
357 #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
359 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
360 1 /* bctsr_dir */ + \
361 1 /* bctsr_use_conn_in_rdma_mode */)
362 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
363 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
364 #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
365 #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
366 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
367 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
368 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
369 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
370 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
371 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
372 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
373 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
374 1 /* layout type */ + \
376 1 /* bitmap size */ + \
377 1 /* notification bitmap length */ + \
378 1 /* notification bitmap, word 0 */)
379 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
380 1 /* layout type */ + \
381 1 /* opaque devaddr4 length */ + \
382 /* devaddr4 payload is read into page */ \
383 1 /* notification bitmap length */ + \
384 1 /* notification bitmap, word 0 */)
385 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
386 encode_stateid_maxsz)
387 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
388 decode_stateid_maxsz + \
389 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
390 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
394 encode_stateid_maxsz + \
395 1 /* new offset (true) */ + \
396 2 /* last byte written */ + \
397 1 /* nt_timechanged (false) */ + \
398 1 /* layoutupdate4 layout type */ + \
399 1 /* layoutupdate4 opaqueue len */)
400 /* the actual content of layoutupdate4 should
401 be allocated by drivers and spliced in
402 using xdr_write_pages */
403 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
404 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
405 encode_stateid_maxsz + \
407 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
408 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
409 1 + decode_stateid_maxsz)
410 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
411 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
412 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
413 XDR_QUADLEN(NFS4_STATEID_SIZE))
414 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
415 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
416 XDR_QUADLEN(NFS4_STATEID_SIZE))
417 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
418 #else /* CONFIG_NFS_V4_1 */
419 #define encode_sequence_maxsz 0
420 #define decode_sequence_maxsz 0
421 #define encode_layoutreturn_maxsz 0
422 #define decode_layoutreturn_maxsz 0
423 #endif /* CONFIG_NFS_V4_1 */
425 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
426 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
427 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
428 encode_sequence_maxsz + \
429 encode_putfh_maxsz + \
431 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
432 decode_sequence_maxsz + \
433 decode_putfh_maxsz + \
435 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
436 encode_sequence_maxsz + \
437 encode_putfh_maxsz + \
438 encode_readlink_maxsz)
439 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
440 decode_sequence_maxsz + \
441 decode_putfh_maxsz + \
442 decode_readlink_maxsz)
443 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
444 encode_sequence_maxsz + \
445 encode_putfh_maxsz + \
446 encode_readdir_maxsz)
447 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
448 decode_sequence_maxsz + \
449 decode_putfh_maxsz + \
450 decode_readdir_maxsz)
451 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
452 encode_sequence_maxsz + \
453 encode_putfh_maxsz + \
454 encode_write_maxsz + \
455 encode_getattr_maxsz)
456 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
457 decode_sequence_maxsz + \
458 decode_putfh_maxsz + \
459 decode_write_maxsz + \
460 decode_getattr_maxsz)
461 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
462 encode_sequence_maxsz + \
463 encode_putfh_maxsz + \
465 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
466 decode_sequence_maxsz + \
467 decode_putfh_maxsz + \
469 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
470 encode_sequence_maxsz + \
471 encode_putfh_maxsz + \
472 encode_open_maxsz + \
473 encode_access_maxsz + \
474 encode_getfh_maxsz + \
475 encode_getattr_maxsz)
476 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
477 decode_sequence_maxsz + \
478 decode_putfh_maxsz + \
479 decode_open_maxsz + \
480 decode_access_maxsz + \
481 decode_getfh_maxsz + \
482 decode_getattr_maxsz)
483 #define NFS4_enc_open_confirm_sz \
484 (compound_encode_hdr_maxsz + \
485 encode_putfh_maxsz + \
486 encode_open_confirm_maxsz)
487 #define NFS4_dec_open_confirm_sz \
488 (compound_decode_hdr_maxsz + \
489 decode_putfh_maxsz + \
490 decode_open_confirm_maxsz)
491 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
492 encode_sequence_maxsz + \
493 encode_putfh_maxsz + \
494 encode_open_maxsz + \
495 encode_access_maxsz + \
496 encode_getattr_maxsz)
497 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
498 decode_sequence_maxsz + \
499 decode_putfh_maxsz + \
500 decode_open_maxsz + \
501 decode_access_maxsz + \
502 decode_getattr_maxsz)
503 #define NFS4_enc_open_downgrade_sz \
504 (compound_encode_hdr_maxsz + \
505 encode_sequence_maxsz + \
506 encode_putfh_maxsz + \
507 encode_layoutreturn_maxsz + \
508 encode_open_downgrade_maxsz)
509 #define NFS4_dec_open_downgrade_sz \
510 (compound_decode_hdr_maxsz + \
511 decode_sequence_maxsz + \
512 decode_putfh_maxsz + \
513 decode_layoutreturn_maxsz + \
514 decode_open_downgrade_maxsz)
515 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
516 encode_sequence_maxsz + \
517 encode_putfh_maxsz + \
518 encode_layoutreturn_maxsz + \
519 encode_close_maxsz + \
520 encode_getattr_maxsz)
521 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
522 decode_sequence_maxsz + \
523 decode_putfh_maxsz + \
524 decode_layoutreturn_maxsz + \
525 decode_close_maxsz + \
526 decode_getattr_maxsz)
527 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
528 encode_sequence_maxsz + \
529 encode_putfh_maxsz + \
530 encode_setattr_maxsz + \
531 encode_getattr_maxsz)
532 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
533 decode_sequence_maxsz + \
534 decode_putfh_maxsz + \
535 decode_setattr_maxsz + \
536 decode_getattr_maxsz)
537 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
538 encode_sequence_maxsz + \
539 encode_putfh_maxsz + \
541 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
542 decode_sequence_maxsz + \
543 decode_putfh_maxsz + \
545 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
547 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
549 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
550 encode_setclientid_maxsz)
551 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
552 decode_setclientid_maxsz)
553 #define NFS4_enc_setclientid_confirm_sz \
554 (compound_encode_hdr_maxsz + \
555 encode_setclientid_confirm_maxsz)
556 #define NFS4_dec_setclientid_confirm_sz \
557 (compound_decode_hdr_maxsz + \
558 decode_setclientid_confirm_maxsz)
559 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
560 encode_sequence_maxsz + \
561 encode_putfh_maxsz + \
563 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
564 decode_sequence_maxsz + \
565 decode_putfh_maxsz + \
567 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
568 encode_sequence_maxsz + \
569 encode_putfh_maxsz + \
571 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
572 decode_sequence_maxsz + \
573 decode_putfh_maxsz + \
575 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
576 encode_sequence_maxsz + \
577 encode_putfh_maxsz + \
579 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
580 decode_sequence_maxsz + \
581 decode_putfh_maxsz + \
583 #define NFS4_enc_release_lockowner_sz \
584 (compound_encode_hdr_maxsz + \
585 encode_lockowner_maxsz)
586 #define NFS4_dec_release_lockowner_sz \
587 (compound_decode_hdr_maxsz + \
588 decode_lockowner_maxsz)
589 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
590 encode_sequence_maxsz + \
591 encode_putfh_maxsz + \
592 encode_access_maxsz + \
593 encode_getattr_maxsz)
594 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
595 decode_sequence_maxsz + \
596 decode_putfh_maxsz + \
597 decode_access_maxsz + \
598 decode_getattr_maxsz)
599 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
600 encode_sequence_maxsz + \
601 encode_putfh_maxsz + \
602 encode_getattr_maxsz + \
604 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
605 decode_sequence_maxsz + \
606 decode_putfh_maxsz + \
607 decode_getattr_maxsz + \
609 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
610 encode_sequence_maxsz + \
611 encode_putfh_maxsz + \
612 encode_lookup_maxsz + \
613 encode_getattr_maxsz + \
615 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
616 decode_sequence_maxsz + \
617 decode_putfh_maxsz + \
618 decode_lookup_maxsz + \
619 decode_getattr_maxsz + \
621 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
622 encode_sequence_maxsz + \
623 encode_putrootfh_maxsz + \
624 encode_getattr_maxsz + \
626 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
627 decode_sequence_maxsz + \
628 decode_putrootfh_maxsz + \
629 decode_getattr_maxsz + \
631 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
632 encode_sequence_maxsz + \
633 encode_putfh_maxsz + \
635 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
636 decode_sequence_maxsz + \
637 decode_putfh_maxsz + \
639 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
640 encode_sequence_maxsz + \
641 encode_putfh_maxsz + \
642 encode_savefh_maxsz + \
643 encode_putfh_maxsz + \
645 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
646 decode_sequence_maxsz + \
647 decode_putfh_maxsz + \
648 decode_savefh_maxsz + \
649 decode_putfh_maxsz + \
651 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
652 encode_sequence_maxsz + \
653 encode_putfh_maxsz + \
654 encode_savefh_maxsz + \
655 encode_putfh_maxsz + \
656 encode_link_maxsz + \
657 encode_restorefh_maxsz + \
658 encode_getattr_maxsz)
659 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
660 decode_sequence_maxsz + \
661 decode_putfh_maxsz + \
662 decode_savefh_maxsz + \
663 decode_putfh_maxsz + \
664 decode_link_maxsz + \
665 decode_restorefh_maxsz + \
666 decode_getattr_maxsz)
667 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
668 encode_sequence_maxsz + \
669 encode_putfh_maxsz + \
670 encode_symlink_maxsz + \
671 encode_getattr_maxsz + \
673 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
674 decode_sequence_maxsz + \
675 decode_putfh_maxsz + \
676 decode_symlink_maxsz + \
677 decode_getattr_maxsz + \
679 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
680 encode_sequence_maxsz + \
681 encode_putfh_maxsz + \
682 encode_create_maxsz + \
683 encode_getfh_maxsz + \
684 encode_getattr_maxsz)
685 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
686 decode_sequence_maxsz + \
687 decode_putfh_maxsz + \
688 decode_create_maxsz + \
689 decode_getfh_maxsz + \
690 decode_getattr_maxsz)
691 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
692 encode_sequence_maxsz + \
693 encode_putfh_maxsz + \
694 encode_getattr_maxsz)
695 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
696 decode_sequence_maxsz + \
697 decode_putfh_maxsz + \
698 decode_getattr_maxsz)
699 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
700 encode_sequence_maxsz + \
701 encode_putfh_maxsz + \
703 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
704 decode_sequence_maxsz + \
705 decode_putfh_maxsz + \
707 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
708 encode_sequence_maxsz + \
709 encode_putfh_maxsz + \
710 encode_getattr_maxsz)
711 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
712 decode_sequence_maxsz + \
713 decode_putfh_maxsz + \
714 decode_getattr_maxsz)
715 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
716 encode_sequence_maxsz + \
717 encode_putfh_maxsz + \
718 encode_layoutreturn_maxsz + \
719 encode_delegreturn_maxsz + \
720 encode_getattr_maxsz)
721 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
722 decode_sequence_maxsz + \
723 decode_putfh_maxsz + \
724 decode_layoutreturn_maxsz + \
725 decode_delegreturn_maxsz + \
726 decode_getattr_maxsz)
727 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
728 encode_sequence_maxsz + \
729 encode_putfh_maxsz + \
731 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
732 decode_sequence_maxsz + \
733 decode_putfh_maxsz + \
735 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
736 encode_sequence_maxsz + \
737 encode_putfh_maxsz + \
739 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
740 decode_sequence_maxsz + \
741 decode_putfh_maxsz + \
743 #define NFS4_enc_fs_locations_sz \
744 (compound_encode_hdr_maxsz + \
745 encode_sequence_maxsz + \
746 encode_putfh_maxsz + \
747 encode_lookup_maxsz + \
748 encode_fs_locations_maxsz + \
750 #define NFS4_dec_fs_locations_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_sequence_maxsz + \
753 decode_putfh_maxsz + \
754 decode_lookup_maxsz + \
755 decode_fs_locations_maxsz + \
757 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
758 encode_sequence_maxsz + \
759 encode_putfh_maxsz + \
760 encode_secinfo_maxsz)
761 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz + \
763 decode_putfh_maxsz + \
764 decode_secinfo_maxsz)
765 #define NFS4_enc_fsid_present_sz \
766 (compound_encode_hdr_maxsz + \
767 encode_sequence_maxsz + \
768 encode_putfh_maxsz + \
769 encode_getfh_maxsz + \
771 #define NFS4_dec_fsid_present_sz \
772 (compound_decode_hdr_maxsz + \
773 decode_sequence_maxsz + \
774 decode_putfh_maxsz + \
775 decode_getfh_maxsz + \
777 #if defined(CONFIG_NFS_V4_1)
778 #define NFS4_enc_bind_conn_to_session_sz \
779 (compound_encode_hdr_maxsz + \
780 encode_bind_conn_to_session_maxsz)
781 #define NFS4_dec_bind_conn_to_session_sz \
782 (compound_decode_hdr_maxsz + \
783 decode_bind_conn_to_session_maxsz)
784 #define NFS4_enc_exchange_id_sz \
785 (compound_encode_hdr_maxsz + \
786 encode_exchange_id_maxsz)
787 #define NFS4_dec_exchange_id_sz \
788 (compound_decode_hdr_maxsz + \
789 decode_exchange_id_maxsz)
790 #define NFS4_enc_create_session_sz \
791 (compound_encode_hdr_maxsz + \
792 encode_create_session_maxsz)
793 #define NFS4_dec_create_session_sz \
794 (compound_decode_hdr_maxsz + \
795 decode_create_session_maxsz)
796 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
797 encode_destroy_session_maxsz)
798 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
799 decode_destroy_session_maxsz)
800 #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
801 encode_destroy_clientid_maxsz)
802 #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
803 decode_destroy_clientid_maxsz)
804 #define NFS4_enc_sequence_sz \
805 (compound_decode_hdr_maxsz + \
806 encode_sequence_maxsz)
807 #define NFS4_dec_sequence_sz \
808 (compound_decode_hdr_maxsz + \
809 decode_sequence_maxsz)
810 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
811 encode_sequence_maxsz + \
812 encode_putrootfh_maxsz + \
814 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_putrootfh_maxsz + \
818 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
819 encode_sequence_maxsz + \
820 encode_reclaim_complete_maxsz)
821 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_reclaim_complete_maxsz)
824 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
825 encode_sequence_maxsz +\
826 encode_getdeviceinfo_maxsz)
827 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
828 decode_sequence_maxsz + \
829 decode_getdeviceinfo_maxsz)
830 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
831 encode_sequence_maxsz + \
832 encode_putfh_maxsz + \
833 encode_layoutget_maxsz)
834 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_putfh_maxsz + \
837 decode_layoutget_maxsz)
838 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
839 encode_sequence_maxsz +\
840 encode_putfh_maxsz + \
841 encode_layoutcommit_maxsz + \
842 encode_getattr_maxsz)
843 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
844 decode_sequence_maxsz + \
845 decode_putfh_maxsz + \
846 decode_layoutcommit_maxsz + \
847 decode_getattr_maxsz)
848 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
849 encode_sequence_maxsz + \
850 encode_putfh_maxsz + \
851 encode_layoutreturn_maxsz)
852 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
853 decode_sequence_maxsz + \
854 decode_putfh_maxsz + \
855 decode_layoutreturn_maxsz)
856 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
857 encode_sequence_maxsz + \
858 encode_putrootfh_maxsz +\
859 encode_secinfo_no_name_maxsz)
860 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
861 decode_sequence_maxsz + \
862 decode_putrootfh_maxsz + \
863 decode_secinfo_no_name_maxsz)
864 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
865 encode_sequence_maxsz + \
866 encode_test_stateid_maxsz)
867 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
868 decode_sequence_maxsz + \
869 decode_test_stateid_maxsz)
870 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
871 encode_sequence_maxsz + \
872 encode_free_stateid_maxsz)
873 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
874 decode_sequence_maxsz + \
875 decode_free_stateid_maxsz)
877 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
878 compound_encode_hdr_maxsz +
879 encode_sequence_maxsz +
881 encode_getattr_maxsz) *
884 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
885 compound_decode_hdr_maxsz +
886 decode_sequence_maxsz +
887 decode_putfh_maxsz) *
890 const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
891 compound_decode_hdr_maxsz +
892 decode_sequence_maxsz) *
894 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
895 #endif /* CONFIG_NFS_V4_1 */
897 static const umode_t nfs_type2fmt[] = {
904 [NF4SOCK] = S_IFSOCK,
910 struct compound_hdr {
916 uint32_t replen; /* expected reply words */
920 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
922 __be32 *p = xdr_reserve_space(xdr, nbytes);
927 static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
929 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
932 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
934 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
937 static void encode_uint32(struct xdr_stream *xdr, u32 n)
939 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
942 static void encode_uint64(struct xdr_stream *xdr, u64 n)
944 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
947 static void encode_nfs4_seqid(struct xdr_stream *xdr,
948 const struct nfs_seqid *seqid)
951 encode_uint32(xdr, seqid->sequence->counter);
953 encode_uint32(xdr, 0);
956 static void encode_compound_hdr(struct xdr_stream *xdr,
957 struct rpc_rqst *req,
958 struct compound_hdr *hdr)
961 struct rpc_auth *auth = req->rq_cred->cr_auth;
963 /* initialize running count of expected bytes in reply.
964 * NOTE: the replied tag SHOULD be the same is the one sent,
965 * but this is not required as a MUST for the server to do so. */
966 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
968 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
969 encode_string(xdr, hdr->taglen, hdr->tag);
970 p = reserve_space(xdr, 8);
971 *p++ = cpu_to_be32(hdr->minorversion);
973 *p = cpu_to_be32(hdr->nops);
976 static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
978 struct compound_hdr *hdr)
980 encode_uint32(xdr, op);
982 hdr->replen += replen;
985 static void encode_nops(struct compound_hdr *hdr)
987 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
988 *hdr->nops_p = htonl(hdr->nops);
991 static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
993 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
996 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
998 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
1001 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1002 const struct nfs4_label *label,
1003 const struct nfs_server *server,
1004 bool excl_check, const umode_t *umask)
1006 char owner_name[IDMAP_NAMESZ];
1007 char owner_group[IDMAP_NAMESZ];
1008 int owner_namelen = 0;
1009 int owner_grouplen = 0;
1014 uint32_t bmval[3] = { 0 };
1017 * We reserve enough space to write the entire attribute buffer at once.
1019 if (iap->ia_valid & ATTR_SIZE) {
1020 bmval[0] |= FATTR4_WORD0_SIZE;
1023 if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK))
1025 if (iap->ia_valid & ATTR_MODE) {
1027 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1030 bmval[1] |= FATTR4_WORD1_MODE;
1034 if (iap->ia_valid & ATTR_UID) {
1035 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1036 if (owner_namelen < 0) {
1037 dprintk("nfs: couldn't resolve uid %d to string\n",
1038 from_kuid(&init_user_ns, iap->ia_uid));
1040 strcpy(owner_name, "nobody");
1041 owner_namelen = sizeof("nobody") - 1;
1044 bmval[1] |= FATTR4_WORD1_OWNER;
1045 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1047 if (iap->ia_valid & ATTR_GID) {
1048 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1049 if (owner_grouplen < 0) {
1050 dprintk("nfs: couldn't resolve gid %d to string\n",
1051 from_kgid(&init_user_ns, iap->ia_gid));
1052 strcpy(owner_group, "nobody");
1053 owner_grouplen = sizeof("nobody") - 1;
1056 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1057 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1059 if (iap->ia_valid & ATTR_ATIME_SET) {
1060 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1062 } else if (iap->ia_valid & ATTR_ATIME) {
1063 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1066 if (iap->ia_valid & ATTR_MTIME_SET) {
1067 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1069 } else if (iap->ia_valid & ATTR_MTIME) {
1070 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1075 const u32 *excl_bmval = server->exclcreat_bitmask;
1076 bmval[0] &= excl_bmval[0];
1077 bmval[1] &= excl_bmval[1];
1078 bmval[2] &= excl_bmval[2];
1080 if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
1085 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1086 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1091 else if (bmval[1] != 0)
1096 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1098 *p++ = cpu_to_be32(bmval_len);
1099 for (i = 0; i < bmval_len; i++)
1100 *p++ = cpu_to_be32(bmval[i]);
1101 *p++ = cpu_to_be32(len);
1103 if (bmval[0] & FATTR4_WORD0_SIZE)
1104 p = xdr_encode_hyper(p, iap->ia_size);
1105 if (bmval[1] & FATTR4_WORD1_MODE)
1106 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1107 if (bmval[1] & FATTR4_WORD1_OWNER)
1108 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1109 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1110 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1111 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1112 if (iap->ia_valid & ATTR_ATIME_SET) {
1113 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1114 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1115 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1117 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1119 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1120 if (iap->ia_valid & ATTR_MTIME_SET) {
1121 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1122 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1123 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1125 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1127 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1128 *p++ = cpu_to_be32(label->lfs);
1129 *p++ = cpu_to_be32(label->pi);
1130 *p++ = cpu_to_be32(label->len);
1131 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1133 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1134 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1135 *p++ = cpu_to_be32(*umask);
1141 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1143 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1144 encode_uint32(xdr, access);
1147 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1149 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1150 encode_nfs4_seqid(xdr, arg->seqid);
1151 encode_nfs4_stateid(xdr, &arg->stateid);
1154 static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1158 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1159 p = reserve_space(xdr, 12);
1160 p = xdr_encode_hyper(p, args->offset);
1161 *p = cpu_to_be32(args->count);
1164 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1168 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1169 encode_uint32(xdr, create->ftype);
1171 switch (create->ftype) {
1173 p = reserve_space(xdr, 4);
1174 *p = cpu_to_be32(create->u.symlink.len);
1175 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1176 create->u.symlink.len);
1177 xdr->buf->flags |= XDRBUF_WRITE;
1180 case NF4BLK: case NF4CHR:
1181 p = reserve_space(xdr, 8);
1182 *p++ = cpu_to_be32(create->u.device.specdata1);
1183 *p = cpu_to_be32(create->u.device.specdata2);
1190 encode_string(xdr, create->name->len, create->name->name);
1191 encode_attrs(xdr, create->attrs, create->label, create->server, false,
1195 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1199 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1200 p = reserve_space(xdr, 8);
1201 *p++ = cpu_to_be32(1);
1202 *p = cpu_to_be32(bitmap);
1205 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1209 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1210 p = reserve_space(xdr, 12);
1211 *p++ = cpu_to_be32(2);
1212 *p++ = cpu_to_be32(bm0);
1213 *p = cpu_to_be32(bm1);
1217 encode_getattr_three(struct xdr_stream *xdr,
1218 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1219 struct compound_hdr *hdr)
1223 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1225 p = reserve_space(xdr, 16);
1226 *p++ = cpu_to_be32(3);
1227 *p++ = cpu_to_be32(bm0);
1228 *p++ = cpu_to_be32(bm1);
1229 *p = cpu_to_be32(bm2);
1231 p = reserve_space(xdr, 12);
1232 *p++ = cpu_to_be32(2);
1233 *p++ = cpu_to_be32(bm0);
1234 *p = cpu_to_be32(bm1);
1236 p = reserve_space(xdr, 8);
1237 *p++ = cpu_to_be32(1);
1238 *p = cpu_to_be32(bm0);
1242 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1244 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1245 bitmask[1] & nfs4_fattr_bitmap[1],
1246 bitmask[2] & nfs4_fattr_bitmap[2],
1250 static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1251 const u32 *open_bitmap,
1252 struct compound_hdr *hdr)
1254 encode_getattr_three(xdr,
1255 bitmask[0] & open_bitmap[0],
1256 bitmask[1] & open_bitmap[1],
1257 bitmask[2] & open_bitmap[2],
1261 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1263 encode_getattr_three(xdr,
1264 bitmask[0] & nfs4_fsinfo_bitmap[0],
1265 bitmask[1] & nfs4_fsinfo_bitmap[1],
1266 bitmask[2] & nfs4_fsinfo_bitmap[2],
1270 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1272 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1273 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1276 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1278 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1281 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1283 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1284 encode_string(xdr, name->len, name->name);
1287 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1289 if (fl->fl_type == F_RDLCK)
1290 return block ? NFS4_READW_LT : NFS4_READ_LT;
1291 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1294 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1296 if (fl->fl_end == OFFSET_MAX)
1297 return ~(uint64_t)0;
1298 return fl->fl_end - fl->fl_start + 1;
1301 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1305 p = reserve_space(xdr, 32);
1306 p = xdr_encode_hyper(p, lowner->clientid);
1307 *p++ = cpu_to_be32(20);
1308 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1309 *p++ = cpu_to_be32(lowner->s_dev);
1310 xdr_encode_hyper(p, lowner->id);
1314 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1315 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1317 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1321 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1322 p = reserve_space(xdr, 28);
1323 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1324 *p++ = cpu_to_be32(args->reclaim);
1325 p = xdr_encode_hyper(p, args->fl->fl_start);
1326 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1327 *p = cpu_to_be32(args->new_lock_owner);
1328 if (args->new_lock_owner){
1329 encode_nfs4_seqid(xdr, args->open_seqid);
1330 encode_nfs4_stateid(xdr, &args->open_stateid);
1331 encode_nfs4_seqid(xdr, args->lock_seqid);
1332 encode_lockowner(xdr, &args->lock_owner);
1335 encode_nfs4_stateid(xdr, &args->lock_stateid);
1336 encode_nfs4_seqid(xdr, args->lock_seqid);
1340 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1344 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1345 p = reserve_space(xdr, 20);
1346 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1347 p = xdr_encode_hyper(p, args->fl->fl_start);
1348 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1349 encode_lockowner(xdr, &args->lock_owner);
1352 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1356 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1357 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1358 encode_nfs4_seqid(xdr, args->seqid);
1359 encode_nfs4_stateid(xdr, &args->stateid);
1360 p = reserve_space(xdr, 16);
1361 p = xdr_encode_hyper(p, args->fl->fl_start);
1362 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1365 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1367 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1368 encode_lockowner(xdr, lowner);
1371 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1373 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1374 encode_string(xdr, name->len, name->name);
1377 static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
1381 p = reserve_space(xdr, 8);
1382 *p++ = cpu_to_be32(share_access);
1383 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1386 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1390 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1393 encode_nfs4_seqid(xdr, arg->seqid);
1394 encode_share_access(xdr, arg->share_access);
1395 p = reserve_space(xdr, 36);
1396 p = xdr_encode_hyper(p, arg->clientid);
1397 *p++ = cpu_to_be32(24);
1398 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1399 *p++ = cpu_to_be32(arg->server->s_dev);
1400 *p++ = cpu_to_be32(arg->id.uniquifier);
1401 xdr_encode_hyper(p, arg->id.create_time);
1404 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1408 p = reserve_space(xdr, 4);
1409 switch(arg->createmode) {
1410 case NFS4_CREATE_UNCHECKED:
1411 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1412 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false,
1415 case NFS4_CREATE_GUARDED:
1416 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1417 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false,
1420 case NFS4_CREATE_EXCLUSIVE:
1421 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1422 encode_nfs4_verifier(xdr, &arg->u.verifier);
1424 case NFS4_CREATE_EXCLUSIVE4_1:
1425 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1426 encode_nfs4_verifier(xdr, &arg->u.verifier);
1427 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true,
1432 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1436 p = reserve_space(xdr, 4);
1437 switch (arg->open_flags & O_CREAT) {
1439 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1442 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1443 encode_createmode(xdr, arg);
1447 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1451 p = reserve_space(xdr, 4);
1452 switch (delegation_type) {
1454 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1457 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1459 case FMODE_WRITE|FMODE_READ:
1460 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1467 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1471 p = reserve_space(xdr, 4);
1472 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1473 encode_string(xdr, name->len, name->name);
1476 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1480 p = reserve_space(xdr, 4);
1481 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1482 encode_delegation_type(xdr, type);
1485 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1489 p = reserve_space(xdr, 4);
1490 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1491 encode_nfs4_stateid(xdr, stateid);
1492 encode_string(xdr, name->len, name->name);
1495 static inline void encode_claim_fh(struct xdr_stream *xdr)
1499 p = reserve_space(xdr, 4);
1500 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1503 static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1507 p = reserve_space(xdr, 4);
1508 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1509 encode_nfs4_stateid(xdr, stateid);
1512 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1514 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1515 encode_openhdr(xdr, arg);
1516 encode_opentype(xdr, arg);
1517 switch (arg->claim) {
1518 case NFS4_OPEN_CLAIM_NULL:
1519 encode_claim_null(xdr, arg->name);
1521 case NFS4_OPEN_CLAIM_PREVIOUS:
1522 encode_claim_previous(xdr, arg->u.delegation_type);
1524 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1525 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1527 case NFS4_OPEN_CLAIM_FH:
1528 encode_claim_fh(xdr);
1530 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1531 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1538 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1540 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1541 encode_nfs4_stateid(xdr, arg->stateid);
1542 encode_nfs4_seqid(xdr, arg->seqid);
1545 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1547 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1548 encode_nfs4_stateid(xdr, &arg->stateid);
1549 encode_nfs4_seqid(xdr, arg->seqid);
1550 encode_share_access(xdr, arg->share_access);
1554 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1556 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1557 encode_string(xdr, fh->size, fh->data);
1560 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1562 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1565 static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1566 struct compound_hdr *hdr)
1570 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1571 encode_nfs4_stateid(xdr, &args->stateid);
1573 p = reserve_space(xdr, 12);
1574 p = xdr_encode_hyper(p, args->offset);
1575 *p = cpu_to_be32(args->count);
1578 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1580 uint32_t attrs[3] = {
1581 FATTR4_WORD0_RDATTR_ERROR,
1582 FATTR4_WORD1_MOUNTED_ON_FILEID,
1584 uint32_t dircount = readdir->count >> 1;
1586 uint32_t attrlen = 0;
1589 if (readdir->plus) {
1590 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1591 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1592 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1593 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1594 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1595 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1596 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1599 /* Use mounted_on_fileid only if the server supports it */
1600 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1601 attrs[0] |= FATTR4_WORD0_FILEID;
1602 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1603 attrs[i] &= readdir->bitmask[i];
1608 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1609 encode_uint64(xdr, readdir->cookie);
1610 encode_nfs4_verifier(xdr, &readdir->verifier);
1611 p = reserve_space(xdr, 12 + (attrlen << 2));
1612 *p++ = cpu_to_be32(dircount);
1613 *p++ = cpu_to_be32(readdir->count);
1614 *p++ = cpu_to_be32(attrlen);
1615 for (i = 0; i < attrlen; i++)
1616 *p++ = cpu_to_be32(attrs[i]);
1617 memcpy(verf, readdir->verifier.data, sizeof(verf));
1619 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1621 (unsigned long long)readdir->cookie,
1623 attrs[0] & readdir->bitmask[0],
1624 attrs[1] & readdir->bitmask[1],
1625 attrs[2] & readdir->bitmask[2]);
1628 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1630 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1633 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1635 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1636 encode_string(xdr, name->len, name->name);
1639 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1641 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1642 encode_string(xdr, oldname->len, oldname->name);
1643 encode_string(xdr, newname->len, newname->name);
1646 static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1647 struct compound_hdr *hdr)
1649 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1650 encode_uint64(xdr, clid);
1654 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1656 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1660 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1664 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1665 encode_nfs4_stateid(xdr, &zero_stateid);
1666 p = reserve_space(xdr, 2*4);
1667 *p++ = cpu_to_be32(1);
1668 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1669 p = reserve_space(xdr, 4);
1670 *p = cpu_to_be32(arg->acl_len);
1671 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
1675 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1677 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1680 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1682 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1683 encode_nfs4_stateid(xdr, &arg->stateid);
1684 encode_attrs(xdr, arg->iap, arg->label, server, false, NULL);
1687 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1691 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1692 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1694 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1695 setclientid->sc_clnt->cl_owner_id);
1696 p = reserve_space(xdr, 4);
1697 *p = cpu_to_be32(setclientid->sc_prog);
1698 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1699 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1700 p = reserve_space(xdr, 4);
1701 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
1704 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1706 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1707 decode_setclientid_confirm_maxsz, hdr);
1708 encode_uint64(xdr, arg->clientid);
1709 encode_nfs4_verifier(xdr, &arg->confirm);
1712 static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1713 struct compound_hdr *hdr)
1717 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1718 encode_nfs4_stateid(xdr, &args->stateid);
1720 p = reserve_space(xdr, 16);
1721 p = xdr_encode_hyper(p, args->offset);
1722 *p++ = cpu_to_be32(args->stable);
1723 *p = cpu_to_be32(args->count);
1725 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1728 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1730 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1731 encode_nfs4_stateid(xdr, stateid);
1734 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1736 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1737 encode_string(xdr, name->len, name->name);
1740 #if defined(CONFIG_NFS_V4_1)
1741 /* NFSv4.1 operations */
1742 static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1743 struct nfs41_bind_conn_to_session_args *args,
1744 struct compound_hdr *hdr)
1748 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1749 decode_bind_conn_to_session_maxsz, hdr);
1750 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1751 p = xdr_reserve_space(xdr, 8);
1752 *p++ = cpu_to_be32(args->dir);
1753 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
1756 static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1759 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1760 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1761 encode_uint32(xdr, op_map->u.words[i]);
1764 static void encode_exchange_id(struct xdr_stream *xdr,
1765 struct nfs41_exchange_id_args *args,
1766 struct compound_hdr *hdr)
1769 char impl_name[IMPL_NAME_LIMIT];
1772 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1773 encode_nfs4_verifier(xdr, args->verifier);
1775 encode_string(xdr, strlen(args->client->cl_owner_id),
1776 args->client->cl_owner_id);
1778 encode_uint32(xdr, args->flags);
1779 encode_uint32(xdr, args->state_protect.how);
1781 switch (args->state_protect.how) {
1785 encode_op_map(xdr, &args->state_protect.enforce);
1786 encode_op_map(xdr, &args->state_protect.allow);
1793 if (send_implementation_id &&
1794 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1795 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1796 <= sizeof(impl_name) + 1)
1797 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1798 utsname()->sysname, utsname()->release,
1799 utsname()->version, utsname()->machine);
1802 encode_uint32(xdr, 1); /* implementation id array length=1 */
1805 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1806 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1807 encode_string(xdr, len, impl_name);
1808 /* just send zeros for nii_date - the date is in nii_name */
1809 p = reserve_space(xdr, 12);
1810 p = xdr_encode_hyper(p, 0);
1811 *p = cpu_to_be32(0);
1813 encode_uint32(xdr, 0); /* implementation id array length=0 */
1816 static void encode_create_session(struct xdr_stream *xdr,
1817 struct nfs41_create_session_args *args,
1818 struct compound_hdr *hdr)
1821 struct nfs_client *clp = args->client;
1822 struct rpc_clnt *clnt = clp->cl_rpcclient;
1823 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1824 u32 max_resp_sz_cached;
1827 * Assumes OPEN is the biggest non-idempotent compound.
1828 * 2 is the verifier.
1830 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1831 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1833 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1834 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
1835 p = xdr_encode_hyper(p, args->clientid);
1836 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
1837 *p++ = cpu_to_be32(args->flags); /*flags */
1840 *p++ = cpu_to_be32(0); /* header padding size */
1841 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1842 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1843 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1844 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1845 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1846 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1849 *p++ = cpu_to_be32(0); /* header padding size */
1850 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1851 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1852 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1853 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1854 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1855 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1857 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1858 *p++ = cpu_to_be32(1);
1859 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1861 /* authsys_parms rfc1831 */
1862 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
1863 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1864 *p++ = cpu_to_be32(0); /* UID */
1865 *p++ = cpu_to_be32(0); /* GID */
1866 *p = cpu_to_be32(0); /* No more gids */
1869 static void encode_destroy_session(struct xdr_stream *xdr,
1870 struct nfs4_session *session,
1871 struct compound_hdr *hdr)
1873 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1874 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1877 static void encode_destroy_clientid(struct xdr_stream *xdr,
1879 struct compound_hdr *hdr)
1881 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1882 encode_uint64(xdr, clientid);
1885 static void encode_reclaim_complete(struct xdr_stream *xdr,
1886 struct nfs41_reclaim_complete_args *args,
1887 struct compound_hdr *hdr)
1889 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1890 encode_uint32(xdr, args->one_fs);
1892 #endif /* CONFIG_NFS_V4_1 */
1894 static void encode_sequence(struct xdr_stream *xdr,
1895 const struct nfs4_sequence_args *args,
1896 struct compound_hdr *hdr)
1898 #if defined(CONFIG_NFS_V4_1)
1899 struct nfs4_session *session;
1900 struct nfs4_slot_table *tp;
1901 struct nfs4_slot *slot = args->sa_slot;
1905 session = tp->session;
1909 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1912 * Sessionid + seqid + slotid + max slotid + cache_this
1914 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1915 "max_slotid=%d cache_this=%d\n",
1917 ((u32 *)session->sess_id.data)[0],
1918 ((u32 *)session->sess_id.data)[1],
1919 ((u32 *)session->sess_id.data)[2],
1920 ((u32 *)session->sess_id.data)[3],
1921 slot->seq_nr, slot->slot_nr,
1922 tp->highest_used_slotid, args->sa_cache_this);
1923 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1924 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1925 *p++ = cpu_to_be32(slot->seq_nr);
1926 *p++ = cpu_to_be32(slot->slot_nr);
1927 *p++ = cpu_to_be32(tp->highest_used_slotid);
1928 *p = cpu_to_be32(args->sa_cache_this);
1929 #endif /* CONFIG_NFS_V4_1 */
1932 #ifdef CONFIG_NFS_V4_1
1934 encode_getdeviceinfo(struct xdr_stream *xdr,
1935 const struct nfs4_getdeviceinfo_args *args,
1936 struct compound_hdr *hdr)
1940 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1941 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1942 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1943 NFS4_DEVICEID4_SIZE);
1944 *p++ = cpu_to_be32(args->pdev->layout_type);
1945 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
1947 p = reserve_space(xdr, 4 + 4);
1948 *p++ = cpu_to_be32(1); /* bitmap length */
1949 *p++ = cpu_to_be32(args->notify_types);
1953 encode_layoutget(struct xdr_stream *xdr,
1954 const struct nfs4_layoutget_args *args,
1955 struct compound_hdr *hdr)
1959 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1960 p = reserve_space(xdr, 36);
1961 *p++ = cpu_to_be32(0); /* Signal layout available */
1962 *p++ = cpu_to_be32(args->type);
1963 *p++ = cpu_to_be32(args->range.iomode);
1964 p = xdr_encode_hyper(p, args->range.offset);
1965 p = xdr_encode_hyper(p, args->range.length);
1966 p = xdr_encode_hyper(p, args->minlength);
1967 encode_nfs4_stateid(xdr, &args->stateid);
1968 encode_uint32(xdr, args->maxcount);
1970 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1974 (unsigned long)args->range.offset,
1975 (unsigned long)args->range.length,
1980 encode_layoutcommit(struct xdr_stream *xdr,
1981 struct inode *inode,
1982 struct nfs4_layoutcommit_args *args,
1983 struct compound_hdr *hdr)
1987 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1988 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1990 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1991 p = reserve_space(xdr, 20);
1992 /* Only whole file layouts */
1993 p = xdr_encode_hyper(p, 0); /* offset */
1994 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1995 *p = cpu_to_be32(0); /* reclaim */
1996 encode_nfs4_stateid(xdr, &args->stateid);
1997 if (args->lastbytewritten != U64_MAX) {
1998 p = reserve_space(xdr, 20);
1999 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2000 p = xdr_encode_hyper(p, args->lastbytewritten);
2002 p = reserve_space(xdr, 12);
2003 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2005 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2006 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2008 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
2009 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2010 NFS_I(inode)->layout, xdr, args);
2012 encode_uint32(xdr, args->layoutupdate_len);
2013 if (args->layoutupdate_pages) {
2014 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2015 args->layoutupdate_len);
2023 encode_layoutreturn(struct xdr_stream *xdr,
2024 const struct nfs4_layoutreturn_args *args,
2025 struct compound_hdr *hdr)
2027 const struct pnfs_layoutdriver_type *lr_ops = NFS_SERVER(args->inode)->pnfs_curr_ld;
2030 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2031 p = reserve_space(xdr, 16);
2032 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2033 *p++ = cpu_to_be32(args->layout_type);
2034 *p++ = cpu_to_be32(args->range.iomode);
2035 *p = cpu_to_be32(RETURN_FILE);
2036 p = reserve_space(xdr, 16);
2037 p = xdr_encode_hyper(p, args->range.offset);
2038 p = xdr_encode_hyper(p, args->range.length);
2039 spin_lock(&args->inode->i_lock);
2040 encode_nfs4_stateid(xdr, &args->stateid);
2041 spin_unlock(&args->inode->i_lock);
2042 if (args->ld_private->ops && args->ld_private->ops->encode)
2043 args->ld_private->ops->encode(xdr, args, args->ld_private);
2044 else if (lr_ops->encode_layoutreturn)
2045 lr_ops->encode_layoutreturn(xdr, args);
2047 encode_uint32(xdr, 0);
2051 encode_secinfo_no_name(struct xdr_stream *xdr,
2052 const struct nfs41_secinfo_no_name_args *args,
2053 struct compound_hdr *hdr)
2055 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2056 encode_uint32(xdr, args->style);
2060 static void encode_test_stateid(struct xdr_stream *xdr,
2061 struct nfs41_test_stateid_args *args,
2062 struct compound_hdr *hdr)
2064 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2065 encode_uint32(xdr, 1);
2066 encode_nfs4_stateid(xdr, args->stateid);
2069 static void encode_free_stateid(struct xdr_stream *xdr,
2070 struct nfs41_free_stateid_args *args,
2071 struct compound_hdr *hdr)
2073 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2074 encode_nfs4_stateid(xdr, &args->stateid);
2078 encode_layoutreturn(struct xdr_stream *xdr,
2079 const struct nfs4_layoutreturn_args *args,
2080 struct compound_hdr *hdr)
2083 #endif /* CONFIG_NFS_V4_1 */
2086 * END OF "GENERIC" ENCODE ROUTINES.
2089 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2091 #if defined(CONFIG_NFS_V4_1)
2092 struct nfs4_session *session = args->sa_slot->table->session;
2094 return session->clp->cl_mvops->minor_version;
2095 #endif /* CONFIG_NFS_V4_1 */
2100 * Encode an ACCESS request
2102 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2103 const struct nfs4_accessargs *args)
2105 struct compound_hdr hdr = {
2106 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2109 encode_compound_hdr(xdr, req, &hdr);
2110 encode_sequence(xdr, &args->seq_args, &hdr);
2111 encode_putfh(xdr, args->fh, &hdr);
2112 encode_access(xdr, args->access, &hdr);
2113 encode_getfattr(xdr, args->bitmask, &hdr);
2118 * Encode LOOKUP request
2120 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2121 const struct nfs4_lookup_arg *args)
2123 struct compound_hdr hdr = {
2124 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2127 encode_compound_hdr(xdr, req, &hdr);
2128 encode_sequence(xdr, &args->seq_args, &hdr);
2129 encode_putfh(xdr, args->dir_fh, &hdr);
2130 encode_lookup(xdr, args->name, &hdr);
2131 encode_getfh(xdr, &hdr);
2132 encode_getfattr(xdr, args->bitmask, &hdr);
2137 * Encode LOOKUP_ROOT request
2139 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2140 struct xdr_stream *xdr,
2141 const struct nfs4_lookup_root_arg *args)
2143 struct compound_hdr hdr = {
2144 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2147 encode_compound_hdr(xdr, req, &hdr);
2148 encode_sequence(xdr, &args->seq_args, &hdr);
2149 encode_putrootfh(xdr, &hdr);
2150 encode_getfh(xdr, &hdr);
2151 encode_getfattr(xdr, args->bitmask, &hdr);
2156 * Encode REMOVE request
2158 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2159 const struct nfs_removeargs *args)
2161 struct compound_hdr hdr = {
2162 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_sequence(xdr, &args->seq_args, &hdr);
2167 encode_putfh(xdr, args->fh, &hdr);
2168 encode_remove(xdr, &args->name, &hdr);
2173 * Encode RENAME request
2175 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2176 const struct nfs_renameargs *args)
2178 struct compound_hdr hdr = {
2179 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2182 encode_compound_hdr(xdr, req, &hdr);
2183 encode_sequence(xdr, &args->seq_args, &hdr);
2184 encode_putfh(xdr, args->old_dir, &hdr);
2185 encode_savefh(xdr, &hdr);
2186 encode_putfh(xdr, args->new_dir, &hdr);
2187 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2192 * Encode LINK request
2194 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2195 const struct nfs4_link_arg *args)
2197 struct compound_hdr hdr = {
2198 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2201 encode_compound_hdr(xdr, req, &hdr);
2202 encode_sequence(xdr, &args->seq_args, &hdr);
2203 encode_putfh(xdr, args->fh, &hdr);
2204 encode_savefh(xdr, &hdr);
2205 encode_putfh(xdr, args->dir_fh, &hdr);
2206 encode_link(xdr, args->name, &hdr);
2207 encode_restorefh(xdr, &hdr);
2208 encode_getfattr(xdr, args->bitmask, &hdr);
2213 * Encode CREATE request
2215 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2216 const struct nfs4_create_arg *args)
2218 struct compound_hdr hdr = {
2219 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2222 encode_compound_hdr(xdr, req, &hdr);
2223 encode_sequence(xdr, &args->seq_args, &hdr);
2224 encode_putfh(xdr, args->dir_fh, &hdr);
2225 encode_create(xdr, args, &hdr);
2226 encode_getfh(xdr, &hdr);
2227 encode_getfattr(xdr, args->bitmask, &hdr);
2232 * Encode SYMLINK request
2234 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2235 const struct nfs4_create_arg *args)
2237 nfs4_xdr_enc_create(req, xdr, args);
2241 * Encode GETATTR request
2243 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2244 const struct nfs4_getattr_arg *args)
2246 struct compound_hdr hdr = {
2247 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2250 encode_compound_hdr(xdr, req, &hdr);
2251 encode_sequence(xdr, &args->seq_args, &hdr);
2252 encode_putfh(xdr, args->fh, &hdr);
2253 encode_getfattr(xdr, args->bitmask, &hdr);
2258 * Encode a CLOSE request
2260 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2261 struct nfs_closeargs *args)
2263 struct compound_hdr hdr = {
2264 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2267 encode_compound_hdr(xdr, req, &hdr);
2268 encode_sequence(xdr, &args->seq_args, &hdr);
2269 encode_putfh(xdr, args->fh, &hdr);
2271 encode_layoutreturn(xdr, args->lr_args, &hdr);
2272 if (args->bitmask != NULL)
2273 encode_getfattr(xdr, args->bitmask, &hdr);
2274 encode_close(xdr, args, &hdr);
2279 * Encode an OPEN request
2281 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2282 struct nfs_openargs *args)
2284 struct compound_hdr hdr = {
2285 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2288 encode_compound_hdr(xdr, req, &hdr);
2289 encode_sequence(xdr, &args->seq_args, &hdr);
2290 encode_putfh(xdr, args->fh, &hdr);
2291 encode_open(xdr, args, &hdr);
2292 encode_getfh(xdr, &hdr);
2294 encode_access(xdr, args->access, &hdr);
2295 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2300 * Encode an OPEN_CONFIRM request
2302 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2303 struct xdr_stream *xdr,
2304 struct nfs_open_confirmargs *args)
2306 struct compound_hdr hdr = {
2310 encode_compound_hdr(xdr, req, &hdr);
2311 encode_putfh(xdr, args->fh, &hdr);
2312 encode_open_confirm(xdr, args, &hdr);
2317 * Encode an OPEN request with no attributes.
2319 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2320 struct xdr_stream *xdr,
2321 struct nfs_openargs *args)
2323 struct compound_hdr hdr = {
2324 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2327 encode_compound_hdr(xdr, req, &hdr);
2328 encode_sequence(xdr, &args->seq_args, &hdr);
2329 encode_putfh(xdr, args->fh, &hdr);
2330 encode_open(xdr, args, &hdr);
2332 encode_access(xdr, args->access, &hdr);
2333 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2338 * Encode an OPEN_DOWNGRADE request
2340 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2341 struct xdr_stream *xdr,
2342 struct nfs_closeargs *args)
2344 struct compound_hdr hdr = {
2345 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2348 encode_compound_hdr(xdr, req, &hdr);
2349 encode_sequence(xdr, &args->seq_args, &hdr);
2350 encode_putfh(xdr, args->fh, &hdr);
2352 encode_layoutreturn(xdr, args->lr_args, &hdr);
2353 encode_open_downgrade(xdr, args, &hdr);
2358 * Encode a LOCK request
2360 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2361 struct nfs_lock_args *args)
2363 struct compound_hdr hdr = {
2364 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2367 encode_compound_hdr(xdr, req, &hdr);
2368 encode_sequence(xdr, &args->seq_args, &hdr);
2369 encode_putfh(xdr, args->fh, &hdr);
2370 encode_lock(xdr, args, &hdr);
2375 * Encode a LOCKT request
2377 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2378 struct nfs_lockt_args *args)
2380 struct compound_hdr hdr = {
2381 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2384 encode_compound_hdr(xdr, req, &hdr);
2385 encode_sequence(xdr, &args->seq_args, &hdr);
2386 encode_putfh(xdr, args->fh, &hdr);
2387 encode_lockt(xdr, args, &hdr);
2392 * Encode a LOCKU request
2394 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2395 struct nfs_locku_args *args)
2397 struct compound_hdr hdr = {
2398 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2401 encode_compound_hdr(xdr, req, &hdr);
2402 encode_sequence(xdr, &args->seq_args, &hdr);
2403 encode_putfh(xdr, args->fh, &hdr);
2404 encode_locku(xdr, args, &hdr);
2408 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2409 struct xdr_stream *xdr,
2410 struct nfs_release_lockowner_args *args)
2412 struct compound_hdr hdr = {
2416 encode_compound_hdr(xdr, req, &hdr);
2417 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2422 * Encode a READLINK request
2424 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2425 const struct nfs4_readlink *args)
2427 struct compound_hdr hdr = {
2428 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2431 encode_compound_hdr(xdr, req, &hdr);
2432 encode_sequence(xdr, &args->seq_args, &hdr);
2433 encode_putfh(xdr, args->fh, &hdr);
2434 encode_readlink(xdr, args, req, &hdr);
2436 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2437 args->pgbase, args->pglen);
2442 * Encode a READDIR request
2444 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2445 const struct nfs4_readdir_arg *args)
2447 struct compound_hdr hdr = {
2448 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2451 encode_compound_hdr(xdr, req, &hdr);
2452 encode_sequence(xdr, &args->seq_args, &hdr);
2453 encode_putfh(xdr, args->fh, &hdr);
2454 encode_readdir(xdr, args, req, &hdr);
2456 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2457 args->pgbase, args->count);
2458 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2459 __func__, hdr.replen << 2, args->pages,
2460 args->pgbase, args->count);
2465 * Encode a READ request
2467 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2468 struct nfs_pgio_args *args)
2470 struct compound_hdr hdr = {
2471 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2474 encode_compound_hdr(xdr, req, &hdr);
2475 encode_sequence(xdr, &args->seq_args, &hdr);
2476 encode_putfh(xdr, args->fh, &hdr);
2477 encode_read(xdr, args, &hdr);
2479 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2480 args->pages, args->pgbase, args->count);
2481 req->rq_rcv_buf.flags |= XDRBUF_READ;
2486 * Encode an SETATTR request
2488 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2489 struct nfs_setattrargs *args)
2491 struct compound_hdr hdr = {
2492 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2495 encode_compound_hdr(xdr, req, &hdr);
2496 encode_sequence(xdr, &args->seq_args, &hdr);
2497 encode_putfh(xdr, args->fh, &hdr);
2498 encode_setattr(xdr, args, args->server, &hdr);
2499 encode_getfattr(xdr, args->bitmask, &hdr);
2504 * Encode a GETACL request
2506 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2507 struct nfs_getaclargs *args)
2509 struct compound_hdr hdr = {
2510 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2514 encode_compound_hdr(xdr, req, &hdr);
2515 encode_sequence(xdr, &args->seq_args, &hdr);
2516 encode_putfh(xdr, args->fh, &hdr);
2517 replen = hdr.replen + op_decode_hdr_maxsz + 1;
2518 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2520 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2521 args->acl_pages, 0, args->acl_len);
2527 * Encode a WRITE request
2529 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2530 struct nfs_pgio_args *args)
2532 struct compound_hdr hdr = {
2533 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2536 encode_compound_hdr(xdr, req, &hdr);
2537 encode_sequence(xdr, &args->seq_args, &hdr);
2538 encode_putfh(xdr, args->fh, &hdr);
2539 encode_write(xdr, args, &hdr);
2540 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2542 encode_getfattr(xdr, args->bitmask, &hdr);
2549 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2550 struct nfs_commitargs *args)
2552 struct compound_hdr hdr = {
2553 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2556 encode_compound_hdr(xdr, req, &hdr);
2557 encode_sequence(xdr, &args->seq_args, &hdr);
2558 encode_putfh(xdr, args->fh, &hdr);
2559 encode_commit(xdr, args, &hdr);
2566 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2567 struct nfs4_fsinfo_arg *args)
2569 struct compound_hdr hdr = {
2570 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2573 encode_compound_hdr(xdr, req, &hdr);
2574 encode_sequence(xdr, &args->seq_args, &hdr);
2575 encode_putfh(xdr, args->fh, &hdr);
2576 encode_fsinfo(xdr, args->bitmask, &hdr);
2581 * a PATHCONF request
2583 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2584 const struct nfs4_pathconf_arg *args)
2586 struct compound_hdr hdr = {
2587 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2590 encode_compound_hdr(xdr, req, &hdr);
2591 encode_sequence(xdr, &args->seq_args, &hdr);
2592 encode_putfh(xdr, args->fh, &hdr);
2593 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2601 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2602 const struct nfs4_statfs_arg *args)
2604 struct compound_hdr hdr = {
2605 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_sequence(xdr, &args->seq_args, &hdr);
2610 encode_putfh(xdr, args->fh, &hdr);
2611 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2612 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2617 * GETATTR_BITMAP request
2619 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2620 struct xdr_stream *xdr,
2621 struct nfs4_server_caps_arg *args)
2623 const u32 *bitmask = args->bitmask;
2624 struct compound_hdr hdr = {
2625 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2628 encode_compound_hdr(xdr, req, &hdr);
2629 encode_sequence(xdr, &args->seq_args, &hdr);
2630 encode_putfh(xdr, args->fhandle, &hdr);
2631 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
2638 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2639 struct nfs_client *clp)
2641 struct compound_hdr hdr = {
2645 encode_compound_hdr(xdr, req, &hdr);
2646 encode_renew(xdr, clp->cl_clientid, &hdr);
2651 * a SETCLIENTID request
2653 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2654 struct xdr_stream *xdr,
2655 struct nfs4_setclientid *sc)
2657 struct compound_hdr hdr = {
2661 encode_compound_hdr(xdr, req, &hdr);
2662 encode_setclientid(xdr, sc, &hdr);
2667 * a SETCLIENTID_CONFIRM request
2669 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2670 struct xdr_stream *xdr,
2671 struct nfs4_setclientid_res *arg)
2673 struct compound_hdr hdr = {
2677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_setclientid_confirm(xdr, arg, &hdr);
2683 * DELEGRETURN request
2685 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2686 struct xdr_stream *xdr,
2687 const struct nfs4_delegreturnargs *args)
2689 struct compound_hdr hdr = {
2690 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2693 encode_compound_hdr(xdr, req, &hdr);
2694 encode_sequence(xdr, &args->seq_args, &hdr);
2695 encode_putfh(xdr, args->fhandle, &hdr);
2697 encode_layoutreturn(xdr, args->lr_args, &hdr);
2699 encode_getfattr(xdr, args->bitmask, &hdr);
2700 encode_delegreturn(xdr, args->stateid, &hdr);
2705 * Encode FS_LOCATIONS request
2707 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2708 struct xdr_stream *xdr,
2709 struct nfs4_fs_locations_arg *args)
2711 struct compound_hdr hdr = {
2712 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2716 encode_compound_hdr(xdr, req, &hdr);
2717 encode_sequence(xdr, &args->seq_args, &hdr);
2718 if (args->migration) {
2719 encode_putfh(xdr, args->fh, &hdr);
2720 replen = hdr.replen;
2721 encode_fs_locations(xdr, args->bitmask, &hdr);
2723 encode_renew(xdr, args->clientid, &hdr);
2725 encode_putfh(xdr, args->dir_fh, &hdr);
2726 encode_lookup(xdr, args->name, &hdr);
2727 replen = hdr.replen;
2728 encode_fs_locations(xdr, args->bitmask, &hdr);
2731 /* Set up reply kvec to capture returned fs_locations array. */
2732 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2738 * Encode SECINFO request
2740 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2741 struct xdr_stream *xdr,
2742 struct nfs4_secinfo_arg *args)
2744 struct compound_hdr hdr = {
2745 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2748 encode_compound_hdr(xdr, req, &hdr);
2749 encode_sequence(xdr, &args->seq_args, &hdr);
2750 encode_putfh(xdr, args->dir_fh, &hdr);
2751 encode_secinfo(xdr, args->name, &hdr);
2756 * Encode FSID_PRESENT request
2758 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2759 struct xdr_stream *xdr,
2760 struct nfs4_fsid_present_arg *args)
2762 struct compound_hdr hdr = {
2763 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2766 encode_compound_hdr(xdr, req, &hdr);
2767 encode_sequence(xdr, &args->seq_args, &hdr);
2768 encode_putfh(xdr, args->fh, &hdr);
2769 encode_getfh(xdr, &hdr);
2771 encode_renew(xdr, args->clientid, &hdr);
2775 #if defined(CONFIG_NFS_V4_1)
2777 * BIND_CONN_TO_SESSION request
2779 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2780 struct xdr_stream *xdr,
2781 struct nfs41_bind_conn_to_session_args *args)
2783 struct compound_hdr hdr = {
2784 .minorversion = args->client->cl_mvops->minor_version,
2787 encode_compound_hdr(xdr, req, &hdr);
2788 encode_bind_conn_to_session(xdr, args, &hdr);
2793 * EXCHANGE_ID request
2795 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2796 struct xdr_stream *xdr,
2797 struct nfs41_exchange_id_args *args)
2799 struct compound_hdr hdr = {
2800 .minorversion = args->client->cl_mvops->minor_version,
2803 encode_compound_hdr(xdr, req, &hdr);
2804 encode_exchange_id(xdr, args, &hdr);
2809 * a CREATE_SESSION request
2811 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2812 struct xdr_stream *xdr,
2813 struct nfs41_create_session_args *args)
2815 struct compound_hdr hdr = {
2816 .minorversion = args->client->cl_mvops->minor_version,
2819 encode_compound_hdr(xdr, req, &hdr);
2820 encode_create_session(xdr, args, &hdr);
2825 * a DESTROY_SESSION request
2827 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2828 struct xdr_stream *xdr,
2829 struct nfs4_session *session)
2831 struct compound_hdr hdr = {
2832 .minorversion = session->clp->cl_mvops->minor_version,
2835 encode_compound_hdr(xdr, req, &hdr);
2836 encode_destroy_session(xdr, session, &hdr);
2841 * a DESTROY_CLIENTID request
2843 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2844 struct xdr_stream *xdr,
2845 struct nfs_client *clp)
2847 struct compound_hdr hdr = {
2848 .minorversion = clp->cl_mvops->minor_version,
2851 encode_compound_hdr(xdr, req, &hdr);
2852 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2857 * a SEQUENCE request
2859 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2860 struct nfs4_sequence_args *args)
2862 struct compound_hdr hdr = {
2863 .minorversion = nfs4_xdr_minorversion(args),
2866 encode_compound_hdr(xdr, req, &hdr);
2867 encode_sequence(xdr, args, &hdr);
2872 * a GET_LEASE_TIME request
2874 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2875 struct xdr_stream *xdr,
2876 struct nfs4_get_lease_time_args *args)
2878 struct compound_hdr hdr = {
2879 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2881 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2883 encode_compound_hdr(xdr, req, &hdr);
2884 encode_sequence(xdr, &args->la_seq_args, &hdr);
2885 encode_putrootfh(xdr, &hdr);
2886 encode_fsinfo(xdr, lease_bitmap, &hdr);
2891 * a RECLAIM_COMPLETE request
2893 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2894 struct xdr_stream *xdr,
2895 struct nfs41_reclaim_complete_args *args)
2897 struct compound_hdr hdr = {
2898 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2901 encode_compound_hdr(xdr, req, &hdr);
2902 encode_sequence(xdr, &args->seq_args, &hdr);
2903 encode_reclaim_complete(xdr, args, &hdr);
2908 * Encode GETDEVICEINFO request
2910 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2911 struct xdr_stream *xdr,
2912 struct nfs4_getdeviceinfo_args *args)
2914 struct compound_hdr hdr = {
2915 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2918 encode_compound_hdr(xdr, req, &hdr);
2919 encode_sequence(xdr, &args->seq_args, &hdr);
2920 encode_getdeviceinfo(xdr, args, &hdr);
2922 /* set up reply kvec. Subtract notification bitmap max size (2)
2923 * so that notification bitmap is put in xdr_buf tail */
2924 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2925 args->pdev->pages, args->pdev->pgbase,
2932 * Encode LAYOUTGET request
2934 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2935 struct xdr_stream *xdr,
2936 struct nfs4_layoutget_args *args)
2938 struct compound_hdr hdr = {
2939 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2942 encode_compound_hdr(xdr, req, &hdr);
2943 encode_sequence(xdr, &args->seq_args, &hdr);
2944 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2945 encode_layoutget(xdr, args, &hdr);
2947 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2948 args->layout.pages, 0, args->layout.pglen);
2954 * Encode LAYOUTCOMMIT request
2956 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2957 struct xdr_stream *xdr,
2958 struct nfs4_layoutcommit_args *args)
2960 struct nfs4_layoutcommit_data *data =
2961 container_of(args, struct nfs4_layoutcommit_data, args);
2962 struct compound_hdr hdr = {
2963 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2966 encode_compound_hdr(xdr, req, &hdr);
2967 encode_sequence(xdr, &args->seq_args, &hdr);
2968 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2969 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2970 encode_getfattr(xdr, args->bitmask, &hdr);
2975 * Encode LAYOUTRETURN request
2977 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2978 struct xdr_stream *xdr,
2979 struct nfs4_layoutreturn_args *args)
2981 struct compound_hdr hdr = {
2982 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2985 encode_compound_hdr(xdr, req, &hdr);
2986 encode_sequence(xdr, &args->seq_args, &hdr);
2987 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2988 encode_layoutreturn(xdr, args, &hdr);
2993 * Encode SECINFO_NO_NAME request
2995 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2996 struct xdr_stream *xdr,
2997 struct nfs41_secinfo_no_name_args *args)
2999 struct compound_hdr hdr = {
3000 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3003 encode_compound_hdr(xdr, req, &hdr);
3004 encode_sequence(xdr, &args->seq_args, &hdr);
3005 encode_putrootfh(xdr, &hdr);
3006 encode_secinfo_no_name(xdr, args, &hdr);
3012 * Encode TEST_STATEID request
3014 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3015 struct xdr_stream *xdr,
3016 struct nfs41_test_stateid_args *args)
3018 struct compound_hdr hdr = {
3019 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3022 encode_compound_hdr(xdr, req, &hdr);
3023 encode_sequence(xdr, &args->seq_args, &hdr);
3024 encode_test_stateid(xdr, args, &hdr);
3029 * Encode FREE_STATEID request
3031 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3032 struct xdr_stream *xdr,
3033 struct nfs41_free_stateid_args *args)
3035 struct compound_hdr hdr = {
3036 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3039 encode_compound_hdr(xdr, req, &hdr);
3040 encode_sequence(xdr, &args->seq_args, &hdr);
3041 encode_free_stateid(xdr, args, &hdr);
3044 #endif /* CONFIG_NFS_V4_1 */
3046 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3048 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3049 "Remaining buffer length is %tu words.\n",
3050 func, xdr->end - xdr->p);
3053 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3055 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3057 if (unlikely(ret < 0)) {
3058 if (ret == -EBADMSG)
3059 print_overflow_msg(__func__, xdr);
3066 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3070 p = xdr_inline_decode(xdr, 8);
3073 hdr->status = be32_to_cpup(p++);
3074 hdr->taglen = be32_to_cpup(p);
3076 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3079 hdr->tag = (char *)p;
3080 p += XDR_QUADLEN(hdr->taglen);
3081 hdr->nops = be32_to_cpup(p);
3082 if (unlikely(hdr->nops < 1))
3083 return nfs4_stat_to_errno(hdr->status);
3086 print_overflow_msg(__func__, xdr);
3090 static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3097 p = xdr_inline_decode(xdr, 8);
3100 opnum = be32_to_cpup(p++);
3101 if (unlikely(opnum != expected))
3102 goto out_bad_operation;
3103 nfserr = be32_to_cpup(p);
3104 if (nfserr == NFS_OK)
3107 *nfs_retval = nfs4_stat_to_errno(nfserr);
3110 dprintk("nfs: Server returned operation"
3111 " %d but we issued a request for %d\n",
3113 *nfs_retval = -EREMOTEIO;
3116 print_overflow_msg(__func__, xdr);
3121 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3125 __decode_op_hdr(xdr, expected, &retval);
3130 static int decode_ace(struct xdr_stream *xdr, void *ace)
3133 unsigned int strlen;
3136 p = xdr_inline_decode(xdr, 12);
3138 return decode_opaque_inline(xdr, &strlen, &str);
3139 print_overflow_msg(__func__, xdr);
3143 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3148 p = xdr_inline_decode(xdr, 4);
3151 bmlen = be32_to_cpup(p);
3153 bitmap[0] = bitmap[1] = bitmap[2] = 0;
3154 p = xdr_inline_decode(xdr, (bmlen << 2));
3158 bitmap[0] = be32_to_cpup(p++);
3160 bitmap[1] = be32_to_cpup(p++);
3162 bitmap[2] = be32_to_cpup(p);
3167 print_overflow_msg(__func__, xdr);
3171 static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
3175 p = xdr_inline_decode(xdr, 4);
3178 *attrlen = be32_to_cpup(p);
3179 *savep = xdr_stream_pos(xdr);
3182 print_overflow_msg(__func__, xdr);
3186 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3188 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3190 ret = decode_attr_bitmap(xdr, bitmask);
3191 if (unlikely(ret < 0))
3193 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3195 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3196 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3197 bitmask[0], bitmask[1], bitmask[2]);
3201 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3207 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3209 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3210 p = xdr_inline_decode(xdr, 4);
3213 *type = be32_to_cpup(p);
3214 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3215 dprintk("%s: bad type %d\n", __func__, *type);
3218 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3219 ret = NFS_ATTR_FATTR_TYPE;
3221 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3224 print_overflow_msg(__func__, xdr);
3228 static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3229 uint32_t *bitmap, uint32_t *type)
3234 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3236 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3237 p = xdr_inline_decode(xdr, 4);
3240 *type = be32_to_cpup(p);
3241 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3243 dprintk("%s: expire type=0x%x\n", __func__, *type);
3246 print_overflow_msg(__func__, xdr);
3250 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3256 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3258 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3259 p = xdr_inline_decode(xdr, 8);
3262 xdr_decode_hyper(p, change);
3263 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3264 ret = NFS_ATTR_FATTR_CHANGE;
3266 dprintk("%s: change attribute=%Lu\n", __func__,
3267 (unsigned long long)*change);
3270 print_overflow_msg(__func__, xdr);
3274 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3280 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3282 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3283 p = xdr_inline_decode(xdr, 8);
3286 xdr_decode_hyper(p, size);
3287 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3288 ret = NFS_ATTR_FATTR_SIZE;
3290 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3293 print_overflow_msg(__func__, xdr);
3297 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3302 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3304 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3305 p = xdr_inline_decode(xdr, 4);
3308 *res = be32_to_cpup(p);
3309 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3311 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3314 print_overflow_msg(__func__, xdr);
3318 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3323 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3325 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3326 p = xdr_inline_decode(xdr, 4);
3329 *res = be32_to_cpup(p);
3330 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3332 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3335 print_overflow_msg(__func__, xdr);
3339 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3346 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3348 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3349 p = xdr_inline_decode(xdr, 16);
3352 p = xdr_decode_hyper(p, &fsid->major);
3353 xdr_decode_hyper(p, &fsid->minor);
3354 bitmap[0] &= ~FATTR4_WORD0_FSID;
3355 ret = NFS_ATTR_FATTR_FSID;
3357 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3358 (unsigned long long)fsid->major,
3359 (unsigned long long)fsid->minor);
3362 print_overflow_msg(__func__, xdr);
3366 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3371 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3373 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3374 p = xdr_inline_decode(xdr, 4);
3377 *res = be32_to_cpup(p);
3378 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3380 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3383 print_overflow_msg(__func__, xdr);
3387 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3391 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3393 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3394 p = xdr_inline_decode(xdr, 4);
3397 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3398 *res = -be32_to_cpup(p);
3402 print_overflow_msg(__func__, xdr);
3406 static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3407 uint32_t *bitmap, uint32_t *bitmask)
3409 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3411 ret = decode_attr_bitmap(xdr, bitmask);
3412 if (unlikely(ret < 0))
3414 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3416 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3417 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3418 bitmask[0], bitmask[1], bitmask[2]);
3422 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3428 memset(fh, 0, sizeof(*fh));
3430 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3432 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3433 p = xdr_inline_decode(xdr, 4);
3436 len = be32_to_cpup(p);
3437 if (len > NFS4_FHSIZE)
3439 p = xdr_inline_decode(xdr, len);
3443 memcpy(fh->data, p, len);
3446 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3450 print_overflow_msg(__func__, xdr);
3454 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3459 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3461 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3462 p = xdr_inline_decode(xdr, 4);
3465 *res = be32_to_cpup(p);
3466 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3468 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3471 print_overflow_msg(__func__, xdr);
3475 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3481 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3483 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3484 p = xdr_inline_decode(xdr, 8);
3487 xdr_decode_hyper(p, fileid);
3488 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3489 ret = NFS_ATTR_FATTR_FILEID;
3491 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3494 print_overflow_msg(__func__, xdr);
3498 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3504 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3506 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3507 p = xdr_inline_decode(xdr, 8);
3510 xdr_decode_hyper(p, fileid);
3511 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3512 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3514 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3517 print_overflow_msg(__func__, xdr);
3521 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3527 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3529 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3530 p = xdr_inline_decode(xdr, 8);
3533 xdr_decode_hyper(p, res);
3534 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3536 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3539 print_overflow_msg(__func__, xdr);
3543 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3549 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3551 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3552 p = xdr_inline_decode(xdr, 8);
3555 xdr_decode_hyper(p, res);
3556 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3558 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3561 print_overflow_msg(__func__, xdr);
3565 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3571 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3573 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3574 p = xdr_inline_decode(xdr, 8);
3577 xdr_decode_hyper(p, res);
3578 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3580 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3583 print_overflow_msg(__func__, xdr);
3587 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3593 p = xdr_inline_decode(xdr, 4);
3596 n = be32_to_cpup(p);
3599 dprintk("pathname4: ");
3600 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3601 dprintk("cannot parse %d components in path\n", n);
3604 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
3605 struct nfs4_string *component = &path->components[path->ncomponents];
3606 status = decode_opaque_inline(xdr, &component->len, &component->data);
3607 if (unlikely(status != 0))
3611 (path->ncomponents != n ? "/ " : ""),
3612 component->len, component->data);
3617 /* a root pathname is sent as a zero component4 */
3618 path->ncomponents = 1;
3619 path->components[0].len=0;
3620 path->components[0].data=NULL;
3621 dprintk("pathname4: /\n");
3624 dprintk(" status %d", status);
3628 print_overflow_msg(__func__, xdr);
3632 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3638 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3641 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3643 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
3645 /* Ignore borken servers that return unrequested attrs */
3646 if (unlikely(res == NULL))
3648 dprintk("%s: fsroot:\n", __func__);
3649 status = decode_pathname(xdr, &res->fs_path);
3650 if (unlikely(status != 0))
3652 p = xdr_inline_decode(xdr, 4);
3655 n = be32_to_cpup(p);
3658 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3660 struct nfs4_fs_location *loc;
3662 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3664 loc = &res->locations[res->nlocations];
3665 p = xdr_inline_decode(xdr, 4);
3668 m = be32_to_cpup(p);
3670 dprintk("%s: servers:\n", __func__);
3671 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3672 struct nfs4_string *server;
3674 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3676 dprintk("%s: using first %u of %u servers "
3677 "returned for location %u\n",
3679 NFS4_FS_LOCATION_MAXSERVERS,
3680 m, res->nlocations);
3681 for (i = loc->nservers; i < m; i++) {
3684 status = decode_opaque_inline(xdr, &len, &data);
3685 if (unlikely(status != 0))
3690 server = &loc->servers[loc->nservers];
3691 status = decode_opaque_inline(xdr, &server->len, &server->data);
3692 if (unlikely(status != 0))
3694 dprintk("%s ", server->data);
3696 status = decode_pathname(xdr, &loc->rootpath);
3697 if (unlikely(status != 0))
3700 if (res->nlocations != 0)
3701 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3703 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3706 print_overflow_msg(__func__, xdr);
3712 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3718 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3720 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3721 p = xdr_inline_decode(xdr, 8);
3724 xdr_decode_hyper(p, res);
3725 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3727 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3730 print_overflow_msg(__func__, xdr);
3734 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3740 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3742 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3743 p = xdr_inline_decode(xdr, 4);
3746 *maxlink = be32_to_cpup(p);
3747 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3749 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3752 print_overflow_msg(__func__, xdr);
3756 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3762 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3764 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3765 p = xdr_inline_decode(xdr, 4);
3768 *maxname = be32_to_cpup(p);
3769 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3771 dprintk("%s: maxname=%u\n", __func__, *maxname);
3774 print_overflow_msg(__func__, xdr);
3778 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3784 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3786 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3788 p = xdr_inline_decode(xdr, 8);
3791 xdr_decode_hyper(p, &maxread);
3792 if (maxread > 0x7FFFFFFF)
3793 maxread = 0x7FFFFFFF;
3794 *res = (uint32_t)maxread;
3795 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3797 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3800 print_overflow_msg(__func__, xdr);
3804 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3810 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3812 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3814 p = xdr_inline_decode(xdr, 8);
3817 xdr_decode_hyper(p, &maxwrite);
3818 if (maxwrite > 0x7FFFFFFF)
3819 maxwrite = 0x7FFFFFFF;
3820 *res = (uint32_t)maxwrite;
3821 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3823 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3826 print_overflow_msg(__func__, xdr);
3830 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3837 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3839 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3840 p = xdr_inline_decode(xdr, 4);
3843 tmp = be32_to_cpup(p);
3844 *mode = tmp & ~S_IFMT;
3845 bitmap[1] &= ~FATTR4_WORD1_MODE;
3846 ret = NFS_ATTR_FATTR_MODE;
3848 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3851 print_overflow_msg(__func__, xdr);
3855 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3861 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3863 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3864 p = xdr_inline_decode(xdr, 4);
3867 *nlink = be32_to_cpup(p);
3868 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3869 ret = NFS_ATTR_FATTR_NLINK;
3871 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3874 print_overflow_msg(__func__, xdr);
3878 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3879 const struct nfs_server *server, kuid_t *uid,
3880 struct nfs4_string *owner_name)
3886 *uid = make_kuid(&init_user_ns, -2);
3887 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3889 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3890 p = xdr_inline_decode(xdr, 4);
3893 len = be32_to_cpup(p);
3894 p = xdr_inline_decode(xdr, len);
3897 if (owner_name != NULL) {
3898 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3899 if (owner_name->data != NULL) {
3900 owner_name->len = len;
3901 ret = NFS_ATTR_FATTR_OWNER_NAME;
3903 } else if (len < XDR_MAX_NETOBJ) {
3904 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3905 ret = NFS_ATTR_FATTR_OWNER;
3907 dprintk("%s: nfs_map_name_to_uid failed!\n",
3910 dprintk("%s: name too long (%u)!\n",
3912 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3914 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3917 print_overflow_msg(__func__, xdr);
3921 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3922 const struct nfs_server *server, kgid_t *gid,
3923 struct nfs4_string *group_name)
3929 *gid = make_kgid(&init_user_ns, -2);
3930 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3932 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3933 p = xdr_inline_decode(xdr, 4);
3936 len = be32_to_cpup(p);
3937 p = xdr_inline_decode(xdr, len);
3940 if (group_name != NULL) {
3941 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3942 if (group_name->data != NULL) {
3943 group_name->len = len;
3944 ret = NFS_ATTR_FATTR_GROUP_NAME;
3946 } else if (len < XDR_MAX_NETOBJ) {
3947 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3948 ret = NFS_ATTR_FATTR_GROUP;
3950 dprintk("%s: nfs_map_group_to_gid failed!\n",
3953 dprintk("%s: name too long (%u)!\n",
3955 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3957 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3960 print_overflow_msg(__func__, xdr);
3964 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3966 uint32_t major = 0, minor = 0;
3971 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3973 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3976 p = xdr_inline_decode(xdr, 8);
3979 major = be32_to_cpup(p++);
3980 minor = be32_to_cpup(p);
3981 tmp = MKDEV(major, minor);
3982 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3984 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3985 ret = NFS_ATTR_FATTR_RDEV;
3987 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3990 print_overflow_msg(__func__, xdr);
3994 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4000 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4002 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
4003 p = xdr_inline_decode(xdr, 8);
4006 xdr_decode_hyper(p, res);
4007 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4009 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
4012 print_overflow_msg(__func__, xdr);
4016 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4022 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4024 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4025 p = xdr_inline_decode(xdr, 8);
4028 xdr_decode_hyper(p, res);
4029 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4031 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
4034 print_overflow_msg(__func__, xdr);
4038 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4044 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4046 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4047 p = xdr_inline_decode(xdr, 8);
4050 xdr_decode_hyper(p, res);
4051 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4053 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
4056 print_overflow_msg(__func__, xdr);
4060 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4066 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4068 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4069 p = xdr_inline_decode(xdr, 8);
4072 xdr_decode_hyper(p, used);
4073 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4074 ret = NFS_ATTR_FATTR_SPACE_USED;
4076 dprintk("%s: space used=%Lu\n", __func__,
4077 (unsigned long long)*used);
4080 print_overflow_msg(__func__, xdr);
4084 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4090 p = xdr_inline_decode(xdr, 12);
4093 p = xdr_decode_hyper(p, &sec);
4094 nsec = be32_to_cpup(p);
4095 time->tv_sec = (time_t)sec;
4096 time->tv_nsec = (long)nsec;
4099 print_overflow_msg(__func__, xdr);
4103 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4109 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4111 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4112 status = decode_attr_time(xdr, time);
4114 status = NFS_ATTR_FATTR_ATIME;
4115 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4117 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
4121 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4127 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4129 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4130 status = decode_attr_time(xdr, time);
4132 status = NFS_ATTR_FATTR_CTIME;
4133 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4135 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
4139 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4140 struct timespec *time)
4146 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4148 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4149 status = decode_attr_time(xdr, time);
4150 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4152 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4153 (long)time->tv_nsec);
4157 static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4158 struct nfs4_label *label)
4166 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4168 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4169 p = xdr_inline_decode(xdr, 4);
4172 lfs = be32_to_cpup(p++);
4173 p = xdr_inline_decode(xdr, 4);
4176 pi = be32_to_cpup(p++);
4177 p = xdr_inline_decode(xdr, 4);
4180 len = be32_to_cpup(p++);
4181 p = xdr_inline_decode(xdr, len);
4184 if (len < NFS4_MAXLABELLEN) {
4186 memcpy(label->label, p, len);
4190 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4192 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4194 printk(KERN_WARNING "%s: label too long (%u)!\n",
4197 if (label && label->label)
4198 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4199 (char *)label->label, label->len, label->pi, label->lfs);
4203 print_overflow_msg(__func__, xdr);
4207 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4213 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4215 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4216 status = decode_attr_time(xdr, time);
4218 status = NFS_ATTR_FATTR_MTIME;
4219 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4221 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
4225 static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
4227 unsigned int attrwords = XDR_QUADLEN(attrlen);
4228 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
4230 if (unlikely(attrwords != nwords)) {
4231 dprintk("%s: server returned incorrect attribute length: "
4235 (attrwords < nwords) ? '<' : '>',
4242 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4246 p = xdr_inline_decode(xdr, 20);
4249 cinfo->atomic = be32_to_cpup(p++);
4250 p = xdr_decode_hyper(p, &cinfo->before);
4251 xdr_decode_hyper(p, &cinfo->after);
4254 print_overflow_msg(__func__, xdr);
4258 static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
4264 status = decode_op_hdr(xdr, OP_ACCESS);
4267 p = xdr_inline_decode(xdr, 8);
4270 supp = be32_to_cpup(p++);
4271 acc = be32_to_cpup(p);
4276 print_overflow_msg(__func__, xdr);
4280 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4282 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4283 if (unlikely(ret < 0)) {
4284 print_overflow_msg(__func__, xdr);
4290 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4292 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4295 static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4297 stateid->type = NFS4_OPEN_STATEID_TYPE;
4298 return decode_stateid(xdr, stateid);
4301 static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4303 stateid->type = NFS4_LOCK_STATEID_TYPE;
4304 return decode_stateid(xdr, stateid);
4307 static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4309 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4310 return decode_stateid(xdr, stateid);
4313 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4317 status = decode_op_hdr(xdr, OP_CLOSE);
4319 nfs_increment_open_seqid(status, res->seqid);
4321 status = decode_open_stateid(xdr, &res->stateid);
4325 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4327 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4330 static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4332 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4335 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4339 status = decode_op_hdr(xdr, OP_COMMIT);
4341 status = decode_write_verifier(xdr, &res->verf->verifier);
4345 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4351 status = decode_op_hdr(xdr, OP_CREATE);
4354 if ((status = decode_change_info(xdr, cinfo)))
4356 p = xdr_inline_decode(xdr, 4);
4359 bmlen = be32_to_cpup(p);
4360 p = xdr_inline_decode(xdr, bmlen << 2);
4364 print_overflow_msg(__func__, xdr);
4368 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4371 uint32_t attrlen, bitmap[3] = {0};
4374 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4376 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4378 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4380 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4382 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4383 &res->fh_expire_type)) != 0)
4385 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4387 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4389 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4391 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4392 res->exclcreat_bitmask)) != 0)
4394 status = verify_attr_len(xdr, savep, attrlen);
4396 dprintk("%s: xdr returned %d!\n", __func__, -status);
4400 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4403 uint32_t attrlen, bitmap[3] = {0};
4406 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4408 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4410 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4413 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4415 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4417 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4421 if (unlikely(bitmap[0]))
4424 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4426 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4428 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4431 status = verify_attr_len(xdr, savep, attrlen);
4433 dprintk("%s: xdr returned %d!\n", __func__, -status);
4437 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4440 uint32_t attrlen, bitmap[3] = {0};
4443 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4445 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4447 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4450 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4452 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4455 status = verify_attr_len(xdr, savep, attrlen);
4457 dprintk("%s: xdr returned %d!\n", __func__, -status);
4461 static int decode_threshold_hint(struct xdr_stream *xdr,
4469 if (likely(bitmap[0] & hint_bit)) {
4470 p = xdr_inline_decode(xdr, 8);
4473 xdr_decode_hyper(p, res);
4477 print_overflow_msg(__func__, xdr);
4481 static int decode_first_threshold_item4(struct xdr_stream *xdr,
4482 struct nfs4_threshold *res)
4486 uint32_t bitmap[3] = {0,}, attrlen;
4490 p = xdr_inline_decode(xdr, 4);
4492 print_overflow_msg(__func__, xdr);
4495 res->l_type = be32_to_cpup(p);
4497 /* thi_hintset bitmap */
4498 status = decode_attr_bitmap(xdr, bitmap);
4502 /* thi_hintlist length */
4503 status = decode_attr_length(xdr, &attrlen, &savep);
4507 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4510 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4513 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4517 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4522 status = verify_attr_len(xdr, savep, attrlen);
4523 res->bm = bitmap[0];
4525 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4526 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4529 dprintk("%s ret=%d!\n", __func__, status);
4534 * Thresholds on pNFS direct I/O vrs MDS I/O
4536 static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4538 struct nfs4_threshold *res)
4544 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4546 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
4547 /* Did the server return an unrequested attribute? */
4548 if (unlikely(res == NULL))
4550 p = xdr_inline_decode(xdr, 4);
4553 num = be32_to_cpup(p);
4557 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4558 "drivers per filesystem not supported\n",
4561 status = decode_first_threshold_item4(xdr, res);
4562 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
4566 print_overflow_msg(__func__, xdr);
4570 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4571 struct nfs_fattr *fattr, struct nfs_fh *fh,
4572 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
4573 const struct nfs_server *server)
4580 status = decode_attr_type(xdr, bitmap, &type);
4585 fattr->mode |= nfs_type2fmt[type];
4586 fattr->valid |= status;
4589 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4592 fattr->valid |= status;
4594 status = decode_attr_size(xdr, bitmap, &fattr->size);
4597 fattr->valid |= status;
4599 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4602 fattr->valid |= status;
4605 status = decode_attr_error(xdr, bitmap, &err);
4609 status = decode_attr_filehandle(xdr, bitmap, fh);
4613 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4616 fattr->valid |= status;
4618 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4621 fattr->valid |= status;
4624 if (unlikely(bitmap[0]))
4627 status = decode_attr_mode(xdr, bitmap, &fmode);
4631 fattr->mode |= fmode;
4632 fattr->valid |= status;
4635 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4638 fattr->valid |= status;
4640 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4643 fattr->valid |= status;
4645 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4648 fattr->valid |= status;
4650 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4653 fattr->valid |= status;
4655 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4658 fattr->valid |= status;
4660 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4663 fattr->valid |= status;
4665 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4668 fattr->valid |= status;
4670 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4673 fattr->valid |= status;
4675 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4678 fattr->valid |= status;
4681 if (unlikely(bitmap[1]))
4684 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4689 status = decode_attr_security_label(xdr, bitmap, label);
4692 fattr->valid |= status;
4696 dprintk("%s: xdr returned %d\n", __func__, -status);
4700 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4701 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4702 struct nfs4_label *label, const struct nfs_server *server)
4709 status = decode_op_hdr(xdr, OP_GETATTR);
4713 status = decode_attr_bitmap(xdr, bitmap);
4717 status = decode_attr_length(xdr, &attrlen, &savep);
4721 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4726 status = verify_attr_len(xdr, savep, attrlen);
4728 dprintk("%s: xdr returned %d\n", __func__, -status);
4732 static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4733 struct nfs4_label *label, const struct nfs_server *server)
4735 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4738 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4739 const struct nfs_server *server)
4741 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4745 * Decode potentially multiple layout types.
4747 static int decode_pnfs_layout_types(struct xdr_stream *xdr,
4748 struct nfs_fsinfo *fsinfo)
4753 p = xdr_inline_decode(xdr, 4);
4756 fsinfo->nlayouttypes = be32_to_cpup(p);
4758 /* pNFS is not supported by the underlying file system */
4759 if (fsinfo->nlayouttypes == 0)
4762 /* Decode and set first layout type, move xdr->p past unused types */
4763 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
4767 /* If we get too many, then just cap it at the max */
4768 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4769 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4770 __func__, fsinfo->nlayouttypes);
4771 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4774 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4775 fsinfo->layouttype[i] = be32_to_cpup(p++);
4778 print_overflow_msg(__func__, xdr);
4783 * The type of file system exported.
4784 * Note we must ensure that layouttype is set in any non-error case.
4786 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4787 struct nfs_fsinfo *fsinfo)
4791 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4792 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4794 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4795 status = decode_pnfs_layout_types(xdr, fsinfo);
4796 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4802 * The prefered block size for layout directed io
4804 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4809 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4811 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4812 p = xdr_inline_decode(xdr, 4);
4814 print_overflow_msg(__func__, xdr);
4817 *res = be32_to_cpup(p);
4818 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4824 * The granularity of a CLONE operation.
4826 static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4831 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4833 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4834 p = xdr_inline_decode(xdr, 4);
4836 print_overflow_msg(__func__, xdr);
4839 *res = be32_to_cpup(p);
4840 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4845 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4848 uint32_t attrlen, bitmap[3];
4851 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4853 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4855 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4858 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4860 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4862 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4864 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4866 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4867 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4869 fsinfo->wtpref = fsinfo->wtmax;
4872 if (unlikely(bitmap[0]))
4875 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4878 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
4883 if (unlikely(bitmap[1]))
4886 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4889 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4893 status = verify_attr_len(xdr, savep, attrlen);
4895 dprintk("%s: xdr returned %d!\n", __func__, -status);
4899 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4905 /* Zero handle first to allow comparisons */
4906 memset(fh, 0, sizeof(*fh));
4908 status = decode_op_hdr(xdr, OP_GETFH);
4912 p = xdr_inline_decode(xdr, 4);
4915 len = be32_to_cpup(p);
4916 if (len > NFS4_FHSIZE)
4919 p = xdr_inline_decode(xdr, len);
4922 memcpy(fh->data, p, len);
4925 print_overflow_msg(__func__, xdr);
4929 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4933 status = decode_op_hdr(xdr, OP_LINK);
4936 return decode_change_info(xdr, cinfo);
4940 * We create the owner, so we know a proper owner.id length is 4.
4942 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4944 uint64_t offset, length, clientid;
4946 uint32_t namelen, type;
4948 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4951 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4952 p = xdr_decode_hyper(p, &length);
4953 type = be32_to_cpup(p++); /* 4 byte read */
4954 if (fl != NULL) { /* manipulate file lock */
4955 fl->fl_start = (loff_t)offset;
4956 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4957 if (length == ~(uint64_t)0)
4958 fl->fl_end = OFFSET_MAX;
4959 fl->fl_type = F_WRLCK;
4961 fl->fl_type = F_RDLCK;
4964 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4965 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4966 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4968 return -NFS4ERR_DENIED;
4970 print_overflow_msg(__func__, xdr);
4974 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4978 status = decode_op_hdr(xdr, OP_LOCK);
4982 status = decode_lock_stateid(xdr, &res->stateid);
4983 if (unlikely(status))
4985 } else if (status == -NFS4ERR_DENIED)
4986 status = decode_lock_denied(xdr, NULL);
4987 if (res->open_seqid != NULL)
4988 nfs_increment_open_seqid(status, res->open_seqid);
4989 nfs_increment_lock_seqid(status, res->lock_seqid);
4994 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4997 status = decode_op_hdr(xdr, OP_LOCKT);
4998 if (status == -NFS4ERR_DENIED)
4999 return decode_lock_denied(xdr, res->denied);
5003 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
5007 status = decode_op_hdr(xdr, OP_LOCKU);
5009 nfs_increment_lock_seqid(status, res->seqid);
5011 status = decode_lock_stateid(xdr, &res->stateid);
5015 static int decode_release_lockowner(struct xdr_stream *xdr)
5017 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5020 static int decode_lookup(struct xdr_stream *xdr)
5022 return decode_op_hdr(xdr, OP_LOOKUP);
5025 /* This is too sick! */
5026 static int decode_space_limit(struct xdr_stream *xdr,
5027 unsigned long *pagemod_limit)
5030 uint32_t limit_type, nblocks, blocksize;
5033 p = xdr_inline_decode(xdr, 12);
5036 limit_type = be32_to_cpup(p++);
5037 switch (limit_type) {
5038 case NFS4_LIMIT_SIZE:
5039 xdr_decode_hyper(p, &maxsize);
5041 case NFS4_LIMIT_BLOCKS:
5042 nblocks = be32_to_cpup(p++);
5043 blocksize = be32_to_cpup(p);
5044 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
5046 maxsize >>= PAGE_SHIFT;
5047 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
5050 print_overflow_msg(__func__, xdr);
5054 static int decode_rw_delegation(struct xdr_stream *xdr,
5055 uint32_t delegation_type,
5056 struct nfs_openres *res)
5061 status = decode_delegation_stateid(xdr, &res->delegation);
5062 if (unlikely(status))
5064 p = xdr_inline_decode(xdr, 4);
5067 res->do_recall = be32_to_cpup(p);
5069 switch (delegation_type) {
5070 case NFS4_OPEN_DELEGATE_READ:
5071 res->delegation_type = FMODE_READ;
5073 case NFS4_OPEN_DELEGATE_WRITE:
5074 res->delegation_type = FMODE_WRITE|FMODE_READ;
5075 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
5078 return decode_ace(xdr, NULL);
5080 print_overflow_msg(__func__, xdr);
5084 static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5087 uint32_t why_no_delegation;
5089 p = xdr_inline_decode(xdr, 4);
5092 why_no_delegation = be32_to_cpup(p);
5093 switch (why_no_delegation) {
5094 case WND4_CONTENTION:
5096 xdr_inline_decode(xdr, 4);
5097 /* Ignore for now */
5101 print_overflow_msg(__func__, xdr);
5105 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5108 uint32_t delegation_type;
5110 p = xdr_inline_decode(xdr, 4);
5113 delegation_type = be32_to_cpup(p);
5114 res->delegation_type = 0;
5115 switch (delegation_type) {
5116 case NFS4_OPEN_DELEGATE_NONE:
5118 case NFS4_OPEN_DELEGATE_READ:
5119 case NFS4_OPEN_DELEGATE_WRITE:
5120 return decode_rw_delegation(xdr, delegation_type, res);
5121 case NFS4_OPEN_DELEGATE_NONE_EXT:
5122 return decode_no_delegation(xdr, res);
5126 print_overflow_msg(__func__, xdr);
5130 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5133 uint32_t savewords, bmlen, i;
5136 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5138 nfs_increment_open_seqid(status, res->seqid);
5141 status = decode_open_stateid(xdr, &res->stateid);
5142 if (unlikely(status))
5145 decode_change_info(xdr, &res->cinfo);
5147 p = xdr_inline_decode(xdr, 8);
5150 res->rflags = be32_to_cpup(p++);
5151 bmlen = be32_to_cpup(p);
5155 p = xdr_inline_decode(xdr, bmlen << 2);
5158 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5159 for (i = 0; i < savewords; ++i)
5160 res->attrset[i] = be32_to_cpup(p++);
5161 for (; i < NFS4_BITMAP_SIZE; i++)
5162 res->attrset[i] = 0;
5164 return decode_delegation(xdr, res);
5166 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
5169 print_overflow_msg(__func__, xdr);
5173 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5177 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5179 nfs_increment_open_seqid(status, res->seqid);
5181 status = decode_open_stateid(xdr, &res->stateid);
5185 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5189 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5191 nfs_increment_open_seqid(status, res->seqid);
5193 status = decode_open_stateid(xdr, &res->stateid);
5197 static int decode_putfh(struct xdr_stream *xdr)
5199 return decode_op_hdr(xdr, OP_PUTFH);
5202 static int decode_putrootfh(struct xdr_stream *xdr)
5204 return decode_op_hdr(xdr, OP_PUTROOTFH);
5207 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5208 struct nfs_pgio_res *res)
5211 uint32_t count, eof, recvd;
5214 status = decode_op_hdr(xdr, OP_READ);
5217 p = xdr_inline_decode(xdr, 8);
5220 eof = be32_to_cpup(p++);
5221 count = be32_to_cpup(p);
5222 recvd = xdr_read_pages(xdr, count);
5223 if (count > recvd) {
5224 dprintk("NFS: server cheating in read reply: "
5225 "count %u > recvd %u\n", count, recvd);
5233 print_overflow_msg(__func__, xdr);
5237 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5242 status = decode_op_hdr(xdr, OP_READDIR);
5244 status = decode_verifier(xdr, readdir->verifier.data);
5245 if (unlikely(status))
5247 memcpy(verf, readdir->verifier.data, sizeof(verf));
5248 dprintk("%s: verifier = %08x:%08x\n",
5249 __func__, verf[0], verf[1]);
5250 return xdr_read_pages(xdr, xdr->buf->page_len);
5253 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5255 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5260 status = decode_op_hdr(xdr, OP_READLINK);
5264 /* Convert length of symlink */
5265 p = xdr_inline_decode(xdr, 4);
5268 len = be32_to_cpup(p);
5269 if (len >= rcvbuf->page_len || len <= 0) {
5270 dprintk("nfs: server returned giant symlink!\n");
5271 return -ENAMETOOLONG;
5273 recvd = xdr_read_pages(xdr, len);
5275 dprintk("NFS: server cheating in readlink reply: "
5276 "count %u > recvd %u\n", len, recvd);
5280 * The XDR encode routine has set things up so that
5281 * the link text will be copied directly into the
5282 * buffer. We just have to do overflow-checking,
5283 * and and null-terminate the text (the VFS expects
5284 * null-termination).
5286 xdr_terminate_string(rcvbuf, len);
5289 print_overflow_msg(__func__, xdr);
5293 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5297 status = decode_op_hdr(xdr, OP_REMOVE);
5300 status = decode_change_info(xdr, cinfo);
5305 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5306 struct nfs4_change_info *new_cinfo)
5310 status = decode_op_hdr(xdr, OP_RENAME);
5313 if ((status = decode_change_info(xdr, old_cinfo)))
5315 status = decode_change_info(xdr, new_cinfo);
5320 static int decode_renew(struct xdr_stream *xdr)
5322 return decode_op_hdr(xdr, OP_RENEW);
5326 decode_restorefh(struct xdr_stream *xdr)
5328 return decode_op_hdr(xdr, OP_RESTOREFH);
5331 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5332 struct nfs_getaclres *res)
5338 unsigned int pg_offset;
5341 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5344 xdr_enter_page(xdr, xdr->buf->page_len);
5346 /* Calculate the offset of the page data */
5347 pg_offset = xdr->buf->head[0].iov_len;
5349 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5351 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5354 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5356 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5358 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5359 * are stored with the acl data to handle the problem of
5360 * variable length bitmaps.*/
5361 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5362 res->acl_len = attrlen;
5364 /* Check for receive buffer overflow */
5365 if (res->acl_len > (xdr->nwords << 2) ||
5366 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5367 res->acl_flags |= NFS4_ACL_TRUNC;
5368 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5369 attrlen, xdr->nwords << 2);
5372 status = -EOPNOTSUPP;
5379 decode_savefh(struct xdr_stream *xdr)
5381 return decode_op_hdr(xdr, OP_SAVEFH);
5384 static int decode_setattr(struct xdr_stream *xdr)
5390 status = decode_op_hdr(xdr, OP_SETATTR);
5393 p = xdr_inline_decode(xdr, 4);
5396 bmlen = be32_to_cpup(p);
5397 p = xdr_inline_decode(xdr, bmlen << 2);
5401 print_overflow_msg(__func__, xdr);
5405 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5411 p = xdr_inline_decode(xdr, 8);
5414 opnum = be32_to_cpup(p++);
5415 if (opnum != OP_SETCLIENTID) {
5416 dprintk("nfs: decode_setclientid: Server returned operation"
5420 nfserr = be32_to_cpup(p);
5421 if (nfserr == NFS_OK) {
5422 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5425 p = xdr_decode_hyper(p, &res->clientid);
5426 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5427 } else if (nfserr == NFSERR_CLID_INUSE) {
5430 /* skip netid string */
5431 p = xdr_inline_decode(xdr, 4);
5434 len = be32_to_cpup(p);
5435 p = xdr_inline_decode(xdr, len);
5439 /* skip uaddr string */
5440 p = xdr_inline_decode(xdr, 4);
5443 len = be32_to_cpup(p);
5444 p = xdr_inline_decode(xdr, len);
5447 return -NFSERR_CLID_INUSE;
5449 return nfs4_stat_to_errno(nfserr);
5453 print_overflow_msg(__func__, xdr);
5457 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5459 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5462 static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
5467 status = decode_op_hdr(xdr, OP_WRITE);
5471 p = xdr_inline_decode(xdr, 8);
5474 res->count = be32_to_cpup(p++);
5475 res->verf->committed = be32_to_cpup(p++);
5476 return decode_write_verifier(xdr, &res->verf->verifier);
5478 print_overflow_msg(__func__, xdr);
5482 static int decode_delegreturn(struct xdr_stream *xdr)
5484 return decode_op_hdr(xdr, OP_DELEGRETURN);
5487 static int decode_secinfo_gss(struct xdr_stream *xdr,
5488 struct nfs4_secinfo4 *flavor)
5493 p = xdr_inline_decode(xdr, 4);
5496 oid_len = be32_to_cpup(p);
5497 if (oid_len > GSS_OID_MAX_LEN)
5500 p = xdr_inline_decode(xdr, oid_len);
5503 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5504 flavor->flavor_info.oid.len = oid_len;
5506 p = xdr_inline_decode(xdr, 8);
5509 flavor->flavor_info.qop = be32_to_cpup(p++);
5510 flavor->flavor_info.service = be32_to_cpup(p);
5515 print_overflow_msg(__func__, xdr);
5521 static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5523 struct nfs4_secinfo4 *sec_flavor;
5524 unsigned int i, num_flavors;
5528 p = xdr_inline_decode(xdr, 4);
5532 res->flavors->num_flavors = 0;
5533 num_flavors = be32_to_cpup(p);
5535 for (i = 0; i < num_flavors; i++) {
5536 sec_flavor = &res->flavors->flavors[i];
5537 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5540 p = xdr_inline_decode(xdr, 4);
5543 sec_flavor->flavor = be32_to_cpup(p);
5545 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5546 status = decode_secinfo_gss(xdr, sec_flavor);
5550 res->flavors->num_flavors++;
5557 print_overflow_msg(__func__, xdr);
5561 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5563 int status = decode_op_hdr(xdr, OP_SECINFO);
5566 return decode_secinfo_common(xdr, res);
5569 #if defined(CONFIG_NFS_V4_1)
5570 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5572 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5575 return decode_secinfo_common(xdr, res);
5578 static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5581 uint32_t bitmap_words;
5584 p = xdr_inline_decode(xdr, 4);
5585 bitmap_words = be32_to_cpup(p++);
5586 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5588 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5589 for (i = 0; i < bitmap_words; i++)
5590 op_map->u.words[i] = be32_to_cpup(p++);
5595 static int decode_exchange_id(struct xdr_stream *xdr,
5596 struct nfs41_exchange_id_res *res)
5602 uint32_t impl_id_count;
5604 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5608 p = xdr_inline_decode(xdr, 8);
5611 xdr_decode_hyper(p, &res->clientid);
5612 p = xdr_inline_decode(xdr, 12);
5615 res->seqid = be32_to_cpup(p++);
5616 res->flags = be32_to_cpup(p++);
5618 res->state_protect.how = be32_to_cpup(p);
5619 switch (res->state_protect.how) {
5623 status = decode_op_map(xdr, &res->state_protect.enforce);
5626 status = decode_op_map(xdr, &res->state_protect.allow);
5635 /* server_owner4.so_minor_id */
5636 p = xdr_inline_decode(xdr, 8);
5639 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5641 /* server_owner4.so_major_id */
5642 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5643 if (unlikely(status))
5645 memcpy(res->server_owner->major_id, dummy_str, dummy);
5646 res->server_owner->major_id_sz = dummy;
5649 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5650 if (unlikely(status))
5652 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5653 res->server_scope->server_scope_sz = dummy;
5655 /* Implementation Id */
5656 p = xdr_inline_decode(xdr, 4);
5659 impl_id_count = be32_to_cpup(p++);
5661 if (impl_id_count) {
5663 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5664 if (unlikely(status))
5666 memcpy(res->impl_id->domain, dummy_str, dummy);
5669 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5670 if (unlikely(status))
5672 memcpy(res->impl_id->name, dummy_str, dummy);
5675 p = xdr_inline_decode(xdr, 12);
5678 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5679 res->impl_id->date.nseconds = be32_to_cpup(p);
5681 /* if there's more than one entry, ignore the rest */
5685 print_overflow_msg(__func__, xdr);
5689 static int decode_chan_attrs(struct xdr_stream *xdr,
5690 struct nfs4_channel_attrs *attrs)
5695 p = xdr_inline_decode(xdr, 28);
5698 val = be32_to_cpup(p++); /* headerpadsz */
5700 return -EINVAL; /* no support for header padding yet */
5701 attrs->max_rqst_sz = be32_to_cpup(p++);
5702 attrs->max_resp_sz = be32_to_cpup(p++);
5703 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5704 attrs->max_ops = be32_to_cpup(p++);
5705 attrs->max_reqs = be32_to_cpup(p++);
5706 nr_attrs = be32_to_cpup(p);
5707 if (unlikely(nr_attrs > 1)) {
5708 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5709 "count %u\n", __func__, nr_attrs);
5712 if (nr_attrs == 1) {
5713 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5719 print_overflow_msg(__func__, xdr);
5723 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5725 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5728 static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5729 struct nfs41_bind_conn_to_session_res *res)
5734 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5736 status = decode_sessionid(xdr, &res->sessionid);
5737 if (unlikely(status))
5740 /* dir flags, rdma mode bool */
5741 p = xdr_inline_decode(xdr, 8);
5745 res->dir = be32_to_cpup(p++);
5746 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5748 if (be32_to_cpup(p) == 0)
5749 res->use_conn_in_rdma_mode = false;
5751 res->use_conn_in_rdma_mode = true;
5755 print_overflow_msg(__func__, xdr);
5759 static int decode_create_session(struct xdr_stream *xdr,
5760 struct nfs41_create_session_res *res)
5765 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5767 status = decode_sessionid(xdr, &res->sessionid);
5768 if (unlikely(status))
5772 p = xdr_inline_decode(xdr, 8);
5775 res->seqid = be32_to_cpup(p++);
5776 res->flags = be32_to_cpup(p);
5778 /* Channel attributes */
5779 status = decode_chan_attrs(xdr, &res->fc_attrs);
5781 status = decode_chan_attrs(xdr, &res->bc_attrs);
5784 print_overflow_msg(__func__, xdr);
5788 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5790 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5793 static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5795 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5798 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5800 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5802 #endif /* CONFIG_NFS_V4_1 */
5804 static int decode_sequence(struct xdr_stream *xdr,
5805 struct nfs4_sequence_res *res,
5806 struct rpc_rqst *rqstp)
5808 #if defined(CONFIG_NFS_V4_1)
5809 struct nfs4_session *session;
5810 struct nfs4_sessionid id;
5815 if (res->sr_slot == NULL)
5817 if (!res->sr_slot->table->session)
5820 status = decode_op_hdr(xdr, OP_SEQUENCE);
5822 status = decode_sessionid(xdr, &id);
5823 if (unlikely(status))
5827 * If the server returns different values for sessionID, slotID or
5828 * sequence number, the server is looney tunes.
5830 status = -EREMOTEIO;
5831 session = res->sr_slot->table->session;
5833 if (memcmp(id.data, session->sess_id.data,
5834 NFS4_MAX_SESSIONID_LEN)) {
5835 dprintk("%s Invalid session id\n", __func__);
5839 p = xdr_inline_decode(xdr, 20);
5844 dummy = be32_to_cpup(p++);
5845 if (dummy != res->sr_slot->seq_nr) {
5846 dprintk("%s Invalid sequence number\n", __func__);
5850 dummy = be32_to_cpup(p++);
5851 if (dummy != res->sr_slot->slot_nr) {
5852 dprintk("%s Invalid slot id\n", __func__);
5855 /* highest slot id */
5856 res->sr_highest_slotid = be32_to_cpup(p++);
5857 /* target highest slot id */
5858 res->sr_target_highest_slotid = be32_to_cpup(p++);
5860 res->sr_status_flags = be32_to_cpup(p);
5863 res->sr_status = status;
5866 print_overflow_msg(__func__, xdr);
5869 #else /* CONFIG_NFS_V4_1 */
5871 #endif /* CONFIG_NFS_V4_1 */
5874 #if defined(CONFIG_NFS_V4_1)
5875 static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5877 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5878 return decode_stateid(xdr, stateid);
5881 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5882 struct nfs4_getdeviceinfo_res *res)
5884 struct pnfs_device *pdev = res->pdev;
5889 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5891 if (status == -ETOOSMALL) {
5892 p = xdr_inline_decode(xdr, 4);
5895 pdev->mincount = be32_to_cpup(p);
5896 dprintk("%s: Min count too small. mincnt = %u\n",
5897 __func__, pdev->mincount);
5902 p = xdr_inline_decode(xdr, 8);
5905 type = be32_to_cpup(p++);
5906 if (type != pdev->layout_type) {
5907 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5908 __func__, pdev->layout_type, type);
5912 * Get the length of the opaque device_addr4. xdr_read_pages places
5913 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5914 * and places the remaining xdr data in xdr_buf->tail
5916 pdev->mincount = be32_to_cpup(p);
5917 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5920 /* Parse notification bitmap, verifying that it is zero. */
5921 p = xdr_inline_decode(xdr, 4);
5924 len = be32_to_cpup(p);
5928 p = xdr_inline_decode(xdr, 4 * len);
5932 res->notification = be32_to_cpup(p++);
5933 for (i = 1; i < len; i++) {
5934 if (be32_to_cpup(p++)) {
5935 dprintk("%s: unsupported notification\n",
5943 print_overflow_msg(__func__, xdr);
5947 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5948 struct nfs4_layoutget_res *res)
5955 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5958 p = xdr_inline_decode(xdr, 4);
5961 res->return_on_close = be32_to_cpup(p);
5962 decode_layout_stateid(xdr, &res->stateid);
5963 p = xdr_inline_decode(xdr, 4);
5966 layout_count = be32_to_cpup(p);
5967 if (!layout_count) {
5968 dprintk("%s: server responded with empty layout array\n",
5973 p = xdr_inline_decode(xdr, 28);
5976 p = xdr_decode_hyper(p, &res->range.offset);
5977 p = xdr_decode_hyper(p, &res->range.length);
5978 res->range.iomode = be32_to_cpup(p++);
5979 res->type = be32_to_cpup(p++);
5980 res->layoutp->len = be32_to_cpup(p);
5982 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5984 (unsigned long)res->range.offset,
5985 (unsigned long)res->range.length,
5990 recvd = xdr_read_pages(xdr, res->layoutp->len);
5991 if (res->layoutp->len > recvd) {
5992 dprintk("NFS: server cheating in layoutget reply: "
5993 "layout len %u > recvd %u\n",
5994 res->layoutp->len, recvd);
5998 if (layout_count > 1) {
5999 /* We only handle a length one array at the moment. Any
6000 * further entries are just ignored. Note that this means
6001 * the client may see a response that is less than the
6002 * minimum it requested.
6004 dprintk("%s: server responded with %d layouts, dropping tail\n",
6005 __func__, layout_count);
6010 print_overflow_msg(__func__, xdr);
6014 static int decode_layoutreturn(struct xdr_stream *xdr,
6015 struct nfs4_layoutreturn_res *res)
6020 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6023 p = xdr_inline_decode(xdr, 4);
6026 res->lrs_present = be32_to_cpup(p);
6027 if (res->lrs_present)
6028 status = decode_layout_stateid(xdr, &res->stateid);
6031 print_overflow_msg(__func__, xdr);
6035 static int decode_layoutcommit(struct xdr_stream *xdr,
6036 struct rpc_rqst *req,
6037 struct nfs4_layoutcommit_res *res)
6043 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
6044 res->status = status;
6048 p = xdr_inline_decode(xdr, 4);
6051 sizechanged = be32_to_cpup(p);
6054 /* throw away new size */
6055 p = xdr_inline_decode(xdr, 8);
6061 print_overflow_msg(__func__, xdr);
6065 static int decode_test_stateid(struct xdr_stream *xdr,
6066 struct nfs41_test_stateid_res *res)
6072 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6076 p = xdr_inline_decode(xdr, 4);
6079 num_res = be32_to_cpup(p++);
6083 p = xdr_inline_decode(xdr, 4);
6086 res->status = be32_to_cpup(p++);
6090 print_overflow_msg(__func__, xdr);
6095 static int decode_free_stateid(struct xdr_stream *xdr,
6096 struct nfs41_free_stateid_res *res)
6098 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
6103 int decode_layoutreturn(struct xdr_stream *xdr,
6104 struct nfs4_layoutreturn_res *res)
6108 #endif /* CONFIG_NFS_V4_1 */
6111 * END OF "GENERIC" DECODE ROUTINES.
6115 * Decode OPEN_DOWNGRADE response
6117 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6118 struct xdr_stream *xdr,
6119 struct nfs_closeres *res)
6121 struct compound_hdr hdr;
6124 status = decode_compound_hdr(xdr, &hdr);
6127 status = decode_sequence(xdr, &res->seq_res, rqstp);
6130 status = decode_putfh(xdr);
6134 status = decode_layoutreturn(xdr, res->lr_res);
6135 res->lr_ret = status;
6139 status = decode_open_downgrade(xdr, res);
6145 * Decode ACCESS response
6147 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6148 struct nfs4_accessres *res)
6150 struct compound_hdr hdr;
6153 status = decode_compound_hdr(xdr, &hdr);
6156 status = decode_sequence(xdr, &res->seq_res, rqstp);
6159 status = decode_putfh(xdr);
6162 status = decode_access(xdr, &res->supported, &res->access);
6165 decode_getfattr(xdr, res->fattr, res->server);
6171 * Decode LOOKUP response
6173 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6174 struct nfs4_lookup_res *res)
6176 struct compound_hdr hdr;
6179 status = decode_compound_hdr(xdr, &hdr);
6182 status = decode_sequence(xdr, &res->seq_res, rqstp);
6185 status = decode_putfh(xdr);
6188 status = decode_lookup(xdr);
6191 status = decode_getfh(xdr, res->fh);
6194 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6200 * Decode LOOKUP_ROOT response
6202 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6203 struct xdr_stream *xdr,
6204 struct nfs4_lookup_res *res)
6206 struct compound_hdr hdr;
6209 status = decode_compound_hdr(xdr, &hdr);
6212 status = decode_sequence(xdr, &res->seq_res, rqstp);
6215 status = decode_putrootfh(xdr);
6218 status = decode_getfh(xdr, res->fh);
6220 status = decode_getfattr_label(xdr, res->fattr,
6221 res->label, res->server);
6227 * Decode REMOVE response
6229 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6230 struct nfs_removeres *res)
6232 struct compound_hdr hdr;
6235 status = decode_compound_hdr(xdr, &hdr);
6238 status = decode_sequence(xdr, &res->seq_res, rqstp);
6241 status = decode_putfh(xdr);
6244 status = decode_remove(xdr, &res->cinfo);
6250 * Decode RENAME response
6252 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6253 struct nfs_renameres *res)
6255 struct compound_hdr hdr;
6258 status = decode_compound_hdr(xdr, &hdr);
6261 status = decode_sequence(xdr, &res->seq_res, rqstp);
6264 status = decode_putfh(xdr);
6267 status = decode_savefh(xdr);
6270 status = decode_putfh(xdr);
6273 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
6279 * Decode LINK response
6281 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6282 struct nfs4_link_res *res)
6284 struct compound_hdr hdr;
6287 status = decode_compound_hdr(xdr, &hdr);
6290 status = decode_sequence(xdr, &res->seq_res, rqstp);
6293 status = decode_putfh(xdr);
6296 status = decode_savefh(xdr);
6299 status = decode_putfh(xdr);
6302 status = decode_link(xdr, &res->cinfo);
6306 * Note order: OP_LINK leaves the directory as the current
6309 status = decode_restorefh(xdr);
6312 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6318 * Decode CREATE response
6320 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6321 struct nfs4_create_res *res)
6323 struct compound_hdr hdr;
6326 status = decode_compound_hdr(xdr, &hdr);
6329 status = decode_sequence(xdr, &res->seq_res, rqstp);
6332 status = decode_putfh(xdr);
6335 status = decode_create(xdr, &res->dir_cinfo);
6338 status = decode_getfh(xdr, res->fh);
6341 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6347 * Decode SYMLINK response
6349 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6350 struct nfs4_create_res *res)
6352 return nfs4_xdr_dec_create(rqstp, xdr, res);
6356 * Decode GETATTR response
6358 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6359 struct nfs4_getattr_res *res)
6361 struct compound_hdr hdr;
6364 status = decode_compound_hdr(xdr, &hdr);
6367 status = decode_sequence(xdr, &res->seq_res, rqstp);
6370 status = decode_putfh(xdr);
6373 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6379 * Encode an SETACL request
6381 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6382 struct nfs_setaclargs *args)
6384 struct compound_hdr hdr = {
6385 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6388 encode_compound_hdr(xdr, req, &hdr);
6389 encode_sequence(xdr, &args->seq_args, &hdr);
6390 encode_putfh(xdr, args->fh, &hdr);
6391 encode_setacl(xdr, args, &hdr);
6396 * Decode SETACL response
6399 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6400 struct nfs_setaclres *res)
6402 struct compound_hdr hdr;
6405 status = decode_compound_hdr(xdr, &hdr);
6408 status = decode_sequence(xdr, &res->seq_res, rqstp);
6411 status = decode_putfh(xdr);
6414 status = decode_setattr(xdr);
6420 * Decode GETACL response
6423 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6424 struct nfs_getaclres *res)
6426 struct compound_hdr hdr;
6429 if (res->acl_scratch != NULL) {
6430 void *p = page_address(res->acl_scratch);
6431 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6433 status = decode_compound_hdr(xdr, &hdr);
6436 status = decode_sequence(xdr, &res->seq_res, rqstp);
6439 status = decode_putfh(xdr);
6442 status = decode_getacl(xdr, rqstp, res);
6449 * Decode CLOSE response
6451 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6452 struct nfs_closeres *res)
6454 struct compound_hdr hdr;
6457 status = decode_compound_hdr(xdr, &hdr);
6460 status = decode_sequence(xdr, &res->seq_res, rqstp);
6463 status = decode_putfh(xdr);
6467 status = decode_layoutreturn(xdr, res->lr_res);
6468 res->lr_ret = status;
6472 if (res->fattr != NULL) {
6473 status = decode_getfattr(xdr, res->fattr, res->server);
6477 status = decode_close(xdr, res);
6483 * Decode OPEN response
6485 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6486 struct nfs_openres *res)
6488 struct compound_hdr hdr;
6491 status = decode_compound_hdr(xdr, &hdr);
6494 status = decode_sequence(xdr, &res->seq_res, rqstp);
6497 status = decode_putfh(xdr);
6500 status = decode_open(xdr, res);
6503 status = decode_getfh(xdr, &res->fh);
6506 if (res->access_request)
6507 decode_access(xdr, &res->access_supported, &res->access_result);
6508 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
6514 * Decode OPEN_CONFIRM response
6516 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6517 struct xdr_stream *xdr,
6518 struct nfs_open_confirmres *res)
6520 struct compound_hdr hdr;
6523 status = decode_compound_hdr(xdr, &hdr);
6526 status = decode_putfh(xdr);
6529 status = decode_open_confirm(xdr, res);
6535 * Decode OPEN response
6537 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6538 struct xdr_stream *xdr,
6539 struct nfs_openres *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_open(xdr, res);
6556 if (res->access_request)
6557 decode_access(xdr, &res->access_supported, &res->access_result);
6558 decode_getfattr(xdr, res->f_attr, res->server);
6564 * Decode SETATTR response
6566 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6567 struct xdr_stream *xdr,
6568 struct nfs_setattrres *res)
6570 struct compound_hdr hdr;
6573 status = decode_compound_hdr(xdr, &hdr);
6576 status = decode_sequence(xdr, &res->seq_res, rqstp);
6579 status = decode_putfh(xdr);
6582 status = decode_setattr(xdr);
6585 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6591 * Decode LOCK response
6593 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6594 struct nfs_lock_res *res)
6596 struct compound_hdr hdr;
6599 status = decode_compound_hdr(xdr, &hdr);
6602 status = decode_sequence(xdr, &res->seq_res, rqstp);
6605 status = decode_putfh(xdr);
6608 status = decode_lock(xdr, res);
6614 * Decode LOCKT response
6616 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6617 struct nfs_lockt_res *res)
6619 struct compound_hdr hdr;
6622 status = decode_compound_hdr(xdr, &hdr);
6625 status = decode_sequence(xdr, &res->seq_res, rqstp);
6628 status = decode_putfh(xdr);
6631 status = decode_lockt(xdr, res);
6637 * Decode LOCKU response
6639 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6640 struct nfs_locku_res *res)
6642 struct compound_hdr hdr;
6645 status = decode_compound_hdr(xdr, &hdr);
6648 status = decode_sequence(xdr, &res->seq_res, rqstp);
6651 status = decode_putfh(xdr);
6654 status = decode_locku(xdr, res);
6659 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6660 struct xdr_stream *xdr, void *dummy)
6662 struct compound_hdr hdr;
6665 status = decode_compound_hdr(xdr, &hdr);
6667 status = decode_release_lockowner(xdr);
6672 * Decode READLINK response
6674 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6675 struct xdr_stream *xdr,
6676 struct nfs4_readlink_res *res)
6678 struct compound_hdr hdr;
6681 status = decode_compound_hdr(xdr, &hdr);
6684 status = decode_sequence(xdr, &res->seq_res, rqstp);
6687 status = decode_putfh(xdr);
6690 status = decode_readlink(xdr, rqstp);
6696 * Decode READDIR response
6698 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6699 struct nfs4_readdir_res *res)
6701 struct compound_hdr hdr;
6704 status = decode_compound_hdr(xdr, &hdr);
6707 status = decode_sequence(xdr, &res->seq_res, rqstp);
6710 status = decode_putfh(xdr);
6713 status = decode_readdir(xdr, rqstp, res);
6719 * Decode Read response
6721 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6722 struct nfs_pgio_res *res)
6724 struct compound_hdr hdr;
6727 status = decode_compound_hdr(xdr, &hdr);
6728 res->op_status = hdr.status;
6731 status = decode_sequence(xdr, &res->seq_res, rqstp);
6734 status = decode_putfh(xdr);
6737 status = decode_read(xdr, rqstp, res);
6739 status = res->count;
6745 * Decode WRITE response
6747 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6748 struct nfs_pgio_res *res)
6750 struct compound_hdr hdr;
6753 status = decode_compound_hdr(xdr, &hdr);
6754 res->op_status = hdr.status;
6757 status = decode_sequence(xdr, &res->seq_res, rqstp);
6760 status = decode_putfh(xdr);
6763 status = decode_write(xdr, res);
6767 decode_getfattr(xdr, res->fattr, res->server);
6769 status = res->count;
6775 * Decode COMMIT response
6777 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6778 struct nfs_commitres *res)
6780 struct compound_hdr hdr;
6783 status = decode_compound_hdr(xdr, &hdr);
6784 res->op_status = hdr.status;
6787 status = decode_sequence(xdr, &res->seq_res, rqstp);
6790 status = decode_putfh(xdr);
6793 status = decode_commit(xdr, res);
6799 * Decode FSINFO response
6801 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6802 struct nfs4_fsinfo_res *res)
6804 struct compound_hdr hdr;
6807 status = decode_compound_hdr(xdr, &hdr);
6809 status = decode_sequence(xdr, &res->seq_res, req);
6811 status = decode_putfh(xdr);
6813 status = decode_fsinfo(xdr, res->fsinfo);
6818 * Decode PATHCONF response
6820 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6821 struct nfs4_pathconf_res *res)
6823 struct compound_hdr hdr;
6826 status = decode_compound_hdr(xdr, &hdr);
6828 status = decode_sequence(xdr, &res->seq_res, req);
6830 status = decode_putfh(xdr);
6832 status = decode_pathconf(xdr, res->pathconf);
6837 * Decode STATFS response
6839 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6840 struct nfs4_statfs_res *res)
6842 struct compound_hdr hdr;
6845 status = decode_compound_hdr(xdr, &hdr);
6847 status = decode_sequence(xdr, &res->seq_res, req);
6849 status = decode_putfh(xdr);
6851 status = decode_statfs(xdr, res->fsstat);
6856 * Decode GETATTR_BITMAP response
6858 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6859 struct xdr_stream *xdr,
6860 struct nfs4_server_caps_res *res)
6862 struct compound_hdr hdr;
6865 status = decode_compound_hdr(xdr, &hdr);
6868 status = decode_sequence(xdr, &res->seq_res, req);
6871 status = decode_putfh(xdr);
6874 status = decode_server_caps(xdr, res);
6880 * Decode RENEW response
6882 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6885 struct compound_hdr hdr;
6888 status = decode_compound_hdr(xdr, &hdr);
6890 status = decode_renew(xdr);
6895 * Decode SETCLIENTID response
6897 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6898 struct xdr_stream *xdr,
6899 struct nfs4_setclientid_res *res)
6901 struct compound_hdr hdr;
6904 status = decode_compound_hdr(xdr, &hdr);
6906 status = decode_setclientid(xdr, res);
6911 * Decode SETCLIENTID_CONFIRM response
6913 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6914 struct xdr_stream *xdr)
6916 struct compound_hdr hdr;
6919 status = decode_compound_hdr(xdr, &hdr);
6921 status = decode_setclientid_confirm(xdr);
6926 * Decode DELEGRETURN response
6928 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6929 struct xdr_stream *xdr,
6930 struct nfs4_delegreturnres *res)
6932 struct compound_hdr hdr;
6935 status = decode_compound_hdr(xdr, &hdr);
6938 status = decode_sequence(xdr, &res->seq_res, rqstp);
6941 status = decode_putfh(xdr);
6945 status = decode_layoutreturn(xdr, res->lr_res);
6946 res->lr_ret = status;
6951 status = decode_getfattr(xdr, res->fattr, res->server);
6955 status = decode_delegreturn(xdr);
6961 * Decode FS_LOCATIONS response
6963 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6964 struct xdr_stream *xdr,
6965 struct nfs4_fs_locations_res *res)
6967 struct compound_hdr hdr;
6970 status = decode_compound_hdr(xdr, &hdr);
6973 status = decode_sequence(xdr, &res->seq_res, req);
6976 status = decode_putfh(xdr);
6979 if (res->migration) {
6980 xdr_enter_page(xdr, PAGE_SIZE);
6981 status = decode_getfattr_generic(xdr,
6982 &res->fs_locations->fattr,
6983 NULL, res->fs_locations,
6984 NULL, res->fs_locations->server);
6988 status = decode_renew(xdr);
6990 status = decode_lookup(xdr);
6993 xdr_enter_page(xdr, PAGE_SIZE);
6994 status = decode_getfattr_generic(xdr,
6995 &res->fs_locations->fattr,
6996 NULL, res->fs_locations,
6997 NULL, res->fs_locations->server);
7004 * Decode SECINFO response
7006 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7007 struct xdr_stream *xdr,
7008 struct nfs4_secinfo_res *res)
7010 struct compound_hdr hdr;
7013 status = decode_compound_hdr(xdr, &hdr);
7016 status = decode_sequence(xdr, &res->seq_res, rqstp);
7019 status = decode_putfh(xdr);
7022 status = decode_secinfo(xdr, res);
7028 * Decode FSID_PRESENT response
7030 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7031 struct xdr_stream *xdr,
7032 struct nfs4_fsid_present_res *res)
7034 struct compound_hdr hdr;
7037 status = decode_compound_hdr(xdr, &hdr);
7040 status = decode_sequence(xdr, &res->seq_res, rqstp);
7043 status = decode_putfh(xdr);
7046 status = decode_getfh(xdr, res->fh);
7050 status = decode_renew(xdr);
7055 #if defined(CONFIG_NFS_V4_1)
7057 * Decode BIND_CONN_TO_SESSION response
7059 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7060 struct xdr_stream *xdr,
7063 struct compound_hdr hdr;
7066 status = decode_compound_hdr(xdr, &hdr);
7068 status = decode_bind_conn_to_session(xdr, res);
7073 * Decode EXCHANGE_ID response
7075 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7076 struct xdr_stream *xdr,
7079 struct compound_hdr hdr;
7082 status = decode_compound_hdr(xdr, &hdr);
7084 status = decode_exchange_id(xdr, res);
7089 * Decode CREATE_SESSION response
7091 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7092 struct xdr_stream *xdr,
7093 struct nfs41_create_session_res *res)
7095 struct compound_hdr hdr;
7098 status = decode_compound_hdr(xdr, &hdr);
7100 status = decode_create_session(xdr, res);
7105 * Decode DESTROY_SESSION response
7107 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7108 struct xdr_stream *xdr,
7111 struct compound_hdr hdr;
7114 status = decode_compound_hdr(xdr, &hdr);
7116 status = decode_destroy_session(xdr, res);
7121 * Decode DESTROY_CLIENTID response
7123 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7124 struct xdr_stream *xdr,
7127 struct compound_hdr hdr;
7130 status = decode_compound_hdr(xdr, &hdr);
7132 status = decode_destroy_clientid(xdr, res);
7137 * Decode SEQUENCE response
7139 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7140 struct xdr_stream *xdr,
7141 struct nfs4_sequence_res *res)
7143 struct compound_hdr hdr;
7146 status = decode_compound_hdr(xdr, &hdr);
7148 status = decode_sequence(xdr, res, rqstp);
7153 * Decode GET_LEASE_TIME response
7155 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7156 struct xdr_stream *xdr,
7157 struct nfs4_get_lease_time_res *res)
7159 struct compound_hdr hdr;
7162 status = decode_compound_hdr(xdr, &hdr);
7164 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
7166 status = decode_putrootfh(xdr);
7168 status = decode_fsinfo(xdr, res->lr_fsinfo);
7173 * Decode RECLAIM_COMPLETE response
7175 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7176 struct xdr_stream *xdr,
7177 struct nfs41_reclaim_complete_res *res)
7179 struct compound_hdr hdr;
7182 status = decode_compound_hdr(xdr, &hdr);
7184 status = decode_sequence(xdr, &res->seq_res, rqstp);
7186 status = decode_reclaim_complete(xdr, NULL);
7191 * Decode GETDEVINFO response
7193 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7194 struct xdr_stream *xdr,
7195 struct nfs4_getdeviceinfo_res *res)
7197 struct compound_hdr hdr;
7200 status = decode_compound_hdr(xdr, &hdr);
7203 status = decode_sequence(xdr, &res->seq_res, rqstp);
7206 status = decode_getdeviceinfo(xdr, res);
7212 * Decode LAYOUTGET response
7214 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7215 struct xdr_stream *xdr,
7216 struct nfs4_layoutget_res *res)
7218 struct compound_hdr hdr;
7221 status = decode_compound_hdr(xdr, &hdr);
7224 status = decode_sequence(xdr, &res->seq_res, rqstp);
7227 status = decode_putfh(xdr);
7230 status = decode_layoutget(xdr, rqstp, res);
7236 * Decode LAYOUTRETURN response
7238 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7239 struct xdr_stream *xdr,
7240 struct nfs4_layoutreturn_res *res)
7242 struct compound_hdr hdr;
7245 status = decode_compound_hdr(xdr, &hdr);
7248 status = decode_sequence(xdr, &res->seq_res, rqstp);
7251 status = decode_putfh(xdr);
7254 status = decode_layoutreturn(xdr, res);
7260 * Decode LAYOUTCOMMIT response
7262 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7263 struct xdr_stream *xdr,
7264 struct nfs4_layoutcommit_res *res)
7266 struct compound_hdr hdr;
7269 status = decode_compound_hdr(xdr, &hdr);
7272 status = decode_sequence(xdr, &res->seq_res, rqstp);
7275 status = decode_putfh(xdr);
7278 status = decode_layoutcommit(xdr, rqstp, res);
7281 decode_getfattr(xdr, res->fattr, res->server);
7287 * Decode SECINFO_NO_NAME response
7289 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7290 struct xdr_stream *xdr,
7291 struct nfs4_secinfo_res *res)
7293 struct compound_hdr hdr;
7296 status = decode_compound_hdr(xdr, &hdr);
7299 status = decode_sequence(xdr, &res->seq_res, rqstp);
7302 status = decode_putrootfh(xdr);
7305 status = decode_secinfo_no_name(xdr, res);
7311 * Decode TEST_STATEID response
7313 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7314 struct xdr_stream *xdr,
7315 struct nfs41_test_stateid_res *res)
7317 struct compound_hdr hdr;
7320 status = decode_compound_hdr(xdr, &hdr);
7323 status = decode_sequence(xdr, &res->seq_res, rqstp);
7326 status = decode_test_stateid(xdr, res);
7332 * Decode FREE_STATEID response
7334 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7335 struct xdr_stream *xdr,
7336 struct nfs41_free_stateid_res *res)
7338 struct compound_hdr hdr;
7341 status = decode_compound_hdr(xdr, &hdr);
7344 status = decode_sequence(xdr, &res->seq_res, rqstp);
7347 status = decode_free_stateid(xdr, res);
7351 #endif /* CONFIG_NFS_V4_1 */
7354 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7355 * the local page cache.
7356 * @xdr: XDR stream where entry resides
7357 * @entry: buffer to fill in with entry data
7358 * @plus: boolean indicating whether this should be a readdirplus entry
7360 * Returns zero if successful, otherwise a negative errno value is
7363 * This function is not invoked during READDIR reply decoding, but
7364 * rather whenever an application invokes the getdents(2) system call
7365 * on a directory already in our cache.
7367 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7371 uint32_t bitmap[3] = {0};
7373 __be32 *p = xdr_inline_decode(xdr, 4);
7376 if (*p == xdr_zero) {
7377 p = xdr_inline_decode(xdr, 4);
7386 p = xdr_inline_decode(xdr, 12);
7389 entry->prev_cookie = entry->cookie;
7390 p = xdr_decode_hyper(p, &entry->cookie);
7391 entry->len = be32_to_cpup(p);
7393 p = xdr_inline_decode(xdr, entry->len);
7396 entry->name = (const char *) p;
7399 * In case the server doesn't return an inode number,
7400 * we fake one here. (We don't use inode number 0,
7401 * since glibc seems to choke on it...)
7404 entry->fattr->valid = 0;
7406 if (decode_attr_bitmap(xdr, bitmap) < 0)
7409 if (decode_attr_length(xdr, &len, &savep) < 0)
7412 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7413 NULL, entry->label, entry->server) < 0)
7415 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7416 entry->ino = entry->fattr->mounted_on_fileid;
7417 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7418 entry->ino = entry->fattr->fileid;
7420 entry->d_type = DT_UNKNOWN;
7421 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7422 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7427 print_overflow_msg(__func__, xdr);
7432 * We need to translate between nfs status return values and
7433 * the local errno values which may not be the same.
7440 { NFS4ERR_PERM, -EPERM },
7441 { NFS4ERR_NOENT, -ENOENT },
7442 { NFS4ERR_IO, -errno_NFSERR_IO},
7443 { NFS4ERR_NXIO, -ENXIO },
7444 { NFS4ERR_ACCESS, -EACCES },
7445 { NFS4ERR_EXIST, -EEXIST },
7446 { NFS4ERR_XDEV, -EXDEV },
7447 { NFS4ERR_NOTDIR, -ENOTDIR },
7448 { NFS4ERR_ISDIR, -EISDIR },
7449 { NFS4ERR_INVAL, -EINVAL },
7450 { NFS4ERR_FBIG, -EFBIG },
7451 { NFS4ERR_NOSPC, -ENOSPC },
7452 { NFS4ERR_ROFS, -EROFS },
7453 { NFS4ERR_MLINK, -EMLINK },
7454 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7455 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7456 { NFS4ERR_DQUOT, -EDQUOT },
7457 { NFS4ERR_STALE, -ESTALE },
7458 { NFS4ERR_BADHANDLE, -EBADHANDLE },
7459 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7460 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7461 { NFS4ERR_TOOSMALL, -ETOOSMALL },
7462 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7463 { NFS4ERR_BADTYPE, -EBADTYPE },
7464 { NFS4ERR_LOCKED, -EAGAIN },
7465 { NFS4ERR_SYMLINK, -ELOOP },
7466 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7467 { NFS4ERR_DEADLOCK, -EDEADLK },
7472 * Convert an NFS error code to a local one.
7473 * This one is used jointly by NFSv2 and NFSv3.
7476 nfs4_stat_to_errno(int stat)
7479 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7480 if (nfs_errtbl[i].stat == stat)
7481 return nfs_errtbl[i].errno;
7483 if (stat <= 10000 || stat > 10100) {
7484 /* The server is looney tunes. */
7487 /* If we cannot translate the error, the recovery routines should
7489 * Note: remaining NFSv4 error codes have values > 10000, so should
7490 * not conflict with native Linux error codes.
7495 #ifdef CONFIG_NFS_V4_2
7496 #include "nfs42xdr.c"
7497 #endif /* CONFIG_NFS_V4_2 */
7499 #define PROC(proc, argtype, restype) \
7500 [NFSPROC4_CLNT_##proc] = { \
7501 .p_proc = NFSPROC4_COMPOUND, \
7502 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7503 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7504 .p_arglen = NFS4_##argtype##_sz, \
7505 .p_replen = NFS4_##restype##_sz, \
7506 .p_statidx = NFSPROC4_CLNT_##proc, \
7510 #define STUB(proc) \
7511 [NFSPROC4_CLNT_##proc] = { \
7515 struct rpc_procinfo nfs4_procedures[] = {
7516 PROC(READ, enc_read, dec_read),
7517 PROC(WRITE, enc_write, dec_write),
7518 PROC(COMMIT, enc_commit, dec_commit),
7519 PROC(OPEN, enc_open, dec_open),
7520 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7521 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7522 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7523 PROC(CLOSE, enc_close, dec_close),
7524 PROC(SETATTR, enc_setattr, dec_setattr),
7525 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7526 PROC(RENEW, enc_renew, dec_renew),
7527 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7528 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7529 PROC(LOCK, enc_lock, dec_lock),
7530 PROC(LOCKT, enc_lockt, dec_lockt),
7531 PROC(LOCKU, enc_locku, dec_locku),
7532 PROC(ACCESS, enc_access, dec_access),
7533 PROC(GETATTR, enc_getattr, dec_getattr),
7534 PROC(LOOKUP, enc_lookup, dec_lookup),
7535 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7536 PROC(REMOVE, enc_remove, dec_remove),
7537 PROC(RENAME, enc_rename, dec_rename),
7538 PROC(LINK, enc_link, dec_link),
7539 PROC(SYMLINK, enc_symlink, dec_symlink),
7540 PROC(CREATE, enc_create, dec_create),
7541 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7542 PROC(STATFS, enc_statfs, dec_statfs),
7543 PROC(READLINK, enc_readlink, dec_readlink),
7544 PROC(READDIR, enc_readdir, dec_readdir),
7545 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7546 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7547 PROC(GETACL, enc_getacl, dec_getacl),
7548 PROC(SETACL, enc_setacl, dec_setacl),
7549 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7550 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7551 PROC(SECINFO, enc_secinfo, dec_secinfo),
7552 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
7553 #if defined(CONFIG_NFS_V4_1)
7554 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7555 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7556 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7557 PROC(SEQUENCE, enc_sequence, dec_sequence),
7558 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7559 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7560 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7561 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7562 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7563 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7564 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7565 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7566 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7567 STUB(GETDEVICELIST),
7568 PROC(BIND_CONN_TO_SESSION,
7569 enc_bind_conn_to_session, dec_bind_conn_to_session),
7570 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
7571 #endif /* CONFIG_NFS_V4_1 */
7572 #ifdef CONFIG_NFS_V4_2
7573 PROC(SEEK, enc_seek, dec_seek),
7574 PROC(ALLOCATE, enc_allocate, dec_allocate),
7575 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
7576 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7577 PROC(CLONE, enc_clone, dec_clone),
7578 PROC(COPY, enc_copy, dec_copy),
7579 #endif /* CONFIG_NFS_V4_2 */
7582 const struct rpc_version nfs_version4 = {
7584 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7585 .procs = nfs4_procedures