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
)
949 encode_uint32(xdr
, seqid
->sequence
->counter
);
952 static void encode_compound_hdr(struct xdr_stream
*xdr
,
953 struct rpc_rqst
*req
,
954 struct compound_hdr
*hdr
)
957 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
959 /* initialize running count of expected bytes in reply.
960 * NOTE: the replied tag SHOULD be the same is the one sent,
961 * but this is not required as a MUST for the server to do so. */
962 hdr
->replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ 3 + hdr
->taglen
;
964 WARN_ON_ONCE(hdr
->taglen
> NFS4_MAXTAGLEN
);
965 encode_string(xdr
, hdr
->taglen
, hdr
->tag
);
966 p
= reserve_space(xdr
, 8);
967 *p
++ = cpu_to_be32(hdr
->minorversion
);
969 *p
= cpu_to_be32(hdr
->nops
);
972 static void encode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 op
,
974 struct compound_hdr
*hdr
)
976 encode_uint32(xdr
, op
);
978 hdr
->replen
+= replen
;
981 static void encode_nops(struct compound_hdr
*hdr
)
983 WARN_ON_ONCE(hdr
->nops
> NFS4_MAX_OPS
);
984 *hdr
->nops_p
= htonl(hdr
->nops
);
987 static void encode_nfs4_stateid(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
)
989 encode_opaque_fixed(xdr
, stateid
, NFS4_STATEID_SIZE
);
992 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
994 encode_opaque_fixed(xdr
, verf
->data
, NFS4_VERIFIER_SIZE
);
997 static void encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
,
998 const struct nfs4_label
*label
,
999 const struct nfs_server
*server
)
1001 char owner_name
[IDMAP_NAMESZ
];
1002 char owner_group
[IDMAP_NAMESZ
];
1003 int owner_namelen
= 0;
1004 int owner_grouplen
= 0;
1009 uint32_t bmval
[3] = { 0 };
1012 * We reserve enough space to write the entire attribute buffer at once.
1013 * In the worst-case, this would be
1014 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1015 * = 40 bytes, plus any contribution from variable-length fields
1016 * such as owner/group.
1018 if (iap
->ia_valid
& ATTR_SIZE
) {
1019 bmval
[0] |= FATTR4_WORD0_SIZE
;
1022 if (iap
->ia_valid
& ATTR_MODE
) {
1023 bmval
[1] |= FATTR4_WORD1_MODE
;
1026 if (iap
->ia_valid
& ATTR_UID
) {
1027 owner_namelen
= nfs_map_uid_to_name(server
, iap
->ia_uid
, owner_name
, IDMAP_NAMESZ
);
1028 if (owner_namelen
< 0) {
1029 dprintk("nfs: couldn't resolve uid %d to string\n",
1030 from_kuid(&init_user_ns
, iap
->ia_uid
));
1032 strcpy(owner_name
, "nobody");
1033 owner_namelen
= sizeof("nobody") - 1;
1036 bmval
[1] |= FATTR4_WORD1_OWNER
;
1037 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
1039 if (iap
->ia_valid
& ATTR_GID
) {
1040 owner_grouplen
= nfs_map_gid_to_group(server
, iap
->ia_gid
, owner_group
, IDMAP_NAMESZ
);
1041 if (owner_grouplen
< 0) {
1042 dprintk("nfs: couldn't resolve gid %d to string\n",
1043 from_kgid(&init_user_ns
, iap
->ia_gid
));
1044 strcpy(owner_group
, "nobody");
1045 owner_grouplen
= sizeof("nobody") - 1;
1048 bmval
[1] |= FATTR4_WORD1_OWNER_GROUP
;
1049 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
1051 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
1052 bmval
[1] |= FATTR4_WORD1_TIME_ACCESS_SET
;
1054 } else if (iap
->ia_valid
& ATTR_ATIME
) {
1055 bmval
[1] |= FATTR4_WORD1_TIME_ACCESS_SET
;
1058 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
1059 bmval
[1] |= FATTR4_WORD1_TIME_MODIFY_SET
;
1061 } else if (iap
->ia_valid
& ATTR_MTIME
) {
1062 bmval
[1] |= FATTR4_WORD1_TIME_MODIFY_SET
;
1066 len
+= 4 + 4 + 4 + (XDR_QUADLEN(label
->len
) << 2);
1067 bmval
[2] |= FATTR4_WORD2_SECURITY_LABEL
;
1072 else if (bmval
[1] != 0)
1077 p
= reserve_space(xdr
, 4 + (bmval_len
<< 2) + 4 + len
);
1079 *p
++ = cpu_to_be32(bmval_len
);
1080 for (i
= 0; i
< bmval_len
; i
++)
1081 *p
++ = cpu_to_be32(bmval
[i
]);
1082 *p
++ = cpu_to_be32(len
);
1084 if (bmval
[0] & FATTR4_WORD0_SIZE
)
1085 p
= xdr_encode_hyper(p
, iap
->ia_size
);
1086 if (bmval
[1] & FATTR4_WORD1_MODE
)
1087 *p
++ = cpu_to_be32(iap
->ia_mode
& S_IALLUGO
);
1088 if (bmval
[1] & FATTR4_WORD1_OWNER
)
1089 p
= xdr_encode_opaque(p
, owner_name
, owner_namelen
);
1090 if (bmval
[1] & FATTR4_WORD1_OWNER_GROUP
)
1091 p
= xdr_encode_opaque(p
, owner_group
, owner_grouplen
);
1092 if (bmval
[1] & FATTR4_WORD1_TIME_ACCESS_SET
) {
1093 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
1094 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
1095 p
= xdr_encode_hyper(p
, (s64
)iap
->ia_atime
.tv_sec
);
1096 *p
++ = cpu_to_be32(iap
->ia_atime
.tv_nsec
);
1098 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
1100 if (bmval
[1] & FATTR4_WORD1_TIME_MODIFY_SET
) {
1101 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
1102 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
1103 p
= xdr_encode_hyper(p
, (s64
)iap
->ia_mtime
.tv_sec
);
1104 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_nsec
);
1106 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
1108 if (bmval
[2] & FATTR4_WORD2_SECURITY_LABEL
) {
1109 *p
++ = cpu_to_be32(label
->lfs
);
1110 *p
++ = cpu_to_be32(label
->pi
);
1111 *p
++ = cpu_to_be32(label
->len
);
1112 p
= xdr_encode_opaque_fixed(p
, label
->label
, label
->len
);
1118 static void encode_access(struct xdr_stream
*xdr
, u32 access
, struct compound_hdr
*hdr
)
1120 encode_op_hdr(xdr
, OP_ACCESS
, decode_access_maxsz
, hdr
);
1121 encode_uint32(xdr
, access
);
1124 static void encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1126 encode_op_hdr(xdr
, OP_CLOSE
, decode_close_maxsz
, hdr
);
1127 encode_nfs4_seqid(xdr
, arg
->seqid
);
1128 encode_nfs4_stateid(xdr
, arg
->stateid
);
1131 static void encode_commit(struct xdr_stream
*xdr
, const struct nfs_commitargs
*args
, struct compound_hdr
*hdr
)
1135 encode_op_hdr(xdr
, OP_COMMIT
, decode_commit_maxsz
, hdr
);
1136 p
= reserve_space(xdr
, 12);
1137 p
= xdr_encode_hyper(p
, args
->offset
);
1138 *p
= cpu_to_be32(args
->count
);
1141 static void encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
, struct compound_hdr
*hdr
)
1145 encode_op_hdr(xdr
, OP_CREATE
, decode_create_maxsz
, hdr
);
1146 encode_uint32(xdr
, create
->ftype
);
1148 switch (create
->ftype
) {
1150 p
= reserve_space(xdr
, 4);
1151 *p
= cpu_to_be32(create
->u
.symlink
.len
);
1152 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0, create
->u
.symlink
.len
);
1155 case NF4BLK
: case NF4CHR
:
1156 p
= reserve_space(xdr
, 8);
1157 *p
++ = cpu_to_be32(create
->u
.device
.specdata1
);
1158 *p
= cpu_to_be32(create
->u
.device
.specdata2
);
1165 encode_string(xdr
, create
->name
->len
, create
->name
->name
);
1166 encode_attrs(xdr
, create
->attrs
, create
->label
, create
->server
);
1169 static void encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
, struct compound_hdr
*hdr
)
1173 encode_op_hdr(xdr
, OP_GETATTR
, decode_getattr_maxsz
, hdr
);
1174 p
= reserve_space(xdr
, 8);
1175 *p
++ = cpu_to_be32(1);
1176 *p
= cpu_to_be32(bitmap
);
1179 static void encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
, struct compound_hdr
*hdr
)
1183 encode_op_hdr(xdr
, OP_GETATTR
, decode_getattr_maxsz
, hdr
);
1184 p
= reserve_space(xdr
, 12);
1185 *p
++ = cpu_to_be32(2);
1186 *p
++ = cpu_to_be32(bm0
);
1187 *p
= cpu_to_be32(bm1
);
1191 encode_getattr_three(struct xdr_stream
*xdr
,
1192 uint32_t bm0
, uint32_t bm1
, uint32_t bm2
,
1193 struct compound_hdr
*hdr
)
1197 encode_op_hdr(xdr
, OP_GETATTR
, decode_getattr_maxsz
, hdr
);
1199 p
= reserve_space(xdr
, 16);
1200 *p
++ = cpu_to_be32(3);
1201 *p
++ = cpu_to_be32(bm0
);
1202 *p
++ = cpu_to_be32(bm1
);
1203 *p
= cpu_to_be32(bm2
);
1205 p
= reserve_space(xdr
, 12);
1206 *p
++ = cpu_to_be32(2);
1207 *p
++ = cpu_to_be32(bm0
);
1208 *p
= cpu_to_be32(bm1
);
1210 p
= reserve_space(xdr
, 8);
1211 *p
++ = cpu_to_be32(1);
1212 *p
= cpu_to_be32(bm0
);
1216 static void encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1218 encode_getattr_three(xdr
, bitmask
[0] & nfs4_fattr_bitmap
[0],
1219 bitmask
[1] & nfs4_fattr_bitmap
[1],
1220 bitmask
[2] & nfs4_fattr_bitmap
[2],
1224 static void encode_getfattr_open(struct xdr_stream
*xdr
, const u32
*bitmask
,
1225 const u32
*open_bitmap
,
1226 struct compound_hdr
*hdr
)
1228 encode_getattr_three(xdr
,
1229 bitmask
[0] & open_bitmap
[0],
1230 bitmask
[1] & open_bitmap
[1],
1231 bitmask
[2] & open_bitmap
[2],
1235 static void encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1237 encode_getattr_three(xdr
,
1238 bitmask
[0] & nfs4_fsinfo_bitmap
[0],
1239 bitmask
[1] & nfs4_fsinfo_bitmap
[1],
1240 bitmask
[2] & nfs4_fsinfo_bitmap
[2],
1244 static void encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1246 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fs_locations_bitmap
[0],
1247 bitmask
[1] & nfs4_fs_locations_bitmap
[1], hdr
);
1250 static void encode_getfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1252 encode_op_hdr(xdr
, OP_GETFH
, decode_getfh_maxsz
, hdr
);
1255 static void encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1257 encode_op_hdr(xdr
, OP_LINK
, decode_link_maxsz
, hdr
);
1258 encode_string(xdr
, name
->len
, name
->name
);
1261 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
1263 if (fl
->fl_type
== F_RDLCK
)
1264 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
1265 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
1268 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
1270 if (fl
->fl_end
== OFFSET_MAX
)
1271 return ~(uint64_t)0;
1272 return fl
->fl_end
- fl
->fl_start
+ 1;
1275 static void encode_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
)
1279 p
= reserve_space(xdr
, 32);
1280 p
= xdr_encode_hyper(p
, lowner
->clientid
);
1281 *p
++ = cpu_to_be32(20);
1282 p
= xdr_encode_opaque_fixed(p
, "lock id:", 8);
1283 *p
++ = cpu_to_be32(lowner
->s_dev
);
1284 xdr_encode_hyper(p
, lowner
->id
);
1288 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1289 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1291 static void encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
, struct compound_hdr
*hdr
)
1295 encode_op_hdr(xdr
, OP_LOCK
, decode_lock_maxsz
, hdr
);
1296 p
= reserve_space(xdr
, 28);
1297 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, args
->block
));
1298 *p
++ = cpu_to_be32(args
->reclaim
);
1299 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1300 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1301 *p
= cpu_to_be32(args
->new_lock_owner
);
1302 if (args
->new_lock_owner
){
1303 encode_nfs4_seqid(xdr
, args
->open_seqid
);
1304 encode_nfs4_stateid(xdr
, args
->open_stateid
);
1305 encode_nfs4_seqid(xdr
, args
->lock_seqid
);
1306 encode_lockowner(xdr
, &args
->lock_owner
);
1309 encode_nfs4_stateid(xdr
, args
->lock_stateid
);
1310 encode_nfs4_seqid(xdr
, args
->lock_seqid
);
1314 static void encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
, struct compound_hdr
*hdr
)
1318 encode_op_hdr(xdr
, OP_LOCKT
, decode_lockt_maxsz
, hdr
);
1319 p
= reserve_space(xdr
, 20);
1320 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1321 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1322 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1323 encode_lockowner(xdr
, &args
->lock_owner
);
1326 static void encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
, struct compound_hdr
*hdr
)
1330 encode_op_hdr(xdr
, OP_LOCKU
, decode_locku_maxsz
, hdr
);
1331 encode_uint32(xdr
, nfs4_lock_type(args
->fl
, 0));
1332 encode_nfs4_seqid(xdr
, args
->seqid
);
1333 encode_nfs4_stateid(xdr
, args
->stateid
);
1334 p
= reserve_space(xdr
, 16);
1335 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1336 xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1339 static void encode_release_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
, struct compound_hdr
*hdr
)
1341 encode_op_hdr(xdr
, OP_RELEASE_LOCKOWNER
, decode_release_lockowner_maxsz
, hdr
);
1342 encode_lockowner(xdr
, lowner
);
1345 static void encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1347 encode_op_hdr(xdr
, OP_LOOKUP
, decode_lookup_maxsz
, hdr
);
1348 encode_string(xdr
, name
->len
, name
->name
);
1351 static void encode_share_access(struct xdr_stream
*xdr
, fmode_t fmode
)
1355 p
= reserve_space(xdr
, 8);
1356 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1358 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ
);
1361 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE
);
1363 case FMODE_READ
|FMODE_WRITE
:
1364 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH
);
1367 *p
++ = cpu_to_be32(0);
1369 *p
= cpu_to_be32(0); /* for linux, share_deny = 0 always */
1372 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1376 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1379 encode_nfs4_seqid(xdr
, arg
->seqid
);
1380 encode_share_access(xdr
, arg
->fmode
);
1381 p
= reserve_space(xdr
, 36);
1382 p
= xdr_encode_hyper(p
, arg
->clientid
);
1383 *p
++ = cpu_to_be32(24);
1384 p
= xdr_encode_opaque_fixed(p
, "open id:", 8);
1385 *p
++ = cpu_to_be32(arg
->server
->s_dev
);
1386 *p
++ = cpu_to_be32(arg
->id
.uniquifier
);
1387 xdr_encode_hyper(p
, arg
->id
.create_time
);
1390 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1395 p
= reserve_space(xdr
, 4);
1396 switch(arg
->createmode
) {
1397 case NFS4_CREATE_UNCHECKED
:
1398 *p
= cpu_to_be32(NFS4_CREATE_UNCHECKED
);
1399 encode_attrs(xdr
, arg
->u
.attrs
, arg
->label
, arg
->server
);
1401 case NFS4_CREATE_GUARDED
:
1402 *p
= cpu_to_be32(NFS4_CREATE_GUARDED
);
1403 encode_attrs(xdr
, arg
->u
.attrs
, arg
->label
, arg
->server
);
1405 case NFS4_CREATE_EXCLUSIVE
:
1406 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE
);
1407 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1409 case NFS4_CREATE_EXCLUSIVE4_1
:
1410 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1
);
1411 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1413 encode_attrs(xdr
, &dummy
, arg
->label
, arg
->server
);
1417 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1421 p
= reserve_space(xdr
, 4);
1422 switch (arg
->open_flags
& O_CREAT
) {
1424 *p
= cpu_to_be32(NFS4_OPEN_NOCREATE
);
1427 *p
= cpu_to_be32(NFS4_OPEN_CREATE
);
1428 encode_createmode(xdr
, arg
);
1432 static inline void encode_delegation_type(struct xdr_stream
*xdr
, fmode_t delegation_type
)
1436 p
= reserve_space(xdr
, 4);
1437 switch (delegation_type
) {
1439 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_NONE
);
1442 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_READ
);
1444 case FMODE_WRITE
|FMODE_READ
:
1445 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE
);
1452 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
1456 p
= reserve_space(xdr
, 4);
1457 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_NULL
);
1458 encode_string(xdr
, name
->len
, name
->name
);
1461 static inline void encode_claim_previous(struct xdr_stream
*xdr
, fmode_t type
)
1465 p
= reserve_space(xdr
, 4);
1466 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS
);
1467 encode_delegation_type(xdr
, type
);
1470 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
1474 p
= reserve_space(xdr
, 4);
1475 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
1476 encode_nfs4_stateid(xdr
, stateid
);
1477 encode_string(xdr
, name
->len
, name
->name
);
1480 static inline void encode_claim_fh(struct xdr_stream
*xdr
)
1484 p
= reserve_space(xdr
, 4);
1485 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_FH
);
1488 static inline void encode_claim_delegate_cur_fh(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
)
1492 p
= reserve_space(xdr
, 4);
1493 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
1494 encode_nfs4_stateid(xdr
, stateid
);
1497 static void encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
, struct compound_hdr
*hdr
)
1499 encode_op_hdr(xdr
, OP_OPEN
, decode_open_maxsz
, hdr
);
1500 encode_openhdr(xdr
, arg
);
1501 encode_opentype(xdr
, arg
);
1502 switch (arg
->claim
) {
1503 case NFS4_OPEN_CLAIM_NULL
:
1504 encode_claim_null(xdr
, arg
->name
);
1506 case NFS4_OPEN_CLAIM_PREVIOUS
:
1507 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
1509 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1510 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
1512 case NFS4_OPEN_CLAIM_FH
:
1513 encode_claim_fh(xdr
);
1515 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1516 encode_claim_delegate_cur_fh(xdr
, &arg
->u
.delegation
);
1523 static void encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
, struct compound_hdr
*hdr
)
1525 encode_op_hdr(xdr
, OP_OPEN_CONFIRM
, decode_open_confirm_maxsz
, hdr
);
1526 encode_nfs4_stateid(xdr
, arg
->stateid
);
1527 encode_nfs4_seqid(xdr
, arg
->seqid
);
1530 static void encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1532 encode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
, decode_open_downgrade_maxsz
, hdr
);
1533 encode_nfs4_stateid(xdr
, arg
->stateid
);
1534 encode_nfs4_seqid(xdr
, arg
->seqid
);
1535 encode_share_access(xdr
, arg
->fmode
);
1539 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
, struct compound_hdr
*hdr
)
1541 encode_op_hdr(xdr
, OP_PUTFH
, decode_putfh_maxsz
, hdr
);
1542 encode_string(xdr
, fh
->size
, fh
->data
);
1545 static void encode_putrootfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1547 encode_op_hdr(xdr
, OP_PUTROOTFH
, decode_putrootfh_maxsz
, hdr
);
1550 static void encode_read(struct xdr_stream
*xdr
, const struct nfs_pgio_args
*args
,
1551 struct compound_hdr
*hdr
)
1555 encode_op_hdr(xdr
, OP_READ
, decode_read_maxsz
, hdr
);
1556 encode_nfs4_stateid(xdr
, &args
->stateid
);
1558 p
= reserve_space(xdr
, 12);
1559 p
= xdr_encode_hyper(p
, args
->offset
);
1560 *p
= cpu_to_be32(args
->count
);
1563 static void encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1565 uint32_t attrs
[3] = {
1566 FATTR4_WORD0_RDATTR_ERROR
,
1567 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1569 uint32_t dircount
= readdir
->count
>> 1;
1571 uint32_t attrlen
= 0;
1574 if (readdir
->plus
) {
1575 attrs
[0] |= FATTR4_WORD0_TYPE
|FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
|
1576 FATTR4_WORD0_FSID
|FATTR4_WORD0_FILEHANDLE
|FATTR4_WORD0_FILEID
;
1577 attrs
[1] |= FATTR4_WORD1_MODE
|FATTR4_WORD1_NUMLINKS
|FATTR4_WORD1_OWNER
|
1578 FATTR4_WORD1_OWNER_GROUP
|FATTR4_WORD1_RAWDEV
|
1579 FATTR4_WORD1_SPACE_USED
|FATTR4_WORD1_TIME_ACCESS
|
1580 FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
1581 attrs
[2] |= FATTR4_WORD2_SECURITY_LABEL
;
1584 /* Use mounted_on_fileid only if the server supports it */
1585 if (!(readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
))
1586 attrs
[0] |= FATTR4_WORD0_FILEID
;
1587 for (i
= 0; i
< ARRAY_SIZE(attrs
); i
++) {
1588 attrs
[i
] &= readdir
->bitmask
[i
];
1593 encode_op_hdr(xdr
, OP_READDIR
, decode_readdir_maxsz
, hdr
);
1594 encode_uint64(xdr
, readdir
->cookie
);
1595 encode_nfs4_verifier(xdr
, &readdir
->verifier
);
1596 p
= reserve_space(xdr
, 12 + (attrlen
<< 2));
1597 *p
++ = cpu_to_be32(dircount
);
1598 *p
++ = cpu_to_be32(readdir
->count
);
1599 *p
++ = cpu_to_be32(attrlen
);
1600 for (i
= 0; i
< attrlen
; i
++)
1601 *p
++ = cpu_to_be32(attrs
[i
]);
1602 memcpy(verf
, readdir
->verifier
.data
, sizeof(verf
));
1604 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1606 (unsigned long long)readdir
->cookie
,
1608 attrs
[0] & readdir
->bitmask
[0],
1609 attrs
[1] & readdir
->bitmask
[1],
1610 attrs
[2] & readdir
->bitmask
[2]);
1613 static void encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1615 encode_op_hdr(xdr
, OP_READLINK
, decode_readlink_maxsz
, hdr
);
1618 static void encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1620 encode_op_hdr(xdr
, OP_REMOVE
, decode_remove_maxsz
, hdr
);
1621 encode_string(xdr
, name
->len
, name
->name
);
1624 static void encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
, struct compound_hdr
*hdr
)
1626 encode_op_hdr(xdr
, OP_RENAME
, decode_rename_maxsz
, hdr
);
1627 encode_string(xdr
, oldname
->len
, oldname
->name
);
1628 encode_string(xdr
, newname
->len
, newname
->name
);
1631 static void encode_renew(struct xdr_stream
*xdr
, clientid4 clid
,
1632 struct compound_hdr
*hdr
)
1634 encode_op_hdr(xdr
, OP_RENEW
, decode_renew_maxsz
, hdr
);
1635 encode_uint64(xdr
, clid
);
1639 encode_restorefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1641 encode_op_hdr(xdr
, OP_RESTOREFH
, decode_restorefh_maxsz
, hdr
);
1645 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
, struct compound_hdr
*hdr
)
1649 encode_op_hdr(xdr
, OP_SETATTR
, decode_setacl_maxsz
, hdr
);
1650 encode_nfs4_stateid(xdr
, &zero_stateid
);
1651 p
= reserve_space(xdr
, 2*4);
1652 *p
++ = cpu_to_be32(1);
1653 *p
= cpu_to_be32(FATTR4_WORD0_ACL
);
1654 p
= reserve_space(xdr
, 4);
1655 *p
= cpu_to_be32(arg
->acl_len
);
1656 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1660 encode_savefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1662 encode_op_hdr(xdr
, OP_SAVEFH
, decode_savefh_maxsz
, hdr
);
1665 static void encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
, struct compound_hdr
*hdr
)
1667 encode_op_hdr(xdr
, OP_SETATTR
, decode_setattr_maxsz
, hdr
);
1668 encode_nfs4_stateid(xdr
, &arg
->stateid
);
1669 encode_attrs(xdr
, arg
->iap
, arg
->label
, server
);
1672 static void encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
, struct compound_hdr
*hdr
)
1676 encode_op_hdr(xdr
, OP_SETCLIENTID
, decode_setclientid_maxsz
, hdr
);
1677 encode_nfs4_verifier(xdr
, setclientid
->sc_verifier
);
1679 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1680 p
= reserve_space(xdr
, 4);
1681 *p
= cpu_to_be32(setclientid
->sc_prog
);
1682 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1683 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1684 p
= reserve_space(xdr
, 4);
1685 *p
= cpu_to_be32(setclientid
->sc_cb_ident
);
1688 static void encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs4_setclientid_res
*arg
, struct compound_hdr
*hdr
)
1690 encode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
,
1691 decode_setclientid_confirm_maxsz
, hdr
);
1692 encode_uint64(xdr
, arg
->clientid
);
1693 encode_nfs4_verifier(xdr
, &arg
->confirm
);
1696 static void encode_write(struct xdr_stream
*xdr
, const struct nfs_pgio_args
*args
,
1697 struct compound_hdr
*hdr
)
1701 encode_op_hdr(xdr
, OP_WRITE
, decode_write_maxsz
, hdr
);
1702 encode_nfs4_stateid(xdr
, &args
->stateid
);
1704 p
= reserve_space(xdr
, 16);
1705 p
= xdr_encode_hyper(p
, args
->offset
);
1706 *p
++ = cpu_to_be32(args
->stable
);
1707 *p
= cpu_to_be32(args
->count
);
1709 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1712 static void encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
, struct compound_hdr
*hdr
)
1714 encode_op_hdr(xdr
, OP_DELEGRETURN
, decode_delegreturn_maxsz
, hdr
);
1715 encode_nfs4_stateid(xdr
, stateid
);
1718 static void encode_secinfo(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1720 encode_op_hdr(xdr
, OP_SECINFO
, decode_secinfo_maxsz
, hdr
);
1721 encode_string(xdr
, name
->len
, name
->name
);
1724 #if defined(CONFIG_NFS_V4_1)
1725 /* NFSv4.1 operations */
1726 static void encode_bind_conn_to_session(struct xdr_stream
*xdr
,
1727 struct nfs4_session
*session
,
1728 struct compound_hdr
*hdr
)
1732 encode_op_hdr(xdr
, OP_BIND_CONN_TO_SESSION
,
1733 decode_bind_conn_to_session_maxsz
, hdr
);
1734 encode_opaque_fixed(xdr
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1735 p
= xdr_reserve_space(xdr
, 8);
1736 *p
++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH
);
1737 *p
= 0; /* use_conn_in_rdma_mode = False */
1740 static void encode_op_map(struct xdr_stream
*xdr
, struct nfs4_op_map
*op_map
)
1743 encode_uint32(xdr
, NFS4_OP_MAP_NUM_WORDS
);
1744 for (i
= 0; i
< NFS4_OP_MAP_NUM_WORDS
; i
++)
1745 encode_uint32(xdr
, op_map
->u
.words
[i
]);
1748 static void encode_exchange_id(struct xdr_stream
*xdr
,
1749 struct nfs41_exchange_id_args
*args
,
1750 struct compound_hdr
*hdr
)
1753 char impl_name
[IMPL_NAME_LIMIT
];
1756 encode_op_hdr(xdr
, OP_EXCHANGE_ID
, decode_exchange_id_maxsz
, hdr
);
1757 encode_nfs4_verifier(xdr
, args
->verifier
);
1759 encode_string(xdr
, args
->id_len
, args
->id
);
1761 encode_uint32(xdr
, args
->flags
);
1762 encode_uint32(xdr
, args
->state_protect
.how
);
1764 switch (args
->state_protect
.how
) {
1768 encode_op_map(xdr
, &args
->state_protect
.enforce
);
1769 encode_op_map(xdr
, &args
->state_protect
.allow
);
1776 if (send_implementation_id
&&
1777 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
) > 1 &&
1778 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
)
1779 <= sizeof(impl_name
) + 1)
1780 len
= snprintf(impl_name
, sizeof(impl_name
), "%s %s %s %s",
1781 utsname()->sysname
, utsname()->release
,
1782 utsname()->version
, utsname()->machine
);
1785 encode_uint32(xdr
, 1); /* implementation id array length=1 */
1788 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
) - 1,
1789 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
);
1790 encode_string(xdr
, len
, impl_name
);
1791 /* just send zeros for nii_date - the date is in nii_name */
1792 p
= reserve_space(xdr
, 12);
1793 p
= xdr_encode_hyper(p
, 0);
1794 *p
= cpu_to_be32(0);
1796 encode_uint32(xdr
, 0); /* implementation id array length=0 */
1799 static void encode_create_session(struct xdr_stream
*xdr
,
1800 struct nfs41_create_session_args
*args
,
1801 struct compound_hdr
*hdr
)
1804 char machine_name
[NFS4_MAX_MACHINE_NAME_LEN
];
1806 struct nfs_client
*clp
= args
->client
;
1807 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
1808 u32 max_resp_sz_cached
;
1811 * Assumes OPEN is the biggest non-idempotent compound.
1812 * 2 is the verifier.
1814 max_resp_sz_cached
= (NFS4_dec_open_sz
+ RPC_REPHDRSIZE
+
1815 RPC_MAX_AUTH_SIZE
+ 2) * XDR_UNIT
;
1817 len
= scnprintf(machine_name
, sizeof(machine_name
), "%s",
1820 encode_op_hdr(xdr
, OP_CREATE_SESSION
, decode_create_session_maxsz
, hdr
);
1821 p
= reserve_space(xdr
, 16 + 2*28 + 20 + len
+ 12);
1822 p
= xdr_encode_hyper(p
, clp
->cl_clientid
);
1823 *p
++ = cpu_to_be32(clp
->cl_seqid
); /*Sequence id */
1824 *p
++ = cpu_to_be32(args
->flags
); /*flags */
1827 *p
++ = cpu_to_be32(0); /* header padding size */
1828 *p
++ = cpu_to_be32(args
->fc_attrs
.max_rqst_sz
); /* max req size */
1829 *p
++ = cpu_to_be32(args
->fc_attrs
.max_resp_sz
); /* max resp size */
1830 *p
++ = cpu_to_be32(max_resp_sz_cached
); /* Max resp sz cached */
1831 *p
++ = cpu_to_be32(args
->fc_attrs
.max_ops
); /* max operations */
1832 *p
++ = cpu_to_be32(args
->fc_attrs
.max_reqs
); /* max requests */
1833 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1836 *p
++ = cpu_to_be32(0); /* header padding size */
1837 *p
++ = cpu_to_be32(args
->bc_attrs
.max_rqst_sz
); /* max req size */
1838 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz
); /* max resp size */
1839 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz_cached
); /* Max resp sz cached */
1840 *p
++ = cpu_to_be32(args
->bc_attrs
.max_ops
); /* max operations */
1841 *p
++ = cpu_to_be32(args
->bc_attrs
.max_reqs
); /* max requests */
1842 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1844 *p
++ = cpu_to_be32(args
->cb_program
); /* cb_program */
1845 *p
++ = cpu_to_be32(1);
1846 *p
++ = cpu_to_be32(RPC_AUTH_UNIX
); /* auth_sys */
1848 /* authsys_parms rfc1831 */
1849 *p
++ = cpu_to_be32(nn
->boot_time
.tv_nsec
); /* stamp */
1850 p
= xdr_encode_opaque(p
, machine_name
, len
);
1851 *p
++ = cpu_to_be32(0); /* UID */
1852 *p
++ = cpu_to_be32(0); /* GID */
1853 *p
= cpu_to_be32(0); /* No more gids */
1856 static void encode_destroy_session(struct xdr_stream
*xdr
,
1857 struct nfs4_session
*session
,
1858 struct compound_hdr
*hdr
)
1860 encode_op_hdr(xdr
, OP_DESTROY_SESSION
, decode_destroy_session_maxsz
, hdr
);
1861 encode_opaque_fixed(xdr
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1864 static void encode_destroy_clientid(struct xdr_stream
*xdr
,
1866 struct compound_hdr
*hdr
)
1868 encode_op_hdr(xdr
, OP_DESTROY_CLIENTID
, decode_destroy_clientid_maxsz
, hdr
);
1869 encode_uint64(xdr
, clientid
);
1872 static void encode_reclaim_complete(struct xdr_stream
*xdr
,
1873 struct nfs41_reclaim_complete_args
*args
,
1874 struct compound_hdr
*hdr
)
1876 encode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
, decode_reclaim_complete_maxsz
, hdr
);
1877 encode_uint32(xdr
, args
->one_fs
);
1879 #endif /* CONFIG_NFS_V4_1 */
1881 static void encode_sequence(struct xdr_stream
*xdr
,
1882 const struct nfs4_sequence_args
*args
,
1883 struct compound_hdr
*hdr
)
1885 #if defined(CONFIG_NFS_V4_1)
1886 struct nfs4_session
*session
;
1887 struct nfs4_slot_table
*tp
;
1888 struct nfs4_slot
*slot
= args
->sa_slot
;
1892 session
= tp
->session
;
1896 encode_op_hdr(xdr
, OP_SEQUENCE
, decode_sequence_maxsz
, hdr
);
1899 * Sessionid + seqid + slotid + max slotid + cache_this
1901 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1902 "max_slotid=%d cache_this=%d\n",
1904 ((u32
*)session
->sess_id
.data
)[0],
1905 ((u32
*)session
->sess_id
.data
)[1],
1906 ((u32
*)session
->sess_id
.data
)[2],
1907 ((u32
*)session
->sess_id
.data
)[3],
1908 slot
->seq_nr
, slot
->slot_nr
,
1909 tp
->highest_used_slotid
, args
->sa_cache_this
);
1910 p
= reserve_space(xdr
, NFS4_MAX_SESSIONID_LEN
+ 16);
1911 p
= xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1912 *p
++ = cpu_to_be32(slot
->seq_nr
);
1913 *p
++ = cpu_to_be32(slot
->slot_nr
);
1914 *p
++ = cpu_to_be32(tp
->highest_used_slotid
);
1915 *p
= cpu_to_be32(args
->sa_cache_this
);
1916 #endif /* CONFIG_NFS_V4_1 */
1919 #ifdef CONFIG_NFS_V4_1
1921 encode_getdeviceinfo(struct xdr_stream
*xdr
,
1922 const struct nfs4_getdeviceinfo_args
*args
,
1923 struct compound_hdr
*hdr
)
1927 encode_op_hdr(xdr
, OP_GETDEVICEINFO
, decode_getdeviceinfo_maxsz
, hdr
);
1928 p
= reserve_space(xdr
, NFS4_DEVICEID4_SIZE
+ 4 + 4);
1929 p
= xdr_encode_opaque_fixed(p
, args
->pdev
->dev_id
.data
,
1930 NFS4_DEVICEID4_SIZE
);
1931 *p
++ = cpu_to_be32(args
->pdev
->layout_type
);
1932 *p
++ = cpu_to_be32(args
->pdev
->maxcount
); /* gdia_maxcount */
1934 p
= reserve_space(xdr
, 4 + 4);
1935 *p
++ = cpu_to_be32(1); /* bitmap length */
1936 *p
++ = cpu_to_be32(NOTIFY_DEVICEID4_CHANGE
| NOTIFY_DEVICEID4_DELETE
);
1940 encode_layoutget(struct xdr_stream
*xdr
,
1941 const struct nfs4_layoutget_args
*args
,
1942 struct compound_hdr
*hdr
)
1946 encode_op_hdr(xdr
, OP_LAYOUTGET
, decode_layoutget_maxsz
, hdr
);
1947 p
= reserve_space(xdr
, 36);
1948 *p
++ = cpu_to_be32(0); /* Signal layout available */
1949 *p
++ = cpu_to_be32(args
->type
);
1950 *p
++ = cpu_to_be32(args
->range
.iomode
);
1951 p
= xdr_encode_hyper(p
, args
->range
.offset
);
1952 p
= xdr_encode_hyper(p
, args
->range
.length
);
1953 p
= xdr_encode_hyper(p
, args
->minlength
);
1954 encode_nfs4_stateid(xdr
, &args
->stateid
);
1955 encode_uint32(xdr
, args
->maxcount
);
1957 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1961 (unsigned long)args
->range
.offset
,
1962 (unsigned long)args
->range
.length
,
1967 encode_layoutcommit(struct xdr_stream
*xdr
,
1968 struct inode
*inode
,
1969 struct nfs4_layoutcommit_args
*args
,
1970 struct compound_hdr
*hdr
)
1974 dprintk("%s: lbw: %llu type: %d\n", __func__
, args
->lastbytewritten
,
1975 NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);
1977 encode_op_hdr(xdr
, OP_LAYOUTCOMMIT
, decode_layoutcommit_maxsz
, hdr
);
1978 p
= reserve_space(xdr
, 20);
1979 /* Only whole file layouts */
1980 p
= xdr_encode_hyper(p
, 0); /* offset */
1981 p
= xdr_encode_hyper(p
, args
->lastbytewritten
+ 1); /* length */
1982 *p
= cpu_to_be32(0); /* reclaim */
1983 encode_nfs4_stateid(xdr
, &args
->stateid
);
1984 p
= reserve_space(xdr
, 20);
1985 *p
++ = cpu_to_be32(1); /* newoffset = TRUE */
1986 p
= xdr_encode_hyper(p
, args
->lastbytewritten
);
1987 *p
++ = cpu_to_be32(0); /* Never send time_modify_changed */
1988 *p
++ = cpu_to_be32(NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);/* type */
1990 if (NFS_SERVER(inode
)->pnfs_curr_ld
->encode_layoutcommit
) {
1991 NFS_SERVER(inode
)->pnfs_curr_ld
->encode_layoutcommit(
1992 NFS_I(inode
)->layout
, xdr
, args
);
1994 encode_uint32(xdr
, args
->layoutupdate_len
);
1995 if (args
->layoutupdate_pages
) {
1996 xdr_write_pages(xdr
, args
->layoutupdate_pages
, 0,
1997 args
->layoutupdate_len
);
2005 encode_layoutreturn(struct xdr_stream
*xdr
,
2006 const struct nfs4_layoutreturn_args
*args
,
2007 struct compound_hdr
*hdr
)
2011 encode_op_hdr(xdr
, OP_LAYOUTRETURN
, decode_layoutreturn_maxsz
, hdr
);
2012 p
= reserve_space(xdr
, 16);
2013 *p
++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2014 *p
++ = cpu_to_be32(args
->layout_type
);
2015 *p
++ = cpu_to_be32(IOMODE_ANY
);
2016 *p
= cpu_to_be32(RETURN_FILE
);
2017 p
= reserve_space(xdr
, 16);
2018 p
= xdr_encode_hyper(p
, 0);
2019 p
= xdr_encode_hyper(p
, NFS4_MAX_UINT64
);
2020 spin_lock(&args
->inode
->i_lock
);
2021 encode_nfs4_stateid(xdr
, &args
->stateid
);
2022 spin_unlock(&args
->inode
->i_lock
);
2023 if (NFS_SERVER(args
->inode
)->pnfs_curr_ld
->encode_layoutreturn
) {
2024 NFS_SERVER(args
->inode
)->pnfs_curr_ld
->encode_layoutreturn(
2025 NFS_I(args
->inode
)->layout
, xdr
, args
);
2027 encode_uint32(xdr
, 0);
2031 encode_secinfo_no_name(struct xdr_stream
*xdr
,
2032 const struct nfs41_secinfo_no_name_args
*args
,
2033 struct compound_hdr
*hdr
)
2035 encode_op_hdr(xdr
, OP_SECINFO_NO_NAME
, decode_secinfo_no_name_maxsz
, hdr
);
2036 encode_uint32(xdr
, args
->style
);
2040 static void encode_test_stateid(struct xdr_stream
*xdr
,
2041 struct nfs41_test_stateid_args
*args
,
2042 struct compound_hdr
*hdr
)
2044 encode_op_hdr(xdr
, OP_TEST_STATEID
, decode_test_stateid_maxsz
, hdr
);
2045 encode_uint32(xdr
, 1);
2046 encode_nfs4_stateid(xdr
, args
->stateid
);
2049 static void encode_free_stateid(struct xdr_stream
*xdr
,
2050 struct nfs41_free_stateid_args
*args
,
2051 struct compound_hdr
*hdr
)
2053 encode_op_hdr(xdr
, OP_FREE_STATEID
, decode_free_stateid_maxsz
, hdr
);
2054 encode_nfs4_stateid(xdr
, &args
->stateid
);
2056 #endif /* CONFIG_NFS_V4_1 */
2059 * END OF "GENERIC" ENCODE ROUTINES.
2062 static u32
nfs4_xdr_minorversion(const struct nfs4_sequence_args
*args
)
2064 #if defined(CONFIG_NFS_V4_1)
2065 struct nfs4_session
*session
= args
->sa_slot
->table
->session
;
2067 return session
->clp
->cl_mvops
->minor_version
;
2068 #endif /* CONFIG_NFS_V4_1 */
2073 * Encode an ACCESS request
2075 static void nfs4_xdr_enc_access(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2076 const struct nfs4_accessargs
*args
)
2078 struct compound_hdr hdr
= {
2079 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2082 encode_compound_hdr(xdr
, req
, &hdr
);
2083 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2084 encode_putfh(xdr
, args
->fh
, &hdr
);
2085 encode_access(xdr
, args
->access
, &hdr
);
2086 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2091 * Encode LOOKUP request
2093 static void nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2094 const struct nfs4_lookup_arg
*args
)
2096 struct compound_hdr hdr
= {
2097 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2100 encode_compound_hdr(xdr
, req
, &hdr
);
2101 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2102 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2103 encode_lookup(xdr
, args
->name
, &hdr
);
2104 encode_getfh(xdr
, &hdr
);
2105 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2110 * Encode LOOKUP_ROOT request
2112 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
,
2113 struct xdr_stream
*xdr
,
2114 const struct nfs4_lookup_root_arg
*args
)
2116 struct compound_hdr hdr
= {
2117 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2120 encode_compound_hdr(xdr
, req
, &hdr
);
2121 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2122 encode_putrootfh(xdr
, &hdr
);
2123 encode_getfh(xdr
, &hdr
);
2124 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2129 * Encode REMOVE request
2131 static void nfs4_xdr_enc_remove(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2132 const struct nfs_removeargs
*args
)
2134 struct compound_hdr hdr
= {
2135 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2138 encode_compound_hdr(xdr
, req
, &hdr
);
2139 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2140 encode_putfh(xdr
, args
->fh
, &hdr
);
2141 encode_remove(xdr
, &args
->name
, &hdr
);
2146 * Encode RENAME request
2148 static void nfs4_xdr_enc_rename(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2149 const struct nfs_renameargs
*args
)
2151 struct compound_hdr hdr
= {
2152 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2155 encode_compound_hdr(xdr
, req
, &hdr
);
2156 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2157 encode_putfh(xdr
, args
->old_dir
, &hdr
);
2158 encode_savefh(xdr
, &hdr
);
2159 encode_putfh(xdr
, args
->new_dir
, &hdr
);
2160 encode_rename(xdr
, args
->old_name
, args
->new_name
, &hdr
);
2165 * Encode LINK request
2167 static void nfs4_xdr_enc_link(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2168 const struct nfs4_link_arg
*args
)
2170 struct compound_hdr hdr
= {
2171 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2174 encode_compound_hdr(xdr
, req
, &hdr
);
2175 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2176 encode_putfh(xdr
, args
->fh
, &hdr
);
2177 encode_savefh(xdr
, &hdr
);
2178 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2179 encode_link(xdr
, args
->name
, &hdr
);
2180 encode_restorefh(xdr
, &hdr
);
2181 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2186 * Encode CREATE request
2188 static void nfs4_xdr_enc_create(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2189 const struct nfs4_create_arg
*args
)
2191 struct compound_hdr hdr
= {
2192 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2195 encode_compound_hdr(xdr
, req
, &hdr
);
2196 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2197 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2198 encode_create(xdr
, args
, &hdr
);
2199 encode_getfh(xdr
, &hdr
);
2200 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2205 * Encode SYMLINK request
2207 static void nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2208 const struct nfs4_create_arg
*args
)
2210 nfs4_xdr_enc_create(req
, xdr
, args
);
2214 * Encode GETATTR request
2216 static void nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2217 const struct nfs4_getattr_arg
*args
)
2219 struct compound_hdr hdr
= {
2220 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2223 encode_compound_hdr(xdr
, req
, &hdr
);
2224 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2225 encode_putfh(xdr
, args
->fh
, &hdr
);
2226 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2231 * Encode a CLOSE request
2233 static void nfs4_xdr_enc_close(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2234 struct nfs_closeargs
*args
)
2236 struct compound_hdr hdr
= {
2237 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2240 encode_compound_hdr(xdr
, req
, &hdr
);
2241 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2242 encode_putfh(xdr
, args
->fh
, &hdr
);
2243 encode_close(xdr
, args
, &hdr
);
2244 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2249 * Encode an OPEN request
2251 static void nfs4_xdr_enc_open(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2252 struct nfs_openargs
*args
)
2254 struct compound_hdr hdr
= {
2255 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2258 encode_compound_hdr(xdr
, req
, &hdr
);
2259 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2260 encode_putfh(xdr
, args
->fh
, &hdr
);
2261 encode_open(xdr
, args
, &hdr
);
2262 encode_getfh(xdr
, &hdr
);
2264 encode_access(xdr
, args
->access
, &hdr
);
2265 encode_getfattr_open(xdr
, args
->bitmask
, args
->open_bitmap
, &hdr
);
2270 * Encode an OPEN_CONFIRM request
2272 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
,
2273 struct xdr_stream
*xdr
,
2274 struct nfs_open_confirmargs
*args
)
2276 struct compound_hdr hdr
= {
2280 encode_compound_hdr(xdr
, req
, &hdr
);
2281 encode_putfh(xdr
, args
->fh
, &hdr
);
2282 encode_open_confirm(xdr
, args
, &hdr
);
2287 * Encode an OPEN request with no attributes.
2289 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
,
2290 struct xdr_stream
*xdr
,
2291 struct nfs_openargs
*args
)
2293 struct compound_hdr hdr
= {
2294 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2297 encode_compound_hdr(xdr
, req
, &hdr
);
2298 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2299 encode_putfh(xdr
, args
->fh
, &hdr
);
2300 encode_open(xdr
, args
, &hdr
);
2302 encode_access(xdr
, args
->access
, &hdr
);
2303 encode_getfattr_open(xdr
, args
->bitmask
, args
->open_bitmap
, &hdr
);
2308 * Encode an OPEN_DOWNGRADE request
2310 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
,
2311 struct xdr_stream
*xdr
,
2312 struct nfs_closeargs
*args
)
2314 struct compound_hdr hdr
= {
2315 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2318 encode_compound_hdr(xdr
, req
, &hdr
);
2319 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2320 encode_putfh(xdr
, args
->fh
, &hdr
);
2321 encode_open_downgrade(xdr
, args
, &hdr
);
2322 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2327 * Encode a LOCK request
2329 static void nfs4_xdr_enc_lock(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2330 struct nfs_lock_args
*args
)
2332 struct compound_hdr hdr
= {
2333 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2336 encode_compound_hdr(xdr
, req
, &hdr
);
2337 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2338 encode_putfh(xdr
, args
->fh
, &hdr
);
2339 encode_lock(xdr
, args
, &hdr
);
2344 * Encode a LOCKT request
2346 static void nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2347 struct nfs_lockt_args
*args
)
2349 struct compound_hdr hdr
= {
2350 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2353 encode_compound_hdr(xdr
, req
, &hdr
);
2354 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2355 encode_putfh(xdr
, args
->fh
, &hdr
);
2356 encode_lockt(xdr
, args
, &hdr
);
2361 * Encode a LOCKU request
2363 static void nfs4_xdr_enc_locku(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2364 struct nfs_locku_args
*args
)
2366 struct compound_hdr hdr
= {
2367 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2370 encode_compound_hdr(xdr
, req
, &hdr
);
2371 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2372 encode_putfh(xdr
, args
->fh
, &hdr
);
2373 encode_locku(xdr
, args
, &hdr
);
2377 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst
*req
,
2378 struct xdr_stream
*xdr
,
2379 struct nfs_release_lockowner_args
*args
)
2381 struct compound_hdr hdr
= {
2385 encode_compound_hdr(xdr
, req
, &hdr
);
2386 encode_release_lockowner(xdr
, &args
->lock_owner
, &hdr
);
2391 * Encode a READLINK request
2393 static void nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2394 const struct nfs4_readlink
*args
)
2396 struct compound_hdr hdr
= {
2397 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2400 encode_compound_hdr(xdr
, req
, &hdr
);
2401 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2402 encode_putfh(xdr
, args
->fh
, &hdr
);
2403 encode_readlink(xdr
, args
, req
, &hdr
);
2405 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2406 args
->pgbase
, args
->pglen
);
2411 * Encode a READDIR request
2413 static void nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2414 const struct nfs4_readdir_arg
*args
)
2416 struct compound_hdr hdr
= {
2417 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2420 encode_compound_hdr(xdr
, req
, &hdr
);
2421 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2422 encode_putfh(xdr
, args
->fh
, &hdr
);
2423 encode_readdir(xdr
, args
, req
, &hdr
);
2425 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2426 args
->pgbase
, args
->count
);
2427 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2428 __func__
, hdr
.replen
<< 2, args
->pages
,
2429 args
->pgbase
, args
->count
);
2434 * Encode a READ request
2436 static void nfs4_xdr_enc_read(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2437 struct nfs_pgio_args
*args
)
2439 struct compound_hdr hdr
= {
2440 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2443 encode_compound_hdr(xdr
, req
, &hdr
);
2444 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2445 encode_putfh(xdr
, args
->fh
, &hdr
);
2446 encode_read(xdr
, args
, &hdr
);
2448 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2449 args
->pages
, args
->pgbase
, args
->count
);
2450 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
2455 * Encode an SETATTR request
2457 static void nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2458 struct nfs_setattrargs
*args
)
2460 struct compound_hdr hdr
= {
2461 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2464 encode_compound_hdr(xdr
, req
, &hdr
);
2465 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2466 encode_putfh(xdr
, args
->fh
, &hdr
);
2467 encode_setattr(xdr
, args
, args
->server
, &hdr
);
2468 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2473 * Encode a GETACL request
2475 static void nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2476 struct nfs_getaclargs
*args
)
2478 struct compound_hdr hdr
= {
2479 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2483 encode_compound_hdr(xdr
, req
, &hdr
);
2484 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2485 encode_putfh(xdr
, args
->fh
, &hdr
);
2486 replen
= hdr
.replen
+ op_decode_hdr_maxsz
+ 1;
2487 encode_getattr_two(xdr
, FATTR4_WORD0_ACL
, 0, &hdr
);
2489 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2,
2490 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
2496 * Encode a WRITE request
2498 static void nfs4_xdr_enc_write(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2499 struct nfs_pgio_args
*args
)
2501 struct compound_hdr hdr
= {
2502 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2505 encode_compound_hdr(xdr
, req
, &hdr
);
2506 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2507 encode_putfh(xdr
, args
->fh
, &hdr
);
2508 encode_write(xdr
, args
, &hdr
);
2509 req
->rq_snd_buf
.flags
|= XDRBUF_WRITE
;
2511 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2518 static void nfs4_xdr_enc_commit(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2519 struct nfs_commitargs
*args
)
2521 struct compound_hdr hdr
= {
2522 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2525 encode_compound_hdr(xdr
, req
, &hdr
);
2526 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2527 encode_putfh(xdr
, args
->fh
, &hdr
);
2528 encode_commit(xdr
, args
, &hdr
);
2535 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2536 struct nfs4_fsinfo_arg
*args
)
2538 struct compound_hdr hdr
= {
2539 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2542 encode_compound_hdr(xdr
, req
, &hdr
);
2543 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2544 encode_putfh(xdr
, args
->fh
, &hdr
);
2545 encode_fsinfo(xdr
, args
->bitmask
, &hdr
);
2550 * a PATHCONF request
2552 static void nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2553 const struct nfs4_pathconf_arg
*args
)
2555 struct compound_hdr hdr
= {
2556 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2559 encode_compound_hdr(xdr
, req
, &hdr
);
2560 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2561 encode_putfh(xdr
, args
->fh
, &hdr
);
2562 encode_getattr_one(xdr
, args
->bitmask
[0] & nfs4_pathconf_bitmap
[0],
2570 static void nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2571 const struct nfs4_statfs_arg
*args
)
2573 struct compound_hdr hdr
= {
2574 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2577 encode_compound_hdr(xdr
, req
, &hdr
);
2578 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2579 encode_putfh(xdr
, args
->fh
, &hdr
);
2580 encode_getattr_two(xdr
, args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
2581 args
->bitmask
[1] & nfs4_statfs_bitmap
[1], &hdr
);
2586 * GETATTR_BITMAP request
2588 static void nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
,
2589 struct xdr_stream
*xdr
,
2590 struct nfs4_server_caps_arg
*args
)
2592 struct compound_hdr hdr
= {
2593 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2596 encode_compound_hdr(xdr
, req
, &hdr
);
2597 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2598 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2599 encode_getattr_one(xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
2600 FATTR4_WORD0_FH_EXPIRE_TYPE
|
2601 FATTR4_WORD0_LINK_SUPPORT
|
2602 FATTR4_WORD0_SYMLINK_SUPPORT
|
2603 FATTR4_WORD0_ACLSUPPORT
, &hdr
);
2610 static void nfs4_xdr_enc_renew(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2611 struct nfs_client
*clp
)
2613 struct compound_hdr hdr
= {
2617 encode_compound_hdr(xdr
, req
, &hdr
);
2618 encode_renew(xdr
, clp
->cl_clientid
, &hdr
);
2623 * a SETCLIENTID request
2625 static void nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
,
2626 struct xdr_stream
*xdr
,
2627 struct nfs4_setclientid
*sc
)
2629 struct compound_hdr hdr
= {
2633 encode_compound_hdr(xdr
, req
, &hdr
);
2634 encode_setclientid(xdr
, sc
, &hdr
);
2639 * a SETCLIENTID_CONFIRM request
2641 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
,
2642 struct xdr_stream
*xdr
,
2643 struct nfs4_setclientid_res
*arg
)
2645 struct compound_hdr hdr
= {
2649 encode_compound_hdr(xdr
, req
, &hdr
);
2650 encode_setclientid_confirm(xdr
, arg
, &hdr
);
2655 * DELEGRETURN request
2657 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
,
2658 struct xdr_stream
*xdr
,
2659 const struct nfs4_delegreturnargs
*args
)
2661 struct compound_hdr hdr
= {
2662 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2665 encode_compound_hdr(xdr
, req
, &hdr
);
2666 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2667 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2668 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2669 encode_delegreturn(xdr
, args
->stateid
, &hdr
);
2674 * Encode FS_LOCATIONS request
2676 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
,
2677 struct xdr_stream
*xdr
,
2678 struct nfs4_fs_locations_arg
*args
)
2680 struct compound_hdr hdr
= {
2681 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2685 encode_compound_hdr(xdr
, req
, &hdr
);
2686 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2687 if (args
->migration
) {
2688 encode_putfh(xdr
, args
->fh
, &hdr
);
2689 replen
= hdr
.replen
;
2690 encode_fs_locations(xdr
, args
->bitmask
, &hdr
);
2692 encode_renew(xdr
, args
->clientid
, &hdr
);
2694 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2695 encode_lookup(xdr
, args
->name
, &hdr
);
2696 replen
= hdr
.replen
;
2697 encode_fs_locations(xdr
, args
->bitmask
, &hdr
);
2700 /* Set up reply kvec to capture returned fs_locations array. */
2701 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, &args
->page
,
2707 * Encode SECINFO request
2709 static void nfs4_xdr_enc_secinfo(struct rpc_rqst
*req
,
2710 struct xdr_stream
*xdr
,
2711 struct nfs4_secinfo_arg
*args
)
2713 struct compound_hdr hdr
= {
2714 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2717 encode_compound_hdr(xdr
, req
, &hdr
);
2718 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2719 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2720 encode_secinfo(xdr
, args
->name
, &hdr
);
2725 * Encode FSID_PRESENT request
2727 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst
*req
,
2728 struct xdr_stream
*xdr
,
2729 struct nfs4_fsid_present_arg
*args
)
2731 struct compound_hdr hdr
= {
2732 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2735 encode_compound_hdr(xdr
, req
, &hdr
);
2736 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2737 encode_putfh(xdr
, args
->fh
, &hdr
);
2738 encode_getfh(xdr
, &hdr
);
2740 encode_renew(xdr
, args
->clientid
, &hdr
);
2744 #if defined(CONFIG_NFS_V4_1)
2746 * BIND_CONN_TO_SESSION request
2748 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst
*req
,
2749 struct xdr_stream
*xdr
,
2750 struct nfs_client
*clp
)
2752 struct compound_hdr hdr
= {
2753 .minorversion
= clp
->cl_mvops
->minor_version
,
2756 encode_compound_hdr(xdr
, req
, &hdr
);
2757 encode_bind_conn_to_session(xdr
, clp
->cl_session
, &hdr
);
2762 * EXCHANGE_ID request
2764 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst
*req
,
2765 struct xdr_stream
*xdr
,
2766 struct nfs41_exchange_id_args
*args
)
2768 struct compound_hdr hdr
= {
2769 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2772 encode_compound_hdr(xdr
, req
, &hdr
);
2773 encode_exchange_id(xdr
, args
, &hdr
);
2778 * a CREATE_SESSION request
2780 static void nfs4_xdr_enc_create_session(struct rpc_rqst
*req
,
2781 struct xdr_stream
*xdr
,
2782 struct nfs41_create_session_args
*args
)
2784 struct compound_hdr hdr
= {
2785 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2788 encode_compound_hdr(xdr
, req
, &hdr
);
2789 encode_create_session(xdr
, args
, &hdr
);
2794 * a DESTROY_SESSION request
2796 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst
*req
,
2797 struct xdr_stream
*xdr
,
2798 struct nfs4_session
*session
)
2800 struct compound_hdr hdr
= {
2801 .minorversion
= session
->clp
->cl_mvops
->minor_version
,
2804 encode_compound_hdr(xdr
, req
, &hdr
);
2805 encode_destroy_session(xdr
, session
, &hdr
);
2810 * a DESTROY_CLIENTID request
2812 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst
*req
,
2813 struct xdr_stream
*xdr
,
2814 struct nfs_client
*clp
)
2816 struct compound_hdr hdr
= {
2817 .minorversion
= clp
->cl_mvops
->minor_version
,
2820 encode_compound_hdr(xdr
, req
, &hdr
);
2821 encode_destroy_clientid(xdr
, clp
->cl_clientid
, &hdr
);
2826 * a SEQUENCE request
2828 static void nfs4_xdr_enc_sequence(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2829 struct nfs4_sequence_args
*args
)
2831 struct compound_hdr hdr
= {
2832 .minorversion
= nfs4_xdr_minorversion(args
),
2835 encode_compound_hdr(xdr
, req
, &hdr
);
2836 encode_sequence(xdr
, args
, &hdr
);
2841 * a GET_LEASE_TIME request
2843 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst
*req
,
2844 struct xdr_stream
*xdr
,
2845 struct nfs4_get_lease_time_args
*args
)
2847 struct compound_hdr hdr
= {
2848 .minorversion
= nfs4_xdr_minorversion(&args
->la_seq_args
),
2850 const u32 lease_bitmap
[3] = { FATTR4_WORD0_LEASE_TIME
};
2852 encode_compound_hdr(xdr
, req
, &hdr
);
2853 encode_sequence(xdr
, &args
->la_seq_args
, &hdr
);
2854 encode_putrootfh(xdr
, &hdr
);
2855 encode_fsinfo(xdr
, lease_bitmap
, &hdr
);
2860 * a RECLAIM_COMPLETE request
2862 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst
*req
,
2863 struct xdr_stream
*xdr
,
2864 struct nfs41_reclaim_complete_args
*args
)
2866 struct compound_hdr hdr
= {
2867 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
)
2870 encode_compound_hdr(xdr
, req
, &hdr
);
2871 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2872 encode_reclaim_complete(xdr
, args
, &hdr
);
2877 * Encode GETDEVICEINFO request
2879 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst
*req
,
2880 struct xdr_stream
*xdr
,
2881 struct nfs4_getdeviceinfo_args
*args
)
2883 struct compound_hdr hdr
= {
2884 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2887 encode_compound_hdr(xdr
, req
, &hdr
);
2888 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2889 encode_getdeviceinfo(xdr
, args
, &hdr
);
2891 /* set up reply kvec. Subtract notification bitmap max size (2)
2892 * so that notification bitmap is put in xdr_buf tail */
2893 xdr_inline_pages(&req
->rq_rcv_buf
, (hdr
.replen
- 2) << 2,
2894 args
->pdev
->pages
, args
->pdev
->pgbase
,
2901 * Encode LAYOUTGET request
2903 static void nfs4_xdr_enc_layoutget(struct rpc_rqst
*req
,
2904 struct xdr_stream
*xdr
,
2905 struct nfs4_layoutget_args
*args
)
2907 struct compound_hdr hdr
= {
2908 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2911 encode_compound_hdr(xdr
, req
, &hdr
);
2912 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2913 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2914 encode_layoutget(xdr
, args
, &hdr
);
2916 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2917 args
->layout
.pages
, 0, args
->layout
.pglen
);
2923 * Encode LAYOUTCOMMIT request
2925 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst
*req
,
2926 struct xdr_stream
*xdr
,
2927 struct nfs4_layoutcommit_args
*args
)
2929 struct nfs4_layoutcommit_data
*data
=
2930 container_of(args
, struct nfs4_layoutcommit_data
, args
);
2931 struct compound_hdr hdr
= {
2932 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2935 encode_compound_hdr(xdr
, req
, &hdr
);
2936 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2937 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2938 encode_layoutcommit(xdr
, data
->args
.inode
, args
, &hdr
);
2939 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2944 * Encode LAYOUTRETURN request
2946 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst
*req
,
2947 struct xdr_stream
*xdr
,
2948 struct nfs4_layoutreturn_args
*args
)
2950 struct compound_hdr hdr
= {
2951 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2954 encode_compound_hdr(xdr
, req
, &hdr
);
2955 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2956 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2957 encode_layoutreturn(xdr
, args
, &hdr
);
2962 * Encode SECINFO_NO_NAME request
2964 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst
*req
,
2965 struct xdr_stream
*xdr
,
2966 struct nfs41_secinfo_no_name_args
*args
)
2968 struct compound_hdr hdr
= {
2969 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2972 encode_compound_hdr(xdr
, req
, &hdr
);
2973 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2974 encode_putrootfh(xdr
, &hdr
);
2975 encode_secinfo_no_name(xdr
, args
, &hdr
);
2981 * Encode TEST_STATEID request
2983 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst
*req
,
2984 struct xdr_stream
*xdr
,
2985 struct nfs41_test_stateid_args
*args
)
2987 struct compound_hdr hdr
= {
2988 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2991 encode_compound_hdr(xdr
, req
, &hdr
);
2992 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2993 encode_test_stateid(xdr
, args
, &hdr
);
2998 * Encode FREE_STATEID request
3000 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst
*req
,
3001 struct xdr_stream
*xdr
,
3002 struct nfs41_free_stateid_args
*args
)
3004 struct compound_hdr hdr
= {
3005 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
3008 encode_compound_hdr(xdr
, req
, &hdr
);
3009 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
3010 encode_free_stateid(xdr
, args
, &hdr
);
3013 #endif /* CONFIG_NFS_V4_1 */
3015 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
3017 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3018 "Remaining buffer length is %tu words.\n",
3019 func
, xdr
->end
- xdr
->p
);
3022 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
3026 p
= xdr_inline_decode(xdr
, 4);
3029 *len
= be32_to_cpup(p
);
3030 p
= xdr_inline_decode(xdr
, *len
);
3033 *string
= (char *)p
;
3036 print_overflow_msg(__func__
, xdr
);
3040 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
3044 p
= xdr_inline_decode(xdr
, 8);
3047 hdr
->status
= be32_to_cpup(p
++);
3048 hdr
->taglen
= be32_to_cpup(p
);
3050 p
= xdr_inline_decode(xdr
, hdr
->taglen
+ 4);
3053 hdr
->tag
= (char *)p
;
3054 p
+= XDR_QUADLEN(hdr
->taglen
);
3055 hdr
->nops
= be32_to_cpup(p
);
3056 if (unlikely(hdr
->nops
< 1))
3057 return nfs4_stat_to_errno(hdr
->status
);
3060 print_overflow_msg(__func__
, xdr
);
3064 static bool __decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
,
3071 p
= xdr_inline_decode(xdr
, 8);
3074 opnum
= be32_to_cpup(p
++);
3075 if (unlikely(opnum
!= expected
))
3076 goto out_bad_operation
;
3077 nfserr
= be32_to_cpup(p
);
3078 if (nfserr
== NFS_OK
)
3081 *nfs_retval
= nfs4_stat_to_errno(nfserr
);
3084 dprintk("nfs: Server returned operation"
3085 " %d but we issued a request for %d\n",
3087 *nfs_retval
= -EREMOTEIO
;
3090 print_overflow_msg(__func__
, xdr
);
3095 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
3099 __decode_op_hdr(xdr
, expected
, &retval
);
3104 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
3107 unsigned int strlen
;
3110 p
= xdr_inline_decode(xdr
, 12);
3112 return decode_opaque_inline(xdr
, &strlen
, &str
);
3113 print_overflow_msg(__func__
, xdr
);
3117 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
3122 p
= xdr_inline_decode(xdr
, 4);
3125 bmlen
= be32_to_cpup(p
);
3127 bitmap
[0] = bitmap
[1] = bitmap
[2] = 0;
3128 p
= xdr_inline_decode(xdr
, (bmlen
<< 2));
3132 bitmap
[0] = be32_to_cpup(p
++);
3134 bitmap
[1] = be32_to_cpup(p
++);
3136 bitmap
[2] = be32_to_cpup(p
);
3141 print_overflow_msg(__func__
, xdr
);
3145 static int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, unsigned int *savep
)
3149 p
= xdr_inline_decode(xdr
, 4);
3152 *attrlen
= be32_to_cpup(p
);
3153 *savep
= xdr_stream_pos(xdr
);
3156 print_overflow_msg(__func__
, xdr
);
3160 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
3162 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
3164 ret
= decode_attr_bitmap(xdr
, bitmask
);
3165 if (unlikely(ret
< 0))
3167 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
3169 bitmask
[0] = bitmask
[1] = bitmask
[2] = 0;
3170 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__
,
3171 bitmask
[0], bitmask
[1], bitmask
[2]);
3175 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
3181 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
3183 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
3184 p
= xdr_inline_decode(xdr
, 4);
3187 *type
= be32_to_cpup(p
);
3188 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
3189 dprintk("%s: bad type %d\n", __func__
, *type
);
3192 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
3193 ret
= NFS_ATTR_FATTR_TYPE
;
3195 dprintk("%s: type=0%o\n", __func__
, nfs_type2fmt
[*type
]);
3198 print_overflow_msg(__func__
, xdr
);
3202 static int decode_attr_fh_expire_type(struct xdr_stream
*xdr
,
3203 uint32_t *bitmap
, uint32_t *type
)
3208 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE
- 1U)))
3210 if (likely(bitmap
[0] & FATTR4_WORD0_FH_EXPIRE_TYPE
)) {
3211 p
= xdr_inline_decode(xdr
, 4);
3214 *type
= be32_to_cpup(p
);
3215 bitmap
[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE
;
3217 dprintk("%s: expire type=0x%x\n", __func__
, *type
);
3220 print_overflow_msg(__func__
, xdr
);
3224 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
3230 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
3232 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
3233 p
= xdr_inline_decode(xdr
, 8);
3236 xdr_decode_hyper(p
, change
);
3237 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
3238 ret
= NFS_ATTR_FATTR_CHANGE
;
3240 dprintk("%s: change attribute=%Lu\n", __func__
,
3241 (unsigned long long)*change
);
3244 print_overflow_msg(__func__
, xdr
);
3248 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
3254 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
3256 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
3257 p
= xdr_inline_decode(xdr
, 8);
3260 xdr_decode_hyper(p
, size
);
3261 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
3262 ret
= NFS_ATTR_FATTR_SIZE
;
3264 dprintk("%s: file size=%Lu\n", __func__
, (unsigned long long)*size
);
3267 print_overflow_msg(__func__
, xdr
);
3271 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3276 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
3278 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
3279 p
= xdr_inline_decode(xdr
, 4);
3282 *res
= be32_to_cpup(p
);
3283 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
3285 dprintk("%s: link support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3288 print_overflow_msg(__func__
, xdr
);
3292 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3297 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
3299 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
3300 p
= xdr_inline_decode(xdr
, 4);
3303 *res
= be32_to_cpup(p
);
3304 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
3306 dprintk("%s: symlink support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3309 print_overflow_msg(__func__
, xdr
);
3313 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
3320 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
3322 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
3323 p
= xdr_inline_decode(xdr
, 16);
3326 p
= xdr_decode_hyper(p
, &fsid
->major
);
3327 xdr_decode_hyper(p
, &fsid
->minor
);
3328 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
3329 ret
= NFS_ATTR_FATTR_FSID
;
3331 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__
,
3332 (unsigned long long)fsid
->major
,
3333 (unsigned long long)fsid
->minor
);
3336 print_overflow_msg(__func__
, xdr
);
3340 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3345 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
3347 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
3348 p
= xdr_inline_decode(xdr
, 4);
3351 *res
= be32_to_cpup(p
);
3352 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
3354 dprintk("%s: file size=%u\n", __func__
, (unsigned int)*res
);
3357 print_overflow_msg(__func__
, xdr
);
3361 static int decode_attr_error(struct xdr_stream
*xdr
, uint32_t *bitmap
, int32_t *res
)
3365 if (unlikely(bitmap
[0] & (FATTR4_WORD0_RDATTR_ERROR
- 1U)))
3367 if (likely(bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
)) {
3368 p
= xdr_inline_decode(xdr
, 4);
3371 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
3372 *res
= -be32_to_cpup(p
);
3376 print_overflow_msg(__func__
, xdr
);
3380 static int decode_attr_filehandle(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fh
*fh
)
3386 memset(fh
, 0, sizeof(*fh
));
3388 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEHANDLE
- 1U)))
3390 if (likely(bitmap
[0] & FATTR4_WORD0_FILEHANDLE
)) {
3391 p
= xdr_inline_decode(xdr
, 4);
3394 len
= be32_to_cpup(p
);
3395 if (len
> NFS4_FHSIZE
)
3397 p
= xdr_inline_decode(xdr
, len
);
3401 memcpy(fh
->data
, p
, len
);
3404 bitmap
[0] &= ~FATTR4_WORD0_FILEHANDLE
;
3408 print_overflow_msg(__func__
, xdr
);
3412 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3417 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
3419 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
3420 p
= xdr_inline_decode(xdr
, 4);
3423 *res
= be32_to_cpup(p
);
3424 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
3426 dprintk("%s: ACLs supported=%u\n", __func__
, (unsigned int)*res
);
3429 print_overflow_msg(__func__
, xdr
);
3433 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3439 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
3441 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
3442 p
= xdr_inline_decode(xdr
, 8);
3445 xdr_decode_hyper(p
, fileid
);
3446 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
3447 ret
= NFS_ATTR_FATTR_FILEID
;
3449 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3452 print_overflow_msg(__func__
, xdr
);
3456 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3462 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
3464 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
3465 p
= xdr_inline_decode(xdr
, 8);
3468 xdr_decode_hyper(p
, fileid
);
3469 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
3470 ret
= NFS_ATTR_FATTR_MOUNTED_ON_FILEID
;
3472 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3475 print_overflow_msg(__func__
, xdr
);
3479 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3485 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
3487 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
3488 p
= xdr_inline_decode(xdr
, 8);
3491 xdr_decode_hyper(p
, res
);
3492 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
3494 dprintk("%s: files avail=%Lu\n", __func__
, (unsigned long long)*res
);
3497 print_overflow_msg(__func__
, xdr
);
3501 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3507 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
3509 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
3510 p
= xdr_inline_decode(xdr
, 8);
3513 xdr_decode_hyper(p
, res
);
3514 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
3516 dprintk("%s: files free=%Lu\n", __func__
, (unsigned long long)*res
);
3519 print_overflow_msg(__func__
, xdr
);
3523 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3529 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
3531 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
3532 p
= xdr_inline_decode(xdr
, 8);
3535 xdr_decode_hyper(p
, res
);
3536 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
3538 dprintk("%s: files total=%Lu\n", __func__
, (unsigned long long)*res
);
3541 print_overflow_msg(__func__
, xdr
);
3545 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
3551 p
= xdr_inline_decode(xdr
, 4);
3554 n
= be32_to_cpup(p
);
3557 dprintk("pathname4: ");
3558 if (n
> NFS4_PATHNAME_MAXCOMPONENTS
) {
3559 dprintk("cannot parse %d components in path\n", n
);
3562 for (path
->ncomponents
= 0; path
->ncomponents
< n
; path
->ncomponents
++) {
3563 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
3564 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
3565 if (unlikely(status
!= 0))
3569 (path
->ncomponents
!= n
? "/ " : ""),
3570 component
->len
, component
->data
);
3575 /* a root pathname is sent as a zero component4 */
3576 path
->ncomponents
= 1;
3577 path
->components
[0].len
=0;
3578 path
->components
[0].data
=NULL
;
3579 dprintk("pathname4: /\n");
3582 dprintk(" status %d", status
);
3586 print_overflow_msg(__func__
, xdr
);
3590 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
3596 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
3599 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
3602 /* Ignore borken servers that return unrequested attrs */
3603 if (unlikely(res
== NULL
))
3605 dprintk("%s: fsroot:\n", __func__
);
3606 status
= decode_pathname(xdr
, &res
->fs_path
);
3607 if (unlikely(status
!= 0))
3609 p
= xdr_inline_decode(xdr
, 4);
3612 n
= be32_to_cpup(p
);
3615 for (res
->nlocations
= 0; res
->nlocations
< n
; res
->nlocations
++) {
3617 struct nfs4_fs_location
*loc
;
3619 if (res
->nlocations
== NFS4_FS_LOCATIONS_MAXENTRIES
)
3621 loc
= &res
->locations
[res
->nlocations
];
3622 p
= xdr_inline_decode(xdr
, 4);
3625 m
= be32_to_cpup(p
);
3627 dprintk("%s: servers:\n", __func__
);
3628 for (loc
->nservers
= 0; loc
->nservers
< m
; loc
->nservers
++) {
3629 struct nfs4_string
*server
;
3631 if (loc
->nservers
== NFS4_FS_LOCATION_MAXSERVERS
) {
3633 dprintk("%s: using first %u of %u servers "
3634 "returned for location %u\n",
3636 NFS4_FS_LOCATION_MAXSERVERS
,
3637 m
, res
->nlocations
);
3638 for (i
= loc
->nservers
; i
< m
; i
++) {
3641 status
= decode_opaque_inline(xdr
, &len
, &data
);
3642 if (unlikely(status
!= 0))
3647 server
= &loc
->servers
[loc
->nservers
];
3648 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
3649 if (unlikely(status
!= 0))
3651 dprintk("%s ", server
->data
);
3653 status
= decode_pathname(xdr
, &loc
->rootpath
);
3654 if (unlikely(status
!= 0))
3657 if (res
->nlocations
!= 0)
3658 status
= NFS_ATTR_FATTR_V4_LOCATIONS
;
3660 dprintk("%s: fs_locations done, error = %d\n", __func__
, status
);
3663 print_overflow_msg(__func__
, xdr
);
3669 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3675 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
3677 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
3678 p
= xdr_inline_decode(xdr
, 8);
3681 xdr_decode_hyper(p
, res
);
3682 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
3684 dprintk("%s: maxfilesize=%Lu\n", __func__
, (unsigned long long)*res
);
3687 print_overflow_msg(__func__
, xdr
);
3691 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
3697 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
3699 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
3700 p
= xdr_inline_decode(xdr
, 4);
3703 *maxlink
= be32_to_cpup(p
);
3704 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
3706 dprintk("%s: maxlink=%u\n", __func__
, *maxlink
);
3709 print_overflow_msg(__func__
, xdr
);
3713 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
3719 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
3721 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
3722 p
= xdr_inline_decode(xdr
, 4);
3725 *maxname
= be32_to_cpup(p
);
3726 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
3728 dprintk("%s: maxname=%u\n", __func__
, *maxname
);
3731 print_overflow_msg(__func__
, xdr
);
3735 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3741 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
3743 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
3745 p
= xdr_inline_decode(xdr
, 8);
3748 xdr_decode_hyper(p
, &maxread
);
3749 if (maxread
> 0x7FFFFFFF)
3750 maxread
= 0x7FFFFFFF;
3751 *res
= (uint32_t)maxread
;
3752 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
3754 dprintk("%s: maxread=%lu\n", __func__
, (unsigned long)*res
);
3757 print_overflow_msg(__func__
, xdr
);
3761 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3767 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
3769 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
3771 p
= xdr_inline_decode(xdr
, 8);
3774 xdr_decode_hyper(p
, &maxwrite
);
3775 if (maxwrite
> 0x7FFFFFFF)
3776 maxwrite
= 0x7FFFFFFF;
3777 *res
= (uint32_t)maxwrite
;
3778 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
3780 dprintk("%s: maxwrite=%lu\n", __func__
, (unsigned long)*res
);
3783 print_overflow_msg(__func__
, xdr
);
3787 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, umode_t
*mode
)
3794 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
3796 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
3797 p
= xdr_inline_decode(xdr
, 4);
3800 tmp
= be32_to_cpup(p
);
3801 *mode
= tmp
& ~S_IFMT
;
3802 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
3803 ret
= NFS_ATTR_FATTR_MODE
;
3805 dprintk("%s: file mode=0%o\n", __func__
, (unsigned int)*mode
);
3808 print_overflow_msg(__func__
, xdr
);
3812 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
3818 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
3820 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
3821 p
= xdr_inline_decode(xdr
, 4);
3824 *nlink
= be32_to_cpup(p
);
3825 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
3826 ret
= NFS_ATTR_FATTR_NLINK
;
3828 dprintk("%s: nlink=%u\n", __func__
, (unsigned int)*nlink
);
3831 print_overflow_msg(__func__
, xdr
);
3835 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3836 const struct nfs_server
*server
, kuid_t
*uid
,
3837 struct nfs4_string
*owner_name
)
3843 *uid
= make_kuid(&init_user_ns
, -2);
3844 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
3846 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
3847 p
= xdr_inline_decode(xdr
, 4);
3850 len
= be32_to_cpup(p
);
3851 p
= xdr_inline_decode(xdr
, len
);
3854 if (owner_name
!= NULL
) {
3855 owner_name
->data
= kmemdup(p
, len
, GFP_NOWAIT
);
3856 if (owner_name
->data
!= NULL
) {
3857 owner_name
->len
= len
;
3858 ret
= NFS_ATTR_FATTR_OWNER_NAME
;
3860 } else if (len
< XDR_MAX_NETOBJ
) {
3861 if (nfs_map_name_to_uid(server
, (char *)p
, len
, uid
) == 0)
3862 ret
= NFS_ATTR_FATTR_OWNER
;
3864 dprintk("%s: nfs_map_name_to_uid failed!\n",
3867 dprintk("%s: name too long (%u)!\n",
3869 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
3871 dprintk("%s: uid=%d\n", __func__
, (int)from_kuid(&init_user_ns
, *uid
));
3874 print_overflow_msg(__func__
, xdr
);
3878 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3879 const struct nfs_server
*server
, kgid_t
*gid
,
3880 struct nfs4_string
*group_name
)
3886 *gid
= make_kgid(&init_user_ns
, -2);
3887 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
3889 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
3890 p
= xdr_inline_decode(xdr
, 4);
3893 len
= be32_to_cpup(p
);
3894 p
= xdr_inline_decode(xdr
, len
);
3897 if (group_name
!= NULL
) {
3898 group_name
->data
= kmemdup(p
, len
, GFP_NOWAIT
);
3899 if (group_name
->data
!= NULL
) {
3900 group_name
->len
= len
;
3901 ret
= NFS_ATTR_FATTR_GROUP_NAME
;
3903 } else if (len
< XDR_MAX_NETOBJ
) {
3904 if (nfs_map_group_to_gid(server
, (char *)p
, len
, gid
) == 0)
3905 ret
= NFS_ATTR_FATTR_GROUP
;
3907 dprintk("%s: nfs_map_group_to_gid failed!\n",
3910 dprintk("%s: name too long (%u)!\n",
3912 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
3914 dprintk("%s: gid=%d\n", __func__
, (int)from_kgid(&init_user_ns
, *gid
));
3917 print_overflow_msg(__func__
, xdr
);
3921 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
3923 uint32_t major
= 0, minor
= 0;
3928 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
3930 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
3933 p
= xdr_inline_decode(xdr
, 8);
3936 major
= be32_to_cpup(p
++);
3937 minor
= be32_to_cpup(p
);
3938 tmp
= MKDEV(major
, minor
);
3939 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
3941 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
3942 ret
= NFS_ATTR_FATTR_RDEV
;
3944 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__
, major
, minor
);
3947 print_overflow_msg(__func__
, xdr
);
3951 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3957 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
3959 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
3960 p
= xdr_inline_decode(xdr
, 8);
3963 xdr_decode_hyper(p
, res
);
3964 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
3966 dprintk("%s: space avail=%Lu\n", __func__
, (unsigned long long)*res
);
3969 print_overflow_msg(__func__
, xdr
);
3973 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3979 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
3981 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
3982 p
= xdr_inline_decode(xdr
, 8);
3985 xdr_decode_hyper(p
, res
);
3986 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
3988 dprintk("%s: space free=%Lu\n", __func__
, (unsigned long long)*res
);
3991 print_overflow_msg(__func__
, xdr
);
3995 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
4001 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
4003 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
4004 p
= xdr_inline_decode(xdr
, 8);
4007 xdr_decode_hyper(p
, res
);
4008 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
4010 dprintk("%s: space total=%Lu\n", __func__
, (unsigned long long)*res
);
4013 print_overflow_msg(__func__
, xdr
);
4017 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
4023 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
4025 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
4026 p
= xdr_inline_decode(xdr
, 8);
4029 xdr_decode_hyper(p
, used
);
4030 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
4031 ret
= NFS_ATTR_FATTR_SPACE_USED
;
4033 dprintk("%s: space used=%Lu\n", __func__
,
4034 (unsigned long long)*used
);
4037 print_overflow_msg(__func__
, xdr
);
4041 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
4047 p
= xdr_inline_decode(xdr
, 12);
4050 p
= xdr_decode_hyper(p
, &sec
);
4051 nsec
= be32_to_cpup(p
);
4052 time
->tv_sec
= (time_t)sec
;
4053 time
->tv_nsec
= (long)nsec
;
4056 print_overflow_msg(__func__
, xdr
);
4060 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4066 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
4068 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
4069 status
= decode_attr_time(xdr
, time
);
4071 status
= NFS_ATTR_FATTR_ATIME
;
4072 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
4074 dprintk("%s: atime=%ld\n", __func__
, (long)time
->tv_sec
);
4078 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4084 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
4086 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
4087 status
= decode_attr_time(xdr
, time
);
4089 status
= NFS_ATTR_FATTR_CTIME
;
4090 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
4092 dprintk("%s: ctime=%ld\n", __func__
, (long)time
->tv_sec
);
4096 static int decode_attr_time_delta(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4097 struct timespec
*time
)
4103 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_DELTA
- 1U)))
4105 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_DELTA
)) {
4106 status
= decode_attr_time(xdr
, time
);
4107 bitmap
[1] &= ~FATTR4_WORD1_TIME_DELTA
;
4109 dprintk("%s: time_delta=%ld %ld\n", __func__
, (long)time
->tv_sec
,
4110 (long)time
->tv_nsec
);
4114 static int decode_attr_security_label(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4115 struct nfs4_label
*label
)
4123 if (unlikely(bitmap
[2] & (FATTR4_WORD2_SECURITY_LABEL
- 1U)))
4125 if (likely(bitmap
[2] & FATTR4_WORD2_SECURITY_LABEL
)) {
4126 p
= xdr_inline_decode(xdr
, 4);
4129 lfs
= be32_to_cpup(p
++);
4130 p
= xdr_inline_decode(xdr
, 4);
4133 pi
= be32_to_cpup(p
++);
4134 p
= xdr_inline_decode(xdr
, 4);
4137 len
= be32_to_cpup(p
++);
4138 p
= xdr_inline_decode(xdr
, len
);
4141 if (len
< NFS4_MAXLABELLEN
) {
4143 memcpy(label
->label
, p
, len
);
4147 status
= NFS_ATTR_FATTR_V4_SECURITY_LABEL
;
4149 bitmap
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
4151 printk(KERN_WARNING
"%s: label too long (%u)!\n",
4154 if (label
&& label
->label
)
4155 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__
,
4156 (char *)label
->label
, label
->len
, label
->pi
, label
->lfs
);
4160 print_overflow_msg(__func__
, xdr
);
4164 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4170 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
4172 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
4173 status
= decode_attr_time(xdr
, time
);
4175 status
= NFS_ATTR_FATTR_MTIME
;
4176 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
4178 dprintk("%s: mtime=%ld\n", __func__
, (long)time
->tv_sec
);
4182 static int verify_attr_len(struct xdr_stream
*xdr
, unsigned int savep
, uint32_t attrlen
)
4184 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
4185 unsigned int nwords
= (xdr_stream_pos(xdr
) - savep
) >> 2;
4187 if (unlikely(attrwords
!= nwords
)) {
4188 dprintk("%s: server returned incorrect attribute length: "
4192 (attrwords
< nwords
) ? '<' : '>',
4199 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4203 p
= xdr_inline_decode(xdr
, 20);
4206 cinfo
->atomic
= be32_to_cpup(p
++);
4207 p
= xdr_decode_hyper(p
, &cinfo
->before
);
4208 xdr_decode_hyper(p
, &cinfo
->after
);
4211 print_overflow_msg(__func__
, xdr
);
4215 static int decode_access(struct xdr_stream
*xdr
, u32
*supported
, u32
*access
)
4221 status
= decode_op_hdr(xdr
, OP_ACCESS
);
4224 p
= xdr_inline_decode(xdr
, 8);
4227 supp
= be32_to_cpup(p
++);
4228 acc
= be32_to_cpup(p
);
4233 print_overflow_msg(__func__
, xdr
);
4237 static int decode_opaque_fixed(struct xdr_stream
*xdr
, void *buf
, size_t len
)
4241 p
= xdr_inline_decode(xdr
, len
);
4243 memcpy(buf
, p
, len
);
4246 print_overflow_msg(__func__
, xdr
);
4250 static int decode_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
4252 return decode_opaque_fixed(xdr
, stateid
, NFS4_STATEID_SIZE
);
4255 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4259 status
= decode_op_hdr(xdr
, OP_CLOSE
);
4261 nfs_increment_open_seqid(status
, res
->seqid
);
4263 status
= decode_stateid(xdr
, &res
->stateid
);
4267 static int decode_verifier(struct xdr_stream
*xdr
, void *verifier
)
4269 return decode_opaque_fixed(xdr
, verifier
, NFS4_VERIFIER_SIZE
);
4272 static int decode_write_verifier(struct xdr_stream
*xdr
, struct nfs_write_verifier
*verifier
)
4274 return decode_opaque_fixed(xdr
, verifier
->data
, NFS4_VERIFIER_SIZE
);
4277 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_commitres
*res
)
4281 status
= decode_op_hdr(xdr
, OP_COMMIT
);
4283 status
= decode_write_verifier(xdr
, &res
->verf
->verifier
);
4287 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4293 status
= decode_op_hdr(xdr
, OP_CREATE
);
4296 if ((status
= decode_change_info(xdr
, cinfo
)))
4298 p
= xdr_inline_decode(xdr
, 4);
4301 bmlen
= be32_to_cpup(p
);
4302 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4306 print_overflow_msg(__func__
, xdr
);
4310 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
4313 uint32_t attrlen
, bitmap
[3] = {0};
4316 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4318 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4320 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4322 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
4324 if ((status
= decode_attr_fh_expire_type(xdr
, bitmap
,
4325 &res
->fh_expire_type
)) != 0)
4327 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
4329 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
4331 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
4333 status
= verify_attr_len(xdr
, savep
, attrlen
);
4335 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4339 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
4342 uint32_t attrlen
, bitmap
[3] = {0};
4345 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4347 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4349 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4352 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
4354 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
4356 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
4358 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
4360 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
4362 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
4365 status
= verify_attr_len(xdr
, savep
, attrlen
);
4367 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4371 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
4374 uint32_t attrlen
, bitmap
[3] = {0};
4377 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4379 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4381 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4384 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
4386 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
4389 status
= verify_attr_len(xdr
, savep
, attrlen
);
4391 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4395 static int decode_threshold_hint(struct xdr_stream
*xdr
,
4403 if (likely(bitmap
[0] & hint_bit
)) {
4404 p
= xdr_inline_decode(xdr
, 8);
4407 xdr_decode_hyper(p
, res
);
4411 print_overflow_msg(__func__
, xdr
);
4415 static int decode_first_threshold_item4(struct xdr_stream
*xdr
,
4416 struct nfs4_threshold
*res
)
4420 uint32_t bitmap
[3] = {0,}, attrlen
;
4424 p
= xdr_inline_decode(xdr
, 4);
4426 print_overflow_msg(__func__
, xdr
);
4429 res
->l_type
= be32_to_cpup(p
);
4431 /* thi_hintset bitmap */
4432 status
= decode_attr_bitmap(xdr
, bitmap
);
4436 /* thi_hintlist length */
4437 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
4441 status
= decode_threshold_hint(xdr
, bitmap
, &res
->rd_sz
, THRESHOLD_RD
);
4444 status
= decode_threshold_hint(xdr
, bitmap
, &res
->wr_sz
, THRESHOLD_WR
);
4447 status
= decode_threshold_hint(xdr
, bitmap
, &res
->rd_io_sz
,
4451 status
= decode_threshold_hint(xdr
, bitmap
, &res
->wr_io_sz
,
4456 status
= verify_attr_len(xdr
, savep
, attrlen
);
4457 res
->bm
= bitmap
[0];
4459 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4460 __func__
, res
->bm
, res
->rd_sz
, res
->wr_sz
, res
->rd_io_sz
,
4463 dprintk("%s ret=%d!\n", __func__
, status
);
4468 * Thresholds on pNFS direct I/O vrs MDS I/O
4470 static int decode_attr_mdsthreshold(struct xdr_stream
*xdr
,
4472 struct nfs4_threshold
*res
)
4478 if (unlikely(bitmap
[2] & (FATTR4_WORD2_MDSTHRESHOLD
- 1U)))
4480 if (bitmap
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
4481 /* Did the server return an unrequested attribute? */
4482 if (unlikely(res
== NULL
))
4484 p
= xdr_inline_decode(xdr
, 4);
4487 num
= be32_to_cpup(p
);
4491 printk(KERN_INFO
"%s: Warning: Multiple pNFS layout "
4492 "drivers per filesystem not supported\n",
4495 status
= decode_first_threshold_item4(xdr
, res
);
4496 bitmap
[2] &= ~FATTR4_WORD2_MDSTHRESHOLD
;
4500 print_overflow_msg(__func__
, xdr
);
4504 static int decode_getfattr_attrs(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4505 struct nfs_fattr
*fattr
, struct nfs_fh
*fh
,
4506 struct nfs4_fs_locations
*fs_loc
, struct nfs4_label
*label
,
4507 const struct nfs_server
*server
)
4514 status
= decode_attr_type(xdr
, bitmap
, &type
);
4519 fattr
->mode
|= nfs_type2fmt
[type
];
4520 fattr
->valid
|= status
;
4523 status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
);
4526 fattr
->valid
|= status
;
4528 status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
);
4531 fattr
->valid
|= status
;
4533 status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
);
4536 fattr
->valid
|= status
;
4539 status
= decode_attr_error(xdr
, bitmap
, &err
);
4543 status
= decode_attr_filehandle(xdr
, bitmap
, fh
);
4547 status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
);
4550 fattr
->valid
|= status
;
4552 status
= decode_attr_fs_locations(xdr
, bitmap
, fs_loc
);
4555 fattr
->valid
|= status
;
4557 status
= decode_attr_mode(xdr
, bitmap
, &fmode
);
4561 fattr
->mode
|= fmode
;
4562 fattr
->valid
|= status
;
4565 status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
);
4568 fattr
->valid
|= status
;
4570 status
= decode_attr_owner(xdr
, bitmap
, server
, &fattr
->uid
, fattr
->owner_name
);
4573 fattr
->valid
|= status
;
4575 status
= decode_attr_group(xdr
, bitmap
, server
, &fattr
->gid
, fattr
->group_name
);
4578 fattr
->valid
|= status
;
4580 status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
);
4583 fattr
->valid
|= status
;
4585 status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
);
4588 fattr
->valid
|= status
;
4590 status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
);
4593 fattr
->valid
|= status
;
4595 status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
);
4598 fattr
->valid
|= status
;
4600 status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
);
4603 fattr
->valid
|= status
;
4605 status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fattr
->mounted_on_fileid
);
4608 fattr
->valid
|= status
;
4610 status
= decode_attr_mdsthreshold(xdr
, bitmap
, fattr
->mdsthreshold
);
4615 status
= decode_attr_security_label(xdr
, bitmap
, label
);
4618 fattr
->valid
|= status
;
4622 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4626 static int decode_getfattr_generic(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4627 struct nfs_fh
*fh
, struct nfs4_fs_locations
*fs_loc
,
4628 struct nfs4_label
*label
, const struct nfs_server
*server
)
4635 status
= decode_op_hdr(xdr
, OP_GETATTR
);
4639 status
= decode_attr_bitmap(xdr
, bitmap
);
4643 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
4647 status
= decode_getfattr_attrs(xdr
, bitmap
, fattr
, fh
, fs_loc
,
4652 status
= verify_attr_len(xdr
, savep
, attrlen
);
4654 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4658 static int decode_getfattr_label(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4659 struct nfs4_label
*label
, const struct nfs_server
*server
)
4661 return decode_getfattr_generic(xdr
, fattr
, NULL
, NULL
, label
, server
);
4664 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4665 const struct nfs_server
*server
)
4667 return decode_getfattr_generic(xdr
, fattr
, NULL
, NULL
, NULL
, server
);
4671 * Decode potentially multiple layout types. Currently we only support
4672 * one layout driver per file system.
4674 static int decode_first_pnfs_layout_type(struct xdr_stream
*xdr
,
4675 uint32_t *layouttype
)
4680 p
= xdr_inline_decode(xdr
, 4);
4683 num
= be32_to_cpup(p
);
4685 /* pNFS is not supported by the underlying file system */
4691 printk(KERN_INFO
"NFS: %s: Warning: Multiple pNFS layout "
4692 "drivers per filesystem not supported\n", __func__
);
4694 /* Decode and set first layout type, move xdr->p past unused types */
4695 p
= xdr_inline_decode(xdr
, num
* 4);
4698 *layouttype
= be32_to_cpup(p
);
4701 print_overflow_msg(__func__
, xdr
);
4706 * The type of file system exported.
4707 * Note we must ensure that layouttype is set in any non-error case.
4709 static int decode_attr_pnfstype(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4710 uint32_t *layouttype
)
4714 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[1]);
4715 if (unlikely(bitmap
[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES
- 1U)))
4717 if (bitmap
[1] & FATTR4_WORD1_FS_LAYOUT_TYPES
) {
4718 status
= decode_first_pnfs_layout_type(xdr
, layouttype
);
4719 bitmap
[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES
;
4726 * The prefered block size for layout directed io
4728 static int decode_attr_layout_blksize(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4733 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[2]);
4735 if (bitmap
[2] & FATTR4_WORD2_LAYOUT_BLKSIZE
) {
4736 p
= xdr_inline_decode(xdr
, 4);
4738 print_overflow_msg(__func__
, xdr
);
4741 *res
= be32_to_cpup(p
);
4742 bitmap
[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE
;
4747 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
4750 uint32_t attrlen
, bitmap
[3];
4753 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4755 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4757 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4760 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
4762 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
4764 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
4766 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
4768 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
4769 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
4771 fsinfo
->wtpref
= fsinfo
->wtmax
;
4772 status
= decode_attr_time_delta(xdr
, bitmap
, &fsinfo
->time_delta
);
4775 status
= decode_attr_pnfstype(xdr
, bitmap
, &fsinfo
->layouttype
);
4778 status
= decode_attr_layout_blksize(xdr
, bitmap
, &fsinfo
->blksize
);
4782 status
= verify_attr_len(xdr
, savep
, attrlen
);
4784 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4788 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
4794 /* Zero handle first to allow comparisons */
4795 memset(fh
, 0, sizeof(*fh
));
4797 status
= decode_op_hdr(xdr
, OP_GETFH
);
4801 p
= xdr_inline_decode(xdr
, 4);
4804 len
= be32_to_cpup(p
);
4805 if (len
> NFS4_FHSIZE
)
4808 p
= xdr_inline_decode(xdr
, len
);
4811 memcpy(fh
->data
, p
, len
);
4814 print_overflow_msg(__func__
, xdr
);
4818 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4822 status
= decode_op_hdr(xdr
, OP_LINK
);
4825 return decode_change_info(xdr
, cinfo
);
4829 * We create the owner, so we know a proper owner.id length is 4.
4831 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
4833 uint64_t offset
, length
, clientid
;
4835 uint32_t namelen
, type
;
4837 p
= xdr_inline_decode(xdr
, 32); /* read 32 bytes */
4840 p
= xdr_decode_hyper(p
, &offset
); /* read 2 8-byte long words */
4841 p
= xdr_decode_hyper(p
, &length
);
4842 type
= be32_to_cpup(p
++); /* 4 byte read */
4843 if (fl
!= NULL
) { /* manipulate file lock */
4844 fl
->fl_start
= (loff_t
)offset
;
4845 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
4846 if (length
== ~(uint64_t)0)
4847 fl
->fl_end
= OFFSET_MAX
;
4848 fl
->fl_type
= F_WRLCK
;
4850 fl
->fl_type
= F_RDLCK
;
4853 p
= xdr_decode_hyper(p
, &clientid
); /* read 8 bytes */
4854 namelen
= be32_to_cpup(p
); /* read 4 bytes */ /* have read all 32 bytes now */
4855 p
= xdr_inline_decode(xdr
, namelen
); /* variable size field */
4857 return -NFS4ERR_DENIED
;
4859 print_overflow_msg(__func__
, xdr
);
4863 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
4867 status
= decode_op_hdr(xdr
, OP_LOCK
);
4871 status
= decode_stateid(xdr
, &res
->stateid
);
4872 if (unlikely(status
))
4874 } else if (status
== -NFS4ERR_DENIED
)
4875 status
= decode_lock_denied(xdr
, NULL
);
4876 if (res
->open_seqid
!= NULL
)
4877 nfs_increment_open_seqid(status
, res
->open_seqid
);
4878 nfs_increment_lock_seqid(status
, res
->lock_seqid
);
4883 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
4886 status
= decode_op_hdr(xdr
, OP_LOCKT
);
4887 if (status
== -NFS4ERR_DENIED
)
4888 return decode_lock_denied(xdr
, res
->denied
);
4892 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
4896 status
= decode_op_hdr(xdr
, OP_LOCKU
);
4898 nfs_increment_lock_seqid(status
, res
->seqid
);
4900 status
= decode_stateid(xdr
, &res
->stateid
);
4904 static int decode_release_lockowner(struct xdr_stream
*xdr
)
4906 return decode_op_hdr(xdr
, OP_RELEASE_LOCKOWNER
);
4909 static int decode_lookup(struct xdr_stream
*xdr
)
4911 return decode_op_hdr(xdr
, OP_LOOKUP
);
4914 /* This is too sick! */
4915 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
4918 uint32_t limit_type
, nblocks
, blocksize
;
4920 p
= xdr_inline_decode(xdr
, 12);
4923 limit_type
= be32_to_cpup(p
++);
4924 switch (limit_type
) {
4926 xdr_decode_hyper(p
, maxsize
);
4929 nblocks
= be32_to_cpup(p
++);
4930 blocksize
= be32_to_cpup(p
);
4931 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
4935 print_overflow_msg(__func__
, xdr
);
4939 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4942 uint32_t delegation_type
;
4945 p
= xdr_inline_decode(xdr
, 4);
4948 delegation_type
= be32_to_cpup(p
);
4949 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
4950 res
->delegation_type
= 0;
4953 status
= decode_stateid(xdr
, &res
->delegation
);
4954 if (unlikely(status
))
4956 p
= xdr_inline_decode(xdr
, 4);
4959 res
->do_recall
= be32_to_cpup(p
);
4961 switch (delegation_type
) {
4962 case NFS4_OPEN_DELEGATE_READ
:
4963 res
->delegation_type
= FMODE_READ
;
4965 case NFS4_OPEN_DELEGATE_WRITE
:
4966 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
4967 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
4970 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
4972 print_overflow_msg(__func__
, xdr
);
4976 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4979 uint32_t savewords
, bmlen
, i
;
4982 if (!__decode_op_hdr(xdr
, OP_OPEN
, &status
))
4984 nfs_increment_open_seqid(status
, res
->seqid
);
4987 status
= decode_stateid(xdr
, &res
->stateid
);
4988 if (unlikely(status
))
4991 decode_change_info(xdr
, &res
->cinfo
);
4993 p
= xdr_inline_decode(xdr
, 8);
4996 res
->rflags
= be32_to_cpup(p
++);
4997 bmlen
= be32_to_cpup(p
);
5001 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
5004 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
5005 for (i
= 0; i
< savewords
; ++i
)
5006 res
->attrset
[i
] = be32_to_cpup(p
++);
5007 for (; i
< NFS4_BITMAP_SIZE
; i
++)
5008 res
->attrset
[i
] = 0;
5010 return decode_delegation(xdr
, res
);
5012 dprintk("%s: Bitmap too large! Length = %u\n", __func__
, bmlen
);
5015 print_overflow_msg(__func__
, xdr
);
5019 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
5023 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
5025 nfs_increment_open_seqid(status
, res
->seqid
);
5027 status
= decode_stateid(xdr
, &res
->stateid
);
5031 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
5035 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
5037 nfs_increment_open_seqid(status
, res
->seqid
);
5039 status
= decode_stateid(xdr
, &res
->stateid
);
5043 static int decode_putfh(struct xdr_stream
*xdr
)
5045 return decode_op_hdr(xdr
, OP_PUTFH
);
5048 static int decode_putrootfh(struct xdr_stream
*xdr
)
5050 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
5053 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5054 struct nfs_pgio_res
*res
)
5057 uint32_t count
, eof
, recvd
;
5060 status
= decode_op_hdr(xdr
, OP_READ
);
5063 p
= xdr_inline_decode(xdr
, 8);
5066 eof
= be32_to_cpup(p
++);
5067 count
= be32_to_cpup(p
);
5068 recvd
= xdr_read_pages(xdr
, count
);
5069 if (count
> recvd
) {
5070 dprintk("NFS: server cheating in read reply: "
5071 "count %u > recvd %u\n", count
, recvd
);
5079 print_overflow_msg(__func__
, xdr
);
5083 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
5088 status
= decode_op_hdr(xdr
, OP_READDIR
);
5090 status
= decode_verifier(xdr
, readdir
->verifier
.data
);
5091 if (unlikely(status
))
5093 memcpy(verf
, readdir
->verifier
.data
, sizeof(verf
));
5094 dprintk("%s: verifier = %08x:%08x\n",
5095 __func__
, verf
[0], verf
[1]);
5096 return xdr_read_pages(xdr
, xdr
->buf
->page_len
);
5099 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
5101 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
5106 status
= decode_op_hdr(xdr
, OP_READLINK
);
5110 /* Convert length of symlink */
5111 p
= xdr_inline_decode(xdr
, 4);
5114 len
= be32_to_cpup(p
);
5115 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
5116 dprintk("nfs: server returned giant symlink!\n");
5117 return -ENAMETOOLONG
;
5119 recvd
= xdr_read_pages(xdr
, len
);
5121 dprintk("NFS: server cheating in readlink reply: "
5122 "count %u > recvd %u\n", len
, recvd
);
5126 * The XDR encode routine has set things up so that
5127 * the link text will be copied directly into the
5128 * buffer. We just have to do overflow-checking,
5129 * and and null-terminate the text (the VFS expects
5130 * null-termination).
5132 xdr_terminate_string(rcvbuf
, len
);
5135 print_overflow_msg(__func__
, xdr
);
5139 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
5143 status
= decode_op_hdr(xdr
, OP_REMOVE
);
5146 status
= decode_change_info(xdr
, cinfo
);
5151 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
5152 struct nfs4_change_info
*new_cinfo
)
5156 status
= decode_op_hdr(xdr
, OP_RENAME
);
5159 if ((status
= decode_change_info(xdr
, old_cinfo
)))
5161 status
= decode_change_info(xdr
, new_cinfo
);
5166 static int decode_renew(struct xdr_stream
*xdr
)
5168 return decode_op_hdr(xdr
, OP_RENEW
);
5172 decode_restorefh(struct xdr_stream
*xdr
)
5174 return decode_op_hdr(xdr
, OP_RESTOREFH
);
5177 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5178 struct nfs_getaclres
*res
)
5184 unsigned int pg_offset
;
5187 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
5190 xdr_enter_page(xdr
, xdr
->buf
->page_len
);
5192 /* Calculate the offset of the page data */
5193 pg_offset
= xdr
->buf
->head
[0].iov_len
;
5195 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
5197 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
5200 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
5202 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
5204 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5205 * are stored with the acl data to handle the problem of
5206 * variable length bitmaps.*/
5207 res
->acl_data_offset
= xdr_stream_pos(xdr
) - pg_offset
;
5208 res
->acl_len
= attrlen
;
5210 /* Check for receive buffer overflow */
5211 if (res
->acl_len
> (xdr
->nwords
<< 2) ||
5212 res
->acl_len
+ res
->acl_data_offset
> xdr
->buf
->page_len
) {
5213 res
->acl_flags
|= NFS4_ACL_TRUNC
;
5214 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5215 attrlen
, xdr
->nwords
<< 2);
5218 status
= -EOPNOTSUPP
;
5225 decode_savefh(struct xdr_stream
*xdr
)
5227 return decode_op_hdr(xdr
, OP_SAVEFH
);
5230 static int decode_setattr(struct xdr_stream
*xdr
)
5236 status
= decode_op_hdr(xdr
, OP_SETATTR
);
5239 p
= xdr_inline_decode(xdr
, 4);
5242 bmlen
= be32_to_cpup(p
);
5243 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
5247 print_overflow_msg(__func__
, xdr
);
5251 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs4_setclientid_res
*res
)
5257 p
= xdr_inline_decode(xdr
, 8);
5260 opnum
= be32_to_cpup(p
++);
5261 if (opnum
!= OP_SETCLIENTID
) {
5262 dprintk("nfs: decode_setclientid: Server returned operation"
5266 nfserr
= be32_to_cpup(p
);
5267 if (nfserr
== NFS_OK
) {
5268 p
= xdr_inline_decode(xdr
, 8 + NFS4_VERIFIER_SIZE
);
5271 p
= xdr_decode_hyper(p
, &res
->clientid
);
5272 memcpy(res
->confirm
.data
, p
, NFS4_VERIFIER_SIZE
);
5273 } else if (nfserr
== NFSERR_CLID_INUSE
) {
5276 /* skip netid string */
5277 p
= xdr_inline_decode(xdr
, 4);
5280 len
= be32_to_cpup(p
);
5281 p
= xdr_inline_decode(xdr
, len
);
5285 /* skip uaddr string */
5286 p
= xdr_inline_decode(xdr
, 4);
5289 len
= be32_to_cpup(p
);
5290 p
= xdr_inline_decode(xdr
, len
);
5293 return -NFSERR_CLID_INUSE
;
5295 return nfs4_stat_to_errno(nfserr
);
5299 print_overflow_msg(__func__
, xdr
);
5303 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
5305 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
5308 static int decode_write(struct xdr_stream
*xdr
, struct nfs_pgio_res
*res
)
5313 status
= decode_op_hdr(xdr
, OP_WRITE
);
5317 p
= xdr_inline_decode(xdr
, 8);
5320 res
->count
= be32_to_cpup(p
++);
5321 res
->verf
->committed
= be32_to_cpup(p
++);
5322 return decode_write_verifier(xdr
, &res
->verf
->verifier
);
5324 print_overflow_msg(__func__
, xdr
);
5328 static int decode_delegreturn(struct xdr_stream
*xdr
)
5330 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
5333 static int decode_secinfo_gss(struct xdr_stream
*xdr
,
5334 struct nfs4_secinfo4
*flavor
)
5339 p
= xdr_inline_decode(xdr
, 4);
5342 oid_len
= be32_to_cpup(p
);
5343 if (oid_len
> GSS_OID_MAX_LEN
)
5346 p
= xdr_inline_decode(xdr
, oid_len
);
5349 memcpy(flavor
->flavor_info
.oid
.data
, p
, oid_len
);
5350 flavor
->flavor_info
.oid
.len
= oid_len
;
5352 p
= xdr_inline_decode(xdr
, 8);
5355 flavor
->flavor_info
.qop
= be32_to_cpup(p
++);
5356 flavor
->flavor_info
.service
= be32_to_cpup(p
);
5361 print_overflow_msg(__func__
, xdr
);
5367 static int decode_secinfo_common(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5369 struct nfs4_secinfo4
*sec_flavor
;
5370 unsigned int i
, num_flavors
;
5374 p
= xdr_inline_decode(xdr
, 4);
5378 res
->flavors
->num_flavors
= 0;
5379 num_flavors
= be32_to_cpup(p
);
5381 for (i
= 0; i
< num_flavors
; i
++) {
5382 sec_flavor
= &res
->flavors
->flavors
[i
];
5383 if ((char *)&sec_flavor
[1] - (char *)res
->flavors
> PAGE_SIZE
)
5386 p
= xdr_inline_decode(xdr
, 4);
5389 sec_flavor
->flavor
= be32_to_cpup(p
);
5391 if (sec_flavor
->flavor
== RPC_AUTH_GSS
) {
5392 status
= decode_secinfo_gss(xdr
, sec_flavor
);
5396 res
->flavors
->num_flavors
++;
5403 print_overflow_msg(__func__
, xdr
);
5407 static int decode_secinfo(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5409 int status
= decode_op_hdr(xdr
, OP_SECINFO
);
5412 return decode_secinfo_common(xdr
, res
);
5415 #if defined(CONFIG_NFS_V4_1)
5416 static int decode_secinfo_no_name(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5418 int status
= decode_op_hdr(xdr
, OP_SECINFO_NO_NAME
);
5421 return decode_secinfo_common(xdr
, res
);
5424 static int decode_op_map(struct xdr_stream
*xdr
, struct nfs4_op_map
*op_map
)
5427 uint32_t bitmap_words
;
5430 p
= xdr_inline_decode(xdr
, 4);
5431 bitmap_words
= be32_to_cpup(p
++);
5432 if (bitmap_words
> NFS4_OP_MAP_NUM_WORDS
)
5434 p
= xdr_inline_decode(xdr
, 4 * bitmap_words
);
5435 for (i
= 0; i
< bitmap_words
; i
++)
5436 op_map
->u
.words
[i
] = be32_to_cpup(p
++);
5441 static int decode_exchange_id(struct xdr_stream
*xdr
,
5442 struct nfs41_exchange_id_res
*res
)
5448 uint32_t impl_id_count
;
5450 status
= decode_op_hdr(xdr
, OP_EXCHANGE_ID
);
5454 p
= xdr_inline_decode(xdr
, 8);
5457 xdr_decode_hyper(p
, &res
->clientid
);
5458 p
= xdr_inline_decode(xdr
, 12);
5461 res
->seqid
= be32_to_cpup(p
++);
5462 res
->flags
= be32_to_cpup(p
++);
5464 res
->state_protect
.how
= be32_to_cpup(p
);
5465 switch (res
->state_protect
.how
) {
5469 status
= decode_op_map(xdr
, &res
->state_protect
.enforce
);
5472 status
= decode_op_map(xdr
, &res
->state_protect
.allow
);
5481 /* server_owner4.so_minor_id */
5482 p
= xdr_inline_decode(xdr
, 8);
5485 p
= xdr_decode_hyper(p
, &res
->server_owner
->minor_id
);
5487 /* server_owner4.so_major_id */
5488 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5489 if (unlikely(status
))
5491 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5493 memcpy(res
->server_owner
->major_id
, dummy_str
, dummy
);
5494 res
->server_owner
->major_id_sz
= dummy
;
5497 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5498 if (unlikely(status
))
5500 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5502 memcpy(res
->server_scope
->server_scope
, dummy_str
, dummy
);
5503 res
->server_scope
->server_scope_sz
= dummy
;
5505 /* Implementation Id */
5506 p
= xdr_inline_decode(xdr
, 4);
5509 impl_id_count
= be32_to_cpup(p
++);
5511 if (impl_id_count
) {
5513 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5514 if (unlikely(status
))
5516 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5518 memcpy(res
->impl_id
->domain
, dummy_str
, dummy
);
5521 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5522 if (unlikely(status
))
5524 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5526 memcpy(res
->impl_id
->name
, dummy_str
, dummy
);
5529 p
= xdr_inline_decode(xdr
, 12);
5532 p
= xdr_decode_hyper(p
, &res
->impl_id
->date
.seconds
);
5533 res
->impl_id
->date
.nseconds
= be32_to_cpup(p
);
5535 /* if there's more than one entry, ignore the rest */
5539 print_overflow_msg(__func__
, xdr
);
5543 static int decode_chan_attrs(struct xdr_stream
*xdr
,
5544 struct nfs4_channel_attrs
*attrs
)
5549 p
= xdr_inline_decode(xdr
, 28);
5552 val
= be32_to_cpup(p
++); /* headerpadsz */
5554 return -EINVAL
; /* no support for header padding yet */
5555 attrs
->max_rqst_sz
= be32_to_cpup(p
++);
5556 attrs
->max_resp_sz
= be32_to_cpup(p
++);
5557 attrs
->max_resp_sz_cached
= be32_to_cpup(p
++);
5558 attrs
->max_ops
= be32_to_cpup(p
++);
5559 attrs
->max_reqs
= be32_to_cpup(p
++);
5560 nr_attrs
= be32_to_cpup(p
);
5561 if (unlikely(nr_attrs
> 1)) {
5562 printk(KERN_WARNING
"NFS: %s: Invalid rdma channel attrs "
5563 "count %u\n", __func__
, nr_attrs
);
5566 if (nr_attrs
== 1) {
5567 p
= xdr_inline_decode(xdr
, 4); /* skip rdma_attrs */
5573 print_overflow_msg(__func__
, xdr
);
5577 static int decode_sessionid(struct xdr_stream
*xdr
, struct nfs4_sessionid
*sid
)
5579 return decode_opaque_fixed(xdr
, sid
->data
, NFS4_MAX_SESSIONID_LEN
);
5582 static int decode_bind_conn_to_session(struct xdr_stream
*xdr
,
5583 struct nfs41_bind_conn_to_session_res
*res
)
5588 status
= decode_op_hdr(xdr
, OP_BIND_CONN_TO_SESSION
);
5590 status
= decode_sessionid(xdr
, &res
->session
->sess_id
);
5591 if (unlikely(status
))
5594 /* dir flags, rdma mode bool */
5595 p
= xdr_inline_decode(xdr
, 8);
5599 res
->dir
= be32_to_cpup(p
++);
5600 if (res
->dir
== 0 || res
->dir
> NFS4_CDFS4_BOTH
)
5602 if (be32_to_cpup(p
) == 0)
5603 res
->use_conn_in_rdma_mode
= false;
5605 res
->use_conn_in_rdma_mode
= true;
5609 print_overflow_msg(__func__
, xdr
);
5613 static int decode_create_session(struct xdr_stream
*xdr
,
5614 struct nfs41_create_session_res
*res
)
5618 struct nfs_client
*clp
= res
->client
;
5619 struct nfs4_session
*session
= clp
->cl_session
;
5621 status
= decode_op_hdr(xdr
, OP_CREATE_SESSION
);
5623 status
= decode_sessionid(xdr
, &session
->sess_id
);
5624 if (unlikely(status
))
5628 p
= xdr_inline_decode(xdr
, 8);
5631 clp
->cl_seqid
= be32_to_cpup(p
++);
5632 session
->flags
= be32_to_cpup(p
);
5634 /* Channel attributes */
5635 status
= decode_chan_attrs(xdr
, &session
->fc_attrs
);
5637 status
= decode_chan_attrs(xdr
, &session
->bc_attrs
);
5640 print_overflow_msg(__func__
, xdr
);
5644 static int decode_destroy_session(struct xdr_stream
*xdr
, void *dummy
)
5646 return decode_op_hdr(xdr
, OP_DESTROY_SESSION
);
5649 static int decode_destroy_clientid(struct xdr_stream
*xdr
, void *dummy
)
5651 return decode_op_hdr(xdr
, OP_DESTROY_CLIENTID
);
5654 static int decode_reclaim_complete(struct xdr_stream
*xdr
, void *dummy
)
5656 return decode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
);
5658 #endif /* CONFIG_NFS_V4_1 */
5660 static int decode_sequence(struct xdr_stream
*xdr
,
5661 struct nfs4_sequence_res
*res
,
5662 struct rpc_rqst
*rqstp
)
5664 #if defined(CONFIG_NFS_V4_1)
5665 struct nfs4_session
*session
;
5666 struct nfs4_sessionid id
;
5671 if (res
->sr_slot
== NULL
)
5673 if (!res
->sr_slot
->table
->session
)
5676 status
= decode_op_hdr(xdr
, OP_SEQUENCE
);
5678 status
= decode_sessionid(xdr
, &id
);
5679 if (unlikely(status
))
5683 * If the server returns different values for sessionID, slotID or
5684 * sequence number, the server is looney tunes.
5686 status
= -EREMOTEIO
;
5687 session
= res
->sr_slot
->table
->session
;
5689 if (memcmp(id
.data
, session
->sess_id
.data
,
5690 NFS4_MAX_SESSIONID_LEN
)) {
5691 dprintk("%s Invalid session id\n", __func__
);
5695 p
= xdr_inline_decode(xdr
, 20);
5700 dummy
= be32_to_cpup(p
++);
5701 if (dummy
!= res
->sr_slot
->seq_nr
) {
5702 dprintk("%s Invalid sequence number\n", __func__
);
5706 dummy
= be32_to_cpup(p
++);
5707 if (dummy
!= res
->sr_slot
->slot_nr
) {
5708 dprintk("%s Invalid slot id\n", __func__
);
5711 /* highest slot id */
5712 res
->sr_highest_slotid
= be32_to_cpup(p
++);
5713 /* target highest slot id */
5714 res
->sr_target_highest_slotid
= be32_to_cpup(p
++);
5716 res
->sr_status_flags
= be32_to_cpup(p
);
5719 res
->sr_status
= status
;
5722 print_overflow_msg(__func__
, xdr
);
5725 #else /* CONFIG_NFS_V4_1 */
5727 #endif /* CONFIG_NFS_V4_1 */
5730 #if defined(CONFIG_NFS_V4_1)
5731 static int decode_getdeviceinfo(struct xdr_stream
*xdr
,
5732 struct pnfs_device
*pdev
)
5738 status
= decode_op_hdr(xdr
, OP_GETDEVICEINFO
);
5740 if (status
== -ETOOSMALL
) {
5741 p
= xdr_inline_decode(xdr
, 4);
5744 pdev
->mincount
= be32_to_cpup(p
);
5745 dprintk("%s: Min count too small. mincnt = %u\n",
5746 __func__
, pdev
->mincount
);
5751 p
= xdr_inline_decode(xdr
, 8);
5754 type
= be32_to_cpup(p
++);
5755 if (type
!= pdev
->layout_type
) {
5756 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5757 __func__
, pdev
->layout_type
, type
);
5761 * Get the length of the opaque device_addr4. xdr_read_pages places
5762 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5763 * and places the remaining xdr data in xdr_buf->tail
5765 pdev
->mincount
= be32_to_cpup(p
);
5766 if (xdr_read_pages(xdr
, pdev
->mincount
) != pdev
->mincount
)
5769 /* Parse notification bitmap, verifying that it is zero. */
5770 p
= xdr_inline_decode(xdr
, 4);
5773 len
= be32_to_cpup(p
);
5777 p
= xdr_inline_decode(xdr
, 4 * len
);
5781 if (be32_to_cpup(p
++) &
5782 ~(NOTIFY_DEVICEID4_CHANGE
| NOTIFY_DEVICEID4_DELETE
)) {
5783 dprintk("%s: unsupported notification\n",
5787 for (i
= 1; i
< len
; i
++) {
5788 if (be32_to_cpup(p
++)) {
5789 dprintk("%s: unsupported notification\n",
5797 print_overflow_msg(__func__
, xdr
);
5801 static int decode_layoutget(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5802 struct nfs4_layoutget_res
*res
)
5809 status
= decode_op_hdr(xdr
, OP_LAYOUTGET
);
5812 p
= xdr_inline_decode(xdr
, 4);
5815 res
->return_on_close
= be32_to_cpup(p
);
5816 decode_stateid(xdr
, &res
->stateid
);
5817 p
= xdr_inline_decode(xdr
, 4);
5820 layout_count
= be32_to_cpup(p
);
5821 if (!layout_count
) {
5822 dprintk("%s: server responded with empty layout array\n",
5827 p
= xdr_inline_decode(xdr
, 28);
5830 p
= xdr_decode_hyper(p
, &res
->range
.offset
);
5831 p
= xdr_decode_hyper(p
, &res
->range
.length
);
5832 res
->range
.iomode
= be32_to_cpup(p
++);
5833 res
->type
= be32_to_cpup(p
++);
5834 res
->layoutp
->len
= be32_to_cpup(p
);
5836 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5838 (unsigned long)res
->range
.offset
,
5839 (unsigned long)res
->range
.length
,
5844 recvd
= xdr_read_pages(xdr
, res
->layoutp
->len
);
5845 if (res
->layoutp
->len
> recvd
) {
5846 dprintk("NFS: server cheating in layoutget reply: "
5847 "layout len %u > recvd %u\n",
5848 res
->layoutp
->len
, recvd
);
5852 if (layout_count
> 1) {
5853 /* We only handle a length one array at the moment. Any
5854 * further entries are just ignored. Note that this means
5855 * the client may see a response that is less than the
5856 * minimum it requested.
5858 dprintk("%s: server responded with %d layouts, dropping tail\n",
5859 __func__
, layout_count
);
5864 print_overflow_msg(__func__
, xdr
);
5868 static int decode_layoutreturn(struct xdr_stream
*xdr
,
5869 struct nfs4_layoutreturn_res
*res
)
5874 status
= decode_op_hdr(xdr
, OP_LAYOUTRETURN
);
5877 p
= xdr_inline_decode(xdr
, 4);
5880 res
->lrs_present
= be32_to_cpup(p
);
5881 if (res
->lrs_present
)
5882 status
= decode_stateid(xdr
, &res
->stateid
);
5885 print_overflow_msg(__func__
, xdr
);
5889 static int decode_layoutcommit(struct xdr_stream
*xdr
,
5890 struct rpc_rqst
*req
,
5891 struct nfs4_layoutcommit_res
*res
)
5897 status
= decode_op_hdr(xdr
, OP_LAYOUTCOMMIT
);
5898 res
->status
= status
;
5902 p
= xdr_inline_decode(xdr
, 4);
5905 sizechanged
= be32_to_cpup(p
);
5908 /* throw away new size */
5909 p
= xdr_inline_decode(xdr
, 8);
5915 print_overflow_msg(__func__
, xdr
);
5919 static int decode_test_stateid(struct xdr_stream
*xdr
,
5920 struct nfs41_test_stateid_res
*res
)
5926 status
= decode_op_hdr(xdr
, OP_TEST_STATEID
);
5930 p
= xdr_inline_decode(xdr
, 4);
5933 num_res
= be32_to_cpup(p
++);
5937 p
= xdr_inline_decode(xdr
, 4);
5940 res
->status
= be32_to_cpup(p
++);
5944 print_overflow_msg(__func__
, xdr
);
5949 static int decode_free_stateid(struct xdr_stream
*xdr
,
5950 struct nfs41_free_stateid_res
*res
)
5952 res
->status
= decode_op_hdr(xdr
, OP_FREE_STATEID
);
5955 #endif /* CONFIG_NFS_V4_1 */
5958 * END OF "GENERIC" DECODE ROUTINES.
5962 * Decode OPEN_DOWNGRADE response
5964 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
,
5965 struct xdr_stream
*xdr
,
5966 struct nfs_closeres
*res
)
5968 struct compound_hdr hdr
;
5971 status
= decode_compound_hdr(xdr
, &hdr
);
5974 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5977 status
= decode_putfh(xdr
);
5980 status
= decode_open_downgrade(xdr
, res
);
5983 decode_getfattr(xdr
, res
->fattr
, res
->server
);
5989 * Decode ACCESS response
5991 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5992 struct nfs4_accessres
*res
)
5994 struct compound_hdr hdr
;
5997 status
= decode_compound_hdr(xdr
, &hdr
);
6000 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6003 status
= decode_putfh(xdr
);
6006 status
= decode_access(xdr
, &res
->supported
, &res
->access
);
6009 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6015 * Decode LOOKUP response
6017 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6018 struct nfs4_lookup_res
*res
)
6020 struct compound_hdr hdr
;
6023 status
= decode_compound_hdr(xdr
, &hdr
);
6026 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6029 status
= decode_putfh(xdr
);
6032 status
= decode_lookup(xdr
);
6035 status
= decode_getfh(xdr
, res
->fh
);
6038 status
= decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6044 * Decode LOOKUP_ROOT response
6046 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
,
6047 struct xdr_stream
*xdr
,
6048 struct nfs4_lookup_res
*res
)
6050 struct compound_hdr hdr
;
6053 status
= decode_compound_hdr(xdr
, &hdr
);
6056 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6059 status
= decode_putrootfh(xdr
);
6062 status
= decode_getfh(xdr
, res
->fh
);
6064 status
= decode_getfattr_label(xdr
, res
->fattr
,
6065 res
->label
, res
->server
);
6071 * Decode REMOVE response
6073 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6074 struct nfs_removeres
*res
)
6076 struct compound_hdr hdr
;
6079 status
= decode_compound_hdr(xdr
, &hdr
);
6082 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6085 status
= decode_putfh(xdr
);
6088 status
= decode_remove(xdr
, &res
->cinfo
);
6094 * Decode RENAME response
6096 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6097 struct nfs_renameres
*res
)
6099 struct compound_hdr hdr
;
6102 status
= decode_compound_hdr(xdr
, &hdr
);
6105 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6108 status
= decode_putfh(xdr
);
6111 status
= decode_savefh(xdr
);
6114 status
= decode_putfh(xdr
);
6117 status
= decode_rename(xdr
, &res
->old_cinfo
, &res
->new_cinfo
);
6123 * Decode LINK response
6125 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6126 struct nfs4_link_res
*res
)
6128 struct compound_hdr hdr
;
6131 status
= decode_compound_hdr(xdr
, &hdr
);
6134 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6137 status
= decode_putfh(xdr
);
6140 status
= decode_savefh(xdr
);
6143 status
= decode_putfh(xdr
);
6146 status
= decode_link(xdr
, &res
->cinfo
);
6150 * Note order: OP_LINK leaves the directory as the current
6153 status
= decode_restorefh(xdr
);
6156 decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6162 * Decode CREATE response
6164 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6165 struct nfs4_create_res
*res
)
6167 struct compound_hdr hdr
;
6170 status
= decode_compound_hdr(xdr
, &hdr
);
6173 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6176 status
= decode_putfh(xdr
);
6179 status
= decode_create(xdr
, &res
->dir_cinfo
);
6182 status
= decode_getfh(xdr
, res
->fh
);
6185 decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6191 * Decode SYMLINK response
6193 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6194 struct nfs4_create_res
*res
)
6196 return nfs4_xdr_dec_create(rqstp
, xdr
, res
);
6200 * Decode GETATTR response
6202 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6203 struct nfs4_getattr_res
*res
)
6205 struct compound_hdr hdr
;
6208 status
= decode_compound_hdr(xdr
, &hdr
);
6211 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6214 status
= decode_putfh(xdr
);
6217 status
= decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6223 * Encode an SETACL request
6225 static void nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6226 struct nfs_setaclargs
*args
)
6228 struct compound_hdr hdr
= {
6229 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
6232 encode_compound_hdr(xdr
, req
, &hdr
);
6233 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
6234 encode_putfh(xdr
, args
->fh
, &hdr
);
6235 encode_setacl(xdr
, args
, &hdr
);
6240 * Decode SETACL response
6243 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6244 struct nfs_setaclres
*res
)
6246 struct compound_hdr hdr
;
6249 status
= decode_compound_hdr(xdr
, &hdr
);
6252 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6255 status
= decode_putfh(xdr
);
6258 status
= decode_setattr(xdr
);
6264 * Decode GETACL response
6267 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6268 struct nfs_getaclres
*res
)
6270 struct compound_hdr hdr
;
6273 if (res
->acl_scratch
!= NULL
) {
6274 void *p
= page_address(res
->acl_scratch
);
6275 xdr_set_scratch_buffer(xdr
, p
, PAGE_SIZE
);
6277 status
= decode_compound_hdr(xdr
, &hdr
);
6280 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6283 status
= decode_putfh(xdr
);
6286 status
= decode_getacl(xdr
, rqstp
, res
);
6293 * Decode CLOSE response
6295 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6296 struct nfs_closeres
*res
)
6298 struct compound_hdr hdr
;
6301 status
= decode_compound_hdr(xdr
, &hdr
);
6304 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6307 status
= decode_putfh(xdr
);
6310 status
= decode_close(xdr
, res
);
6314 * Note: Server may do delete on close for this file
6315 * in which case the getattr call will fail with
6316 * an ESTALE error. Shouldn't be a problem,
6317 * though, since fattr->valid will remain unset.
6319 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6325 * Decode OPEN response
6327 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6328 struct nfs_openres
*res
)
6330 struct compound_hdr hdr
;
6333 status
= decode_compound_hdr(xdr
, &hdr
);
6336 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6339 status
= decode_putfh(xdr
);
6342 status
= decode_open(xdr
, res
);
6345 status
= decode_getfh(xdr
, &res
->fh
);
6348 if (res
->access_request
)
6349 decode_access(xdr
, &res
->access_supported
, &res
->access_result
);
6350 decode_getfattr_label(xdr
, res
->f_attr
, res
->f_label
, res
->server
);
6356 * Decode OPEN_CONFIRM response
6358 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
,
6359 struct xdr_stream
*xdr
,
6360 struct nfs_open_confirmres
*res
)
6362 struct compound_hdr hdr
;
6365 status
= decode_compound_hdr(xdr
, &hdr
);
6368 status
= decode_putfh(xdr
);
6371 status
= decode_open_confirm(xdr
, res
);
6377 * Decode OPEN response
6379 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
,
6380 struct xdr_stream
*xdr
,
6381 struct nfs_openres
*res
)
6383 struct compound_hdr hdr
;
6386 status
= decode_compound_hdr(xdr
, &hdr
);
6389 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6392 status
= decode_putfh(xdr
);
6395 status
= decode_open(xdr
, res
);
6398 if (res
->access_request
)
6399 decode_access(xdr
, &res
->access_supported
, &res
->access_result
);
6400 decode_getfattr(xdr
, res
->f_attr
, res
->server
);
6406 * Decode SETATTR response
6408 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
,
6409 struct xdr_stream
*xdr
,
6410 struct nfs_setattrres
*res
)
6412 struct compound_hdr hdr
;
6415 status
= decode_compound_hdr(xdr
, &hdr
);
6418 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6421 status
= decode_putfh(xdr
);
6424 status
= decode_setattr(xdr
);
6427 decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6433 * Decode LOCK response
6435 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6436 struct nfs_lock_res
*res
)
6438 struct compound_hdr hdr
;
6441 status
= decode_compound_hdr(xdr
, &hdr
);
6444 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6447 status
= decode_putfh(xdr
);
6450 status
= decode_lock(xdr
, res
);
6456 * Decode LOCKT response
6458 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6459 struct nfs_lockt_res
*res
)
6461 struct compound_hdr hdr
;
6464 status
= decode_compound_hdr(xdr
, &hdr
);
6467 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6470 status
= decode_putfh(xdr
);
6473 status
= decode_lockt(xdr
, res
);
6479 * Decode LOCKU response
6481 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6482 struct nfs_locku_res
*res
)
6484 struct compound_hdr hdr
;
6487 status
= decode_compound_hdr(xdr
, &hdr
);
6490 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6493 status
= decode_putfh(xdr
);
6496 status
= decode_locku(xdr
, res
);
6501 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst
*rqstp
,
6502 struct xdr_stream
*xdr
, void *dummy
)
6504 struct compound_hdr hdr
;
6507 status
= decode_compound_hdr(xdr
, &hdr
);
6509 status
= decode_release_lockowner(xdr
);
6514 * Decode READLINK response
6516 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
,
6517 struct xdr_stream
*xdr
,
6518 struct nfs4_readlink_res
*res
)
6520 struct compound_hdr hdr
;
6523 status
= decode_compound_hdr(xdr
, &hdr
);
6526 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6529 status
= decode_putfh(xdr
);
6532 status
= decode_readlink(xdr
, rqstp
);
6538 * Decode READDIR response
6540 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6541 struct nfs4_readdir_res
*res
)
6543 struct compound_hdr hdr
;
6546 status
= decode_compound_hdr(xdr
, &hdr
);
6549 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6552 status
= decode_putfh(xdr
);
6555 status
= decode_readdir(xdr
, rqstp
, res
);
6561 * Decode Read response
6563 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6564 struct nfs_pgio_res
*res
)
6566 struct compound_hdr hdr
;
6569 status
= decode_compound_hdr(xdr
, &hdr
);
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
);
6597 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6600 status
= decode_putfh(xdr
);
6603 status
= decode_write(xdr
, res
);
6607 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6609 status
= res
->count
;
6615 * Decode COMMIT response
6617 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6618 struct nfs_commitres
*res
)
6620 struct compound_hdr hdr
;
6623 status
= decode_compound_hdr(xdr
, &hdr
);
6626 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6629 status
= decode_putfh(xdr
);
6632 status
= decode_commit(xdr
, res
);
6638 * Decode FSINFO response
6640 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6641 struct nfs4_fsinfo_res
*res
)
6643 struct compound_hdr hdr
;
6646 status
= decode_compound_hdr(xdr
, &hdr
);
6648 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6650 status
= decode_putfh(xdr
);
6652 status
= decode_fsinfo(xdr
, res
->fsinfo
);
6657 * Decode PATHCONF response
6659 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6660 struct nfs4_pathconf_res
*res
)
6662 struct compound_hdr hdr
;
6665 status
= decode_compound_hdr(xdr
, &hdr
);
6667 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6669 status
= decode_putfh(xdr
);
6671 status
= decode_pathconf(xdr
, res
->pathconf
);
6676 * Decode STATFS response
6678 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6679 struct nfs4_statfs_res
*res
)
6681 struct compound_hdr hdr
;
6684 status
= decode_compound_hdr(xdr
, &hdr
);
6686 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6688 status
= decode_putfh(xdr
);
6690 status
= decode_statfs(xdr
, res
->fsstat
);
6695 * Decode GETATTR_BITMAP response
6697 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
,
6698 struct xdr_stream
*xdr
,
6699 struct nfs4_server_caps_res
*res
)
6701 struct compound_hdr hdr
;
6704 status
= decode_compound_hdr(xdr
, &hdr
);
6707 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6710 status
= decode_putfh(xdr
);
6713 status
= decode_server_caps(xdr
, res
);
6719 * Decode RENEW response
6721 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6724 struct compound_hdr hdr
;
6727 status
= decode_compound_hdr(xdr
, &hdr
);
6729 status
= decode_renew(xdr
);
6734 * Decode SETCLIENTID response
6736 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
,
6737 struct xdr_stream
*xdr
,
6738 struct nfs4_setclientid_res
*res
)
6740 struct compound_hdr hdr
;
6743 status
= decode_compound_hdr(xdr
, &hdr
);
6745 status
= decode_setclientid(xdr
, res
);
6750 * Decode SETCLIENTID_CONFIRM response
6752 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
,
6753 struct xdr_stream
*xdr
)
6755 struct compound_hdr hdr
;
6758 status
= decode_compound_hdr(xdr
, &hdr
);
6760 status
= decode_setclientid_confirm(xdr
);
6765 * Decode DELEGRETURN response
6767 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
,
6768 struct xdr_stream
*xdr
,
6769 struct nfs4_delegreturnres
*res
)
6771 struct compound_hdr hdr
;
6774 status
= decode_compound_hdr(xdr
, &hdr
);
6777 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6780 status
= decode_putfh(xdr
);
6783 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
);
6786 status
= decode_delegreturn(xdr
);
6792 * Decode FS_LOCATIONS response
6794 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
,
6795 struct xdr_stream
*xdr
,
6796 struct nfs4_fs_locations_res
*res
)
6798 struct compound_hdr hdr
;
6801 status
= decode_compound_hdr(xdr
, &hdr
);
6804 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6807 status
= decode_putfh(xdr
);
6810 if (res
->migration
) {
6811 xdr_enter_page(xdr
, PAGE_SIZE
);
6812 status
= decode_getfattr_generic(xdr
,
6813 &res
->fs_locations
->fattr
,
6814 NULL
, res
->fs_locations
,
6815 NULL
, res
->fs_locations
->server
);
6819 status
= decode_renew(xdr
);
6821 status
= decode_lookup(xdr
);
6824 xdr_enter_page(xdr
, PAGE_SIZE
);
6825 status
= decode_getfattr_generic(xdr
,
6826 &res
->fs_locations
->fattr
,
6827 NULL
, res
->fs_locations
,
6828 NULL
, res
->fs_locations
->server
);
6835 * Decode SECINFO response
6837 static int nfs4_xdr_dec_secinfo(struct rpc_rqst
*rqstp
,
6838 struct xdr_stream
*xdr
,
6839 struct nfs4_secinfo_res
*res
)
6841 struct compound_hdr hdr
;
6844 status
= decode_compound_hdr(xdr
, &hdr
);
6847 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6850 status
= decode_putfh(xdr
);
6853 status
= decode_secinfo(xdr
, res
);
6859 * Decode FSID_PRESENT response
6861 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst
*rqstp
,
6862 struct xdr_stream
*xdr
,
6863 struct nfs4_fsid_present_res
*res
)
6865 struct compound_hdr hdr
;
6868 status
= decode_compound_hdr(xdr
, &hdr
);
6871 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6874 status
= decode_putfh(xdr
);
6877 status
= decode_getfh(xdr
, res
->fh
);
6881 status
= decode_renew(xdr
);
6886 #if defined(CONFIG_NFS_V4_1)
6888 * Decode BIND_CONN_TO_SESSION response
6890 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst
*rqstp
,
6891 struct xdr_stream
*xdr
,
6894 struct compound_hdr hdr
;
6897 status
= decode_compound_hdr(xdr
, &hdr
);
6899 status
= decode_bind_conn_to_session(xdr
, res
);
6904 * Decode EXCHANGE_ID response
6906 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst
*rqstp
,
6907 struct xdr_stream
*xdr
,
6910 struct compound_hdr hdr
;
6913 status
= decode_compound_hdr(xdr
, &hdr
);
6915 status
= decode_exchange_id(xdr
, res
);
6920 * Decode CREATE_SESSION response
6922 static int nfs4_xdr_dec_create_session(struct rpc_rqst
*rqstp
,
6923 struct xdr_stream
*xdr
,
6924 struct nfs41_create_session_res
*res
)
6926 struct compound_hdr hdr
;
6929 status
= decode_compound_hdr(xdr
, &hdr
);
6931 status
= decode_create_session(xdr
, res
);
6936 * Decode DESTROY_SESSION response
6938 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst
*rqstp
,
6939 struct xdr_stream
*xdr
,
6942 struct compound_hdr hdr
;
6945 status
= decode_compound_hdr(xdr
, &hdr
);
6947 status
= decode_destroy_session(xdr
, res
);
6952 * Decode DESTROY_CLIENTID response
6954 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst
*rqstp
,
6955 struct xdr_stream
*xdr
,
6958 struct compound_hdr hdr
;
6961 status
= decode_compound_hdr(xdr
, &hdr
);
6963 status
= decode_destroy_clientid(xdr
, res
);
6968 * Decode SEQUENCE response
6970 static int nfs4_xdr_dec_sequence(struct rpc_rqst
*rqstp
,
6971 struct xdr_stream
*xdr
,
6972 struct nfs4_sequence_res
*res
)
6974 struct compound_hdr hdr
;
6977 status
= decode_compound_hdr(xdr
, &hdr
);
6979 status
= decode_sequence(xdr
, res
, rqstp
);
6984 * Decode GET_LEASE_TIME response
6986 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst
*rqstp
,
6987 struct xdr_stream
*xdr
,
6988 struct nfs4_get_lease_time_res
*res
)
6990 struct compound_hdr hdr
;
6993 status
= decode_compound_hdr(xdr
, &hdr
);
6995 status
= decode_sequence(xdr
, &res
->lr_seq_res
, rqstp
);
6997 status
= decode_putrootfh(xdr
);
6999 status
= decode_fsinfo(xdr
, res
->lr_fsinfo
);
7004 * Decode RECLAIM_COMPLETE response
7006 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst
*rqstp
,
7007 struct xdr_stream
*xdr
,
7008 struct nfs41_reclaim_complete_res
*res
)
7010 struct compound_hdr hdr
;
7013 status
= decode_compound_hdr(xdr
, &hdr
);
7015 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7017 status
= decode_reclaim_complete(xdr
, NULL
);
7022 * Decode GETDEVINFO response
7024 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst
*rqstp
,
7025 struct xdr_stream
*xdr
,
7026 struct nfs4_getdeviceinfo_res
*res
)
7028 struct compound_hdr hdr
;
7031 status
= decode_compound_hdr(xdr
, &hdr
);
7034 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7037 status
= decode_getdeviceinfo(xdr
, res
->pdev
);
7043 * Decode LAYOUTGET response
7045 static int nfs4_xdr_dec_layoutget(struct rpc_rqst
*rqstp
,
7046 struct xdr_stream
*xdr
,
7047 struct nfs4_layoutget_res
*res
)
7049 struct compound_hdr hdr
;
7052 status
= decode_compound_hdr(xdr
, &hdr
);
7055 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7058 status
= decode_putfh(xdr
);
7061 status
= decode_layoutget(xdr
, rqstp
, res
);
7067 * Decode LAYOUTRETURN response
7069 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst
*rqstp
,
7070 struct xdr_stream
*xdr
,
7071 struct nfs4_layoutreturn_res
*res
)
7073 struct compound_hdr hdr
;
7076 status
= decode_compound_hdr(xdr
, &hdr
);
7079 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7082 status
= decode_putfh(xdr
);
7085 status
= decode_layoutreturn(xdr
, res
);
7091 * Decode LAYOUTCOMMIT response
7093 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst
*rqstp
,
7094 struct xdr_stream
*xdr
,
7095 struct nfs4_layoutcommit_res
*res
)
7097 struct compound_hdr hdr
;
7100 status
= decode_compound_hdr(xdr
, &hdr
);
7103 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7106 status
= decode_putfh(xdr
);
7109 status
= decode_layoutcommit(xdr
, rqstp
, res
);
7112 decode_getfattr(xdr
, res
->fattr
, res
->server
);
7118 * Decode SECINFO_NO_NAME response
7120 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst
*rqstp
,
7121 struct xdr_stream
*xdr
,
7122 struct nfs4_secinfo_res
*res
)
7124 struct compound_hdr hdr
;
7127 status
= decode_compound_hdr(xdr
, &hdr
);
7130 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7133 status
= decode_putrootfh(xdr
);
7136 status
= decode_secinfo_no_name(xdr
, res
);
7142 * Decode TEST_STATEID response
7144 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst
*rqstp
,
7145 struct xdr_stream
*xdr
,
7146 struct nfs41_test_stateid_res
*res
)
7148 struct compound_hdr hdr
;
7151 status
= decode_compound_hdr(xdr
, &hdr
);
7154 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7157 status
= decode_test_stateid(xdr
, res
);
7163 * Decode FREE_STATEID response
7165 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst
*rqstp
,
7166 struct xdr_stream
*xdr
,
7167 struct nfs41_free_stateid_res
*res
)
7169 struct compound_hdr hdr
;
7172 status
= decode_compound_hdr(xdr
, &hdr
);
7175 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7178 status
= decode_free_stateid(xdr
, res
);
7182 #endif /* CONFIG_NFS_V4_1 */
7185 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7186 * the local page cache.
7187 * @xdr: XDR stream where entry resides
7188 * @entry: buffer to fill in with entry data
7189 * @plus: boolean indicating whether this should be a readdirplus entry
7191 * Returns zero if successful, otherwise a negative errno value is
7194 * This function is not invoked during READDIR reply decoding, but
7195 * rather whenever an application invokes the getdents(2) system call
7196 * on a directory already in our cache.
7198 int nfs4_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
7202 uint32_t bitmap
[3] = {0};
7204 __be32
*p
= xdr_inline_decode(xdr
, 4);
7207 if (*p
== xdr_zero
) {
7208 p
= xdr_inline_decode(xdr
, 4);
7217 p
= xdr_inline_decode(xdr
, 12);
7220 entry
->prev_cookie
= entry
->cookie
;
7221 p
= xdr_decode_hyper(p
, &entry
->cookie
);
7222 entry
->len
= be32_to_cpup(p
);
7224 p
= xdr_inline_decode(xdr
, entry
->len
);
7227 entry
->name
= (const char *) p
;
7230 * In case the server doesn't return an inode number,
7231 * we fake one here. (We don't use inode number 0,
7232 * since glibc seems to choke on it...)
7235 entry
->fattr
->valid
= 0;
7237 if (decode_attr_bitmap(xdr
, bitmap
) < 0)
7240 if (decode_attr_length(xdr
, &len
, &savep
) < 0)
7243 if (decode_getfattr_attrs(xdr
, bitmap
, entry
->fattr
, entry
->fh
,
7244 NULL
, entry
->label
, entry
->server
) < 0)
7246 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
)
7247 entry
->ino
= entry
->fattr
->mounted_on_fileid
;
7248 else if (entry
->fattr
->valid
& NFS_ATTR_FATTR_FILEID
)
7249 entry
->ino
= entry
->fattr
->fileid
;
7251 entry
->d_type
= DT_UNKNOWN
;
7252 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_TYPE
)
7253 entry
->d_type
= nfs_umode_to_dtype(entry
->fattr
->mode
);
7258 print_overflow_msg(__func__
, xdr
);
7263 * We need to translate between nfs status return values and
7264 * the local errno values which may not be the same.
7271 { NFS4ERR_PERM
, -EPERM
},
7272 { NFS4ERR_NOENT
, -ENOENT
},
7273 { NFS4ERR_IO
, -errno_NFSERR_IO
},
7274 { NFS4ERR_NXIO
, -ENXIO
},
7275 { NFS4ERR_ACCESS
, -EACCES
},
7276 { NFS4ERR_EXIST
, -EEXIST
},
7277 { NFS4ERR_XDEV
, -EXDEV
},
7278 { NFS4ERR_NOTDIR
, -ENOTDIR
},
7279 { NFS4ERR_ISDIR
, -EISDIR
},
7280 { NFS4ERR_INVAL
, -EINVAL
},
7281 { NFS4ERR_FBIG
, -EFBIG
},
7282 { NFS4ERR_NOSPC
, -ENOSPC
},
7283 { NFS4ERR_ROFS
, -EROFS
},
7284 { NFS4ERR_MLINK
, -EMLINK
},
7285 { NFS4ERR_NAMETOOLONG
, -ENAMETOOLONG
},
7286 { NFS4ERR_NOTEMPTY
, -ENOTEMPTY
},
7287 { NFS4ERR_DQUOT
, -EDQUOT
},
7288 { NFS4ERR_STALE
, -ESTALE
},
7289 { NFS4ERR_BADHANDLE
, -EBADHANDLE
},
7290 { NFS4ERR_BAD_COOKIE
, -EBADCOOKIE
},
7291 { NFS4ERR_NOTSUPP
, -ENOTSUPP
},
7292 { NFS4ERR_TOOSMALL
, -ETOOSMALL
},
7293 { NFS4ERR_SERVERFAULT
, -EREMOTEIO
},
7294 { NFS4ERR_BADTYPE
, -EBADTYPE
},
7295 { NFS4ERR_LOCKED
, -EAGAIN
},
7296 { NFS4ERR_SYMLINK
, -ELOOP
},
7297 { NFS4ERR_OP_ILLEGAL
, -EOPNOTSUPP
},
7298 { NFS4ERR_DEADLOCK
, -EDEADLK
},
7303 * Convert an NFS error code to a local one.
7304 * This one is used jointly by NFSv2 and NFSv3.
7307 nfs4_stat_to_errno(int stat
)
7310 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
7311 if (nfs_errtbl
[i
].stat
== stat
)
7312 return nfs_errtbl
[i
].errno
;
7314 if (stat
<= 10000 || stat
> 10100) {
7315 /* The server is looney tunes. */
7318 /* If we cannot translate the error, the recovery routines should
7320 * Note: remaining NFSv4 error codes have values > 10000, so should
7321 * not conflict with native Linux error codes.
7326 #ifdef CONFIG_NFS_V4_2
7327 #include "nfs42xdr.c"
7328 #endif /* CONFIG_NFS_V4_2 */
7330 #define PROC(proc, argtype, restype) \
7331 [NFSPROC4_CLNT_##proc] = { \
7332 .p_proc = NFSPROC4_COMPOUND, \
7333 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7334 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7335 .p_arglen = NFS4_##argtype##_sz, \
7336 .p_replen = NFS4_##restype##_sz, \
7337 .p_statidx = NFSPROC4_CLNT_##proc, \
7341 struct rpc_procinfo nfs4_procedures
[] = {
7342 PROC(READ
, enc_read
, dec_read
),
7343 PROC(WRITE
, enc_write
, dec_write
),
7344 PROC(COMMIT
, enc_commit
, dec_commit
),
7345 PROC(OPEN
, enc_open
, dec_open
),
7346 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
7347 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
7348 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
7349 PROC(CLOSE
, enc_close
, dec_close
),
7350 PROC(SETATTR
, enc_setattr
, dec_setattr
),
7351 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
7352 PROC(RENEW
, enc_renew
, dec_renew
),
7353 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
7354 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
7355 PROC(LOCK
, enc_lock
, dec_lock
),
7356 PROC(LOCKT
, enc_lockt
, dec_lockt
),
7357 PROC(LOCKU
, enc_locku
, dec_locku
),
7358 PROC(ACCESS
, enc_access
, dec_access
),
7359 PROC(GETATTR
, enc_getattr
, dec_getattr
),
7360 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
7361 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
7362 PROC(REMOVE
, enc_remove
, dec_remove
),
7363 PROC(RENAME
, enc_rename
, dec_rename
),
7364 PROC(LINK
, enc_link
, dec_link
),
7365 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
7366 PROC(CREATE
, enc_create
, dec_create
),
7367 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
7368 PROC(STATFS
, enc_statfs
, dec_statfs
),
7369 PROC(READLINK
, enc_readlink
, dec_readlink
),
7370 PROC(READDIR
, enc_readdir
, dec_readdir
),
7371 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
7372 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
7373 PROC(GETACL
, enc_getacl
, dec_getacl
),
7374 PROC(SETACL
, enc_setacl
, dec_setacl
),
7375 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
7376 PROC(RELEASE_LOCKOWNER
, enc_release_lockowner
, dec_release_lockowner
),
7377 PROC(SECINFO
, enc_secinfo
, dec_secinfo
),
7378 PROC(FSID_PRESENT
, enc_fsid_present
, dec_fsid_present
),
7379 #if defined(CONFIG_NFS_V4_1)
7380 PROC(EXCHANGE_ID
, enc_exchange_id
, dec_exchange_id
),
7381 PROC(CREATE_SESSION
, enc_create_session
, dec_create_session
),
7382 PROC(DESTROY_SESSION
, enc_destroy_session
, dec_destroy_session
),
7383 PROC(SEQUENCE
, enc_sequence
, dec_sequence
),
7384 PROC(GET_LEASE_TIME
, enc_get_lease_time
, dec_get_lease_time
),
7385 PROC(RECLAIM_COMPLETE
, enc_reclaim_complete
, dec_reclaim_complete
),
7386 PROC(GETDEVICEINFO
, enc_getdeviceinfo
, dec_getdeviceinfo
),
7387 PROC(LAYOUTGET
, enc_layoutget
, dec_layoutget
),
7388 PROC(LAYOUTCOMMIT
, enc_layoutcommit
, dec_layoutcommit
),
7389 PROC(LAYOUTRETURN
, enc_layoutreturn
, dec_layoutreturn
),
7390 PROC(SECINFO_NO_NAME
, enc_secinfo_no_name
, dec_secinfo_no_name
),
7391 PROC(TEST_STATEID
, enc_test_stateid
, dec_test_stateid
),
7392 PROC(FREE_STATEID
, enc_free_stateid
, dec_free_stateid
),
7393 PROC(BIND_CONN_TO_SESSION
,
7394 enc_bind_conn_to_session
, dec_bind_conn_to_session
),
7395 PROC(DESTROY_CLIENTID
, enc_destroy_clientid
, dec_destroy_clientid
),
7396 #endif /* CONFIG_NFS_V4_1 */
7397 #ifdef CONFIG_NFS_V4_2
7398 PROC(SEEK
, enc_seek
, dec_seek
),
7399 PROC(ALLOCATE
, enc_allocate
, dec_allocate
),
7400 PROC(DEALLOCATE
, enc_deallocate
, dec_deallocate
),
7401 #endif /* CONFIG_NFS_V4_2 */
7404 const struct rpc_version nfs_version4
= {
7406 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
7407 .procs
= nfs4_procedures