4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/module.h>
48 #include <linux/utsname.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/sunrpc/msg_prot.h>
51 #include <linux/sunrpc/gss_api.h>
52 #include <linux/nfs.h>
53 #include <linux/nfs4.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/nfs_idmap.h>
59 #include "nfs4session.h"
63 #define NFSDBG_FACILITY NFSDBG_XDR
65 /* Mapping from NFS error code to "errno" error code. */
66 #define errno_NFSERR_IO EIO
68 static int nfs4_stat_to_errno(int);
70 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
72 #define NFS4_MAXTAGLEN 20
74 #define NFS4_MAXTAGLEN 0
77 /* lock,open owner id:
78 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
80 #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
81 #define lock_owner_id_maxsz (1 + 1 + 4)
82 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
83 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85 #define op_encode_hdr_maxsz (1)
86 #define op_decode_hdr_maxsz (2)
87 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
91 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
93 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
94 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
97 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
99 #define nfs4_fattr_bitmap_maxsz 4
100 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
101 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
103 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
106 /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107 #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
109 #define nfs4_label_maxsz 0
111 /* We support only one layout type per file system */
112 #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
113 /* This is based on getfattr, which uses the most attributes: */
114 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
115 3 + 3 + 3 + nfs4_owner_maxsz + \
116 nfs4_group_maxsz + nfs4_label_maxsz + \
117 decode_mdsthreshold_maxsz))
118 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 nfs4_fattr_value_maxsz)
120 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
121 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
127 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
128 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
129 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
131 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
132 /* The 5 accounts for the PNFS attributes, and assumes that at most three
133 * layout types will be returned.
135 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
137 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138 #define decode_renew_maxsz (op_decode_hdr_maxsz)
139 #define encode_setclientid_maxsz \
140 (op_encode_hdr_maxsz + \
141 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
142 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
144 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
145 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
147 #define decode_setclientid_maxsz \
148 (op_decode_hdr_maxsz + \
150 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
151 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
152 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
153 #define encode_setclientid_confirm_maxsz \
154 (op_encode_hdr_maxsz + \
155 3 + (NFS4_VERIFIER_SIZE >> 2))
156 #define decode_setclientid_confirm_maxsz \
157 (op_decode_hdr_maxsz)
158 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
159 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
160 #define encode_share_access_maxsz \
162 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
163 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
164 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
165 #define encode_open_maxsz (op_encode_hdr_maxsz + \
166 2 + encode_share_access_maxsz + 2 + \
167 open_owner_id_maxsz + \
168 encode_opentype_maxsz + \
169 encode_claim_null_maxsz)
170 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
171 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
173 #define decode_change_info_maxsz (5)
174 #define decode_open_maxsz (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz + \
176 decode_change_info_maxsz + 1 + \
177 nfs4_fattr_bitmap_maxsz + \
178 decode_delegation_maxsz)
179 #define encode_open_confirm_maxsz \
180 (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + 1)
182 #define decode_open_confirm_maxsz \
183 (op_decode_hdr_maxsz + \
184 decode_stateid_maxsz)
185 #define encode_open_downgrade_maxsz \
186 (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 1 + \
188 encode_share_access_maxsz)
189 #define decode_open_downgrade_maxsz \
190 (op_decode_hdr_maxsz + \
191 decode_stateid_maxsz)
192 #define encode_close_maxsz (op_encode_hdr_maxsz + \
193 1 + encode_stateid_maxsz)
194 #define decode_close_maxsz (op_decode_hdr_maxsz + \
195 decode_stateid_maxsz)
196 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
197 encode_stateid_maxsz + \
199 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
200 nfs4_fattr_bitmap_maxsz)
201 #define encode_read_maxsz (op_encode_hdr_maxsz + \
202 encode_stateid_maxsz + 3)
203 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
204 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
205 2 + encode_verifier_maxsz + 5 + \
207 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
208 decode_verifier_maxsz)
209 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
210 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
211 #define encode_write_maxsz (op_encode_hdr_maxsz + \
212 encode_stateid_maxsz + 4)
213 #define decode_write_maxsz (op_decode_hdr_maxsz + \
214 2 + decode_verifier_maxsz)
215 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
216 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
217 decode_verifier_maxsz)
218 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
220 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
221 decode_change_info_maxsz)
222 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
224 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
225 decode_change_info_maxsz + \
226 decode_change_info_maxsz)
227 #define encode_link_maxsz (op_encode_hdr_maxsz + \
229 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
230 #define encode_lockowner_maxsz (7)
231 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
233 1 + encode_stateid_maxsz + 1 + \
234 encode_lockowner_maxsz)
235 #define decode_lock_denied_maxsz \
236 (8 + decode_lockowner_maxsz)
237 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
238 decode_lock_denied_maxsz)
239 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
240 encode_lockowner_maxsz)
241 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
242 decode_lock_denied_maxsz)
243 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
244 encode_stateid_maxsz + \
246 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
247 decode_stateid_maxsz)
248 #define encode_release_lockowner_maxsz \
249 (op_encode_hdr_maxsz + \
250 encode_lockowner_maxsz)
251 #define decode_release_lockowner_maxsz \
252 (op_decode_hdr_maxsz)
253 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
254 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
255 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
256 1 + nfs4_name_maxsz + \
259 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
260 #define encode_create_maxsz (op_encode_hdr_maxsz + \
261 1 + 2 + nfs4_name_maxsz + \
263 #define decode_create_maxsz (op_decode_hdr_maxsz + \
264 decode_change_info_maxsz + \
265 nfs4_fattr_bitmap_maxsz)
266 #define encode_statfs_maxsz (encode_getattr_maxsz)
267 #define decode_statfs_maxsz (decode_getattr_maxsz)
268 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
269 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
270 #define encode_getacl_maxsz (encode_getattr_maxsz)
271 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
272 nfs4_fattr_bitmap_maxsz + 1)
273 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
274 encode_stateid_maxsz + 3)
275 #define decode_setacl_maxsz (decode_setattr_maxsz)
276 #define encode_fs_locations_maxsz \
277 (encode_getattr_maxsz)
278 #define decode_fs_locations_maxsz \
280 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
281 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
283 #if defined(CONFIG_NFS_V4_1)
284 #define NFS4_MAX_MACHINE_NAME_LEN (64)
285 #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
286 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
288 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
289 encode_verifier_maxsz + \
290 1 /* co_ownerid.len */ + \
291 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
294 /* max is SP4_MACH_CRED (for now) */ + \
295 1 + NFS4_OP_MAP_NUM_WORDS + \
296 1 + NFS4_OP_MAP_NUM_WORDS + \
297 1 /* implementation id array of size 1 */ + \
298 1 /* nii_domain */ + \
299 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
301 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
303 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
304 2 /* eir_clientid */ + \
305 1 /* eir_sequenceid */ + \
306 1 /* eir_flags */ + \
308 /* max is SP4_MACH_CRED (for now) */ + \
309 1 + NFS4_OP_MAP_NUM_WORDS + \
310 1 + NFS4_OP_MAP_NUM_WORDS + \
311 2 /* eir_server_owner.so_minor_id */ + \
312 /* eir_server_owner.so_major_id<> */ \
313 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
314 /* eir_server_scope<> */ \
315 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
316 1 /* eir_server_impl_id array length */ + \
317 1 /* nii_domain */ + \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
322 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
323 #define decode_channel_attrs_maxsz (6 + \
324 1 /* ca_rdma_ird.len */ + \
326 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
327 2 /* csa_clientid */ + \
328 1 /* csa_sequence */ + \
329 1 /* csa_flags */ + \
330 encode_channel_attrs_maxsz + \
331 encode_channel_attrs_maxsz + \
332 1 /* csa_cb_program */ + \
333 1 /* csa_sec_parms.len (1) */ + \
334 1 /* cb_secflavor (AUTH_SYS) */ + \
336 1 /* machinename.len */ + \
337 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
340 1 /* gids.len (0) */)
341 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
342 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
343 1 /* csr_sequence */ + \
344 1 /* csr_flags */ + \
345 decode_channel_attrs_maxsz + \
346 decode_channel_attrs_maxsz)
347 #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
349 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
350 1 /* bctsa_dir */ + \
351 1 /* bctsa_use_conn_in_rdma_mode */)
352 #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
354 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
355 1 /* bctsr_dir */ + \
356 1 /* bctsr_use_conn_in_rdma_mode */)
357 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
358 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
359 #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
360 #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
361 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
362 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
363 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
364 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
365 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
366 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
367 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
368 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
369 1 /* layout type */ + \
371 1 /* bitmap size */ + \
372 1 /* notification bitmap length */ + \
373 1 /* notification bitmap, word 0 */)
374 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
375 1 /* layout type */ + \
376 1 /* opaque devaddr4 length */ + \
377 /* devaddr4 payload is read into page */ \
378 1 /* notification bitmap length */ + \
379 1 /* notification bitmap, word 0 */)
380 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
381 encode_stateid_maxsz)
382 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
383 decode_stateid_maxsz + \
384 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
385 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
389 encode_stateid_maxsz + \
390 1 /* new offset (true) */ + \
391 2 /* last byte written */ + \
392 1 /* nt_timechanged (false) */ + \
393 1 /* layoutupdate4 layout type */ + \
394 1 /* layoutupdate4 opaqueue len */)
395 /* the actual content of layoutupdate4 should
396 be allocated by drivers and spliced in
397 using xdr_write_pages */
398 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
399 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
400 encode_stateid_maxsz + \
401 1 /* FIXME: opaque lrf_body always empty at the moment */)
402 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
403 1 + decode_stateid_maxsz)
404 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
405 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
406 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
407 XDR_QUADLEN(NFS4_STATEID_SIZE))
408 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
409 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
410 XDR_QUADLEN(NFS4_STATEID_SIZE))
411 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
412 #else /* CONFIG_NFS_V4_1 */
413 #define encode_sequence_maxsz 0
414 #define decode_sequence_maxsz 0
415 #endif /* CONFIG_NFS_V4_1 */
417 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
418 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
419 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
420 encode_sequence_maxsz + \
421 encode_putfh_maxsz + \
423 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
424 decode_sequence_maxsz + \
425 decode_putfh_maxsz + \
427 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
428 encode_sequence_maxsz + \
429 encode_putfh_maxsz + \
430 encode_readlink_maxsz)
431 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
432 decode_sequence_maxsz + \
433 decode_putfh_maxsz + \
434 decode_readlink_maxsz)
435 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
436 encode_sequence_maxsz + \
437 encode_putfh_maxsz + \
438 encode_readdir_maxsz)
439 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
440 decode_sequence_maxsz + \
441 decode_putfh_maxsz + \
442 decode_readdir_maxsz)
443 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
444 encode_sequence_maxsz + \
445 encode_putfh_maxsz + \
446 encode_write_maxsz + \
447 encode_getattr_maxsz)
448 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
449 decode_sequence_maxsz + \
450 decode_putfh_maxsz + \
451 decode_write_maxsz + \
452 decode_getattr_maxsz)
453 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
454 encode_sequence_maxsz + \
455 encode_putfh_maxsz + \
457 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
458 decode_sequence_maxsz + \
459 decode_putfh_maxsz + \
461 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
462 encode_sequence_maxsz + \
463 encode_putfh_maxsz + \
464 encode_open_maxsz + \
465 encode_access_maxsz + \
466 encode_getfh_maxsz + \
467 encode_getattr_maxsz)
468 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
469 decode_sequence_maxsz + \
470 decode_putfh_maxsz + \
471 decode_open_maxsz + \
472 decode_access_maxsz + \
473 decode_getfh_maxsz + \
474 decode_getattr_maxsz)
475 #define NFS4_enc_open_confirm_sz \
476 (compound_encode_hdr_maxsz + \
477 encode_putfh_maxsz + \
478 encode_open_confirm_maxsz)
479 #define NFS4_dec_open_confirm_sz \
480 (compound_decode_hdr_maxsz + \
481 decode_putfh_maxsz + \
482 decode_open_confirm_maxsz)
483 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
484 encode_sequence_maxsz + \
485 encode_putfh_maxsz + \
486 encode_open_maxsz + \
487 encode_access_maxsz + \
488 encode_getattr_maxsz)
489 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
490 decode_sequence_maxsz + \
491 decode_putfh_maxsz + \
492 decode_open_maxsz + \
493 decode_access_maxsz + \
494 decode_getattr_maxsz)
495 #define NFS4_enc_open_downgrade_sz \
496 (compound_encode_hdr_maxsz + \
497 encode_sequence_maxsz + \
498 encode_putfh_maxsz + \
499 encode_open_downgrade_maxsz + \
500 encode_getattr_maxsz)
501 #define NFS4_dec_open_downgrade_sz \
502 (compound_decode_hdr_maxsz + \
503 decode_sequence_maxsz + \
504 decode_putfh_maxsz + \
505 decode_open_downgrade_maxsz + \
506 decode_getattr_maxsz)
507 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
508 encode_sequence_maxsz + \
509 encode_putfh_maxsz + \
510 encode_close_maxsz + \
511 encode_getattr_maxsz)
512 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
513 decode_sequence_maxsz + \
514 decode_putfh_maxsz + \
515 decode_close_maxsz + \
516 decode_getattr_maxsz)
517 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
518 encode_sequence_maxsz + \
519 encode_putfh_maxsz + \
520 encode_setattr_maxsz + \
521 encode_getattr_maxsz)
522 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
523 decode_sequence_maxsz + \
524 decode_putfh_maxsz + \
525 decode_setattr_maxsz + \
526 decode_getattr_maxsz)
527 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
528 encode_sequence_maxsz + \
529 encode_putfh_maxsz + \
531 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
532 decode_sequence_maxsz + \
533 decode_putfh_maxsz + \
535 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
537 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
539 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
540 encode_setclientid_maxsz)
541 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
542 decode_setclientid_maxsz)
543 #define NFS4_enc_setclientid_confirm_sz \
544 (compound_encode_hdr_maxsz + \
545 encode_setclientid_confirm_maxsz)
546 #define NFS4_dec_setclientid_confirm_sz \
547 (compound_decode_hdr_maxsz + \
548 decode_setclientid_confirm_maxsz)
549 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
550 encode_sequence_maxsz + \
551 encode_putfh_maxsz + \
553 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
554 decode_sequence_maxsz + \
555 decode_putfh_maxsz + \
557 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
558 encode_sequence_maxsz + \
559 encode_putfh_maxsz + \
561 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
562 decode_sequence_maxsz + \
563 decode_putfh_maxsz + \
565 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
566 encode_sequence_maxsz + \
567 encode_putfh_maxsz + \
569 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
570 decode_sequence_maxsz + \
571 decode_putfh_maxsz + \
573 #define NFS4_enc_release_lockowner_sz \
574 (compound_encode_hdr_maxsz + \
575 encode_lockowner_maxsz)
576 #define NFS4_dec_release_lockowner_sz \
577 (compound_decode_hdr_maxsz + \
578 decode_lockowner_maxsz)
579 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
580 encode_sequence_maxsz + \
581 encode_putfh_maxsz + \
582 encode_access_maxsz + \
583 encode_getattr_maxsz)
584 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
585 decode_sequence_maxsz + \
586 decode_putfh_maxsz + \
587 decode_access_maxsz + \
588 decode_getattr_maxsz)
589 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
590 encode_sequence_maxsz + \
591 encode_putfh_maxsz + \
592 encode_getattr_maxsz + \
594 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
595 decode_sequence_maxsz + \
596 decode_putfh_maxsz + \
597 decode_getattr_maxsz + \
599 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
600 encode_sequence_maxsz + \
601 encode_putfh_maxsz + \
602 encode_lookup_maxsz + \
603 encode_getattr_maxsz + \
605 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
606 decode_sequence_maxsz + \
607 decode_putfh_maxsz + \
608 decode_lookup_maxsz + \
609 decode_getattr_maxsz + \
611 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
612 encode_sequence_maxsz + \
613 encode_putrootfh_maxsz + \
614 encode_getattr_maxsz + \
616 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
617 decode_sequence_maxsz + \
618 decode_putrootfh_maxsz + \
619 decode_getattr_maxsz + \
621 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
622 encode_sequence_maxsz + \
623 encode_putfh_maxsz + \
625 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
626 decode_sequence_maxsz + \
627 decode_putfh_maxsz + \
629 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
630 encode_sequence_maxsz + \
631 encode_putfh_maxsz + \
632 encode_savefh_maxsz + \
633 encode_putfh_maxsz + \
635 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
636 decode_sequence_maxsz + \
637 decode_putfh_maxsz + \
638 decode_savefh_maxsz + \
639 decode_putfh_maxsz + \
641 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
642 encode_sequence_maxsz + \
643 encode_putfh_maxsz + \
644 encode_savefh_maxsz + \
645 encode_putfh_maxsz + \
646 encode_link_maxsz + \
647 encode_restorefh_maxsz + \
648 encode_getattr_maxsz)
649 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
650 decode_sequence_maxsz + \
651 decode_putfh_maxsz + \
652 decode_savefh_maxsz + \
653 decode_putfh_maxsz + \
654 decode_link_maxsz + \
655 decode_restorefh_maxsz + \
656 decode_getattr_maxsz)
657 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
658 encode_sequence_maxsz + \
659 encode_putfh_maxsz + \
660 encode_symlink_maxsz + \
661 encode_getattr_maxsz + \
663 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
664 decode_sequence_maxsz + \
665 decode_putfh_maxsz + \
666 decode_symlink_maxsz + \
667 decode_getattr_maxsz + \
669 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
670 encode_sequence_maxsz + \
671 encode_putfh_maxsz + \
672 encode_create_maxsz + \
673 encode_getfh_maxsz + \
674 encode_getattr_maxsz)
675 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
676 decode_sequence_maxsz + \
677 decode_putfh_maxsz + \
678 decode_create_maxsz + \
679 decode_getfh_maxsz + \
680 decode_getattr_maxsz)
681 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
682 encode_sequence_maxsz + \
683 encode_putfh_maxsz + \
684 encode_getattr_maxsz)
685 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
686 decode_sequence_maxsz + \
687 decode_putfh_maxsz + \
688 decode_getattr_maxsz)
689 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
690 encode_sequence_maxsz + \
691 encode_putfh_maxsz + \
693 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
694 decode_sequence_maxsz + \
695 decode_putfh_maxsz + \
697 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
698 encode_sequence_maxsz + \
699 encode_putfh_maxsz + \
700 encode_getattr_maxsz)
701 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
702 decode_sequence_maxsz + \
703 decode_putfh_maxsz + \
704 decode_getattr_maxsz)
705 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
706 encode_sequence_maxsz + \
707 encode_putfh_maxsz + \
708 encode_delegreturn_maxsz + \
709 encode_getattr_maxsz)
710 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
711 decode_sequence_maxsz + \
712 decode_delegreturn_maxsz + \
713 decode_getattr_maxsz)
714 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
715 encode_sequence_maxsz + \
716 encode_putfh_maxsz + \
718 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
719 decode_sequence_maxsz + \
720 decode_putfh_maxsz + \
722 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
723 encode_sequence_maxsz + \
724 encode_putfh_maxsz + \
726 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
727 decode_sequence_maxsz + \
728 decode_putfh_maxsz + \
730 #define NFS4_enc_fs_locations_sz \
731 (compound_encode_hdr_maxsz + \
732 encode_sequence_maxsz + \
733 encode_putfh_maxsz + \
734 encode_lookup_maxsz + \
735 encode_fs_locations_maxsz + \
737 #define NFS4_dec_fs_locations_sz \
738 (compound_decode_hdr_maxsz + \
739 decode_sequence_maxsz + \
740 decode_putfh_maxsz + \
741 decode_lookup_maxsz + \
742 decode_fs_locations_maxsz + \
744 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
745 encode_sequence_maxsz + \
746 encode_putfh_maxsz + \
747 encode_secinfo_maxsz)
748 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
749 decode_sequence_maxsz + \
750 decode_putfh_maxsz + \
751 decode_secinfo_maxsz)
752 #define NFS4_enc_fsid_present_sz \
753 (compound_encode_hdr_maxsz + \
754 encode_sequence_maxsz + \
755 encode_putfh_maxsz + \
756 encode_getfh_maxsz + \
758 #define NFS4_dec_fsid_present_sz \
759 (compound_decode_hdr_maxsz + \
760 decode_sequence_maxsz + \
761 decode_putfh_maxsz + \
762 decode_getfh_maxsz + \
764 #if defined(CONFIG_NFS_V4_1)
765 #define NFS4_enc_bind_conn_to_session_sz \
766 (compound_encode_hdr_maxsz + \
767 encode_bind_conn_to_session_maxsz)
768 #define NFS4_dec_bind_conn_to_session_sz \
769 (compound_decode_hdr_maxsz + \
770 decode_bind_conn_to_session_maxsz)
771 #define NFS4_enc_exchange_id_sz \
772 (compound_encode_hdr_maxsz + \
773 encode_exchange_id_maxsz)
774 #define NFS4_dec_exchange_id_sz \
775 (compound_decode_hdr_maxsz + \
776 decode_exchange_id_maxsz)
777 #define NFS4_enc_create_session_sz \
778 (compound_encode_hdr_maxsz + \
779 encode_create_session_maxsz)
780 #define NFS4_dec_create_session_sz \
781 (compound_decode_hdr_maxsz + \
782 decode_create_session_maxsz)
783 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
784 encode_destroy_session_maxsz)
785 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
786 decode_destroy_session_maxsz)
787 #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
788 encode_destroy_clientid_maxsz)
789 #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
790 decode_destroy_clientid_maxsz)
791 #define NFS4_enc_sequence_sz \
792 (compound_decode_hdr_maxsz + \
793 encode_sequence_maxsz)
794 #define NFS4_dec_sequence_sz \
795 (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz)
797 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putrootfh_maxsz + \
801 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putrootfh_maxsz + \
805 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz + \
807 encode_reclaim_complete_maxsz)
808 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
809 decode_sequence_maxsz + \
810 decode_reclaim_complete_maxsz)
811 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz +\
813 encode_getdeviceinfo_maxsz)
814 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_getdeviceinfo_maxsz)
817 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putfh_maxsz + \
820 encode_layoutget_maxsz)
821 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putfh_maxsz + \
824 decode_layoutget_maxsz)
825 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz +\
827 encode_putfh_maxsz + \
828 encode_layoutcommit_maxsz + \
829 encode_getattr_maxsz)
830 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
831 decode_sequence_maxsz + \
832 decode_putfh_maxsz + \
833 decode_layoutcommit_maxsz + \
834 decode_getattr_maxsz)
835 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
836 encode_sequence_maxsz + \
837 encode_putfh_maxsz + \
838 encode_layoutreturn_maxsz)
839 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
840 decode_sequence_maxsz + \
841 decode_putfh_maxsz + \
842 decode_layoutreturn_maxsz)
843 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
844 encode_sequence_maxsz + \
845 encode_putrootfh_maxsz +\
846 encode_secinfo_no_name_maxsz)
847 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_putrootfh_maxsz + \
850 decode_secinfo_no_name_maxsz)
851 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz + \
853 encode_test_stateid_maxsz)
854 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
855 decode_sequence_maxsz + \
856 decode_test_stateid_maxsz)
857 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
858 encode_sequence_maxsz + \
859 encode_free_stateid_maxsz)
860 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
861 decode_sequence_maxsz + \
862 decode_free_stateid_maxsz)
864 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
865 compound_encode_hdr_maxsz +
866 encode_sequence_maxsz +
868 encode_getattr_maxsz) *
871 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
872 compound_decode_hdr_maxsz +
873 decode_sequence_maxsz +
874 decode_putfh_maxsz) *
877 const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
878 compound_decode_hdr_maxsz +
879 decode_sequence_maxsz) *
881 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
882 #endif /* CONFIG_NFS_V4_1 */
884 static const umode_t nfs_type2fmt[] = {
891 [NF4SOCK] = S_IFSOCK,
897 struct compound_hdr {
903 uint32_t replen; /* expected reply words */
907 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
909 __be32 *p = xdr_reserve_space(xdr, nbytes);
914 static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
918 p = xdr_reserve_space(xdr, len);
919 xdr_encode_opaque_fixed(p, buf, len);
922 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
926 p = reserve_space(xdr, 4 + len);
927 xdr_encode_opaque(p, str, len);
930 static void encode_uint32(struct xdr_stream *xdr, u32 n)
934 p = reserve_space(xdr, 4);
938 static void encode_uint64(struct xdr_stream *xdr, u64 n)
942 p = reserve_space(xdr, 8);
943 xdr_encode_hyper(p, n);
946 static void encode_nfs4_seqid(struct xdr_stream *xdr,
947 const struct nfs_seqid *seqid)
950 encode_uint32(xdr, seqid->sequence->counter);
952 encode_uint32(xdr, 0);
955 static void encode_compound_hdr(struct xdr_stream *xdr,
956 struct rpc_rqst *req,
957 struct compound_hdr *hdr)
960 struct rpc_auth *auth = req->rq_cred->cr_auth;
962 /* initialize running count of expected bytes in reply.
963 * NOTE: the replied tag SHOULD be the same is the one sent,
964 * but this is not required as a MUST for the server to do so. */
965 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
967 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
968 encode_string(xdr, hdr->taglen, hdr->tag);
969 p = reserve_space(xdr, 8);
970 *p++ = cpu_to_be32(hdr->minorversion);
972 *p = cpu_to_be32(hdr->nops);
975 static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
977 struct compound_hdr *hdr)
979 encode_uint32(xdr, op);
981 hdr->replen += replen;
984 static void encode_nops(struct compound_hdr *hdr)
986 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
987 *hdr->nops_p = htonl(hdr->nops);
990 static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
992 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
995 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
997 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
1000 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1001 const struct nfs4_label *label,
1002 const struct nfs_server *server)
1004 char owner_name[IDMAP_NAMESZ];
1005 char owner_group[IDMAP_NAMESZ];
1006 int owner_namelen = 0;
1007 int owner_grouplen = 0;
1012 uint32_t bmval[3] = { 0 };
1015 * We reserve enough space to write the entire attribute buffer at once.
1016 * In the worst-case, this would be
1017 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1018 * = 40 bytes, plus any contribution from variable-length fields
1019 * such as owner/group.
1021 if (iap->ia_valid & ATTR_SIZE) {
1022 bmval[0] |= FATTR4_WORD0_SIZE;
1025 if (iap->ia_valid & ATTR_MODE) {
1026 bmval[1] |= FATTR4_WORD1_MODE;
1029 if (iap->ia_valid & ATTR_UID) {
1030 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1031 if (owner_namelen < 0) {
1032 dprintk("nfs: couldn't resolve uid %d to string\n",
1033 from_kuid(&init_user_ns, iap->ia_uid));
1035 strcpy(owner_name, "nobody");
1036 owner_namelen = sizeof("nobody") - 1;
1039 bmval[1] |= FATTR4_WORD1_OWNER;
1040 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1042 if (iap->ia_valid & ATTR_GID) {
1043 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1044 if (owner_grouplen < 0) {
1045 dprintk("nfs: couldn't resolve gid %d to string\n",
1046 from_kgid(&init_user_ns, iap->ia_gid));
1047 strcpy(owner_group, "nobody");
1048 owner_grouplen = sizeof("nobody") - 1;
1051 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1052 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1054 if (iap->ia_valid & ATTR_ATIME_SET) {
1055 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1057 } else if (iap->ia_valid & ATTR_ATIME) {
1058 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1061 if (iap->ia_valid & ATTR_MTIME_SET) {
1062 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1064 } else if (iap->ia_valid & ATTR_MTIME) {
1065 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1069 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1070 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1075 else if (bmval[1] != 0)
1080 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1082 *p++ = cpu_to_be32(bmval_len);
1083 for (i = 0; i < bmval_len; i++)
1084 *p++ = cpu_to_be32(bmval[i]);
1085 *p++ = cpu_to_be32(len);
1087 if (bmval[0] & FATTR4_WORD0_SIZE)
1088 p = xdr_encode_hyper(p, iap->ia_size);
1089 if (bmval[1] & FATTR4_WORD1_MODE)
1090 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1091 if (bmval[1] & FATTR4_WORD1_OWNER)
1092 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1093 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1094 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1095 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1096 if (iap->ia_valid & ATTR_ATIME_SET) {
1097 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1098 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1099 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1101 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1103 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1104 if (iap->ia_valid & ATTR_MTIME_SET) {
1105 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1106 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1107 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1109 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1111 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1112 *p++ = cpu_to_be32(label->lfs);
1113 *p++ = cpu_to_be32(label->pi);
1114 *p++ = cpu_to_be32(label->len);
1115 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1121 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1123 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1124 encode_uint32(xdr, access);
1127 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1129 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1130 encode_nfs4_seqid(xdr, arg->seqid);
1131 encode_nfs4_stateid(xdr, &arg->stateid);
1134 static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1138 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1139 p = reserve_space(xdr, 12);
1140 p = xdr_encode_hyper(p, args->offset);
1141 *p = cpu_to_be32(args->count);
1144 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1148 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1149 encode_uint32(xdr, create->ftype);
1151 switch (create->ftype) {
1153 p = reserve_space(xdr, 4);
1154 *p = cpu_to_be32(create->u.symlink.len);
1155 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1158 case NF4BLK: case NF4CHR:
1159 p = reserve_space(xdr, 8);
1160 *p++ = cpu_to_be32(create->u.device.specdata1);
1161 *p = cpu_to_be32(create->u.device.specdata2);
1168 encode_string(xdr, create->name->len, create->name->name);
1169 encode_attrs(xdr, create->attrs, create->label, create->server);
1172 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1176 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1177 p = reserve_space(xdr, 8);
1178 *p++ = cpu_to_be32(1);
1179 *p = cpu_to_be32(bitmap);
1182 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1186 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1187 p = reserve_space(xdr, 12);
1188 *p++ = cpu_to_be32(2);
1189 *p++ = cpu_to_be32(bm0);
1190 *p = cpu_to_be32(bm1);
1194 encode_getattr_three(struct xdr_stream *xdr,
1195 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1196 struct compound_hdr *hdr)
1200 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1202 p = reserve_space(xdr, 16);
1203 *p++ = cpu_to_be32(3);
1204 *p++ = cpu_to_be32(bm0);
1205 *p++ = cpu_to_be32(bm1);
1206 *p = cpu_to_be32(bm2);
1208 p = reserve_space(xdr, 12);
1209 *p++ = cpu_to_be32(2);
1210 *p++ = cpu_to_be32(bm0);
1211 *p = cpu_to_be32(bm1);
1213 p = reserve_space(xdr, 8);
1214 *p++ = cpu_to_be32(1);
1215 *p = cpu_to_be32(bm0);
1219 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1221 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1222 bitmask[1] & nfs4_fattr_bitmap[1],
1223 bitmask[2] & nfs4_fattr_bitmap[2],
1227 static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1228 const u32 *open_bitmap,
1229 struct compound_hdr *hdr)
1231 encode_getattr_three(xdr,
1232 bitmask[0] & open_bitmap[0],
1233 bitmask[1] & open_bitmap[1],
1234 bitmask[2] & open_bitmap[2],
1238 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1240 encode_getattr_three(xdr,
1241 bitmask[0] & nfs4_fsinfo_bitmap[0],
1242 bitmask[1] & nfs4_fsinfo_bitmap[1],
1243 bitmask[2] & nfs4_fsinfo_bitmap[2],
1247 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1249 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1250 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1253 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1255 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1258 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1260 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1261 encode_string(xdr, name->len, name->name);
1264 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1266 if (fl->fl_type == F_RDLCK)
1267 return block ? NFS4_READW_LT : NFS4_READ_LT;
1268 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1271 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1273 if (fl->fl_end == OFFSET_MAX)
1274 return ~(uint64_t)0;
1275 return fl->fl_end - fl->fl_start + 1;
1278 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1282 p = reserve_space(xdr, 32);
1283 p = xdr_encode_hyper(p, lowner->clientid);
1284 *p++ = cpu_to_be32(20);
1285 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1286 *p++ = cpu_to_be32(lowner->s_dev);
1287 xdr_encode_hyper(p, lowner->id);
1291 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1292 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1294 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1298 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1299 p = reserve_space(xdr, 28);
1300 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1301 *p++ = cpu_to_be32(args->reclaim);
1302 p = xdr_encode_hyper(p, args->fl->fl_start);
1303 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1304 *p = cpu_to_be32(args->new_lock_owner);
1305 if (args->new_lock_owner){
1306 encode_nfs4_seqid(xdr, args->open_seqid);
1307 encode_nfs4_stateid(xdr, &args->open_stateid);
1308 encode_nfs4_seqid(xdr, args->lock_seqid);
1309 encode_lockowner(xdr, &args->lock_owner);
1312 encode_nfs4_stateid(xdr, &args->lock_stateid);
1313 encode_nfs4_seqid(xdr, args->lock_seqid);
1317 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1321 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1322 p = reserve_space(xdr, 20);
1323 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1324 p = xdr_encode_hyper(p, args->fl->fl_start);
1325 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1326 encode_lockowner(xdr, &args->lock_owner);
1329 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1333 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1334 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1335 encode_nfs4_seqid(xdr, args->seqid);
1336 encode_nfs4_stateid(xdr, &args->stateid);
1337 p = reserve_space(xdr, 16);
1338 p = xdr_encode_hyper(p, args->fl->fl_start);
1339 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1342 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1344 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1345 encode_lockowner(xdr, lowner);
1348 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1350 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1351 encode_string(xdr, name->len, name->name);
1354 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1358 p = reserve_space(xdr, 8);
1359 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1361 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1364 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1366 case FMODE_READ|FMODE_WRITE:
1367 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1370 *p++ = cpu_to_be32(0);
1372 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1375 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1379 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1382 encode_nfs4_seqid(xdr, arg->seqid);
1383 encode_share_access(xdr, arg->fmode);
1384 p = reserve_space(xdr, 36);
1385 p = xdr_encode_hyper(p, arg->clientid);
1386 *p++ = cpu_to_be32(24);
1387 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1388 *p++ = cpu_to_be32(arg->server->s_dev);
1389 *p++ = cpu_to_be32(arg->id.uniquifier);
1390 xdr_encode_hyper(p, arg->id.create_time);
1393 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1398 p = reserve_space(xdr, 4);
1399 switch(arg->createmode) {
1400 case NFS4_CREATE_UNCHECKED:
1401 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1402 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
1404 case NFS4_CREATE_GUARDED:
1405 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1406 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
1408 case NFS4_CREATE_EXCLUSIVE:
1409 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1410 encode_nfs4_verifier(xdr, &arg->u.verifier);
1412 case NFS4_CREATE_EXCLUSIVE4_1:
1413 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1414 encode_nfs4_verifier(xdr, &arg->u.verifier);
1416 encode_attrs(xdr, &dummy, arg->label, arg->server);
1420 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1424 p = reserve_space(xdr, 4);
1425 switch (arg->open_flags & O_CREAT) {
1427 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1430 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1431 encode_createmode(xdr, arg);
1435 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1439 p = reserve_space(xdr, 4);
1440 switch (delegation_type) {
1442 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1445 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1447 case FMODE_WRITE|FMODE_READ:
1448 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1455 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1459 p = reserve_space(xdr, 4);
1460 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1461 encode_string(xdr, name->len, name->name);
1464 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1468 p = reserve_space(xdr, 4);
1469 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1470 encode_delegation_type(xdr, type);
1473 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1477 p = reserve_space(xdr, 4);
1478 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1479 encode_nfs4_stateid(xdr, stateid);
1480 encode_string(xdr, name->len, name->name);
1483 static inline void encode_claim_fh(struct xdr_stream *xdr)
1487 p = reserve_space(xdr, 4);
1488 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1491 static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1495 p = reserve_space(xdr, 4);
1496 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1497 encode_nfs4_stateid(xdr, stateid);
1500 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1502 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1503 encode_openhdr(xdr, arg);
1504 encode_opentype(xdr, arg);
1505 switch (arg->claim) {
1506 case NFS4_OPEN_CLAIM_NULL:
1507 encode_claim_null(xdr, arg->name);
1509 case NFS4_OPEN_CLAIM_PREVIOUS:
1510 encode_claim_previous(xdr, arg->u.delegation_type);
1512 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1513 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1515 case NFS4_OPEN_CLAIM_FH:
1516 encode_claim_fh(xdr);
1518 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1519 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1526 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1528 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1529 encode_nfs4_stateid(xdr, arg->stateid);
1530 encode_nfs4_seqid(xdr, arg->seqid);
1533 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1535 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1536 encode_nfs4_stateid(xdr, &arg->stateid);
1537 encode_nfs4_seqid(xdr, arg->seqid);
1538 encode_share_access(xdr, arg->fmode);
1542 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1544 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1545 encode_string(xdr, fh->size, fh->data);
1548 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1550 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1553 static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1554 struct compound_hdr *hdr)
1558 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1559 encode_nfs4_stateid(xdr, &args->stateid);
1561 p = reserve_space(xdr, 12);
1562 p = xdr_encode_hyper(p, args->offset);
1563 *p = cpu_to_be32(args->count);
1566 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1568 uint32_t attrs[3] = {
1569 FATTR4_WORD0_RDATTR_ERROR,
1570 FATTR4_WORD1_MOUNTED_ON_FILEID,
1572 uint32_t dircount = readdir->count >> 1;
1574 uint32_t attrlen = 0;
1577 if (readdir->plus) {
1578 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1579 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1580 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1581 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1582 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1583 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1584 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1587 /* Use mounted_on_fileid only if the server supports it */
1588 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1589 attrs[0] |= FATTR4_WORD0_FILEID;
1590 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1591 attrs[i] &= readdir->bitmask[i];
1596 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1597 encode_uint64(xdr, readdir->cookie);
1598 encode_nfs4_verifier(xdr, &readdir->verifier);
1599 p = reserve_space(xdr, 12 + (attrlen << 2));
1600 *p++ = cpu_to_be32(dircount);
1601 *p++ = cpu_to_be32(readdir->count);
1602 *p++ = cpu_to_be32(attrlen);
1603 for (i = 0; i < attrlen; i++)
1604 *p++ = cpu_to_be32(attrs[i]);
1605 memcpy(verf, readdir->verifier.data, sizeof(verf));
1607 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1609 (unsigned long long)readdir->cookie,
1611 attrs[0] & readdir->bitmask[0],
1612 attrs[1] & readdir->bitmask[1],
1613 attrs[2] & readdir->bitmask[2]);
1616 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1618 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1621 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1623 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1624 encode_string(xdr, name->len, name->name);
1627 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1629 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1630 encode_string(xdr, oldname->len, oldname->name);
1631 encode_string(xdr, newname->len, newname->name);
1634 static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1635 struct compound_hdr *hdr)
1637 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1638 encode_uint64(xdr, clid);
1642 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1644 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1648 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1652 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1653 encode_nfs4_stateid(xdr, &zero_stateid);
1654 p = reserve_space(xdr, 2*4);
1655 *p++ = cpu_to_be32(1);
1656 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1657 p = reserve_space(xdr, 4);
1658 *p = cpu_to_be32(arg->acl_len);
1659 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1663 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1665 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1668 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1670 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1671 encode_nfs4_stateid(xdr, &arg->stateid);
1672 encode_attrs(xdr, arg->iap, arg->label, server);
1675 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1679 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1680 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1682 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1683 p = reserve_space(xdr, 4);
1684 *p = cpu_to_be32(setclientid->sc_prog);
1685 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1686 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1687 p = reserve_space(xdr, 4);
1688 *p = cpu_to_be32(setclientid->sc_cb_ident);
1691 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1693 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1694 decode_setclientid_confirm_maxsz, hdr);
1695 encode_uint64(xdr, arg->clientid);
1696 encode_nfs4_verifier(xdr, &arg->confirm);
1699 static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1700 struct compound_hdr *hdr)
1704 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1705 encode_nfs4_stateid(xdr, &args->stateid);
1707 p = reserve_space(xdr, 16);
1708 p = xdr_encode_hyper(p, args->offset);
1709 *p++ = cpu_to_be32(args->stable);
1710 *p = cpu_to_be32(args->count);
1712 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1715 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1717 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1718 encode_nfs4_stateid(xdr, stateid);
1721 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1723 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1724 encode_string(xdr, name->len, name->name);
1727 #if defined(CONFIG_NFS_V4_1)
1728 /* NFSv4.1 operations */
1729 static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1730 struct nfs4_session *session,
1731 struct compound_hdr *hdr)
1735 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1736 decode_bind_conn_to_session_maxsz, hdr);
1737 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1738 p = xdr_reserve_space(xdr, 8);
1739 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1740 *p = 0; /* use_conn_in_rdma_mode = False */
1743 static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1746 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1747 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1748 encode_uint32(xdr, op_map->u.words[i]);
1751 static void encode_exchange_id(struct xdr_stream *xdr,
1752 struct nfs41_exchange_id_args *args,
1753 struct compound_hdr *hdr)
1756 char impl_name[IMPL_NAME_LIMIT];
1759 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1760 encode_nfs4_verifier(xdr, args->verifier);
1762 encode_string(xdr, args->id_len, args->id);
1764 encode_uint32(xdr, args->flags);
1765 encode_uint32(xdr, args->state_protect.how);
1767 switch (args->state_protect.how) {
1771 encode_op_map(xdr, &args->state_protect.enforce);
1772 encode_op_map(xdr, &args->state_protect.allow);
1779 if (send_implementation_id &&
1780 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1781 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1782 <= sizeof(impl_name) + 1)
1783 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1784 utsname()->sysname, utsname()->release,
1785 utsname()->version, utsname()->machine);
1788 encode_uint32(xdr, 1); /* implementation id array length=1 */
1791 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1792 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1793 encode_string(xdr, len, impl_name);
1794 /* just send zeros for nii_date - the date is in nii_name */
1795 p = reserve_space(xdr, 12);
1796 p = xdr_encode_hyper(p, 0);
1797 *p = cpu_to_be32(0);
1799 encode_uint32(xdr, 0); /* implementation id array length=0 */
1802 static void encode_create_session(struct xdr_stream *xdr,
1803 struct nfs41_create_session_args *args,
1804 struct compound_hdr *hdr)
1807 struct nfs_client *clp = args->client;
1808 struct rpc_clnt *clnt = clp->cl_rpcclient;
1809 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1810 u32 max_resp_sz_cached;
1813 * Assumes OPEN is the biggest non-idempotent compound.
1814 * 2 is the verifier.
1816 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1817 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1819 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1820 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
1821 p = xdr_encode_hyper(p, clp->cl_clientid);
1822 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1823 *p++ = cpu_to_be32(args->flags); /*flags */
1826 *p++ = cpu_to_be32(0); /* header padding size */
1827 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1828 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1829 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1830 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1831 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1832 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1835 *p++ = cpu_to_be32(0); /* header padding size */
1836 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1837 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1838 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1839 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1840 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1841 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1843 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1844 *p++ = cpu_to_be32(1);
1845 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1847 /* authsys_parms rfc1831 */
1848 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
1849 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1850 *p++ = cpu_to_be32(0); /* UID */
1851 *p++ = cpu_to_be32(0); /* GID */
1852 *p = cpu_to_be32(0); /* No more gids */
1855 static void encode_destroy_session(struct xdr_stream *xdr,
1856 struct nfs4_session *session,
1857 struct compound_hdr *hdr)
1859 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1860 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1863 static void encode_destroy_clientid(struct xdr_stream *xdr,
1865 struct compound_hdr *hdr)
1867 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1868 encode_uint64(xdr, clientid);
1871 static void encode_reclaim_complete(struct xdr_stream *xdr,
1872 struct nfs41_reclaim_complete_args *args,
1873 struct compound_hdr *hdr)
1875 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1876 encode_uint32(xdr, args->one_fs);
1878 #endif /* CONFIG_NFS_V4_1 */
1880 static void encode_sequence(struct xdr_stream *xdr,
1881 const struct nfs4_sequence_args *args,
1882 struct compound_hdr *hdr)
1884 #if defined(CONFIG_NFS_V4_1)
1885 struct nfs4_session *session;
1886 struct nfs4_slot_table *tp;
1887 struct nfs4_slot *slot = args->sa_slot;
1891 session = tp->session;
1895 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1898 * Sessionid + seqid + slotid + max slotid + cache_this
1900 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1901 "max_slotid=%d cache_this=%d\n",
1903 ((u32 *)session->sess_id.data)[0],
1904 ((u32 *)session->sess_id.data)[1],
1905 ((u32 *)session->sess_id.data)[2],
1906 ((u32 *)session->sess_id.data)[3],
1907 slot->seq_nr, slot->slot_nr,
1908 tp->highest_used_slotid, args->sa_cache_this);
1909 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1910 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1911 *p++ = cpu_to_be32(slot->seq_nr);
1912 *p++ = cpu_to_be32(slot->slot_nr);
1913 *p++ = cpu_to_be32(tp->highest_used_slotid);
1914 *p = cpu_to_be32(args->sa_cache_this);
1915 #endif /* CONFIG_NFS_V4_1 */
1918 #ifdef CONFIG_NFS_V4_1
1920 encode_getdeviceinfo(struct xdr_stream *xdr,
1921 const struct nfs4_getdeviceinfo_args *args,
1922 struct compound_hdr *hdr)
1926 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1927 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1928 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1929 NFS4_DEVICEID4_SIZE);
1930 *p++ = cpu_to_be32(args->pdev->layout_type);
1931 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
1933 p = reserve_space(xdr, 4 + 4);
1934 *p++ = cpu_to_be32(1); /* bitmap length */
1935 *p++ = cpu_to_be32(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE);
1939 encode_layoutget(struct xdr_stream *xdr,
1940 const struct nfs4_layoutget_args *args,
1941 struct compound_hdr *hdr)
1945 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1946 p = reserve_space(xdr, 36);
1947 *p++ = cpu_to_be32(0); /* Signal layout available */
1948 *p++ = cpu_to_be32(args->type);
1949 *p++ = cpu_to_be32(args->range.iomode);
1950 p = xdr_encode_hyper(p, args->range.offset);
1951 p = xdr_encode_hyper(p, args->range.length);
1952 p = xdr_encode_hyper(p, args->minlength);
1953 encode_nfs4_stateid(xdr, &args->stateid);
1954 encode_uint32(xdr, args->maxcount);
1956 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1960 (unsigned long)args->range.offset,
1961 (unsigned long)args->range.length,
1966 encode_layoutcommit(struct xdr_stream *xdr,
1967 struct inode *inode,
1968 struct nfs4_layoutcommit_args *args,
1969 struct compound_hdr *hdr)
1973 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1974 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1976 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1977 p = reserve_space(xdr, 20);
1978 /* Only whole file layouts */
1979 p = xdr_encode_hyper(p, 0); /* offset */
1980 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1981 *p = cpu_to_be32(0); /* reclaim */
1982 encode_nfs4_stateid(xdr, &args->stateid);
1983 p = reserve_space(xdr, 20);
1984 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1985 p = xdr_encode_hyper(p, args->lastbytewritten);
1986 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1987 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1989 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
1990 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1991 NFS_I(inode)->layout, xdr, args);
1993 encode_uint32(xdr, args->layoutupdate_len);
1994 if (args->layoutupdate_pages) {
1995 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1996 args->layoutupdate_len);
2004 encode_layoutreturn(struct xdr_stream *xdr,
2005 const struct nfs4_layoutreturn_args *args,
2006 struct compound_hdr *hdr)
2010 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2011 p = reserve_space(xdr, 16);
2012 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2013 *p++ = cpu_to_be32(args->layout_type);
2014 *p++ = cpu_to_be32(args->range.iomode);
2015 *p = cpu_to_be32(RETURN_FILE);
2016 p = reserve_space(xdr, 16);
2017 p = xdr_encode_hyper(p, args->range.offset);
2018 p = xdr_encode_hyper(p, args->range.length);
2019 spin_lock(&args->inode->i_lock);
2020 encode_nfs4_stateid(xdr, &args->stateid);
2021 spin_unlock(&args->inode->i_lock);
2022 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2023 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2024 NFS_I(args->inode)->layout, xdr, args);
2026 encode_uint32(xdr, 0);
2030 encode_secinfo_no_name(struct xdr_stream *xdr,
2031 const struct nfs41_secinfo_no_name_args *args,
2032 struct compound_hdr *hdr)
2034 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2035 encode_uint32(xdr, args->style);
2039 static void encode_test_stateid(struct xdr_stream *xdr,
2040 struct nfs41_test_stateid_args *args,
2041 struct compound_hdr *hdr)
2043 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2044 encode_uint32(xdr, 1);
2045 encode_nfs4_stateid(xdr, args->stateid);
2048 static void encode_free_stateid(struct xdr_stream *xdr,
2049 struct nfs41_free_stateid_args *args,
2050 struct compound_hdr *hdr)
2052 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2053 encode_nfs4_stateid(xdr, &args->stateid);
2055 #endif /* CONFIG_NFS_V4_1 */
2058 * END OF "GENERIC" ENCODE ROUTINES.
2061 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2063 #if defined(CONFIG_NFS_V4_1)
2064 struct nfs4_session *session = args->sa_slot->table->session;
2066 return session->clp->cl_mvops->minor_version;
2067 #endif /* CONFIG_NFS_V4_1 */
2072 * Encode an ACCESS request
2074 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2075 const struct nfs4_accessargs *args)
2077 struct compound_hdr hdr = {
2078 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2081 encode_compound_hdr(xdr, req, &hdr);
2082 encode_sequence(xdr, &args->seq_args, &hdr);
2083 encode_putfh(xdr, args->fh, &hdr);
2084 encode_access(xdr, args->access, &hdr);
2085 encode_getfattr(xdr, args->bitmask, &hdr);
2090 * Encode LOOKUP request
2092 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2093 const struct nfs4_lookup_arg *args)
2095 struct compound_hdr hdr = {
2096 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2099 encode_compound_hdr(xdr, req, &hdr);
2100 encode_sequence(xdr, &args->seq_args, &hdr);
2101 encode_putfh(xdr, args->dir_fh, &hdr);
2102 encode_lookup(xdr, args->name, &hdr);
2103 encode_getfh(xdr, &hdr);
2104 encode_getfattr(xdr, args->bitmask, &hdr);
2109 * Encode LOOKUP_ROOT request
2111 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2112 struct xdr_stream *xdr,
2113 const struct nfs4_lookup_root_arg *args)
2115 struct compound_hdr hdr = {
2116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2119 encode_compound_hdr(xdr, req, &hdr);
2120 encode_sequence(xdr, &args->seq_args, &hdr);
2121 encode_putrootfh(xdr, &hdr);
2122 encode_getfh(xdr, &hdr);
2123 encode_getfattr(xdr, args->bitmask, &hdr);
2128 * Encode REMOVE request
2130 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2131 const struct nfs_removeargs *args)
2133 struct compound_hdr hdr = {
2134 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2137 encode_compound_hdr(xdr, req, &hdr);
2138 encode_sequence(xdr, &args->seq_args, &hdr);
2139 encode_putfh(xdr, args->fh, &hdr);
2140 encode_remove(xdr, &args->name, &hdr);
2145 * Encode RENAME request
2147 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2148 const struct nfs_renameargs *args)
2150 struct compound_hdr hdr = {
2151 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2154 encode_compound_hdr(xdr, req, &hdr);
2155 encode_sequence(xdr, &args->seq_args, &hdr);
2156 encode_putfh(xdr, args->old_dir, &hdr);
2157 encode_savefh(xdr, &hdr);
2158 encode_putfh(xdr, args->new_dir, &hdr);
2159 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2164 * Encode LINK request
2166 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2167 const struct nfs4_link_arg *args)
2169 struct compound_hdr hdr = {
2170 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2173 encode_compound_hdr(xdr, req, &hdr);
2174 encode_sequence(xdr, &args->seq_args, &hdr);
2175 encode_putfh(xdr, args->fh, &hdr);
2176 encode_savefh(xdr, &hdr);
2177 encode_putfh(xdr, args->dir_fh, &hdr);
2178 encode_link(xdr, args->name, &hdr);
2179 encode_restorefh(xdr, &hdr);
2180 encode_getfattr(xdr, args->bitmask, &hdr);
2185 * Encode CREATE request
2187 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2188 const struct nfs4_create_arg *args)
2190 struct compound_hdr hdr = {
2191 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2194 encode_compound_hdr(xdr, req, &hdr);
2195 encode_sequence(xdr, &args->seq_args, &hdr);
2196 encode_putfh(xdr, args->dir_fh, &hdr);
2197 encode_create(xdr, args, &hdr);
2198 encode_getfh(xdr, &hdr);
2199 encode_getfattr(xdr, args->bitmask, &hdr);
2204 * Encode SYMLINK request
2206 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2207 const struct nfs4_create_arg *args)
2209 nfs4_xdr_enc_create(req, xdr, args);
2213 * Encode GETATTR request
2215 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2216 const struct nfs4_getattr_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->fh, &hdr);
2225 encode_getfattr(xdr, args->bitmask, &hdr);
2230 * Encode a CLOSE request
2232 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2233 struct nfs_closeargs *args)
2235 struct compound_hdr hdr = {
2236 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2239 encode_compound_hdr(xdr, req, &hdr);
2240 encode_sequence(xdr, &args->seq_args, &hdr);
2241 encode_putfh(xdr, args->fh, &hdr);
2242 encode_close(xdr, args, &hdr);
2243 encode_getfattr(xdr, args->bitmask, &hdr);
2248 * Encode an OPEN request
2250 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2251 struct nfs_openargs *args)
2253 struct compound_hdr hdr = {
2254 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2257 encode_compound_hdr(xdr, req, &hdr);
2258 encode_sequence(xdr, &args->seq_args, &hdr);
2259 encode_putfh(xdr, args->fh, &hdr);
2260 encode_open(xdr, args, &hdr);
2261 encode_getfh(xdr, &hdr);
2263 encode_access(xdr, args->access, &hdr);
2264 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2269 * Encode an OPEN_CONFIRM request
2271 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2272 struct xdr_stream *xdr,
2273 struct nfs_open_confirmargs *args)
2275 struct compound_hdr hdr = {
2279 encode_compound_hdr(xdr, req, &hdr);
2280 encode_putfh(xdr, args->fh, &hdr);
2281 encode_open_confirm(xdr, args, &hdr);
2286 * Encode an OPEN request with no attributes.
2288 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2289 struct xdr_stream *xdr,
2290 struct nfs_openargs *args)
2292 struct compound_hdr hdr = {
2293 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2296 encode_compound_hdr(xdr, req, &hdr);
2297 encode_sequence(xdr, &args->seq_args, &hdr);
2298 encode_putfh(xdr, args->fh, &hdr);
2299 encode_open(xdr, args, &hdr);
2301 encode_access(xdr, args->access, &hdr);
2302 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2307 * Encode an OPEN_DOWNGRADE request
2309 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2310 struct xdr_stream *xdr,
2311 struct nfs_closeargs *args)
2313 struct compound_hdr hdr = {
2314 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2317 encode_compound_hdr(xdr, req, &hdr);
2318 encode_sequence(xdr, &args->seq_args, &hdr);
2319 encode_putfh(xdr, args->fh, &hdr);
2320 encode_open_downgrade(xdr, args, &hdr);
2321 encode_getfattr(xdr, args->bitmask, &hdr);
2326 * Encode a LOCK request
2328 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2329 struct nfs_lock_args *args)
2331 struct compound_hdr hdr = {
2332 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2335 encode_compound_hdr(xdr, req, &hdr);
2336 encode_sequence(xdr, &args->seq_args, &hdr);
2337 encode_putfh(xdr, args->fh, &hdr);
2338 encode_lock(xdr, args, &hdr);
2343 * Encode a LOCKT request
2345 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2346 struct nfs_lockt_args *args)
2348 struct compound_hdr hdr = {
2349 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2352 encode_compound_hdr(xdr, req, &hdr);
2353 encode_sequence(xdr, &args->seq_args, &hdr);
2354 encode_putfh(xdr, args->fh, &hdr);
2355 encode_lockt(xdr, args, &hdr);
2360 * Encode a LOCKU request
2362 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2363 struct nfs_locku_args *args)
2365 struct compound_hdr hdr = {
2366 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2369 encode_compound_hdr(xdr, req, &hdr);
2370 encode_sequence(xdr, &args->seq_args, &hdr);
2371 encode_putfh(xdr, args->fh, &hdr);
2372 encode_locku(xdr, args, &hdr);
2376 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2377 struct xdr_stream *xdr,
2378 struct nfs_release_lockowner_args *args)
2380 struct compound_hdr hdr = {
2384 encode_compound_hdr(xdr, req, &hdr);
2385 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2390 * Encode a READLINK request
2392 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2393 const struct nfs4_readlink *args)
2395 struct compound_hdr hdr = {
2396 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2399 encode_compound_hdr(xdr, req, &hdr);
2400 encode_sequence(xdr, &args->seq_args, &hdr);
2401 encode_putfh(xdr, args->fh, &hdr);
2402 encode_readlink(xdr, args, req, &hdr);
2404 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2405 args->pgbase, args->pglen);
2410 * Encode a READDIR request
2412 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2413 const struct nfs4_readdir_arg *args)
2415 struct compound_hdr hdr = {
2416 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2419 encode_compound_hdr(xdr, req, &hdr);
2420 encode_sequence(xdr, &args->seq_args, &hdr);
2421 encode_putfh(xdr, args->fh, &hdr);
2422 encode_readdir(xdr, args, req, &hdr);
2424 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2425 args->pgbase, args->count);
2426 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2427 __func__, hdr.replen << 2, args->pages,
2428 args->pgbase, args->count);
2433 * Encode a READ request
2435 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2436 struct nfs_pgio_args *args)
2438 struct compound_hdr hdr = {
2439 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2442 encode_compound_hdr(xdr, req, &hdr);
2443 encode_sequence(xdr, &args->seq_args, &hdr);
2444 encode_putfh(xdr, args->fh, &hdr);
2445 encode_read(xdr, args, &hdr);
2447 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2448 args->pages, args->pgbase, args->count);
2449 req->rq_rcv_buf.flags |= XDRBUF_READ;
2454 * Encode an SETATTR request
2456 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2457 struct nfs_setattrargs *args)
2459 struct compound_hdr hdr = {
2460 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2463 encode_compound_hdr(xdr, req, &hdr);
2464 encode_sequence(xdr, &args->seq_args, &hdr);
2465 encode_putfh(xdr, args->fh, &hdr);
2466 encode_setattr(xdr, args, args->server, &hdr);
2467 encode_getfattr(xdr, args->bitmask, &hdr);
2472 * Encode a GETACL request
2474 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2475 struct nfs_getaclargs *args)
2477 struct compound_hdr hdr = {
2478 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2482 encode_compound_hdr(xdr, req, &hdr);
2483 encode_sequence(xdr, &args->seq_args, &hdr);
2484 encode_putfh(xdr, args->fh, &hdr);
2485 replen = hdr.replen + op_decode_hdr_maxsz + 1;
2486 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2488 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2489 args->acl_pages, args->acl_pgbase, args->acl_len);
2495 * Encode a WRITE request
2497 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2498 struct nfs_pgio_args *args)
2500 struct compound_hdr hdr = {
2501 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2504 encode_compound_hdr(xdr, req, &hdr);
2505 encode_sequence(xdr, &args->seq_args, &hdr);
2506 encode_putfh(xdr, args->fh, &hdr);
2507 encode_write(xdr, args, &hdr);
2508 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2510 encode_getfattr(xdr, args->bitmask, &hdr);
2517 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2518 struct nfs_commitargs *args)
2520 struct compound_hdr hdr = {
2521 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2524 encode_compound_hdr(xdr, req, &hdr);
2525 encode_sequence(xdr, &args->seq_args, &hdr);
2526 encode_putfh(xdr, args->fh, &hdr);
2527 encode_commit(xdr, args, &hdr);
2534 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2535 struct nfs4_fsinfo_arg *args)
2537 struct compound_hdr hdr = {
2538 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2541 encode_compound_hdr(xdr, req, &hdr);
2542 encode_sequence(xdr, &args->seq_args, &hdr);
2543 encode_putfh(xdr, args->fh, &hdr);
2544 encode_fsinfo(xdr, args->bitmask, &hdr);
2549 * a PATHCONF request
2551 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2552 const struct nfs4_pathconf_arg *args)
2554 struct compound_hdr hdr = {
2555 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2558 encode_compound_hdr(xdr, req, &hdr);
2559 encode_sequence(xdr, &args->seq_args, &hdr);
2560 encode_putfh(xdr, args->fh, &hdr);
2561 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2569 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2570 const struct nfs4_statfs_arg *args)
2572 struct compound_hdr hdr = {
2573 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2576 encode_compound_hdr(xdr, req, &hdr);
2577 encode_sequence(xdr, &args->seq_args, &hdr);
2578 encode_putfh(xdr, args->fh, &hdr);
2579 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2580 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2585 * GETATTR_BITMAP request
2587 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2588 struct xdr_stream *xdr,
2589 struct nfs4_server_caps_arg *args)
2591 struct compound_hdr hdr = {
2592 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2595 encode_compound_hdr(xdr, req, &hdr);
2596 encode_sequence(xdr, &args->seq_args, &hdr);
2597 encode_putfh(xdr, args->fhandle, &hdr);
2598 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2599 FATTR4_WORD0_FH_EXPIRE_TYPE|
2600 FATTR4_WORD0_LINK_SUPPORT|
2601 FATTR4_WORD0_SYMLINK_SUPPORT|
2602 FATTR4_WORD0_ACLSUPPORT, &hdr);
2609 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2610 struct nfs_client *clp)
2612 struct compound_hdr hdr = {
2616 encode_compound_hdr(xdr, req, &hdr);
2617 encode_renew(xdr, clp->cl_clientid, &hdr);
2622 * a SETCLIENTID request
2624 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2625 struct xdr_stream *xdr,
2626 struct nfs4_setclientid *sc)
2628 struct compound_hdr hdr = {
2632 encode_compound_hdr(xdr, req, &hdr);
2633 encode_setclientid(xdr, sc, &hdr);
2638 * a SETCLIENTID_CONFIRM request
2640 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2641 struct xdr_stream *xdr,
2642 struct nfs4_setclientid_res *arg)
2644 struct compound_hdr hdr = {
2648 encode_compound_hdr(xdr, req, &hdr);
2649 encode_setclientid_confirm(xdr, arg, &hdr);
2654 * DELEGRETURN request
2656 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2657 struct xdr_stream *xdr,
2658 const struct nfs4_delegreturnargs *args)
2660 struct compound_hdr hdr = {
2661 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2664 encode_compound_hdr(xdr, req, &hdr);
2665 encode_sequence(xdr, &args->seq_args, &hdr);
2666 encode_putfh(xdr, args->fhandle, &hdr);
2667 encode_getfattr(xdr, args->bitmask, &hdr);
2668 encode_delegreturn(xdr, args->stateid, &hdr);
2673 * Encode FS_LOCATIONS request
2675 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2676 struct xdr_stream *xdr,
2677 struct nfs4_fs_locations_arg *args)
2679 struct compound_hdr hdr = {
2680 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2684 encode_compound_hdr(xdr, req, &hdr);
2685 encode_sequence(xdr, &args->seq_args, &hdr);
2686 if (args->migration) {
2687 encode_putfh(xdr, args->fh, &hdr);
2688 replen = hdr.replen;
2689 encode_fs_locations(xdr, args->bitmask, &hdr);
2691 encode_renew(xdr, args->clientid, &hdr);
2693 encode_putfh(xdr, args->dir_fh, &hdr);
2694 encode_lookup(xdr, args->name, &hdr);
2695 replen = hdr.replen;
2696 encode_fs_locations(xdr, args->bitmask, &hdr);
2699 /* Set up reply kvec to capture returned fs_locations array. */
2700 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2706 * Encode SECINFO request
2708 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2709 struct xdr_stream *xdr,
2710 struct nfs4_secinfo_arg *args)
2712 struct compound_hdr hdr = {
2713 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2716 encode_compound_hdr(xdr, req, &hdr);
2717 encode_sequence(xdr, &args->seq_args, &hdr);
2718 encode_putfh(xdr, args->dir_fh, &hdr);
2719 encode_secinfo(xdr, args->name, &hdr);
2724 * Encode FSID_PRESENT request
2726 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2727 struct xdr_stream *xdr,
2728 struct nfs4_fsid_present_arg *args)
2730 struct compound_hdr hdr = {
2731 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2734 encode_compound_hdr(xdr, req, &hdr);
2735 encode_sequence(xdr, &args->seq_args, &hdr);
2736 encode_putfh(xdr, args->fh, &hdr);
2737 encode_getfh(xdr, &hdr);
2739 encode_renew(xdr, args->clientid, &hdr);
2743 #if defined(CONFIG_NFS_V4_1)
2745 * BIND_CONN_TO_SESSION request
2747 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2748 struct xdr_stream *xdr,
2749 struct nfs_client *clp)
2751 struct compound_hdr hdr = {
2752 .minorversion = clp->cl_mvops->minor_version,
2755 encode_compound_hdr(xdr, req, &hdr);
2756 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2761 * EXCHANGE_ID request
2763 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2764 struct xdr_stream *xdr,
2765 struct nfs41_exchange_id_args *args)
2767 struct compound_hdr hdr = {
2768 .minorversion = args->client->cl_mvops->minor_version,
2771 encode_compound_hdr(xdr, req, &hdr);
2772 encode_exchange_id(xdr, args, &hdr);
2777 * a CREATE_SESSION request
2779 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2780 struct xdr_stream *xdr,
2781 struct nfs41_create_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_create_session(xdr, args, &hdr);
2793 * a DESTROY_SESSION request
2795 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2796 struct xdr_stream *xdr,
2797 struct nfs4_session *session)
2799 struct compound_hdr hdr = {
2800 .minorversion = session->clp->cl_mvops->minor_version,
2803 encode_compound_hdr(xdr, req, &hdr);
2804 encode_destroy_session(xdr, session, &hdr);
2809 * a DESTROY_CLIENTID request
2811 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2812 struct xdr_stream *xdr,
2813 struct nfs_client *clp)
2815 struct compound_hdr hdr = {
2816 .minorversion = clp->cl_mvops->minor_version,
2819 encode_compound_hdr(xdr, req, &hdr);
2820 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2825 * a SEQUENCE request
2827 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2828 struct nfs4_sequence_args *args)
2830 struct compound_hdr hdr = {
2831 .minorversion = nfs4_xdr_minorversion(args),
2834 encode_compound_hdr(xdr, req, &hdr);
2835 encode_sequence(xdr, args, &hdr);
2840 * a GET_LEASE_TIME request
2842 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2843 struct xdr_stream *xdr,
2844 struct nfs4_get_lease_time_args *args)
2846 struct compound_hdr hdr = {
2847 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2849 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2851 encode_compound_hdr(xdr, req, &hdr);
2852 encode_sequence(xdr, &args->la_seq_args, &hdr);
2853 encode_putrootfh(xdr, &hdr);
2854 encode_fsinfo(xdr, lease_bitmap, &hdr);
2859 * a RECLAIM_COMPLETE request
2861 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2862 struct xdr_stream *xdr,
2863 struct nfs41_reclaim_complete_args *args)
2865 struct compound_hdr hdr = {
2866 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2869 encode_compound_hdr(xdr, req, &hdr);
2870 encode_sequence(xdr, &args->seq_args, &hdr);
2871 encode_reclaim_complete(xdr, args, &hdr);
2876 * Encode GETDEVICEINFO request
2878 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2879 struct xdr_stream *xdr,
2880 struct nfs4_getdeviceinfo_args *args)
2882 struct compound_hdr hdr = {
2883 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2886 encode_compound_hdr(xdr, req, &hdr);
2887 encode_sequence(xdr, &args->seq_args, &hdr);
2888 encode_getdeviceinfo(xdr, args, &hdr);
2890 /* set up reply kvec. Subtract notification bitmap max size (2)
2891 * so that notification bitmap is put in xdr_buf tail */
2892 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2893 args->pdev->pages, args->pdev->pgbase,
2900 * Encode LAYOUTGET request
2902 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2903 struct xdr_stream *xdr,
2904 struct nfs4_layoutget_args *args)
2906 struct compound_hdr hdr = {
2907 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2910 encode_compound_hdr(xdr, req, &hdr);
2911 encode_sequence(xdr, &args->seq_args, &hdr);
2912 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2913 encode_layoutget(xdr, args, &hdr);
2915 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2916 args->layout.pages, 0, args->layout.pglen);
2922 * Encode LAYOUTCOMMIT request
2924 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2925 struct xdr_stream *xdr,
2926 struct nfs4_layoutcommit_args *args)
2928 struct nfs4_layoutcommit_data *data =
2929 container_of(args, struct nfs4_layoutcommit_data, args);
2930 struct compound_hdr hdr = {
2931 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2934 encode_compound_hdr(xdr, req, &hdr);
2935 encode_sequence(xdr, &args->seq_args, &hdr);
2936 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2937 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2938 encode_getfattr(xdr, args->bitmask, &hdr);
2943 * Encode LAYOUTRETURN request
2945 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2946 struct xdr_stream *xdr,
2947 struct nfs4_layoutreturn_args *args)
2949 struct compound_hdr hdr = {
2950 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2953 encode_compound_hdr(xdr, req, &hdr);
2954 encode_sequence(xdr, &args->seq_args, &hdr);
2955 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2956 encode_layoutreturn(xdr, args, &hdr);
2961 * Encode SECINFO_NO_NAME request
2963 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2964 struct xdr_stream *xdr,
2965 struct nfs41_secinfo_no_name_args *args)
2967 struct compound_hdr hdr = {
2968 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2971 encode_compound_hdr(xdr, req, &hdr);
2972 encode_sequence(xdr, &args->seq_args, &hdr);
2973 encode_putrootfh(xdr, &hdr);
2974 encode_secinfo_no_name(xdr, args, &hdr);
2980 * Encode TEST_STATEID request
2982 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2983 struct xdr_stream *xdr,
2984 struct nfs41_test_stateid_args *args)
2986 struct compound_hdr hdr = {
2987 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2990 encode_compound_hdr(xdr, req, &hdr);
2991 encode_sequence(xdr, &args->seq_args, &hdr);
2992 encode_test_stateid(xdr, args, &hdr);
2997 * Encode FREE_STATEID request
2999 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3000 struct xdr_stream *xdr,
3001 struct nfs41_free_stateid_args *args)
3003 struct compound_hdr hdr = {
3004 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3007 encode_compound_hdr(xdr, req, &hdr);
3008 encode_sequence(xdr, &args->seq_args, &hdr);
3009 encode_free_stateid(xdr, args, &hdr);
3012 #endif /* CONFIG_NFS_V4_1 */
3014 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3016 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3017 "Remaining buffer length is %tu words.\n",
3018 func, xdr->end - xdr->p);
3021 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3025 p = xdr_inline_decode(xdr, 4);
3028 *len = be32_to_cpup(p);
3029 p = xdr_inline_decode(xdr, *len);
3032 *string = (char *)p;
3035 print_overflow_msg(__func__, xdr);
3039 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3043 p = xdr_inline_decode(xdr, 8);
3046 hdr->status = be32_to_cpup(p++);
3047 hdr->taglen = be32_to_cpup(p);
3049 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3052 hdr->tag = (char *)p;
3053 p += XDR_QUADLEN(hdr->taglen);
3054 hdr->nops = be32_to_cpup(p);
3055 if (unlikely(hdr->nops < 1))
3056 return nfs4_stat_to_errno(hdr->status);
3059 print_overflow_msg(__func__, xdr);
3063 static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3070 p = xdr_inline_decode(xdr, 8);
3073 opnum = be32_to_cpup(p++);
3074 if (unlikely(opnum != expected))
3075 goto out_bad_operation;
3076 nfserr = be32_to_cpup(p);
3077 if (nfserr == NFS_OK)
3080 *nfs_retval = nfs4_stat_to_errno(nfserr);
3083 dprintk("nfs: Server returned operation"
3084 " %d but we issued a request for %d\n",
3086 *nfs_retval = -EREMOTEIO;
3089 print_overflow_msg(__func__, xdr);
3094 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3098 __decode_op_hdr(xdr, expected, &retval);
3103 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
3106 unsigned int strlen;
3109 p = xdr_inline_decode(xdr, 12);
3111 return decode_opaque_inline(xdr, &strlen, &str);
3112 print_overflow_msg(__func__, xdr);
3116 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3121 p = xdr_inline_decode(xdr, 4);
3124 bmlen = be32_to_cpup(p);
3126 bitmap[0] = bitmap[1] = bitmap[2] = 0;
3127 p = xdr_inline_decode(xdr, (bmlen << 2));
3131 bitmap[0] = be32_to_cpup(p++);
3133 bitmap[1] = be32_to_cpup(p++);
3135 bitmap[2] = be32_to_cpup(p);
3140 print_overflow_msg(__func__, xdr);
3144 static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
3148 p = xdr_inline_decode(xdr, 4);
3151 *attrlen = be32_to_cpup(p);
3152 *savep = xdr_stream_pos(xdr);
3155 print_overflow_msg(__func__, xdr);
3159 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3161 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3163 ret = decode_attr_bitmap(xdr, bitmask);
3164 if (unlikely(ret < 0))
3166 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3168 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3169 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3170 bitmask[0], bitmask[1], bitmask[2]);
3174 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3180 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3182 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3183 p = xdr_inline_decode(xdr, 4);
3186 *type = be32_to_cpup(p);
3187 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3188 dprintk("%s: bad type %d\n", __func__, *type);
3191 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3192 ret = NFS_ATTR_FATTR_TYPE;
3194 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3197 print_overflow_msg(__func__, xdr);
3201 static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3202 uint32_t *bitmap, uint32_t *type)
3207 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3209 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3210 p = xdr_inline_decode(xdr, 4);
3213 *type = be32_to_cpup(p);
3214 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3216 dprintk("%s: expire type=0x%x\n", __func__, *type);
3219 print_overflow_msg(__func__, xdr);
3223 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3229 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3231 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3232 p = xdr_inline_decode(xdr, 8);
3235 xdr_decode_hyper(p, change);
3236 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3237 ret = NFS_ATTR_FATTR_CHANGE;
3239 dprintk("%s: change attribute=%Lu\n", __func__,
3240 (unsigned long long)*change);
3243 print_overflow_msg(__func__, xdr);
3247 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3253 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3255 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3256 p = xdr_inline_decode(xdr, 8);
3259 xdr_decode_hyper(p, size);
3260 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3261 ret = NFS_ATTR_FATTR_SIZE;
3263 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3266 print_overflow_msg(__func__, xdr);
3270 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3275 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3277 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3278 p = xdr_inline_decode(xdr, 4);
3281 *res = be32_to_cpup(p);
3282 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3284 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3287 print_overflow_msg(__func__, xdr);
3291 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3296 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3298 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3299 p = xdr_inline_decode(xdr, 4);
3302 *res = be32_to_cpup(p);
3303 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3305 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3308 print_overflow_msg(__func__, xdr);
3312 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3319 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3321 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3322 p = xdr_inline_decode(xdr, 16);
3325 p = xdr_decode_hyper(p, &fsid->major);
3326 xdr_decode_hyper(p, &fsid->minor);
3327 bitmap[0] &= ~FATTR4_WORD0_FSID;
3328 ret = NFS_ATTR_FATTR_FSID;
3330 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3331 (unsigned long long)fsid->major,
3332 (unsigned long long)fsid->minor);
3335 print_overflow_msg(__func__, xdr);
3339 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3344 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3346 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3347 p = xdr_inline_decode(xdr, 4);
3350 *res = be32_to_cpup(p);
3351 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3353 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3356 print_overflow_msg(__func__, xdr);
3360 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3364 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3366 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3367 p = xdr_inline_decode(xdr, 4);
3370 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3371 *res = -be32_to_cpup(p);
3375 print_overflow_msg(__func__, xdr);
3379 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3385 memset(fh, 0, sizeof(*fh));
3387 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3389 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3390 p = xdr_inline_decode(xdr, 4);
3393 len = be32_to_cpup(p);
3394 if (len > NFS4_FHSIZE)
3396 p = xdr_inline_decode(xdr, len);
3400 memcpy(fh->data, p, len);
3403 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3407 print_overflow_msg(__func__, xdr);
3411 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3416 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3418 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3419 p = xdr_inline_decode(xdr, 4);
3422 *res = be32_to_cpup(p);
3423 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3425 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3428 print_overflow_msg(__func__, xdr);
3432 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3438 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3440 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3441 p = xdr_inline_decode(xdr, 8);
3444 xdr_decode_hyper(p, fileid);
3445 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3446 ret = NFS_ATTR_FATTR_FILEID;
3448 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3451 print_overflow_msg(__func__, xdr);
3455 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3461 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3463 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3464 p = xdr_inline_decode(xdr, 8);
3467 xdr_decode_hyper(p, fileid);
3468 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3469 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3471 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3474 print_overflow_msg(__func__, xdr);
3478 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3484 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3486 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3487 p = xdr_inline_decode(xdr, 8);
3490 xdr_decode_hyper(p, res);
3491 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3493 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3496 print_overflow_msg(__func__, xdr);
3500 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3506 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3508 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3509 p = xdr_inline_decode(xdr, 8);
3512 xdr_decode_hyper(p, res);
3513 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3515 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3518 print_overflow_msg(__func__, xdr);
3522 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3528 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3530 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3531 p = xdr_inline_decode(xdr, 8);
3534 xdr_decode_hyper(p, res);
3535 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3537 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3540 print_overflow_msg(__func__, xdr);
3544 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3550 p = xdr_inline_decode(xdr, 4);
3553 n = be32_to_cpup(p);
3556 dprintk("pathname4: ");
3557 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3558 dprintk("cannot parse %d components in path\n", n);
3561 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
3562 struct nfs4_string *component = &path->components[path->ncomponents];
3563 status = decode_opaque_inline(xdr, &component->len, &component->data);
3564 if (unlikely(status != 0))
3568 (path->ncomponents != n ? "/ " : ""),
3569 component->len, component->data);
3574 /* a root pathname is sent as a zero component4 */
3575 path->ncomponents = 1;
3576 path->components[0].len=0;
3577 path->components[0].data=NULL;
3578 dprintk("pathname4: /\n");
3581 dprintk(" status %d", status);
3585 print_overflow_msg(__func__, xdr);
3589 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3595 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3598 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3601 /* Ignore borken servers that return unrequested attrs */
3602 if (unlikely(res == NULL))
3604 dprintk("%s: fsroot:\n", __func__);
3605 status = decode_pathname(xdr, &res->fs_path);
3606 if (unlikely(status != 0))
3608 p = xdr_inline_decode(xdr, 4);
3611 n = be32_to_cpup(p);
3614 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3616 struct nfs4_fs_location *loc;
3618 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3620 loc = &res->locations[res->nlocations];
3621 p = xdr_inline_decode(xdr, 4);
3624 m = be32_to_cpup(p);
3626 dprintk("%s: servers:\n", __func__);
3627 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3628 struct nfs4_string *server;
3630 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3632 dprintk("%s: using first %u of %u servers "
3633 "returned for location %u\n",
3635 NFS4_FS_LOCATION_MAXSERVERS,
3636 m, res->nlocations);
3637 for (i = loc->nservers; i < m; i++) {
3640 status = decode_opaque_inline(xdr, &len, &data);
3641 if (unlikely(status != 0))
3646 server = &loc->servers[loc->nservers];
3647 status = decode_opaque_inline(xdr, &server->len, &server->data);
3648 if (unlikely(status != 0))
3650 dprintk("%s ", server->data);
3652 status = decode_pathname(xdr, &loc->rootpath);
3653 if (unlikely(status != 0))
3656 if (res->nlocations != 0)
3657 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3659 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3662 print_overflow_msg(__func__, xdr);
3668 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3674 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3676 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3677 p = xdr_inline_decode(xdr, 8);
3680 xdr_decode_hyper(p, res);
3681 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3683 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3686 print_overflow_msg(__func__, xdr);
3690 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3696 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3698 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3699 p = xdr_inline_decode(xdr, 4);
3702 *maxlink = be32_to_cpup(p);
3703 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3705 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3708 print_overflow_msg(__func__, xdr);
3712 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3718 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3720 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3721 p = xdr_inline_decode(xdr, 4);
3724 *maxname = be32_to_cpup(p);
3725 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3727 dprintk("%s: maxname=%u\n", __func__, *maxname);
3730 print_overflow_msg(__func__, xdr);
3734 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3740 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3742 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3744 p = xdr_inline_decode(xdr, 8);
3747 xdr_decode_hyper(p, &maxread);
3748 if (maxread > 0x7FFFFFFF)
3749 maxread = 0x7FFFFFFF;
3750 *res = (uint32_t)maxread;
3751 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3753 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3756 print_overflow_msg(__func__, xdr);
3760 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3766 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3768 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3770 p = xdr_inline_decode(xdr, 8);
3773 xdr_decode_hyper(p, &maxwrite);
3774 if (maxwrite > 0x7FFFFFFF)
3775 maxwrite = 0x7FFFFFFF;
3776 *res = (uint32_t)maxwrite;
3777 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3779 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3782 print_overflow_msg(__func__, xdr);
3786 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3793 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3795 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3796 p = xdr_inline_decode(xdr, 4);
3799 tmp = be32_to_cpup(p);
3800 *mode = tmp & ~S_IFMT;
3801 bitmap[1] &= ~FATTR4_WORD1_MODE;
3802 ret = NFS_ATTR_FATTR_MODE;
3804 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3807 print_overflow_msg(__func__, xdr);
3811 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3817 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3819 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3820 p = xdr_inline_decode(xdr, 4);
3823 *nlink = be32_to_cpup(p);
3824 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3825 ret = NFS_ATTR_FATTR_NLINK;
3827 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3830 print_overflow_msg(__func__, xdr);
3834 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3835 const struct nfs_server *server, kuid_t *uid,
3836 struct nfs4_string *owner_name)
3842 *uid = make_kuid(&init_user_ns, -2);
3843 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3845 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3846 p = xdr_inline_decode(xdr, 4);
3849 len = be32_to_cpup(p);
3850 p = xdr_inline_decode(xdr, len);
3853 if (owner_name != NULL) {
3854 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3855 if (owner_name->data != NULL) {
3856 owner_name->len = len;
3857 ret = NFS_ATTR_FATTR_OWNER_NAME;
3859 } else if (len < XDR_MAX_NETOBJ) {
3860 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3861 ret = NFS_ATTR_FATTR_OWNER;
3863 dprintk("%s: nfs_map_name_to_uid failed!\n",
3866 dprintk("%s: name too long (%u)!\n",
3868 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3870 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3873 print_overflow_msg(__func__, xdr);
3877 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3878 const struct nfs_server *server, kgid_t *gid,
3879 struct nfs4_string *group_name)
3885 *gid = make_kgid(&init_user_ns, -2);
3886 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3888 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3889 p = xdr_inline_decode(xdr, 4);
3892 len = be32_to_cpup(p);
3893 p = xdr_inline_decode(xdr, len);
3896 if (group_name != NULL) {
3897 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3898 if (group_name->data != NULL) {
3899 group_name->len = len;
3900 ret = NFS_ATTR_FATTR_GROUP_NAME;
3902 } else if (len < XDR_MAX_NETOBJ) {
3903 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3904 ret = NFS_ATTR_FATTR_GROUP;
3906 dprintk("%s: nfs_map_group_to_gid failed!\n",
3909 dprintk("%s: name too long (%u)!\n",
3911 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3913 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3916 print_overflow_msg(__func__, xdr);
3920 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3922 uint32_t major = 0, minor = 0;
3927 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3929 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3932 p = xdr_inline_decode(xdr, 8);
3935 major = be32_to_cpup(p++);
3936 minor = be32_to_cpup(p);
3937 tmp = MKDEV(major, minor);
3938 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3940 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3941 ret = NFS_ATTR_FATTR_RDEV;
3943 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3946 print_overflow_msg(__func__, xdr);
3950 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3956 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3958 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3959 p = xdr_inline_decode(xdr, 8);
3962 xdr_decode_hyper(p, res);
3963 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3965 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3968 print_overflow_msg(__func__, xdr);
3972 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3978 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3980 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3981 p = xdr_inline_decode(xdr, 8);
3984 xdr_decode_hyper(p, res);
3985 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3987 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3990 print_overflow_msg(__func__, xdr);
3994 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4000 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4002 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4003 p = xdr_inline_decode(xdr, 8);
4006 xdr_decode_hyper(p, res);
4007 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4009 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
4012 print_overflow_msg(__func__, xdr);
4016 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4022 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4024 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4025 p = xdr_inline_decode(xdr, 8);
4028 xdr_decode_hyper(p, used);
4029 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4030 ret = NFS_ATTR_FATTR_SPACE_USED;
4032 dprintk("%s: space used=%Lu\n", __func__,
4033 (unsigned long long)*used);
4036 print_overflow_msg(__func__, xdr);
4040 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4046 p = xdr_inline_decode(xdr, 12);
4049 p = xdr_decode_hyper(p, &sec);
4050 nsec = be32_to_cpup(p);
4051 time->tv_sec = (time_t)sec;
4052 time->tv_nsec = (long)nsec;
4055 print_overflow_msg(__func__, xdr);
4059 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4065 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4067 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4068 status = decode_attr_time(xdr, time);
4070 status = NFS_ATTR_FATTR_ATIME;
4071 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4073 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
4077 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4083 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4085 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4086 status = decode_attr_time(xdr, time);
4088 status = NFS_ATTR_FATTR_CTIME;
4089 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4091 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
4095 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4096 struct timespec *time)
4102 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4104 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4105 status = decode_attr_time(xdr, time);
4106 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4108 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4109 (long)time->tv_nsec);
4113 static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4114 struct nfs4_label *label)
4122 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4124 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4125 p = xdr_inline_decode(xdr, 4);
4128 lfs = be32_to_cpup(p++);
4129 p = xdr_inline_decode(xdr, 4);
4132 pi = be32_to_cpup(p++);
4133 p = xdr_inline_decode(xdr, 4);
4136 len = be32_to_cpup(p++);
4137 p = xdr_inline_decode(xdr, len);
4140 if (len < NFS4_MAXLABELLEN) {
4142 memcpy(label->label, p, len);
4146 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4148 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4150 printk(KERN_WARNING "%s: label too long (%u)!\n",
4153 if (label && label->label)
4154 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4155 (char *)label->label, label->len, label->pi, label->lfs);
4159 print_overflow_msg(__func__, xdr);
4163 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4169 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4171 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4172 status = decode_attr_time(xdr, time);
4174 status = NFS_ATTR_FATTR_MTIME;
4175 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4177 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
4181 static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
4183 unsigned int attrwords = XDR_QUADLEN(attrlen);
4184 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
4186 if (unlikely(attrwords != nwords)) {
4187 dprintk("%s: server returned incorrect attribute length: "
4191 (attrwords < nwords) ? '<' : '>',
4198 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4202 p = xdr_inline_decode(xdr, 20);
4205 cinfo->atomic = be32_to_cpup(p++);
4206 p = xdr_decode_hyper(p, &cinfo->before);
4207 xdr_decode_hyper(p, &cinfo->after);
4210 print_overflow_msg(__func__, xdr);
4214 static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
4220 status = decode_op_hdr(xdr, OP_ACCESS);
4223 p = xdr_inline_decode(xdr, 8);
4226 supp = be32_to_cpup(p++);
4227 acc = be32_to_cpup(p);
4232 print_overflow_msg(__func__, xdr);
4236 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4240 p = xdr_inline_decode(xdr, len);
4242 memcpy(buf, p, len);
4245 print_overflow_msg(__func__, xdr);
4249 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4251 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4254 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4258 status = decode_op_hdr(xdr, OP_CLOSE);
4260 nfs_increment_open_seqid(status, res->seqid);
4262 status = decode_stateid(xdr, &res->stateid);
4266 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4268 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4271 static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4273 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4276 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4280 status = decode_op_hdr(xdr, OP_COMMIT);
4282 status = decode_write_verifier(xdr, &res->verf->verifier);
4286 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4292 status = decode_op_hdr(xdr, OP_CREATE);
4295 if ((status = decode_change_info(xdr, cinfo)))
4297 p = xdr_inline_decode(xdr, 4);
4300 bmlen = be32_to_cpup(p);
4301 p = xdr_inline_decode(xdr, bmlen << 2);
4305 print_overflow_msg(__func__, xdr);
4309 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4312 uint32_t attrlen, bitmap[3] = {0};
4315 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4317 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4319 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4321 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4323 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4324 &res->fh_expire_type)) != 0)
4326 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4328 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4330 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4332 status = verify_attr_len(xdr, savep, attrlen);
4334 dprintk("%s: xdr returned %d!\n", __func__, -status);
4338 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4341 uint32_t attrlen, bitmap[3] = {0};
4344 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4346 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4348 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4351 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4353 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4355 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4357 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4359 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4361 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4364 status = verify_attr_len(xdr, savep, attrlen);
4366 dprintk("%s: xdr returned %d!\n", __func__, -status);
4370 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4373 uint32_t attrlen, bitmap[3] = {0};
4376 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4378 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4380 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4383 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4385 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4388 status = verify_attr_len(xdr, savep, attrlen);
4390 dprintk("%s: xdr returned %d!\n", __func__, -status);
4394 static int decode_threshold_hint(struct xdr_stream *xdr,
4402 if (likely(bitmap[0] & hint_bit)) {
4403 p = xdr_inline_decode(xdr, 8);
4406 xdr_decode_hyper(p, res);
4410 print_overflow_msg(__func__, xdr);
4414 static int decode_first_threshold_item4(struct xdr_stream *xdr,
4415 struct nfs4_threshold *res)
4419 uint32_t bitmap[3] = {0,}, attrlen;
4423 p = xdr_inline_decode(xdr, 4);
4425 print_overflow_msg(__func__, xdr);
4428 res->l_type = be32_to_cpup(p);
4430 /* thi_hintset bitmap */
4431 status = decode_attr_bitmap(xdr, bitmap);
4435 /* thi_hintlist length */
4436 status = decode_attr_length(xdr, &attrlen, &savep);
4440 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4443 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4446 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4450 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4455 status = verify_attr_len(xdr, savep, attrlen);
4456 res->bm = bitmap[0];
4458 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4459 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4462 dprintk("%s ret=%d!\n", __func__, status);
4467 * Thresholds on pNFS direct I/O vrs MDS I/O
4469 static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4471 struct nfs4_threshold *res)
4477 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4479 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
4480 /* Did the server return an unrequested attribute? */
4481 if (unlikely(res == NULL))
4483 p = xdr_inline_decode(xdr, 4);
4486 num = be32_to_cpup(p);
4490 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4491 "drivers per filesystem not supported\n",
4494 status = decode_first_threshold_item4(xdr, res);
4495 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
4499 print_overflow_msg(__func__, xdr);
4503 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4504 struct nfs_fattr *fattr, struct nfs_fh *fh,
4505 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
4506 const struct nfs_server *server)
4513 status = decode_attr_type(xdr, bitmap, &type);
4518 fattr->mode |= nfs_type2fmt[type];
4519 fattr->valid |= status;
4522 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4525 fattr->valid |= status;
4527 status = decode_attr_size(xdr, bitmap, &fattr->size);
4530 fattr->valid |= status;
4532 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4535 fattr->valid |= status;
4538 status = decode_attr_error(xdr, bitmap, &err);
4542 status = decode_attr_filehandle(xdr, bitmap, fh);
4546 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4549 fattr->valid |= status;
4551 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4554 fattr->valid |= status;
4556 status = decode_attr_mode(xdr, bitmap, &fmode);
4560 fattr->mode |= fmode;
4561 fattr->valid |= status;
4564 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4567 fattr->valid |= status;
4569 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4572 fattr->valid |= status;
4574 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4577 fattr->valid |= status;
4579 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4582 fattr->valid |= status;
4584 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4587 fattr->valid |= status;
4589 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4592 fattr->valid |= status;
4594 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4597 fattr->valid |= status;
4599 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4602 fattr->valid |= status;
4604 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4607 fattr->valid |= status;
4609 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4614 status = decode_attr_security_label(xdr, bitmap, label);
4617 fattr->valid |= status;
4621 dprintk("%s: xdr returned %d\n", __func__, -status);
4625 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4626 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4627 struct nfs4_label *label, const struct nfs_server *server)
4634 status = decode_op_hdr(xdr, OP_GETATTR);
4638 status = decode_attr_bitmap(xdr, bitmap);
4642 status = decode_attr_length(xdr, &attrlen, &savep);
4646 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4651 status = verify_attr_len(xdr, savep, attrlen);
4653 dprintk("%s: xdr returned %d\n", __func__, -status);
4657 static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4658 struct nfs4_label *label, const struct nfs_server *server)
4660 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4663 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4664 const struct nfs_server *server)
4666 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4670 * Decode potentially multiple layout types. Currently we only support
4671 * one layout driver per file system.
4673 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4674 uint32_t *layouttype)
4679 p = xdr_inline_decode(xdr, 4);
4682 num = be32_to_cpup(p);
4684 /* pNFS is not supported by the underlying file system */
4690 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4691 "drivers per filesystem not supported\n", __func__);
4693 /* Decode and set first layout type, move xdr->p past unused types */
4694 p = xdr_inline_decode(xdr, num * 4);
4697 *layouttype = be32_to_cpup(p);
4700 print_overflow_msg(__func__, xdr);
4705 * The type of file system exported.
4706 * Note we must ensure that layouttype is set in any non-error case.
4708 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4709 uint32_t *layouttype)
4713 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4714 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4716 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4717 status = decode_first_pnfs_layout_type(xdr, layouttype);
4718 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4725 * The prefered block size for layout directed io
4727 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4732 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4734 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4735 p = xdr_inline_decode(xdr, 4);
4737 print_overflow_msg(__func__, xdr);
4740 *res = be32_to_cpup(p);
4741 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4746 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4749 uint32_t attrlen, bitmap[3];
4752 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4754 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4756 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4759 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4761 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4763 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4765 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4767 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4768 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4770 fsinfo->wtpref = fsinfo->wtmax;
4771 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4774 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4777 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4781 status = verify_attr_len(xdr, savep, attrlen);
4783 dprintk("%s: xdr returned %d!\n", __func__, -status);
4787 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4793 /* Zero handle first to allow comparisons */
4794 memset(fh, 0, sizeof(*fh));
4796 status = decode_op_hdr(xdr, OP_GETFH);
4800 p = xdr_inline_decode(xdr, 4);
4803 len = be32_to_cpup(p);
4804 if (len > NFS4_FHSIZE)
4807 p = xdr_inline_decode(xdr, len);
4810 memcpy(fh->data, p, len);
4813 print_overflow_msg(__func__, xdr);
4817 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4821 status = decode_op_hdr(xdr, OP_LINK);
4824 return decode_change_info(xdr, cinfo);
4828 * We create the owner, so we know a proper owner.id length is 4.
4830 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4832 uint64_t offset, length, clientid;
4834 uint32_t namelen, type;
4836 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4839 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4840 p = xdr_decode_hyper(p, &length);
4841 type = be32_to_cpup(p++); /* 4 byte read */
4842 if (fl != NULL) { /* manipulate file lock */
4843 fl->fl_start = (loff_t)offset;
4844 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4845 if (length == ~(uint64_t)0)
4846 fl->fl_end = OFFSET_MAX;
4847 fl->fl_type = F_WRLCK;
4849 fl->fl_type = F_RDLCK;
4852 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4853 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4854 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4856 return -NFS4ERR_DENIED;
4858 print_overflow_msg(__func__, xdr);
4862 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4866 status = decode_op_hdr(xdr, OP_LOCK);
4870 status = decode_stateid(xdr, &res->stateid);
4871 if (unlikely(status))
4873 } else if (status == -NFS4ERR_DENIED)
4874 status = decode_lock_denied(xdr, NULL);
4875 if (res->open_seqid != NULL)
4876 nfs_increment_open_seqid(status, res->open_seqid);
4877 nfs_increment_lock_seqid(status, res->lock_seqid);
4882 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4885 status = decode_op_hdr(xdr, OP_LOCKT);
4886 if (status == -NFS4ERR_DENIED)
4887 return decode_lock_denied(xdr, res->denied);
4891 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4895 status = decode_op_hdr(xdr, OP_LOCKU);
4897 nfs_increment_lock_seqid(status, res->seqid);
4899 status = decode_stateid(xdr, &res->stateid);
4903 static int decode_release_lockowner(struct xdr_stream *xdr)
4905 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4908 static int decode_lookup(struct xdr_stream *xdr)
4910 return decode_op_hdr(xdr, OP_LOOKUP);
4913 /* This is too sick! */
4914 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4917 uint32_t limit_type, nblocks, blocksize;
4919 p = xdr_inline_decode(xdr, 12);
4922 limit_type = be32_to_cpup(p++);
4923 switch (limit_type) {
4925 xdr_decode_hyper(p, maxsize);
4928 nblocks = be32_to_cpup(p++);
4929 blocksize = be32_to_cpup(p);
4930 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4934 print_overflow_msg(__func__, xdr);
4938 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4941 uint32_t delegation_type;
4944 p = xdr_inline_decode(xdr, 4);
4947 delegation_type = be32_to_cpup(p);
4948 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4949 res->delegation_type = 0;
4952 status = decode_stateid(xdr, &res->delegation);
4953 if (unlikely(status))
4955 p = xdr_inline_decode(xdr, 4);
4958 res->do_recall = be32_to_cpup(p);
4960 switch (delegation_type) {
4961 case NFS4_OPEN_DELEGATE_READ:
4962 res->delegation_type = FMODE_READ;
4964 case NFS4_OPEN_DELEGATE_WRITE:
4965 res->delegation_type = FMODE_WRITE|FMODE_READ;
4966 if (decode_space_limit(xdr, &res->maxsize) < 0)
4969 return decode_ace(xdr, NULL, res->server->nfs_client);
4971 print_overflow_msg(__func__, xdr);
4975 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4978 uint32_t savewords, bmlen, i;
4981 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
4983 nfs_increment_open_seqid(status, res->seqid);
4986 status = decode_stateid(xdr, &res->stateid);
4987 if (unlikely(status))
4990 decode_change_info(xdr, &res->cinfo);
4992 p = xdr_inline_decode(xdr, 8);
4995 res->rflags = be32_to_cpup(p++);
4996 bmlen = be32_to_cpup(p);
5000 p = xdr_inline_decode(xdr, bmlen << 2);
5003 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5004 for (i = 0; i < savewords; ++i)
5005 res->attrset[i] = be32_to_cpup(p++);
5006 for (; i < NFS4_BITMAP_SIZE; i++)
5007 res->attrset[i] = 0;
5009 return decode_delegation(xdr, res);
5011 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
5014 print_overflow_msg(__func__, xdr);
5018 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5022 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5024 nfs_increment_open_seqid(status, res->seqid);
5026 status = decode_stateid(xdr, &res->stateid);
5030 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5034 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5036 nfs_increment_open_seqid(status, res->seqid);
5038 status = decode_stateid(xdr, &res->stateid);
5042 static int decode_putfh(struct xdr_stream *xdr)
5044 return decode_op_hdr(xdr, OP_PUTFH);
5047 static int decode_putrootfh(struct xdr_stream *xdr)
5049 return decode_op_hdr(xdr, OP_PUTROOTFH);
5052 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5053 struct nfs_pgio_res *res)
5056 uint32_t count, eof, recvd;
5059 status = decode_op_hdr(xdr, OP_READ);
5062 p = xdr_inline_decode(xdr, 8);
5065 eof = be32_to_cpup(p++);
5066 count = be32_to_cpup(p);
5067 recvd = xdr_read_pages(xdr, count);
5068 if (count > recvd) {
5069 dprintk("NFS: server cheating in read reply: "
5070 "count %u > recvd %u\n", count, recvd);
5078 print_overflow_msg(__func__, xdr);
5082 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5087 status = decode_op_hdr(xdr, OP_READDIR);
5089 status = decode_verifier(xdr, readdir->verifier.data);
5090 if (unlikely(status))
5092 memcpy(verf, readdir->verifier.data, sizeof(verf));
5093 dprintk("%s: verifier = %08x:%08x\n",
5094 __func__, verf[0], verf[1]);
5095 return xdr_read_pages(xdr, xdr->buf->page_len);
5098 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5100 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5105 status = decode_op_hdr(xdr, OP_READLINK);
5109 /* Convert length of symlink */
5110 p = xdr_inline_decode(xdr, 4);
5113 len = be32_to_cpup(p);
5114 if (len >= rcvbuf->page_len || len <= 0) {
5115 dprintk("nfs: server returned giant symlink!\n");
5116 return -ENAMETOOLONG;
5118 recvd = xdr_read_pages(xdr, len);
5120 dprintk("NFS: server cheating in readlink reply: "
5121 "count %u > recvd %u\n", len, recvd);
5125 * The XDR encode routine has set things up so that
5126 * the link text will be copied directly into the
5127 * buffer. We just have to do overflow-checking,
5128 * and and null-terminate the text (the VFS expects
5129 * null-termination).
5131 xdr_terminate_string(rcvbuf, len);
5134 print_overflow_msg(__func__, xdr);
5138 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5142 status = decode_op_hdr(xdr, OP_REMOVE);
5145 status = decode_change_info(xdr, cinfo);
5150 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5151 struct nfs4_change_info *new_cinfo)
5155 status = decode_op_hdr(xdr, OP_RENAME);
5158 if ((status = decode_change_info(xdr, old_cinfo)))
5160 status = decode_change_info(xdr, new_cinfo);
5165 static int decode_renew(struct xdr_stream *xdr)
5167 return decode_op_hdr(xdr, OP_RENEW);
5171 decode_restorefh(struct xdr_stream *xdr)
5173 return decode_op_hdr(xdr, OP_RESTOREFH);
5176 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5177 struct nfs_getaclres *res)
5183 unsigned int pg_offset;
5186 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5189 xdr_enter_page(xdr, xdr->buf->page_len);
5191 /* Calculate the offset of the page data */
5192 pg_offset = xdr->buf->head[0].iov_len;
5194 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5196 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5199 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5201 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5203 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5204 * are stored with the acl data to handle the problem of
5205 * variable length bitmaps.*/
5206 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5207 res->acl_len = attrlen;
5209 /* Check for receive buffer overflow */
5210 if (res->acl_len > (xdr->nwords << 2) ||
5211 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5212 res->acl_flags |= NFS4_ACL_TRUNC;
5213 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5214 attrlen, xdr->nwords << 2);
5217 status = -EOPNOTSUPP;
5224 decode_savefh(struct xdr_stream *xdr)
5226 return decode_op_hdr(xdr, OP_SAVEFH);
5229 static int decode_setattr(struct xdr_stream *xdr)
5235 status = decode_op_hdr(xdr, OP_SETATTR);
5238 p = xdr_inline_decode(xdr, 4);
5241 bmlen = be32_to_cpup(p);
5242 p = xdr_inline_decode(xdr, bmlen << 2);
5246 print_overflow_msg(__func__, xdr);
5250 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5256 p = xdr_inline_decode(xdr, 8);
5259 opnum = be32_to_cpup(p++);
5260 if (opnum != OP_SETCLIENTID) {
5261 dprintk("nfs: decode_setclientid: Server returned operation"
5265 nfserr = be32_to_cpup(p);
5266 if (nfserr == NFS_OK) {
5267 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5270 p = xdr_decode_hyper(p, &res->clientid);
5271 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5272 } else if (nfserr == NFSERR_CLID_INUSE) {
5275 /* skip netid string */
5276 p = xdr_inline_decode(xdr, 4);
5279 len = be32_to_cpup(p);
5280 p = xdr_inline_decode(xdr, len);
5284 /* skip uaddr string */
5285 p = xdr_inline_decode(xdr, 4);
5288 len = be32_to_cpup(p);
5289 p = xdr_inline_decode(xdr, len);
5292 return -NFSERR_CLID_INUSE;
5294 return nfs4_stat_to_errno(nfserr);
5298 print_overflow_msg(__func__, xdr);
5302 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5304 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5307 static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
5312 status = decode_op_hdr(xdr, OP_WRITE);
5316 p = xdr_inline_decode(xdr, 8);
5319 res->count = be32_to_cpup(p++);
5320 res->verf->committed = be32_to_cpup(p++);
5321 return decode_write_verifier(xdr, &res->verf->verifier);
5323 print_overflow_msg(__func__, xdr);
5327 static int decode_delegreturn(struct xdr_stream *xdr)
5329 return decode_op_hdr(xdr, OP_DELEGRETURN);
5332 static int decode_secinfo_gss(struct xdr_stream *xdr,
5333 struct nfs4_secinfo4 *flavor)
5338 p = xdr_inline_decode(xdr, 4);
5341 oid_len = be32_to_cpup(p);
5342 if (oid_len > GSS_OID_MAX_LEN)
5345 p = xdr_inline_decode(xdr, oid_len);
5348 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5349 flavor->flavor_info.oid.len = oid_len;
5351 p = xdr_inline_decode(xdr, 8);
5354 flavor->flavor_info.qop = be32_to_cpup(p++);
5355 flavor->flavor_info.service = be32_to_cpup(p);
5360 print_overflow_msg(__func__, xdr);
5366 static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5368 struct nfs4_secinfo4 *sec_flavor;
5369 unsigned int i, num_flavors;
5373 p = xdr_inline_decode(xdr, 4);
5377 res->flavors->num_flavors = 0;
5378 num_flavors = be32_to_cpup(p);
5380 for (i = 0; i < num_flavors; i++) {
5381 sec_flavor = &res->flavors->flavors[i];
5382 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5385 p = xdr_inline_decode(xdr, 4);
5388 sec_flavor->flavor = be32_to_cpup(p);
5390 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5391 status = decode_secinfo_gss(xdr, sec_flavor);
5395 res->flavors->num_flavors++;
5402 print_overflow_msg(__func__, xdr);
5406 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5408 int status = decode_op_hdr(xdr, OP_SECINFO);
5411 return decode_secinfo_common(xdr, res);
5414 #if defined(CONFIG_NFS_V4_1)
5415 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5417 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5420 return decode_secinfo_common(xdr, res);
5423 static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5426 uint32_t bitmap_words;
5429 p = xdr_inline_decode(xdr, 4);
5430 bitmap_words = be32_to_cpup(p++);
5431 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5433 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5434 for (i = 0; i < bitmap_words; i++)
5435 op_map->u.words[i] = be32_to_cpup(p++);
5440 static int decode_exchange_id(struct xdr_stream *xdr,
5441 struct nfs41_exchange_id_res *res)
5447 uint32_t impl_id_count;
5449 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5453 p = xdr_inline_decode(xdr, 8);
5456 xdr_decode_hyper(p, &res->clientid);
5457 p = xdr_inline_decode(xdr, 12);
5460 res->seqid = be32_to_cpup(p++);
5461 res->flags = be32_to_cpup(p++);
5463 res->state_protect.how = be32_to_cpup(p);
5464 switch (res->state_protect.how) {
5468 status = decode_op_map(xdr, &res->state_protect.enforce);
5471 status = decode_op_map(xdr, &res->state_protect.allow);
5480 /* server_owner4.so_minor_id */
5481 p = xdr_inline_decode(xdr, 8);
5484 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5486 /* server_owner4.so_major_id */
5487 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5488 if (unlikely(status))
5490 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5492 memcpy(res->server_owner->major_id, dummy_str, dummy);
5493 res->server_owner->major_id_sz = dummy;
5496 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5497 if (unlikely(status))
5499 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5501 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5502 res->server_scope->server_scope_sz = dummy;
5504 /* Implementation Id */
5505 p = xdr_inline_decode(xdr, 4);
5508 impl_id_count = be32_to_cpup(p++);
5510 if (impl_id_count) {
5512 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5513 if (unlikely(status))
5515 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5517 memcpy(res->impl_id->domain, dummy_str, dummy);
5520 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5521 if (unlikely(status))
5523 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5525 memcpy(res->impl_id->name, dummy_str, dummy);
5528 p = xdr_inline_decode(xdr, 12);
5531 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5532 res->impl_id->date.nseconds = be32_to_cpup(p);
5534 /* if there's more than one entry, ignore the rest */
5538 print_overflow_msg(__func__, xdr);
5542 static int decode_chan_attrs(struct xdr_stream *xdr,
5543 struct nfs4_channel_attrs *attrs)
5548 p = xdr_inline_decode(xdr, 28);
5551 val = be32_to_cpup(p++); /* headerpadsz */
5553 return -EINVAL; /* no support for header padding yet */
5554 attrs->max_rqst_sz = be32_to_cpup(p++);
5555 attrs->max_resp_sz = be32_to_cpup(p++);
5556 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5557 attrs->max_ops = be32_to_cpup(p++);
5558 attrs->max_reqs = be32_to_cpup(p++);
5559 nr_attrs = be32_to_cpup(p);
5560 if (unlikely(nr_attrs > 1)) {
5561 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5562 "count %u\n", __func__, nr_attrs);
5565 if (nr_attrs == 1) {
5566 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5572 print_overflow_msg(__func__, xdr);
5576 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5578 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5581 static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5582 struct nfs41_bind_conn_to_session_res *res)
5587 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5589 status = decode_sessionid(xdr, &res->session->sess_id);
5590 if (unlikely(status))
5593 /* dir flags, rdma mode bool */
5594 p = xdr_inline_decode(xdr, 8);
5598 res->dir = be32_to_cpup(p++);
5599 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5601 if (be32_to_cpup(p) == 0)
5602 res->use_conn_in_rdma_mode = false;
5604 res->use_conn_in_rdma_mode = true;
5608 print_overflow_msg(__func__, xdr);
5612 static int decode_create_session(struct xdr_stream *xdr,
5613 struct nfs41_create_session_res *res)
5617 struct nfs_client *clp = res->client;
5618 struct nfs4_session *session = clp->cl_session;
5620 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5622 status = decode_sessionid(xdr, &session->sess_id);
5623 if (unlikely(status))
5627 p = xdr_inline_decode(xdr, 8);
5630 clp->cl_seqid = be32_to_cpup(p++);
5631 session->flags = be32_to_cpup(p);
5633 /* Channel attributes */
5634 status = decode_chan_attrs(xdr, &session->fc_attrs);
5636 status = decode_chan_attrs(xdr, &session->bc_attrs);
5639 print_overflow_msg(__func__, xdr);
5643 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5645 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5648 static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5650 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5653 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5655 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5657 #endif /* CONFIG_NFS_V4_1 */
5659 static int decode_sequence(struct xdr_stream *xdr,
5660 struct nfs4_sequence_res *res,
5661 struct rpc_rqst *rqstp)
5663 #if defined(CONFIG_NFS_V4_1)
5664 struct nfs4_session *session;
5665 struct nfs4_sessionid id;
5670 if (res->sr_slot == NULL)
5672 if (!res->sr_slot->table->session)
5675 status = decode_op_hdr(xdr, OP_SEQUENCE);
5677 status = decode_sessionid(xdr, &id);
5678 if (unlikely(status))
5682 * If the server returns different values for sessionID, slotID or
5683 * sequence number, the server is looney tunes.
5685 status = -EREMOTEIO;
5686 session = res->sr_slot->table->session;
5688 if (memcmp(id.data, session->sess_id.data,
5689 NFS4_MAX_SESSIONID_LEN)) {
5690 dprintk("%s Invalid session id\n", __func__);
5694 p = xdr_inline_decode(xdr, 20);
5699 dummy = be32_to_cpup(p++);
5700 if (dummy != res->sr_slot->seq_nr) {
5701 dprintk("%s Invalid sequence number\n", __func__);
5705 dummy = be32_to_cpup(p++);
5706 if (dummy != res->sr_slot->slot_nr) {
5707 dprintk("%s Invalid slot id\n", __func__);
5710 /* highest slot id */
5711 res->sr_highest_slotid = be32_to_cpup(p++);
5712 /* target highest slot id */
5713 res->sr_target_highest_slotid = be32_to_cpup(p++);
5715 res->sr_status_flags = be32_to_cpup(p);
5718 res->sr_status = status;
5721 print_overflow_msg(__func__, xdr);
5724 #else /* CONFIG_NFS_V4_1 */
5726 #endif /* CONFIG_NFS_V4_1 */
5729 #if defined(CONFIG_NFS_V4_1)
5730 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5731 struct pnfs_device *pdev)
5737 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5739 if (status == -ETOOSMALL) {
5740 p = xdr_inline_decode(xdr, 4);
5743 pdev->mincount = be32_to_cpup(p);
5744 dprintk("%s: Min count too small. mincnt = %u\n",
5745 __func__, pdev->mincount);
5750 p = xdr_inline_decode(xdr, 8);
5753 type = be32_to_cpup(p++);
5754 if (type != pdev->layout_type) {
5755 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5756 __func__, pdev->layout_type, type);
5760 * Get the length of the opaque device_addr4. xdr_read_pages places
5761 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5762 * and places the remaining xdr data in xdr_buf->tail
5764 pdev->mincount = be32_to_cpup(p);
5765 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5768 /* Parse notification bitmap, verifying that it is zero. */
5769 p = xdr_inline_decode(xdr, 4);
5772 len = be32_to_cpup(p);
5776 p = xdr_inline_decode(xdr, 4 * len);
5780 if (be32_to_cpup(p++) &
5781 ~(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE)) {
5782 dprintk("%s: unsupported notification\n",
5786 for (i = 1; i < len; i++) {
5787 if (be32_to_cpup(p++)) {
5788 dprintk("%s: unsupported notification\n",
5796 print_overflow_msg(__func__, xdr);
5800 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5801 struct nfs4_layoutget_res *res)
5808 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5811 p = xdr_inline_decode(xdr, 4);
5814 res->return_on_close = be32_to_cpup(p);
5815 decode_stateid(xdr, &res->stateid);
5816 p = xdr_inline_decode(xdr, 4);
5819 layout_count = be32_to_cpup(p);
5820 if (!layout_count) {
5821 dprintk("%s: server responded with empty layout array\n",
5826 p = xdr_inline_decode(xdr, 28);
5829 p = xdr_decode_hyper(p, &res->range.offset);
5830 p = xdr_decode_hyper(p, &res->range.length);
5831 res->range.iomode = be32_to_cpup(p++);
5832 res->type = be32_to_cpup(p++);
5833 res->layoutp->len = be32_to_cpup(p);
5835 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5837 (unsigned long)res->range.offset,
5838 (unsigned long)res->range.length,
5843 recvd = xdr_read_pages(xdr, res->layoutp->len);
5844 if (res->layoutp->len > recvd) {
5845 dprintk("NFS: server cheating in layoutget reply: "
5846 "layout len %u > recvd %u\n",
5847 res->layoutp->len, recvd);
5851 if (layout_count > 1) {
5852 /* We only handle a length one array at the moment. Any
5853 * further entries are just ignored. Note that this means
5854 * the client may see a response that is less than the
5855 * minimum it requested.
5857 dprintk("%s: server responded with %d layouts, dropping tail\n",
5858 __func__, layout_count);
5863 print_overflow_msg(__func__, xdr);
5867 static int decode_layoutreturn(struct xdr_stream *xdr,
5868 struct nfs4_layoutreturn_res *res)
5873 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5876 p = xdr_inline_decode(xdr, 4);
5879 res->lrs_present = be32_to_cpup(p);
5880 if (res->lrs_present)
5881 status = decode_stateid(xdr, &res->stateid);
5884 print_overflow_msg(__func__, xdr);
5888 static int decode_layoutcommit(struct xdr_stream *xdr,
5889 struct rpc_rqst *req,
5890 struct nfs4_layoutcommit_res *res)
5896 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5897 res->status = status;
5901 p = xdr_inline_decode(xdr, 4);
5904 sizechanged = be32_to_cpup(p);
5907 /* throw away new size */
5908 p = xdr_inline_decode(xdr, 8);
5914 print_overflow_msg(__func__, xdr);
5918 static int decode_test_stateid(struct xdr_stream *xdr,
5919 struct nfs41_test_stateid_res *res)
5925 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5929 p = xdr_inline_decode(xdr, 4);
5932 num_res = be32_to_cpup(p++);
5936 p = xdr_inline_decode(xdr, 4);
5939 res->status = be32_to_cpup(p++);
5943 print_overflow_msg(__func__, xdr);
5948 static int decode_free_stateid(struct xdr_stream *xdr,
5949 struct nfs41_free_stateid_res *res)
5951 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
5954 #endif /* CONFIG_NFS_V4_1 */
5957 * END OF "GENERIC" DECODE ROUTINES.
5961 * Decode OPEN_DOWNGRADE response
5963 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5964 struct xdr_stream *xdr,
5965 struct nfs_closeres *res)
5967 struct compound_hdr hdr;
5970 status = decode_compound_hdr(xdr, &hdr);
5973 status = decode_sequence(xdr, &res->seq_res, rqstp);
5976 status = decode_putfh(xdr);
5979 status = decode_open_downgrade(xdr, res);
5982 decode_getfattr(xdr, res->fattr, res->server);
5988 * Decode ACCESS response
5990 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5991 struct nfs4_accessres *res)
5993 struct compound_hdr hdr;
5996 status = decode_compound_hdr(xdr, &hdr);
5999 status = decode_sequence(xdr, &res->seq_res, rqstp);
6002 status = decode_putfh(xdr);
6005 status = decode_access(xdr, &res->supported, &res->access);
6008 decode_getfattr(xdr, res->fattr, res->server);
6014 * Decode LOOKUP response
6016 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6017 struct nfs4_lookup_res *res)
6019 struct compound_hdr hdr;
6022 status = decode_compound_hdr(xdr, &hdr);
6025 status = decode_sequence(xdr, &res->seq_res, rqstp);
6028 status = decode_putfh(xdr);
6031 status = decode_lookup(xdr);
6034 status = decode_getfh(xdr, res->fh);
6037 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6043 * Decode LOOKUP_ROOT response
6045 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6046 struct xdr_stream *xdr,
6047 struct nfs4_lookup_res *res)
6049 struct compound_hdr hdr;
6052 status = decode_compound_hdr(xdr, &hdr);
6055 status = decode_sequence(xdr, &res->seq_res, rqstp);
6058 status = decode_putrootfh(xdr);
6061 status = decode_getfh(xdr, res->fh);
6063 status = decode_getfattr_label(xdr, res->fattr,
6064 res->label, res->server);
6070 * Decode REMOVE response
6072 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6073 struct nfs_removeres *res)
6075 struct compound_hdr hdr;
6078 status = decode_compound_hdr(xdr, &hdr);
6081 status = decode_sequence(xdr, &res->seq_res, rqstp);
6084 status = decode_putfh(xdr);
6087 status = decode_remove(xdr, &res->cinfo);
6093 * Decode RENAME response
6095 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6096 struct nfs_renameres *res)
6098 struct compound_hdr hdr;
6101 status = decode_compound_hdr(xdr, &hdr);
6104 status = decode_sequence(xdr, &res->seq_res, rqstp);
6107 status = decode_putfh(xdr);
6110 status = decode_savefh(xdr);
6113 status = decode_putfh(xdr);
6116 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
6122 * Decode LINK response
6124 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6125 struct nfs4_link_res *res)
6127 struct compound_hdr hdr;
6130 status = decode_compound_hdr(xdr, &hdr);
6133 status = decode_sequence(xdr, &res->seq_res, rqstp);
6136 status = decode_putfh(xdr);
6139 status = decode_savefh(xdr);
6142 status = decode_putfh(xdr);
6145 status = decode_link(xdr, &res->cinfo);
6149 * Note order: OP_LINK leaves the directory as the current
6152 status = decode_restorefh(xdr);
6155 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6161 * Decode CREATE response
6163 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6164 struct nfs4_create_res *res)
6166 struct compound_hdr hdr;
6169 status = decode_compound_hdr(xdr, &hdr);
6172 status = decode_sequence(xdr, &res->seq_res, rqstp);
6175 status = decode_putfh(xdr);
6178 status = decode_create(xdr, &res->dir_cinfo);
6181 status = decode_getfh(xdr, res->fh);
6184 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6190 * Decode SYMLINK response
6192 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6193 struct nfs4_create_res *res)
6195 return nfs4_xdr_dec_create(rqstp, xdr, res);
6199 * Decode GETATTR response
6201 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6202 struct nfs4_getattr_res *res)
6204 struct compound_hdr hdr;
6207 status = decode_compound_hdr(xdr, &hdr);
6210 status = decode_sequence(xdr, &res->seq_res, rqstp);
6213 status = decode_putfh(xdr);
6216 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6222 * Encode an SETACL request
6224 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6225 struct nfs_setaclargs *args)
6227 struct compound_hdr hdr = {
6228 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6231 encode_compound_hdr(xdr, req, &hdr);
6232 encode_sequence(xdr, &args->seq_args, &hdr);
6233 encode_putfh(xdr, args->fh, &hdr);
6234 encode_setacl(xdr, args, &hdr);
6239 * Decode SETACL response
6242 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6243 struct nfs_setaclres *res)
6245 struct compound_hdr hdr;
6248 status = decode_compound_hdr(xdr, &hdr);
6251 status = decode_sequence(xdr, &res->seq_res, rqstp);
6254 status = decode_putfh(xdr);
6257 status = decode_setattr(xdr);
6263 * Decode GETACL response
6266 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6267 struct nfs_getaclres *res)
6269 struct compound_hdr hdr;
6272 if (res->acl_scratch != NULL) {
6273 void *p = page_address(res->acl_scratch);
6274 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6276 status = decode_compound_hdr(xdr, &hdr);
6279 status = decode_sequence(xdr, &res->seq_res, rqstp);
6282 status = decode_putfh(xdr);
6285 status = decode_getacl(xdr, rqstp, res);
6292 * Decode CLOSE response
6294 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6295 struct nfs_closeres *res)
6297 struct compound_hdr hdr;
6300 status = decode_compound_hdr(xdr, &hdr);
6303 status = decode_sequence(xdr, &res->seq_res, rqstp);
6306 status = decode_putfh(xdr);
6309 status = decode_close(xdr, res);
6313 * Note: Server may do delete on close for this file
6314 * in which case the getattr call will fail with
6315 * an ESTALE error. Shouldn't be a problem,
6316 * though, since fattr->valid will remain unset.
6318 decode_getfattr(xdr, res->fattr, res->server);
6324 * Decode OPEN response
6326 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6327 struct nfs_openres *res)
6329 struct compound_hdr hdr;
6332 status = decode_compound_hdr(xdr, &hdr);
6335 status = decode_sequence(xdr, &res->seq_res, rqstp);
6338 status = decode_putfh(xdr);
6341 status = decode_open(xdr, res);
6344 status = decode_getfh(xdr, &res->fh);
6347 if (res->access_request)
6348 decode_access(xdr, &res->access_supported, &res->access_result);
6349 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
6355 * Decode OPEN_CONFIRM response
6357 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6358 struct xdr_stream *xdr,
6359 struct nfs_open_confirmres *res)
6361 struct compound_hdr hdr;
6364 status = decode_compound_hdr(xdr, &hdr);
6367 status = decode_putfh(xdr);
6370 status = decode_open_confirm(xdr, res);
6376 * Decode OPEN response
6378 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6379 struct xdr_stream *xdr,
6380 struct nfs_openres *res)
6382 struct compound_hdr hdr;
6385 status = decode_compound_hdr(xdr, &hdr);
6388 status = decode_sequence(xdr, &res->seq_res, rqstp);
6391 status = decode_putfh(xdr);
6394 status = decode_open(xdr, res);
6397 if (res->access_request)
6398 decode_access(xdr, &res->access_supported, &res->access_result);
6399 decode_getfattr(xdr, res->f_attr, res->server);
6405 * Decode SETATTR response
6407 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6408 struct xdr_stream *xdr,
6409 struct nfs_setattrres *res)
6411 struct compound_hdr hdr;
6414 status = decode_compound_hdr(xdr, &hdr);
6417 status = decode_sequence(xdr, &res->seq_res, rqstp);
6420 status = decode_putfh(xdr);
6423 status = decode_setattr(xdr);
6426 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6432 * Decode LOCK response
6434 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6435 struct nfs_lock_res *res)
6437 struct compound_hdr hdr;
6440 status = decode_compound_hdr(xdr, &hdr);
6443 status = decode_sequence(xdr, &res->seq_res, rqstp);
6446 status = decode_putfh(xdr);
6449 status = decode_lock(xdr, res);
6455 * Decode LOCKT response
6457 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6458 struct nfs_lockt_res *res)
6460 struct compound_hdr hdr;
6463 status = decode_compound_hdr(xdr, &hdr);
6466 status = decode_sequence(xdr, &res->seq_res, rqstp);
6469 status = decode_putfh(xdr);
6472 status = decode_lockt(xdr, res);
6478 * Decode LOCKU response
6480 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6481 struct nfs_locku_res *res)
6483 struct compound_hdr hdr;
6486 status = decode_compound_hdr(xdr, &hdr);
6489 status = decode_sequence(xdr, &res->seq_res, rqstp);
6492 status = decode_putfh(xdr);
6495 status = decode_locku(xdr, res);
6500 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6501 struct xdr_stream *xdr, void *dummy)
6503 struct compound_hdr hdr;
6506 status = decode_compound_hdr(xdr, &hdr);
6508 status = decode_release_lockowner(xdr);
6513 * Decode READLINK response
6515 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6516 struct xdr_stream *xdr,
6517 struct nfs4_readlink_res *res)
6519 struct compound_hdr hdr;
6522 status = decode_compound_hdr(xdr, &hdr);
6525 status = decode_sequence(xdr, &res->seq_res, rqstp);
6528 status = decode_putfh(xdr);
6531 status = decode_readlink(xdr, rqstp);
6537 * Decode READDIR response
6539 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6540 struct nfs4_readdir_res *res)
6542 struct compound_hdr hdr;
6545 status = decode_compound_hdr(xdr, &hdr);
6548 status = decode_sequence(xdr, &res->seq_res, rqstp);
6551 status = decode_putfh(xdr);
6554 status = decode_readdir(xdr, rqstp, res);
6560 * Decode Read response
6562 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6563 struct nfs_pgio_res *res)
6565 struct compound_hdr hdr;
6568 status = decode_compound_hdr(xdr, &hdr);
6569 res->op_status = hdr.status;
6572 status = decode_sequence(xdr, &res->seq_res, rqstp);
6575 status = decode_putfh(xdr);
6578 status = decode_read(xdr, rqstp, res);
6580 status = res->count;
6586 * Decode WRITE response
6588 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6589 struct nfs_pgio_res *res)
6591 struct compound_hdr hdr;
6594 status = decode_compound_hdr(xdr, &hdr);
6595 res->op_status = hdr.status;
6598 status = decode_sequence(xdr, &res->seq_res, rqstp);
6601 status = decode_putfh(xdr);
6604 status = decode_write(xdr, res);
6608 decode_getfattr(xdr, res->fattr, res->server);
6610 status = res->count;
6616 * Decode COMMIT response
6618 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6619 struct nfs_commitres *res)
6621 struct compound_hdr hdr;
6624 status = decode_compound_hdr(xdr, &hdr);
6625 res->op_status = hdr.status;
6628 status = decode_sequence(xdr, &res->seq_res, rqstp);
6631 status = decode_putfh(xdr);
6634 status = decode_commit(xdr, res);
6640 * Decode FSINFO response
6642 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6643 struct nfs4_fsinfo_res *res)
6645 struct compound_hdr hdr;
6648 status = decode_compound_hdr(xdr, &hdr);
6650 status = decode_sequence(xdr, &res->seq_res, req);
6652 status = decode_putfh(xdr);
6654 status = decode_fsinfo(xdr, res->fsinfo);
6659 * Decode PATHCONF response
6661 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6662 struct nfs4_pathconf_res *res)
6664 struct compound_hdr hdr;
6667 status = decode_compound_hdr(xdr, &hdr);
6669 status = decode_sequence(xdr, &res->seq_res, req);
6671 status = decode_putfh(xdr);
6673 status = decode_pathconf(xdr, res->pathconf);
6678 * Decode STATFS response
6680 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6681 struct nfs4_statfs_res *res)
6683 struct compound_hdr hdr;
6686 status = decode_compound_hdr(xdr, &hdr);
6688 status = decode_sequence(xdr, &res->seq_res, req);
6690 status = decode_putfh(xdr);
6692 status = decode_statfs(xdr, res->fsstat);
6697 * Decode GETATTR_BITMAP response
6699 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6700 struct xdr_stream *xdr,
6701 struct nfs4_server_caps_res *res)
6703 struct compound_hdr hdr;
6706 status = decode_compound_hdr(xdr, &hdr);
6709 status = decode_sequence(xdr, &res->seq_res, req);
6712 status = decode_putfh(xdr);
6715 status = decode_server_caps(xdr, res);
6721 * Decode RENEW response
6723 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6726 struct compound_hdr hdr;
6729 status = decode_compound_hdr(xdr, &hdr);
6731 status = decode_renew(xdr);
6736 * Decode SETCLIENTID response
6738 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6739 struct xdr_stream *xdr,
6740 struct nfs4_setclientid_res *res)
6742 struct compound_hdr hdr;
6745 status = decode_compound_hdr(xdr, &hdr);
6747 status = decode_setclientid(xdr, res);
6752 * Decode SETCLIENTID_CONFIRM response
6754 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6755 struct xdr_stream *xdr)
6757 struct compound_hdr hdr;
6760 status = decode_compound_hdr(xdr, &hdr);
6762 status = decode_setclientid_confirm(xdr);
6767 * Decode DELEGRETURN response
6769 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6770 struct xdr_stream *xdr,
6771 struct nfs4_delegreturnres *res)
6773 struct compound_hdr hdr;
6776 status = decode_compound_hdr(xdr, &hdr);
6779 status = decode_sequence(xdr, &res->seq_res, rqstp);
6782 status = decode_putfh(xdr);
6785 status = decode_getfattr(xdr, res->fattr, res->server);
6788 status = decode_delegreturn(xdr);
6794 * Decode FS_LOCATIONS response
6796 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6797 struct xdr_stream *xdr,
6798 struct nfs4_fs_locations_res *res)
6800 struct compound_hdr hdr;
6803 status = decode_compound_hdr(xdr, &hdr);
6806 status = decode_sequence(xdr, &res->seq_res, req);
6809 status = decode_putfh(xdr);
6812 if (res->migration) {
6813 xdr_enter_page(xdr, PAGE_SIZE);
6814 status = decode_getfattr_generic(xdr,
6815 &res->fs_locations->fattr,
6816 NULL, res->fs_locations,
6817 NULL, res->fs_locations->server);
6821 status = decode_renew(xdr);
6823 status = decode_lookup(xdr);
6826 xdr_enter_page(xdr, PAGE_SIZE);
6827 status = decode_getfattr_generic(xdr,
6828 &res->fs_locations->fattr,
6829 NULL, res->fs_locations,
6830 NULL, res->fs_locations->server);
6837 * Decode SECINFO response
6839 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6840 struct xdr_stream *xdr,
6841 struct nfs4_secinfo_res *res)
6843 struct compound_hdr hdr;
6846 status = decode_compound_hdr(xdr, &hdr);
6849 status = decode_sequence(xdr, &res->seq_res, rqstp);
6852 status = decode_putfh(xdr);
6855 status = decode_secinfo(xdr, res);
6861 * Decode FSID_PRESENT response
6863 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6864 struct xdr_stream *xdr,
6865 struct nfs4_fsid_present_res *res)
6867 struct compound_hdr hdr;
6870 status = decode_compound_hdr(xdr, &hdr);
6873 status = decode_sequence(xdr, &res->seq_res, rqstp);
6876 status = decode_putfh(xdr);
6879 status = decode_getfh(xdr, res->fh);
6883 status = decode_renew(xdr);
6888 #if defined(CONFIG_NFS_V4_1)
6890 * Decode BIND_CONN_TO_SESSION response
6892 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6893 struct xdr_stream *xdr,
6896 struct compound_hdr hdr;
6899 status = decode_compound_hdr(xdr, &hdr);
6901 status = decode_bind_conn_to_session(xdr, res);
6906 * Decode EXCHANGE_ID response
6908 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6909 struct xdr_stream *xdr,
6912 struct compound_hdr hdr;
6915 status = decode_compound_hdr(xdr, &hdr);
6917 status = decode_exchange_id(xdr, res);
6922 * Decode CREATE_SESSION response
6924 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6925 struct xdr_stream *xdr,
6926 struct nfs41_create_session_res *res)
6928 struct compound_hdr hdr;
6931 status = decode_compound_hdr(xdr, &hdr);
6933 status = decode_create_session(xdr, res);
6938 * Decode DESTROY_SESSION response
6940 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6941 struct xdr_stream *xdr,
6944 struct compound_hdr hdr;
6947 status = decode_compound_hdr(xdr, &hdr);
6949 status = decode_destroy_session(xdr, res);
6954 * Decode DESTROY_CLIENTID response
6956 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6957 struct xdr_stream *xdr,
6960 struct compound_hdr hdr;
6963 status = decode_compound_hdr(xdr, &hdr);
6965 status = decode_destroy_clientid(xdr, res);
6970 * Decode SEQUENCE response
6972 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6973 struct xdr_stream *xdr,
6974 struct nfs4_sequence_res *res)
6976 struct compound_hdr hdr;
6979 status = decode_compound_hdr(xdr, &hdr);
6981 status = decode_sequence(xdr, res, rqstp);
6986 * Decode GET_LEASE_TIME response
6988 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6989 struct xdr_stream *xdr,
6990 struct nfs4_get_lease_time_res *res)
6992 struct compound_hdr hdr;
6995 status = decode_compound_hdr(xdr, &hdr);
6997 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
6999 status = decode_putrootfh(xdr);
7001 status = decode_fsinfo(xdr, res->lr_fsinfo);
7006 * Decode RECLAIM_COMPLETE response
7008 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7009 struct xdr_stream *xdr,
7010 struct nfs41_reclaim_complete_res *res)
7012 struct compound_hdr hdr;
7015 status = decode_compound_hdr(xdr, &hdr);
7017 status = decode_sequence(xdr, &res->seq_res, rqstp);
7019 status = decode_reclaim_complete(xdr, NULL);
7024 * Decode GETDEVINFO response
7026 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7027 struct xdr_stream *xdr,
7028 struct nfs4_getdeviceinfo_res *res)
7030 struct compound_hdr hdr;
7033 status = decode_compound_hdr(xdr, &hdr);
7036 status = decode_sequence(xdr, &res->seq_res, rqstp);
7039 status = decode_getdeviceinfo(xdr, res->pdev);
7045 * Decode LAYOUTGET response
7047 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7048 struct xdr_stream *xdr,
7049 struct nfs4_layoutget_res *res)
7051 struct compound_hdr hdr;
7054 status = decode_compound_hdr(xdr, &hdr);
7057 status = decode_sequence(xdr, &res->seq_res, rqstp);
7060 status = decode_putfh(xdr);
7063 status = decode_layoutget(xdr, rqstp, res);
7069 * Decode LAYOUTRETURN response
7071 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7072 struct xdr_stream *xdr,
7073 struct nfs4_layoutreturn_res *res)
7075 struct compound_hdr hdr;
7078 status = decode_compound_hdr(xdr, &hdr);
7081 status = decode_sequence(xdr, &res->seq_res, rqstp);
7084 status = decode_putfh(xdr);
7087 status = decode_layoutreturn(xdr, res);
7093 * Decode LAYOUTCOMMIT response
7095 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7096 struct xdr_stream *xdr,
7097 struct nfs4_layoutcommit_res *res)
7099 struct compound_hdr hdr;
7102 status = decode_compound_hdr(xdr, &hdr);
7105 status = decode_sequence(xdr, &res->seq_res, rqstp);
7108 status = decode_putfh(xdr);
7111 status = decode_layoutcommit(xdr, rqstp, res);
7114 decode_getfattr(xdr, res->fattr, res->server);
7120 * Decode SECINFO_NO_NAME response
7122 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7123 struct xdr_stream *xdr,
7124 struct nfs4_secinfo_res *res)
7126 struct compound_hdr hdr;
7129 status = decode_compound_hdr(xdr, &hdr);
7132 status = decode_sequence(xdr, &res->seq_res, rqstp);
7135 status = decode_putrootfh(xdr);
7138 status = decode_secinfo_no_name(xdr, res);
7144 * Decode TEST_STATEID response
7146 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7147 struct xdr_stream *xdr,
7148 struct nfs41_test_stateid_res *res)
7150 struct compound_hdr hdr;
7153 status = decode_compound_hdr(xdr, &hdr);
7156 status = decode_sequence(xdr, &res->seq_res, rqstp);
7159 status = decode_test_stateid(xdr, res);
7165 * Decode FREE_STATEID response
7167 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7168 struct xdr_stream *xdr,
7169 struct nfs41_free_stateid_res *res)
7171 struct compound_hdr hdr;
7174 status = decode_compound_hdr(xdr, &hdr);
7177 status = decode_sequence(xdr, &res->seq_res, rqstp);
7180 status = decode_free_stateid(xdr, res);
7184 #endif /* CONFIG_NFS_V4_1 */
7187 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7188 * the local page cache.
7189 * @xdr: XDR stream where entry resides
7190 * @entry: buffer to fill in with entry data
7191 * @plus: boolean indicating whether this should be a readdirplus entry
7193 * Returns zero if successful, otherwise a negative errno value is
7196 * This function is not invoked during READDIR reply decoding, but
7197 * rather whenever an application invokes the getdents(2) system call
7198 * on a directory already in our cache.
7200 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7204 uint32_t bitmap[3] = {0};
7206 __be32 *p = xdr_inline_decode(xdr, 4);
7209 if (*p == xdr_zero) {
7210 p = xdr_inline_decode(xdr, 4);
7219 p = xdr_inline_decode(xdr, 12);
7222 entry->prev_cookie = entry->cookie;
7223 p = xdr_decode_hyper(p, &entry->cookie);
7224 entry->len = be32_to_cpup(p);
7226 p = xdr_inline_decode(xdr, entry->len);
7229 entry->name = (const char *) p;
7232 * In case the server doesn't return an inode number,
7233 * we fake one here. (We don't use inode number 0,
7234 * since glibc seems to choke on it...)
7237 entry->fattr->valid = 0;
7239 if (decode_attr_bitmap(xdr, bitmap) < 0)
7242 if (decode_attr_length(xdr, &len, &savep) < 0)
7245 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7246 NULL, entry->label, entry->server) < 0)
7248 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7249 entry->ino = entry->fattr->mounted_on_fileid;
7250 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7251 entry->ino = entry->fattr->fileid;
7253 entry->d_type = DT_UNKNOWN;
7254 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7255 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7260 print_overflow_msg(__func__, xdr);
7265 * We need to translate between nfs status return values and
7266 * the local errno values which may not be the same.
7273 { NFS4ERR_PERM, -EPERM },
7274 { NFS4ERR_NOENT, -ENOENT },
7275 { NFS4ERR_IO, -errno_NFSERR_IO},
7276 { NFS4ERR_NXIO, -ENXIO },
7277 { NFS4ERR_ACCESS, -EACCES },
7278 { NFS4ERR_EXIST, -EEXIST },
7279 { NFS4ERR_XDEV, -EXDEV },
7280 { NFS4ERR_NOTDIR, -ENOTDIR },
7281 { NFS4ERR_ISDIR, -EISDIR },
7282 { NFS4ERR_INVAL, -EINVAL },
7283 { NFS4ERR_FBIG, -EFBIG },
7284 { NFS4ERR_NOSPC, -ENOSPC },
7285 { NFS4ERR_ROFS, -EROFS },
7286 { NFS4ERR_MLINK, -EMLINK },
7287 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7288 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7289 { NFS4ERR_DQUOT, -EDQUOT },
7290 { NFS4ERR_STALE, -ESTALE },
7291 { NFS4ERR_BADHANDLE, -EBADHANDLE },
7292 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7293 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7294 { NFS4ERR_TOOSMALL, -ETOOSMALL },
7295 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7296 { NFS4ERR_BADTYPE, -EBADTYPE },
7297 { NFS4ERR_LOCKED, -EAGAIN },
7298 { NFS4ERR_SYMLINK, -ELOOP },
7299 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7300 { NFS4ERR_DEADLOCK, -EDEADLK },
7305 * Convert an NFS error code to a local one.
7306 * This one is used jointly by NFSv2 and NFSv3.
7309 nfs4_stat_to_errno(int stat)
7312 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7313 if (nfs_errtbl[i].stat == stat)
7314 return nfs_errtbl[i].errno;
7316 if (stat <= 10000 || stat > 10100) {
7317 /* The server is looney tunes. */
7320 /* If we cannot translate the error, the recovery routines should
7322 * Note: remaining NFSv4 error codes have values > 10000, so should
7323 * not conflict with native Linux error codes.
7328 #ifdef CONFIG_NFS_V4_2
7329 #include "nfs42xdr.c"
7330 #endif /* CONFIG_NFS_V4_2 */
7332 #define PROC(proc, argtype, restype) \
7333 [NFSPROC4_CLNT_##proc] = { \
7334 .p_proc = NFSPROC4_COMPOUND, \
7335 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7336 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7337 .p_arglen = NFS4_##argtype##_sz, \
7338 .p_replen = NFS4_##restype##_sz, \
7339 .p_statidx = NFSPROC4_CLNT_##proc, \
7343 struct rpc_procinfo nfs4_procedures[] = {
7344 PROC(READ, enc_read, dec_read),
7345 PROC(WRITE, enc_write, dec_write),
7346 PROC(COMMIT, enc_commit, dec_commit),
7347 PROC(OPEN, enc_open, dec_open),
7348 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7349 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7350 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7351 PROC(CLOSE, enc_close, dec_close),
7352 PROC(SETATTR, enc_setattr, dec_setattr),
7353 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7354 PROC(RENEW, enc_renew, dec_renew),
7355 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7356 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7357 PROC(LOCK, enc_lock, dec_lock),
7358 PROC(LOCKT, enc_lockt, dec_lockt),
7359 PROC(LOCKU, enc_locku, dec_locku),
7360 PROC(ACCESS, enc_access, dec_access),
7361 PROC(GETATTR, enc_getattr, dec_getattr),
7362 PROC(LOOKUP, enc_lookup, dec_lookup),
7363 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7364 PROC(REMOVE, enc_remove, dec_remove),
7365 PROC(RENAME, enc_rename, dec_rename),
7366 PROC(LINK, enc_link, dec_link),
7367 PROC(SYMLINK, enc_symlink, dec_symlink),
7368 PROC(CREATE, enc_create, dec_create),
7369 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7370 PROC(STATFS, enc_statfs, dec_statfs),
7371 PROC(READLINK, enc_readlink, dec_readlink),
7372 PROC(READDIR, enc_readdir, dec_readdir),
7373 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7374 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7375 PROC(GETACL, enc_getacl, dec_getacl),
7376 PROC(SETACL, enc_setacl, dec_setacl),
7377 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7378 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7379 PROC(SECINFO, enc_secinfo, dec_secinfo),
7380 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
7381 #if defined(CONFIG_NFS_V4_1)
7382 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7383 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7384 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7385 PROC(SEQUENCE, enc_sequence, dec_sequence),
7386 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7387 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7388 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7389 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7390 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7391 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7392 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7393 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7394 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7395 PROC(BIND_CONN_TO_SESSION,
7396 enc_bind_conn_to_session, dec_bind_conn_to_session),
7397 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
7398 #endif /* CONFIG_NFS_V4_1 */
7399 #ifdef CONFIG_NFS_V4_2
7400 PROC(SEEK, enc_seek, dec_seek),
7401 PROC(ALLOCATE, enc_allocate, dec_allocate),
7402 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
7403 #endif /* CONFIG_NFS_V4_2 */
7406 const struct rpc_version nfs_version4 = {
7408 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7409 .procs = nfs4_procedures