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>
58 #include "nfs4idmap.h"
59 #include "nfs4session.h"
63 #define NFSDBG_FACILITY NFSDBG_XDR
65 /* Mapping from NFS error code to "errno" error code. */
66 #define errno_NFSERR_IO EIO
68 static int nfs4_stat_to_errno(int);
70 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
72 #define NFS4_MAXTAGLEN 20
74 #define NFS4_MAXTAGLEN 0
77 /* lock,open owner id:
78 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
80 #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
81 #define lock_owner_id_maxsz (1 + 1 + 4)
82 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
83 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85 #define op_encode_hdr_maxsz (1)
86 #define op_decode_hdr_maxsz (2)
87 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
91 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
93 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
94 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
97 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
99 #define nfs4_fattr_bitmap_maxsz 4
100 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
101 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
103 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
106 /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107 #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
109 #define nfs4_label_maxsz 0
111 /* We support only one layout type per file system */
112 #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
113 /* This is based on getfattr, which uses the most attributes: */
114 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
115 3 + 3 + 3 + nfs4_owner_maxsz + \
116 nfs4_group_maxsz + nfs4_label_maxsz + \
117 decode_mdsthreshold_maxsz))
118 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 nfs4_fattr_value_maxsz)
120 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
121 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
127 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
128 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
129 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
131 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
132 /* The 5 accounts for the PNFS attributes, and assumes that at most three
133 * layout types will be returned.
135 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
137 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138 #define decode_renew_maxsz (op_decode_hdr_maxsz)
139 #define encode_setclientid_maxsz \
140 (op_encode_hdr_maxsz + \
141 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
142 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
144 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
145 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
147 #define decode_setclientid_maxsz \
148 (op_decode_hdr_maxsz + \
150 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
151 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
152 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
153 #define encode_setclientid_confirm_maxsz \
154 (op_encode_hdr_maxsz + \
155 3 + (NFS4_VERIFIER_SIZE >> 2))
156 #define decode_setclientid_confirm_maxsz \
157 (op_decode_hdr_maxsz)
158 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
159 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
160 #define encode_share_access_maxsz \
162 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
163 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
164 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
165 #define encode_open_maxsz (op_encode_hdr_maxsz + \
166 2 + encode_share_access_maxsz + 2 + \
167 open_owner_id_maxsz + \
168 encode_opentype_maxsz + \
169 encode_claim_null_maxsz)
170 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
171 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
173 #define decode_change_info_maxsz (5)
174 #define decode_open_maxsz (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz + \
176 decode_change_info_maxsz + 1 + \
177 nfs4_fattr_bitmap_maxsz + \
178 decode_delegation_maxsz)
179 #define encode_open_confirm_maxsz \
180 (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + 1)
182 #define decode_open_confirm_maxsz \
183 (op_decode_hdr_maxsz + \
184 decode_stateid_maxsz)
185 #define encode_open_downgrade_maxsz \
186 (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 1 + \
188 encode_share_access_maxsz)
189 #define decode_open_downgrade_maxsz \
190 (op_decode_hdr_maxsz + \
191 decode_stateid_maxsz)
192 #define encode_close_maxsz (op_encode_hdr_maxsz + \
193 1 + encode_stateid_maxsz)
194 #define decode_close_maxsz (op_decode_hdr_maxsz + \
195 decode_stateid_maxsz)
196 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
197 encode_stateid_maxsz + \
199 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
200 nfs4_fattr_bitmap_maxsz)
201 #define encode_read_maxsz (op_encode_hdr_maxsz + \
202 encode_stateid_maxsz + 3)
203 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
204 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
205 2 + encode_verifier_maxsz + 5 + \
207 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
208 decode_verifier_maxsz)
209 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
210 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
211 #define encode_write_maxsz (op_encode_hdr_maxsz + \
212 encode_stateid_maxsz + 4)
213 #define decode_write_maxsz (op_decode_hdr_maxsz + \
214 2 + decode_verifier_maxsz)
215 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
216 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
217 decode_verifier_maxsz)
218 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
220 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
221 decode_change_info_maxsz)
222 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
224 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
225 decode_change_info_maxsz + \
226 decode_change_info_maxsz)
227 #define encode_link_maxsz (op_encode_hdr_maxsz + \
229 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
230 #define encode_lockowner_maxsz (7)
231 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
233 1 + encode_stateid_maxsz + 1 + \
234 encode_lockowner_maxsz)
235 #define decode_lock_denied_maxsz \
236 (8 + decode_lockowner_maxsz)
237 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
238 decode_lock_denied_maxsz)
239 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
240 encode_lockowner_maxsz)
241 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
242 decode_lock_denied_maxsz)
243 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
244 encode_stateid_maxsz + \
246 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
247 decode_stateid_maxsz)
248 #define encode_release_lockowner_maxsz \
249 (op_encode_hdr_maxsz + \
250 encode_lockowner_maxsz)
251 #define decode_release_lockowner_maxsz \
252 (op_decode_hdr_maxsz)
253 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
254 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
255 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
256 1 + nfs4_name_maxsz + \
259 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
260 #define encode_create_maxsz (op_encode_hdr_maxsz + \
261 1 + 2 + nfs4_name_maxsz + \
263 #define decode_create_maxsz (op_decode_hdr_maxsz + \
264 decode_change_info_maxsz + \
265 nfs4_fattr_bitmap_maxsz)
266 #define encode_statfs_maxsz (encode_getattr_maxsz)
267 #define decode_statfs_maxsz (decode_getattr_maxsz)
268 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
269 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
270 #define encode_getacl_maxsz (encode_getattr_maxsz)
271 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
272 nfs4_fattr_bitmap_maxsz + 1)
273 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
274 encode_stateid_maxsz + 3)
275 #define decode_setacl_maxsz (decode_setattr_maxsz)
276 #define encode_fs_locations_maxsz \
277 (encode_getattr_maxsz)
278 #define decode_fs_locations_maxsz \
280 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
281 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
283 #if defined(CONFIG_NFS_V4_1)
284 #define NFS4_MAX_MACHINE_NAME_LEN (64)
285 #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
286 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
288 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
289 encode_verifier_maxsz + \
290 1 /* co_ownerid.len */ + \
291 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
294 /* max is SP4_MACH_CRED (for now) */ + \
295 1 + NFS4_OP_MAP_NUM_WORDS + \
296 1 + NFS4_OP_MAP_NUM_WORDS + \
297 1 /* implementation id array of size 1 */ + \
298 1 /* nii_domain */ + \
299 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
301 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
303 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
304 2 /* eir_clientid */ + \
305 1 /* eir_sequenceid */ + \
306 1 /* eir_flags */ + \
308 /* max is SP4_MACH_CRED (for now) */ + \
309 1 + NFS4_OP_MAP_NUM_WORDS + \
310 1 + NFS4_OP_MAP_NUM_WORDS + \
311 2 /* eir_server_owner.so_minor_id */ + \
312 /* eir_server_owner.so_major_id<> */ \
313 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
314 /* eir_server_scope<> */ \
315 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
316 1 /* eir_server_impl_id array length */ + \
317 1 /* nii_domain */ + \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
322 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
323 #define decode_channel_attrs_maxsz (6 + \
324 1 /* ca_rdma_ird.len */ + \
326 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
327 2 /* csa_clientid */ + \
328 1 /* csa_sequence */ + \
329 1 /* csa_flags */ + \
330 encode_channel_attrs_maxsz + \
331 encode_channel_attrs_maxsz + \
332 1 /* csa_cb_program */ + \
333 1 /* csa_sec_parms.len (1) */ + \
334 1 /* cb_secflavor (AUTH_SYS) */ + \
336 1 /* machinename.len */ + \
337 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
340 1 /* gids.len (0) */)
341 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
342 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
343 1 /* csr_sequence */ + \
344 1 /* csr_flags */ + \
345 decode_channel_attrs_maxsz + \
346 decode_channel_attrs_maxsz)
347 #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
349 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
350 1 /* bctsa_dir */ + \
351 1 /* bctsa_use_conn_in_rdma_mode */)
352 #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
354 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
355 1 /* bctsr_dir */ + \
356 1 /* bctsr_use_conn_in_rdma_mode */)
357 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
358 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
359 #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
360 #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
361 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
362 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
363 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
364 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
365 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
366 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
367 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
368 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
369 1 /* layout type */ + \
371 1 /* bitmap size */ + \
372 1 /* notification bitmap length */ + \
373 1 /* notification bitmap, word 0 */)
374 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
375 1 /* layout type */ + \
376 1 /* opaque devaddr4 length */ + \
377 /* devaddr4 payload is read into page */ \
378 1 /* notification bitmap length */ + \
379 1 /* notification bitmap, word 0 */)
380 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
381 encode_stateid_maxsz)
382 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
383 decode_stateid_maxsz + \
384 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
385 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
389 encode_stateid_maxsz + \
390 1 /* new offset (true) */ + \
391 2 /* last byte written */ + \
392 1 /* nt_timechanged (false) */ + \
393 1 /* layoutupdate4 layout type */ + \
394 1 /* layoutupdate4 opaqueue len */)
395 /* the actual content of layoutupdate4 should
396 be allocated by drivers and spliced in
397 using xdr_write_pages */
398 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
399 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
400 encode_stateid_maxsz + \
401 1 /* FIXME: opaque lrf_body always empty at the moment */)
402 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
403 1 + decode_stateid_maxsz)
404 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
405 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
406 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
407 XDR_QUADLEN(NFS4_STATEID_SIZE))
408 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
409 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
410 XDR_QUADLEN(NFS4_STATEID_SIZE))
411 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
412 #else /* CONFIG_NFS_V4_1 */
413 #define encode_sequence_maxsz 0
414 #define decode_sequence_maxsz 0
415 #endif /* CONFIG_NFS_V4_1 */
417 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
418 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
419 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
420 encode_sequence_maxsz + \
421 encode_putfh_maxsz + \
423 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
424 decode_sequence_maxsz + \
425 decode_putfh_maxsz + \
427 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
428 encode_sequence_maxsz + \
429 encode_putfh_maxsz + \
430 encode_readlink_maxsz)
431 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
432 decode_sequence_maxsz + \
433 decode_putfh_maxsz + \
434 decode_readlink_maxsz)
435 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
436 encode_sequence_maxsz + \
437 encode_putfh_maxsz + \
438 encode_readdir_maxsz)
439 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
440 decode_sequence_maxsz + \
441 decode_putfh_maxsz + \
442 decode_readdir_maxsz)
443 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
444 encode_sequence_maxsz + \
445 encode_putfh_maxsz + \
446 encode_write_maxsz + \
447 encode_getattr_maxsz)
448 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
449 decode_sequence_maxsz + \
450 decode_putfh_maxsz + \
451 decode_write_maxsz + \
452 decode_getattr_maxsz)
453 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
454 encode_sequence_maxsz + \
455 encode_putfh_maxsz + \
457 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
458 decode_sequence_maxsz + \
459 decode_putfh_maxsz + \
461 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
462 encode_sequence_maxsz + \
463 encode_putfh_maxsz + \
464 encode_open_maxsz + \
465 encode_access_maxsz + \
466 encode_getfh_maxsz + \
467 encode_getattr_maxsz)
468 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
469 decode_sequence_maxsz + \
470 decode_putfh_maxsz + \
471 decode_open_maxsz + \
472 decode_access_maxsz + \
473 decode_getfh_maxsz + \
474 decode_getattr_maxsz)
475 #define NFS4_enc_open_confirm_sz \
476 (compound_encode_hdr_maxsz + \
477 encode_putfh_maxsz + \
478 encode_open_confirm_maxsz)
479 #define NFS4_dec_open_confirm_sz \
480 (compound_decode_hdr_maxsz + \
481 decode_putfh_maxsz + \
482 decode_open_confirm_maxsz)
483 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
484 encode_sequence_maxsz + \
485 encode_putfh_maxsz + \
486 encode_open_maxsz + \
487 encode_access_maxsz + \
488 encode_getattr_maxsz)
489 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
490 decode_sequence_maxsz + \
491 decode_putfh_maxsz + \
492 decode_open_maxsz + \
493 decode_access_maxsz + \
494 decode_getattr_maxsz)
495 #define NFS4_enc_open_downgrade_sz \
496 (compound_encode_hdr_maxsz + \
497 encode_sequence_maxsz + \
498 encode_putfh_maxsz + \
499 encode_open_downgrade_maxsz + \
500 encode_getattr_maxsz)
501 #define NFS4_dec_open_downgrade_sz \
502 (compound_decode_hdr_maxsz + \
503 decode_sequence_maxsz + \
504 decode_putfh_maxsz + \
505 decode_open_downgrade_maxsz + \
506 decode_getattr_maxsz)
507 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
508 encode_sequence_maxsz + \
509 encode_putfh_maxsz + \
510 encode_close_maxsz + \
511 encode_getattr_maxsz)
512 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
513 decode_sequence_maxsz + \
514 decode_putfh_maxsz + \
515 decode_close_maxsz + \
516 decode_getattr_maxsz)
517 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
518 encode_sequence_maxsz + \
519 encode_putfh_maxsz + \
520 encode_setattr_maxsz + \
521 encode_getattr_maxsz)
522 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
523 decode_sequence_maxsz + \
524 decode_putfh_maxsz + \
525 decode_setattr_maxsz + \
526 decode_getattr_maxsz)
527 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
528 encode_sequence_maxsz + \
529 encode_putfh_maxsz + \
531 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
532 decode_sequence_maxsz + \
533 decode_putfh_maxsz + \
535 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
537 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
539 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
540 encode_setclientid_maxsz)
541 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
542 decode_setclientid_maxsz)
543 #define NFS4_enc_setclientid_confirm_sz \
544 (compound_encode_hdr_maxsz + \
545 encode_setclientid_confirm_maxsz)
546 #define NFS4_dec_setclientid_confirm_sz \
547 (compound_decode_hdr_maxsz + \
548 decode_setclientid_confirm_maxsz)
549 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
550 encode_sequence_maxsz + \
551 encode_putfh_maxsz + \
553 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
554 decode_sequence_maxsz + \
555 decode_putfh_maxsz + \
557 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
558 encode_sequence_maxsz + \
559 encode_putfh_maxsz + \
561 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
562 decode_sequence_maxsz + \
563 decode_putfh_maxsz + \
565 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
566 encode_sequence_maxsz + \
567 encode_putfh_maxsz + \
569 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
570 decode_sequence_maxsz + \
571 decode_putfh_maxsz + \
573 #define NFS4_enc_release_lockowner_sz \
574 (compound_encode_hdr_maxsz + \
575 encode_lockowner_maxsz)
576 #define NFS4_dec_release_lockowner_sz \
577 (compound_decode_hdr_maxsz + \
578 decode_lockowner_maxsz)
579 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
580 encode_sequence_maxsz + \
581 encode_putfh_maxsz + \
582 encode_access_maxsz + \
583 encode_getattr_maxsz)
584 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
585 decode_sequence_maxsz + \
586 decode_putfh_maxsz + \
587 decode_access_maxsz + \
588 decode_getattr_maxsz)
589 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
590 encode_sequence_maxsz + \
591 encode_putfh_maxsz + \
592 encode_getattr_maxsz + \
594 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
595 decode_sequence_maxsz + \
596 decode_putfh_maxsz + \
597 decode_getattr_maxsz + \
599 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
600 encode_sequence_maxsz + \
601 encode_putfh_maxsz + \
602 encode_lookup_maxsz + \
603 encode_getattr_maxsz + \
605 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
606 decode_sequence_maxsz + \
607 decode_putfh_maxsz + \
608 decode_lookup_maxsz + \
609 decode_getattr_maxsz + \
611 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
612 encode_sequence_maxsz + \
613 encode_putrootfh_maxsz + \
614 encode_getattr_maxsz + \
616 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
617 decode_sequence_maxsz + \
618 decode_putrootfh_maxsz + \
619 decode_getattr_maxsz + \
621 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
622 encode_sequence_maxsz + \
623 encode_putfh_maxsz + \
625 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
626 decode_sequence_maxsz + \
627 decode_putfh_maxsz + \
629 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
630 encode_sequence_maxsz + \
631 encode_putfh_maxsz + \
632 encode_savefh_maxsz + \
633 encode_putfh_maxsz + \
635 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
636 decode_sequence_maxsz + \
637 decode_putfh_maxsz + \
638 decode_savefh_maxsz + \
639 decode_putfh_maxsz + \
641 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
642 encode_sequence_maxsz + \
643 encode_putfh_maxsz + \
644 encode_savefh_maxsz + \
645 encode_putfh_maxsz + \
646 encode_link_maxsz + \
647 encode_restorefh_maxsz + \
648 encode_getattr_maxsz)
649 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
650 decode_sequence_maxsz + \
651 decode_putfh_maxsz + \
652 decode_savefh_maxsz + \
653 decode_putfh_maxsz + \
654 decode_link_maxsz + \
655 decode_restorefh_maxsz + \
656 decode_getattr_maxsz)
657 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
658 encode_sequence_maxsz + \
659 encode_putfh_maxsz + \
660 encode_symlink_maxsz + \
661 encode_getattr_maxsz + \
663 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
664 decode_sequence_maxsz + \
665 decode_putfh_maxsz + \
666 decode_symlink_maxsz + \
667 decode_getattr_maxsz + \
669 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
670 encode_sequence_maxsz + \
671 encode_putfh_maxsz + \
672 encode_create_maxsz + \
673 encode_getfh_maxsz + \
674 encode_getattr_maxsz)
675 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
676 decode_sequence_maxsz + \
677 decode_putfh_maxsz + \
678 decode_create_maxsz + \
679 decode_getfh_maxsz + \
680 decode_getattr_maxsz)
681 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
682 encode_sequence_maxsz + \
683 encode_putfh_maxsz + \
684 encode_getattr_maxsz)
685 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
686 decode_sequence_maxsz + \
687 decode_putfh_maxsz + \
688 decode_getattr_maxsz)
689 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
690 encode_sequence_maxsz + \
691 encode_putfh_maxsz + \
693 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
694 decode_sequence_maxsz + \
695 decode_putfh_maxsz + \
697 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
698 encode_sequence_maxsz + \
699 encode_putfh_maxsz + \
700 encode_getattr_maxsz)
701 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
702 decode_sequence_maxsz + \
703 decode_putfh_maxsz + \
704 decode_getattr_maxsz)
705 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
706 encode_sequence_maxsz + \
707 encode_putfh_maxsz + \
708 encode_delegreturn_maxsz + \
709 encode_getattr_maxsz)
710 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
711 decode_sequence_maxsz + \
712 decode_delegreturn_maxsz + \
713 decode_getattr_maxsz)
714 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
715 encode_sequence_maxsz + \
716 encode_putfh_maxsz + \
718 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
719 decode_sequence_maxsz + \
720 decode_putfh_maxsz + \
722 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
723 encode_sequence_maxsz + \
724 encode_putfh_maxsz + \
726 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
727 decode_sequence_maxsz + \
728 decode_putfh_maxsz + \
730 #define NFS4_enc_fs_locations_sz \
731 (compound_encode_hdr_maxsz + \
732 encode_sequence_maxsz + \
733 encode_putfh_maxsz + \
734 encode_lookup_maxsz + \
735 encode_fs_locations_maxsz + \
737 #define NFS4_dec_fs_locations_sz \
738 (compound_decode_hdr_maxsz + \
739 decode_sequence_maxsz + \
740 decode_putfh_maxsz + \
741 decode_lookup_maxsz + \
742 decode_fs_locations_maxsz + \
744 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
745 encode_sequence_maxsz + \
746 encode_putfh_maxsz + \
747 encode_secinfo_maxsz)
748 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
749 decode_sequence_maxsz + \
750 decode_putfh_maxsz + \
751 decode_secinfo_maxsz)
752 #define NFS4_enc_fsid_present_sz \
753 (compound_encode_hdr_maxsz + \
754 encode_sequence_maxsz + \
755 encode_putfh_maxsz + \
756 encode_getfh_maxsz + \
758 #define NFS4_dec_fsid_present_sz \
759 (compound_decode_hdr_maxsz + \
760 decode_sequence_maxsz + \
761 decode_putfh_maxsz + \
762 decode_getfh_maxsz + \
764 #if defined(CONFIG_NFS_V4_1)
765 #define NFS4_enc_bind_conn_to_session_sz \
766 (compound_encode_hdr_maxsz + \
767 encode_bind_conn_to_session_maxsz)
768 #define NFS4_dec_bind_conn_to_session_sz \
769 (compound_decode_hdr_maxsz + \
770 decode_bind_conn_to_session_maxsz)
771 #define NFS4_enc_exchange_id_sz \
772 (compound_encode_hdr_maxsz + \
773 encode_exchange_id_maxsz)
774 #define NFS4_dec_exchange_id_sz \
775 (compound_decode_hdr_maxsz + \
776 decode_exchange_id_maxsz)
777 #define NFS4_enc_create_session_sz \
778 (compound_encode_hdr_maxsz + \
779 encode_create_session_maxsz)
780 #define NFS4_dec_create_session_sz \
781 (compound_decode_hdr_maxsz + \
782 decode_create_session_maxsz)
783 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
784 encode_destroy_session_maxsz)
785 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
786 decode_destroy_session_maxsz)
787 #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
788 encode_destroy_clientid_maxsz)
789 #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
790 decode_destroy_clientid_maxsz)
791 #define NFS4_enc_sequence_sz \
792 (compound_decode_hdr_maxsz + \
793 encode_sequence_maxsz)
794 #define NFS4_dec_sequence_sz \
795 (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz)
797 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putrootfh_maxsz + \
801 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putrootfh_maxsz + \
805 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz + \
807 encode_reclaim_complete_maxsz)
808 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
809 decode_sequence_maxsz + \
810 decode_reclaim_complete_maxsz)
811 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz +\
813 encode_getdeviceinfo_maxsz)
814 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_getdeviceinfo_maxsz)
817 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putfh_maxsz + \
820 encode_layoutget_maxsz)
821 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putfh_maxsz + \
824 decode_layoutget_maxsz)
825 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz +\
827 encode_putfh_maxsz + \
828 encode_layoutcommit_maxsz + \
829 encode_getattr_maxsz)
830 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
831 decode_sequence_maxsz + \
832 decode_putfh_maxsz + \
833 decode_layoutcommit_maxsz + \
834 decode_getattr_maxsz)
835 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
836 encode_sequence_maxsz + \
837 encode_putfh_maxsz + \
838 encode_layoutreturn_maxsz)
839 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
840 decode_sequence_maxsz + \
841 decode_putfh_maxsz + \
842 decode_layoutreturn_maxsz)
843 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
844 encode_sequence_maxsz + \
845 encode_putrootfh_maxsz +\
846 encode_secinfo_no_name_maxsz)
847 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_putrootfh_maxsz + \
850 decode_secinfo_no_name_maxsz)
851 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz + \
853 encode_test_stateid_maxsz)
854 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
855 decode_sequence_maxsz + \
856 decode_test_stateid_maxsz)
857 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
858 encode_sequence_maxsz + \
859 encode_free_stateid_maxsz)
860 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
861 decode_sequence_maxsz + \
862 decode_free_stateid_maxsz)
864 const u32 nfs41_maxwrite_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
865 compound_encode_hdr_maxsz
+
866 encode_sequence_maxsz
+
868 encode_getattr_maxsz
) *
871 const u32 nfs41_maxread_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
872 compound_decode_hdr_maxsz
+
873 decode_sequence_maxsz
+
874 decode_putfh_maxsz
) *
877 const u32 nfs41_maxgetdevinfo_overhead
= ((RPC_MAX_REPHEADER_WITH_AUTH
+
878 compound_decode_hdr_maxsz
+
879 decode_sequence_maxsz
) *
881 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead
);
882 #endif /* CONFIG_NFS_V4_1 */
884 static const umode_t nfs_type2fmt
[] = {
891 [NF4SOCK
] = S_IFSOCK
,
897 struct compound_hdr
{
903 uint32_t replen
; /* expected reply words */
907 static __be32
*reserve_space(struct xdr_stream
*xdr
, size_t nbytes
)
909 __be32
*p
= xdr_reserve_space(xdr
, nbytes
);
914 static void encode_opaque_fixed(struct xdr_stream
*xdr
, const void *buf
, size_t len
)
918 p
= xdr_reserve_space(xdr
, len
);
919 xdr_encode_opaque_fixed(p
, buf
, len
);
922 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
926 p
= reserve_space(xdr
, 4 + len
);
927 xdr_encode_opaque(p
, str
, len
);
930 static void encode_uint32(struct xdr_stream
*xdr
, u32 n
)
934 p
= reserve_space(xdr
, 4);
938 static void encode_uint64(struct xdr_stream
*xdr
, u64 n
)
942 p
= reserve_space(xdr
, 8);
943 xdr_encode_hyper(p
, n
);
946 static void encode_nfs4_seqid(struct xdr_stream
*xdr
,
947 const struct nfs_seqid
*seqid
)
950 encode_uint32(xdr
, seqid
->sequence
->counter
);
952 encode_uint32(xdr
, 0);
955 static void encode_compound_hdr(struct xdr_stream
*xdr
,
956 struct rpc_rqst
*req
,
957 struct compound_hdr
*hdr
)
960 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
962 /* initialize running count of expected bytes in reply.
963 * NOTE: the replied tag SHOULD be the same is the one sent,
964 * but this is not required as a MUST for the server to do so. */
965 hdr
->replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ 3 + hdr
->taglen
;
967 WARN_ON_ONCE(hdr
->taglen
> NFS4_MAXTAGLEN
);
968 encode_string(xdr
, hdr
->taglen
, hdr
->tag
);
969 p
= reserve_space(xdr
, 8);
970 *p
++ = cpu_to_be32(hdr
->minorversion
);
972 *p
= cpu_to_be32(hdr
->nops
);
975 static void encode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 op
,
977 struct compound_hdr
*hdr
)
979 encode_uint32(xdr
, op
);
981 hdr
->replen
+= replen
;
984 static void encode_nops(struct compound_hdr
*hdr
)
986 WARN_ON_ONCE(hdr
->nops
> NFS4_MAX_OPS
);
987 *hdr
->nops_p
= htonl(hdr
->nops
);
990 static void encode_nfs4_stateid(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
)
992 encode_opaque_fixed(xdr
, stateid
, NFS4_STATEID_SIZE
);
995 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
997 encode_opaque_fixed(xdr
, verf
->data
, NFS4_VERIFIER_SIZE
);
1000 static void encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
,
1001 const struct nfs4_label
*label
,
1002 const struct nfs_server
*server
)
1004 char owner_name
[IDMAP_NAMESZ
];
1005 char owner_group
[IDMAP_NAMESZ
];
1006 int owner_namelen
= 0;
1007 int owner_grouplen
= 0;
1012 uint32_t bmval
[3] = { 0 };
1015 * We reserve enough space to write the entire attribute buffer at once.
1016 * In the worst-case, this would be
1017 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1018 * = 40 bytes, plus any contribution from variable-length fields
1019 * such as owner/group.
1021 if (iap
->ia_valid
& ATTR_SIZE
) {
1022 bmval
[0] |= FATTR4_WORD0_SIZE
;
1025 if (iap
->ia_valid
& ATTR_MODE
) {
1026 bmval
[1] |= FATTR4_WORD1_MODE
;
1029 if (iap
->ia_valid
& ATTR_UID
) {
1030 owner_namelen
= nfs_map_uid_to_name(server
, iap
->ia_uid
, owner_name
, IDMAP_NAMESZ
);
1031 if (owner_namelen
< 0) {
1032 dprintk("nfs: couldn't resolve uid %d to string\n",
1033 from_kuid(&init_user_ns
, iap
->ia_uid
));
1035 strcpy(owner_name
, "nobody");
1036 owner_namelen
= sizeof("nobody") - 1;
1039 bmval
[1] |= FATTR4_WORD1_OWNER
;
1040 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
1042 if (iap
->ia_valid
& ATTR_GID
) {
1043 owner_grouplen
= nfs_map_gid_to_group(server
, iap
->ia_gid
, owner_group
, IDMAP_NAMESZ
);
1044 if (owner_grouplen
< 0) {
1045 dprintk("nfs: couldn't resolve gid %d to string\n",
1046 from_kgid(&init_user_ns
, iap
->ia_gid
));
1047 strcpy(owner_group
, "nobody");
1048 owner_grouplen
= sizeof("nobody") - 1;
1051 bmval
[1] |= FATTR4_WORD1_OWNER_GROUP
;
1052 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
1054 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
1055 bmval
[1] |= FATTR4_WORD1_TIME_ACCESS_SET
;
1057 } else if (iap
->ia_valid
& ATTR_ATIME
) {
1058 bmval
[1] |= FATTR4_WORD1_TIME_ACCESS_SET
;
1061 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
1062 bmval
[1] |= FATTR4_WORD1_TIME_MODIFY_SET
;
1064 } else if (iap
->ia_valid
& ATTR_MTIME
) {
1065 bmval
[1] |= FATTR4_WORD1_TIME_MODIFY_SET
;
1069 len
+= 4 + 4 + 4 + (XDR_QUADLEN(label
->len
) << 2);
1070 bmval
[2] |= FATTR4_WORD2_SECURITY_LABEL
;
1075 else if (bmval
[1] != 0)
1080 p
= reserve_space(xdr
, 4 + (bmval_len
<< 2) + 4 + len
);
1082 *p
++ = cpu_to_be32(bmval_len
);
1083 for (i
= 0; i
< bmval_len
; i
++)
1084 *p
++ = cpu_to_be32(bmval
[i
]);
1085 *p
++ = cpu_to_be32(len
);
1087 if (bmval
[0] & FATTR4_WORD0_SIZE
)
1088 p
= xdr_encode_hyper(p
, iap
->ia_size
);
1089 if (bmval
[1] & FATTR4_WORD1_MODE
)
1090 *p
++ = cpu_to_be32(iap
->ia_mode
& S_IALLUGO
);
1091 if (bmval
[1] & FATTR4_WORD1_OWNER
)
1092 p
= xdr_encode_opaque(p
, owner_name
, owner_namelen
);
1093 if (bmval
[1] & FATTR4_WORD1_OWNER_GROUP
)
1094 p
= xdr_encode_opaque(p
, owner_group
, owner_grouplen
);
1095 if (bmval
[1] & FATTR4_WORD1_TIME_ACCESS_SET
) {
1096 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
1097 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
1098 p
= xdr_encode_hyper(p
, (s64
)iap
->ia_atime
.tv_sec
);
1099 *p
++ = cpu_to_be32(iap
->ia_atime
.tv_nsec
);
1101 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
1103 if (bmval
[1] & FATTR4_WORD1_TIME_MODIFY_SET
) {
1104 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
1105 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
1106 p
= xdr_encode_hyper(p
, (s64
)iap
->ia_mtime
.tv_sec
);
1107 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_nsec
);
1109 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
1111 if (bmval
[2] & FATTR4_WORD2_SECURITY_LABEL
) {
1112 *p
++ = cpu_to_be32(label
->lfs
);
1113 *p
++ = cpu_to_be32(label
->pi
);
1114 *p
++ = cpu_to_be32(label
->len
);
1115 p
= xdr_encode_opaque_fixed(p
, label
->label
, label
->len
);
1121 static void encode_access(struct xdr_stream
*xdr
, u32 access
, struct compound_hdr
*hdr
)
1123 encode_op_hdr(xdr
, OP_ACCESS
, decode_access_maxsz
, hdr
);
1124 encode_uint32(xdr
, access
);
1127 static void encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1129 encode_op_hdr(xdr
, OP_CLOSE
, decode_close_maxsz
, hdr
);
1130 encode_nfs4_seqid(xdr
, arg
->seqid
);
1131 encode_nfs4_stateid(xdr
, &arg
->stateid
);
1134 static void encode_commit(struct xdr_stream
*xdr
, const struct nfs_commitargs
*args
, struct compound_hdr
*hdr
)
1138 encode_op_hdr(xdr
, OP_COMMIT
, decode_commit_maxsz
, hdr
);
1139 p
= reserve_space(xdr
, 12);
1140 p
= xdr_encode_hyper(p
, args
->offset
);
1141 *p
= cpu_to_be32(args
->count
);
1144 static void encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
, struct compound_hdr
*hdr
)
1148 encode_op_hdr(xdr
, OP_CREATE
, decode_create_maxsz
, hdr
);
1149 encode_uint32(xdr
, create
->ftype
);
1151 switch (create
->ftype
) {
1153 p
= reserve_space(xdr
, 4);
1154 *p
= cpu_to_be32(create
->u
.symlink
.len
);
1155 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0, create
->u
.symlink
.len
);
1158 case NF4BLK
: case NF4CHR
:
1159 p
= reserve_space(xdr
, 8);
1160 *p
++ = cpu_to_be32(create
->u
.device
.specdata1
);
1161 *p
= cpu_to_be32(create
->u
.device
.specdata2
);
1168 encode_string(xdr
, create
->name
->len
, create
->name
->name
);
1169 encode_attrs(xdr
, create
->attrs
, create
->label
, create
->server
);
1172 static void encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
, struct compound_hdr
*hdr
)
1176 encode_op_hdr(xdr
, OP_GETATTR
, decode_getattr_maxsz
, hdr
);
1177 p
= reserve_space(xdr
, 8);
1178 *p
++ = cpu_to_be32(1);
1179 *p
= cpu_to_be32(bitmap
);
1182 static void encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
, struct compound_hdr
*hdr
)
1186 encode_op_hdr(xdr
, OP_GETATTR
, decode_getattr_maxsz
, hdr
);
1187 p
= reserve_space(xdr
, 12);
1188 *p
++ = cpu_to_be32(2);
1189 *p
++ = cpu_to_be32(bm0
);
1190 *p
= cpu_to_be32(bm1
);
1194 encode_getattr_three(struct xdr_stream
*xdr
,
1195 uint32_t bm0
, uint32_t bm1
, uint32_t bm2
,
1196 struct compound_hdr
*hdr
)
1200 encode_op_hdr(xdr
, OP_GETATTR
, decode_getattr_maxsz
, hdr
);
1202 p
= reserve_space(xdr
, 16);
1203 *p
++ = cpu_to_be32(3);
1204 *p
++ = cpu_to_be32(bm0
);
1205 *p
++ = cpu_to_be32(bm1
);
1206 *p
= cpu_to_be32(bm2
);
1208 p
= reserve_space(xdr
, 12);
1209 *p
++ = cpu_to_be32(2);
1210 *p
++ = cpu_to_be32(bm0
);
1211 *p
= cpu_to_be32(bm1
);
1213 p
= reserve_space(xdr
, 8);
1214 *p
++ = cpu_to_be32(1);
1215 *p
= cpu_to_be32(bm0
);
1219 static void encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1221 encode_getattr_three(xdr
, bitmask
[0] & nfs4_fattr_bitmap
[0],
1222 bitmask
[1] & nfs4_fattr_bitmap
[1],
1223 bitmask
[2] & nfs4_fattr_bitmap
[2],
1227 static void encode_getfattr_open(struct xdr_stream
*xdr
, const u32
*bitmask
,
1228 const u32
*open_bitmap
,
1229 struct compound_hdr
*hdr
)
1231 encode_getattr_three(xdr
,
1232 bitmask
[0] & open_bitmap
[0],
1233 bitmask
[1] & open_bitmap
[1],
1234 bitmask
[2] & open_bitmap
[2],
1238 static void encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1240 encode_getattr_three(xdr
,
1241 bitmask
[0] & nfs4_fsinfo_bitmap
[0],
1242 bitmask
[1] & nfs4_fsinfo_bitmap
[1],
1243 bitmask
[2] & nfs4_fsinfo_bitmap
[2],
1247 static void encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1249 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fs_locations_bitmap
[0],
1250 bitmask
[1] & nfs4_fs_locations_bitmap
[1], hdr
);
1253 static void encode_getfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1255 encode_op_hdr(xdr
, OP_GETFH
, decode_getfh_maxsz
, hdr
);
1258 static void encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1260 encode_op_hdr(xdr
, OP_LINK
, decode_link_maxsz
, hdr
);
1261 encode_string(xdr
, name
->len
, name
->name
);
1264 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
1266 if (fl
->fl_type
== F_RDLCK
)
1267 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
1268 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
1271 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
1273 if (fl
->fl_end
== OFFSET_MAX
)
1274 return ~(uint64_t)0;
1275 return fl
->fl_end
- fl
->fl_start
+ 1;
1278 static void encode_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
)
1282 p
= reserve_space(xdr
, 32);
1283 p
= xdr_encode_hyper(p
, lowner
->clientid
);
1284 *p
++ = cpu_to_be32(20);
1285 p
= xdr_encode_opaque_fixed(p
, "lock id:", 8);
1286 *p
++ = cpu_to_be32(lowner
->s_dev
);
1287 xdr_encode_hyper(p
, lowner
->id
);
1291 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1292 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1294 static void encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
, struct compound_hdr
*hdr
)
1298 encode_op_hdr(xdr
, OP_LOCK
, decode_lock_maxsz
, hdr
);
1299 p
= reserve_space(xdr
, 28);
1300 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, args
->block
));
1301 *p
++ = cpu_to_be32(args
->reclaim
);
1302 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1303 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1304 *p
= cpu_to_be32(args
->new_lock_owner
);
1305 if (args
->new_lock_owner
){
1306 encode_nfs4_seqid(xdr
, args
->open_seqid
);
1307 encode_nfs4_stateid(xdr
, &args
->open_stateid
);
1308 encode_nfs4_seqid(xdr
, args
->lock_seqid
);
1309 encode_lockowner(xdr
, &args
->lock_owner
);
1312 encode_nfs4_stateid(xdr
, &args
->lock_stateid
);
1313 encode_nfs4_seqid(xdr
, args
->lock_seqid
);
1317 static void encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
, struct compound_hdr
*hdr
)
1321 encode_op_hdr(xdr
, OP_LOCKT
, decode_lockt_maxsz
, hdr
);
1322 p
= reserve_space(xdr
, 20);
1323 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1324 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1325 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1326 encode_lockowner(xdr
, &args
->lock_owner
);
1329 static void encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
, struct compound_hdr
*hdr
)
1333 encode_op_hdr(xdr
, OP_LOCKU
, decode_locku_maxsz
, hdr
);
1334 encode_uint32(xdr
, nfs4_lock_type(args
->fl
, 0));
1335 encode_nfs4_seqid(xdr
, args
->seqid
);
1336 encode_nfs4_stateid(xdr
, &args
->stateid
);
1337 p
= reserve_space(xdr
, 16);
1338 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1339 xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1342 static void encode_release_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
, struct compound_hdr
*hdr
)
1344 encode_op_hdr(xdr
, OP_RELEASE_LOCKOWNER
, decode_release_lockowner_maxsz
, hdr
);
1345 encode_lockowner(xdr
, lowner
);
1348 static void encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1350 encode_op_hdr(xdr
, OP_LOOKUP
, decode_lookup_maxsz
, hdr
);
1351 encode_string(xdr
, name
->len
, name
->name
);
1354 static void encode_share_access(struct xdr_stream
*xdr
, u32 share_access
)
1358 p
= reserve_space(xdr
, 8);
1359 *p
++ = cpu_to_be32(share_access
);
1360 *p
= cpu_to_be32(0); /* for linux, share_deny = 0 always */
1363 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1367 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1370 encode_nfs4_seqid(xdr
, arg
->seqid
);
1371 encode_share_access(xdr
, arg
->share_access
);
1372 p
= reserve_space(xdr
, 36);
1373 p
= xdr_encode_hyper(p
, arg
->clientid
);
1374 *p
++ = cpu_to_be32(24);
1375 p
= xdr_encode_opaque_fixed(p
, "open id:", 8);
1376 *p
++ = cpu_to_be32(arg
->server
->s_dev
);
1377 *p
++ = cpu_to_be32(arg
->id
.uniquifier
);
1378 xdr_encode_hyper(p
, arg
->id
.create_time
);
1381 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1386 p
= reserve_space(xdr
, 4);
1387 switch(arg
->createmode
) {
1388 case NFS4_CREATE_UNCHECKED
:
1389 *p
= cpu_to_be32(NFS4_CREATE_UNCHECKED
);
1390 encode_attrs(xdr
, arg
->u
.attrs
, arg
->label
, arg
->server
);
1392 case NFS4_CREATE_GUARDED
:
1393 *p
= cpu_to_be32(NFS4_CREATE_GUARDED
);
1394 encode_attrs(xdr
, arg
->u
.attrs
, arg
->label
, arg
->server
);
1396 case NFS4_CREATE_EXCLUSIVE
:
1397 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE
);
1398 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1400 case NFS4_CREATE_EXCLUSIVE4_1
:
1401 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1
);
1402 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1404 encode_attrs(xdr
, &dummy
, arg
->label
, arg
->server
);
1408 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1412 p
= reserve_space(xdr
, 4);
1413 switch (arg
->open_flags
& O_CREAT
) {
1415 *p
= cpu_to_be32(NFS4_OPEN_NOCREATE
);
1418 *p
= cpu_to_be32(NFS4_OPEN_CREATE
);
1419 encode_createmode(xdr
, arg
);
1423 static inline void encode_delegation_type(struct xdr_stream
*xdr
, fmode_t delegation_type
)
1427 p
= reserve_space(xdr
, 4);
1428 switch (delegation_type
) {
1430 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_NONE
);
1433 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_READ
);
1435 case FMODE_WRITE
|FMODE_READ
:
1436 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE
);
1443 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
1447 p
= reserve_space(xdr
, 4);
1448 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_NULL
);
1449 encode_string(xdr
, name
->len
, name
->name
);
1452 static inline void encode_claim_previous(struct xdr_stream
*xdr
, fmode_t type
)
1456 p
= reserve_space(xdr
, 4);
1457 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS
);
1458 encode_delegation_type(xdr
, type
);
1461 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
1465 p
= reserve_space(xdr
, 4);
1466 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
1467 encode_nfs4_stateid(xdr
, stateid
);
1468 encode_string(xdr
, name
->len
, name
->name
);
1471 static inline void encode_claim_fh(struct xdr_stream
*xdr
)
1475 p
= reserve_space(xdr
, 4);
1476 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_FH
);
1479 static inline void encode_claim_delegate_cur_fh(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
)
1483 p
= reserve_space(xdr
, 4);
1484 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
1485 encode_nfs4_stateid(xdr
, stateid
);
1488 static void encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
, struct compound_hdr
*hdr
)
1490 encode_op_hdr(xdr
, OP_OPEN
, decode_open_maxsz
, hdr
);
1491 encode_openhdr(xdr
, arg
);
1492 encode_opentype(xdr
, arg
);
1493 switch (arg
->claim
) {
1494 case NFS4_OPEN_CLAIM_NULL
:
1495 encode_claim_null(xdr
, arg
->name
);
1497 case NFS4_OPEN_CLAIM_PREVIOUS
:
1498 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
1500 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1501 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
1503 case NFS4_OPEN_CLAIM_FH
:
1504 encode_claim_fh(xdr
);
1506 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1507 encode_claim_delegate_cur_fh(xdr
, &arg
->u
.delegation
);
1514 static void encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
, struct compound_hdr
*hdr
)
1516 encode_op_hdr(xdr
, OP_OPEN_CONFIRM
, decode_open_confirm_maxsz
, hdr
);
1517 encode_nfs4_stateid(xdr
, arg
->stateid
);
1518 encode_nfs4_seqid(xdr
, arg
->seqid
);
1521 static void encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1523 encode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
, decode_open_downgrade_maxsz
, hdr
);
1524 encode_nfs4_stateid(xdr
, &arg
->stateid
);
1525 encode_nfs4_seqid(xdr
, arg
->seqid
);
1526 encode_share_access(xdr
, arg
->share_access
);
1530 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
, struct compound_hdr
*hdr
)
1532 encode_op_hdr(xdr
, OP_PUTFH
, decode_putfh_maxsz
, hdr
);
1533 encode_string(xdr
, fh
->size
, fh
->data
);
1536 static void encode_putrootfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1538 encode_op_hdr(xdr
, OP_PUTROOTFH
, decode_putrootfh_maxsz
, hdr
);
1541 static void encode_read(struct xdr_stream
*xdr
, const struct nfs_pgio_args
*args
,
1542 struct compound_hdr
*hdr
)
1546 encode_op_hdr(xdr
, OP_READ
, decode_read_maxsz
, hdr
);
1547 encode_nfs4_stateid(xdr
, &args
->stateid
);
1549 p
= reserve_space(xdr
, 12);
1550 p
= xdr_encode_hyper(p
, args
->offset
);
1551 *p
= cpu_to_be32(args
->count
);
1554 static void encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1556 uint32_t attrs
[3] = {
1557 FATTR4_WORD0_RDATTR_ERROR
,
1558 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1560 uint32_t dircount
= readdir
->count
>> 1;
1562 uint32_t attrlen
= 0;
1565 if (readdir
->plus
) {
1566 attrs
[0] |= FATTR4_WORD0_TYPE
|FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
|
1567 FATTR4_WORD0_FSID
|FATTR4_WORD0_FILEHANDLE
|FATTR4_WORD0_FILEID
;
1568 attrs
[1] |= FATTR4_WORD1_MODE
|FATTR4_WORD1_NUMLINKS
|FATTR4_WORD1_OWNER
|
1569 FATTR4_WORD1_OWNER_GROUP
|FATTR4_WORD1_RAWDEV
|
1570 FATTR4_WORD1_SPACE_USED
|FATTR4_WORD1_TIME_ACCESS
|
1571 FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
1572 attrs
[2] |= FATTR4_WORD2_SECURITY_LABEL
;
1575 /* Use mounted_on_fileid only if the server supports it */
1576 if (!(readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
))
1577 attrs
[0] |= FATTR4_WORD0_FILEID
;
1578 for (i
= 0; i
< ARRAY_SIZE(attrs
); i
++) {
1579 attrs
[i
] &= readdir
->bitmask
[i
];
1584 encode_op_hdr(xdr
, OP_READDIR
, decode_readdir_maxsz
, hdr
);
1585 encode_uint64(xdr
, readdir
->cookie
);
1586 encode_nfs4_verifier(xdr
, &readdir
->verifier
);
1587 p
= reserve_space(xdr
, 12 + (attrlen
<< 2));
1588 *p
++ = cpu_to_be32(dircount
);
1589 *p
++ = cpu_to_be32(readdir
->count
);
1590 *p
++ = cpu_to_be32(attrlen
);
1591 for (i
= 0; i
< attrlen
; i
++)
1592 *p
++ = cpu_to_be32(attrs
[i
]);
1593 memcpy(verf
, readdir
->verifier
.data
, sizeof(verf
));
1595 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1597 (unsigned long long)readdir
->cookie
,
1599 attrs
[0] & readdir
->bitmask
[0],
1600 attrs
[1] & readdir
->bitmask
[1],
1601 attrs
[2] & readdir
->bitmask
[2]);
1604 static void encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1606 encode_op_hdr(xdr
, OP_READLINK
, decode_readlink_maxsz
, hdr
);
1609 static void encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1611 encode_op_hdr(xdr
, OP_REMOVE
, decode_remove_maxsz
, hdr
);
1612 encode_string(xdr
, name
->len
, name
->name
);
1615 static void encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
, struct compound_hdr
*hdr
)
1617 encode_op_hdr(xdr
, OP_RENAME
, decode_rename_maxsz
, hdr
);
1618 encode_string(xdr
, oldname
->len
, oldname
->name
);
1619 encode_string(xdr
, newname
->len
, newname
->name
);
1622 static void encode_renew(struct xdr_stream
*xdr
, clientid4 clid
,
1623 struct compound_hdr
*hdr
)
1625 encode_op_hdr(xdr
, OP_RENEW
, decode_renew_maxsz
, hdr
);
1626 encode_uint64(xdr
, clid
);
1630 encode_restorefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1632 encode_op_hdr(xdr
, OP_RESTOREFH
, decode_restorefh_maxsz
, hdr
);
1636 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
, struct compound_hdr
*hdr
)
1640 encode_op_hdr(xdr
, OP_SETATTR
, decode_setacl_maxsz
, hdr
);
1641 encode_nfs4_stateid(xdr
, &zero_stateid
);
1642 p
= reserve_space(xdr
, 2*4);
1643 *p
++ = cpu_to_be32(1);
1644 *p
= cpu_to_be32(FATTR4_WORD0_ACL
);
1645 p
= reserve_space(xdr
, 4);
1646 *p
= cpu_to_be32(arg
->acl_len
);
1647 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1651 encode_savefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1653 encode_op_hdr(xdr
, OP_SAVEFH
, decode_savefh_maxsz
, hdr
);
1656 static void encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
, struct compound_hdr
*hdr
)
1658 encode_op_hdr(xdr
, OP_SETATTR
, decode_setattr_maxsz
, hdr
);
1659 encode_nfs4_stateid(xdr
, &arg
->stateid
);
1660 encode_attrs(xdr
, arg
->iap
, arg
->label
, server
);
1663 static void encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
, struct compound_hdr
*hdr
)
1667 encode_op_hdr(xdr
, OP_SETCLIENTID
, decode_setclientid_maxsz
, hdr
);
1668 encode_nfs4_verifier(xdr
, setclientid
->sc_verifier
);
1670 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1671 p
= reserve_space(xdr
, 4);
1672 *p
= cpu_to_be32(setclientid
->sc_prog
);
1673 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1674 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1675 p
= reserve_space(xdr
, 4);
1676 *p
= cpu_to_be32(setclientid
->sc_cb_ident
);
1679 static void encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs4_setclientid_res
*arg
, struct compound_hdr
*hdr
)
1681 encode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
,
1682 decode_setclientid_confirm_maxsz
, hdr
);
1683 encode_uint64(xdr
, arg
->clientid
);
1684 encode_nfs4_verifier(xdr
, &arg
->confirm
);
1687 static void encode_write(struct xdr_stream
*xdr
, const struct nfs_pgio_args
*args
,
1688 struct compound_hdr
*hdr
)
1692 encode_op_hdr(xdr
, OP_WRITE
, decode_write_maxsz
, hdr
);
1693 encode_nfs4_stateid(xdr
, &args
->stateid
);
1695 p
= reserve_space(xdr
, 16);
1696 p
= xdr_encode_hyper(p
, args
->offset
);
1697 *p
++ = cpu_to_be32(args
->stable
);
1698 *p
= cpu_to_be32(args
->count
);
1700 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1703 static void encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
, struct compound_hdr
*hdr
)
1705 encode_op_hdr(xdr
, OP_DELEGRETURN
, decode_delegreturn_maxsz
, hdr
);
1706 encode_nfs4_stateid(xdr
, stateid
);
1709 static void encode_secinfo(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1711 encode_op_hdr(xdr
, OP_SECINFO
, decode_secinfo_maxsz
, hdr
);
1712 encode_string(xdr
, name
->len
, name
->name
);
1715 #if defined(CONFIG_NFS_V4_1)
1716 /* NFSv4.1 operations */
1717 static void encode_bind_conn_to_session(struct xdr_stream
*xdr
,
1718 struct nfs41_bind_conn_to_session_args
*args
,
1719 struct compound_hdr
*hdr
)
1723 encode_op_hdr(xdr
, OP_BIND_CONN_TO_SESSION
,
1724 decode_bind_conn_to_session_maxsz
, hdr
);
1725 encode_opaque_fixed(xdr
, args
->sessionid
.data
, NFS4_MAX_SESSIONID_LEN
);
1726 p
= xdr_reserve_space(xdr
, 8);
1727 *p
++ = cpu_to_be32(args
->dir
);
1728 *p
= (args
->use_conn_in_rdma_mode
) ? cpu_to_be32(1) : cpu_to_be32(0);
1731 static void encode_op_map(struct xdr_stream
*xdr
, struct nfs4_op_map
*op_map
)
1734 encode_uint32(xdr
, NFS4_OP_MAP_NUM_WORDS
);
1735 for (i
= 0; i
< NFS4_OP_MAP_NUM_WORDS
; i
++)
1736 encode_uint32(xdr
, op_map
->u
.words
[i
]);
1739 static void encode_exchange_id(struct xdr_stream
*xdr
,
1740 struct nfs41_exchange_id_args
*args
,
1741 struct compound_hdr
*hdr
)
1744 char impl_name
[IMPL_NAME_LIMIT
];
1747 encode_op_hdr(xdr
, OP_EXCHANGE_ID
, decode_exchange_id_maxsz
, hdr
);
1748 encode_nfs4_verifier(xdr
, args
->verifier
);
1750 encode_string(xdr
, args
->id_len
, args
->id
);
1752 encode_uint32(xdr
, args
->flags
);
1753 encode_uint32(xdr
, args
->state_protect
.how
);
1755 switch (args
->state_protect
.how
) {
1759 encode_op_map(xdr
, &args
->state_protect
.enforce
);
1760 encode_op_map(xdr
, &args
->state_protect
.allow
);
1767 if (send_implementation_id
&&
1768 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
) > 1 &&
1769 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
)
1770 <= sizeof(impl_name
) + 1)
1771 len
= snprintf(impl_name
, sizeof(impl_name
), "%s %s %s %s",
1772 utsname()->sysname
, utsname()->release
,
1773 utsname()->version
, utsname()->machine
);
1776 encode_uint32(xdr
, 1); /* implementation id array length=1 */
1779 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
) - 1,
1780 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
);
1781 encode_string(xdr
, len
, impl_name
);
1782 /* just send zeros for nii_date - the date is in nii_name */
1783 p
= reserve_space(xdr
, 12);
1784 p
= xdr_encode_hyper(p
, 0);
1785 *p
= cpu_to_be32(0);
1787 encode_uint32(xdr
, 0); /* implementation id array length=0 */
1790 static void encode_create_session(struct xdr_stream
*xdr
,
1791 struct nfs41_create_session_args
*args
,
1792 struct compound_hdr
*hdr
)
1795 struct nfs_client
*clp
= args
->client
;
1796 struct rpc_clnt
*clnt
= clp
->cl_rpcclient
;
1797 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
1798 u32 max_resp_sz_cached
;
1801 * Assumes OPEN is the biggest non-idempotent compound.
1802 * 2 is the verifier.
1804 max_resp_sz_cached
= (NFS4_dec_open_sz
+ RPC_REPHDRSIZE
+
1805 RPC_MAX_AUTH_SIZE
+ 2) * XDR_UNIT
;
1807 encode_op_hdr(xdr
, OP_CREATE_SESSION
, decode_create_session_maxsz
, hdr
);
1808 p
= reserve_space(xdr
, 16 + 2*28 + 20 + clnt
->cl_nodelen
+ 12);
1809 p
= xdr_encode_hyper(p
, args
->clientid
);
1810 *p
++ = cpu_to_be32(args
->seqid
); /*Sequence id */
1811 *p
++ = cpu_to_be32(args
->flags
); /*flags */
1814 *p
++ = cpu_to_be32(0); /* header padding size */
1815 *p
++ = cpu_to_be32(args
->fc_attrs
.max_rqst_sz
); /* max req size */
1816 *p
++ = cpu_to_be32(args
->fc_attrs
.max_resp_sz
); /* max resp size */
1817 *p
++ = cpu_to_be32(max_resp_sz_cached
); /* Max resp sz cached */
1818 *p
++ = cpu_to_be32(args
->fc_attrs
.max_ops
); /* max operations */
1819 *p
++ = cpu_to_be32(args
->fc_attrs
.max_reqs
); /* max requests */
1820 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1823 *p
++ = cpu_to_be32(0); /* header padding size */
1824 *p
++ = cpu_to_be32(args
->bc_attrs
.max_rqst_sz
); /* max req size */
1825 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz
); /* max resp size */
1826 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz_cached
); /* Max resp sz cached */
1827 *p
++ = cpu_to_be32(args
->bc_attrs
.max_ops
); /* max operations */
1828 *p
++ = cpu_to_be32(args
->bc_attrs
.max_reqs
); /* max requests */
1829 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1831 *p
++ = cpu_to_be32(args
->cb_program
); /* cb_program */
1832 *p
++ = cpu_to_be32(1);
1833 *p
++ = cpu_to_be32(RPC_AUTH_UNIX
); /* auth_sys */
1835 /* authsys_parms rfc1831 */
1836 *p
++ = cpu_to_be32(nn
->boot_time
.tv_nsec
); /* stamp */
1837 p
= xdr_encode_array(p
, clnt
->cl_nodename
, clnt
->cl_nodelen
);
1838 *p
++ = cpu_to_be32(0); /* UID */
1839 *p
++ = cpu_to_be32(0); /* GID */
1840 *p
= cpu_to_be32(0); /* No more gids */
1843 static void encode_destroy_session(struct xdr_stream
*xdr
,
1844 struct nfs4_session
*session
,
1845 struct compound_hdr
*hdr
)
1847 encode_op_hdr(xdr
, OP_DESTROY_SESSION
, decode_destroy_session_maxsz
, hdr
);
1848 encode_opaque_fixed(xdr
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1851 static void encode_destroy_clientid(struct xdr_stream
*xdr
,
1853 struct compound_hdr
*hdr
)
1855 encode_op_hdr(xdr
, OP_DESTROY_CLIENTID
, decode_destroy_clientid_maxsz
, hdr
);
1856 encode_uint64(xdr
, clientid
);
1859 static void encode_reclaim_complete(struct xdr_stream
*xdr
,
1860 struct nfs41_reclaim_complete_args
*args
,
1861 struct compound_hdr
*hdr
)
1863 encode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
, decode_reclaim_complete_maxsz
, hdr
);
1864 encode_uint32(xdr
, args
->one_fs
);
1866 #endif /* CONFIG_NFS_V4_1 */
1868 static void encode_sequence(struct xdr_stream
*xdr
,
1869 const struct nfs4_sequence_args
*args
,
1870 struct compound_hdr
*hdr
)
1872 #if defined(CONFIG_NFS_V4_1)
1873 struct nfs4_session
*session
;
1874 struct nfs4_slot_table
*tp
;
1875 struct nfs4_slot
*slot
= args
->sa_slot
;
1879 session
= tp
->session
;
1883 encode_op_hdr(xdr
, OP_SEQUENCE
, decode_sequence_maxsz
, hdr
);
1886 * Sessionid + seqid + slotid + max slotid + cache_this
1888 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1889 "max_slotid=%d cache_this=%d\n",
1891 ((u32
*)session
->sess_id
.data
)[0],
1892 ((u32
*)session
->sess_id
.data
)[1],
1893 ((u32
*)session
->sess_id
.data
)[2],
1894 ((u32
*)session
->sess_id
.data
)[3],
1895 slot
->seq_nr
, slot
->slot_nr
,
1896 tp
->highest_used_slotid
, args
->sa_cache_this
);
1897 p
= reserve_space(xdr
, NFS4_MAX_SESSIONID_LEN
+ 16);
1898 p
= xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1899 *p
++ = cpu_to_be32(slot
->seq_nr
);
1900 *p
++ = cpu_to_be32(slot
->slot_nr
);
1901 *p
++ = cpu_to_be32(tp
->highest_used_slotid
);
1902 *p
= cpu_to_be32(args
->sa_cache_this
);
1903 #endif /* CONFIG_NFS_V4_1 */
1906 #ifdef CONFIG_NFS_V4_1
1908 encode_getdeviceinfo(struct xdr_stream
*xdr
,
1909 const struct nfs4_getdeviceinfo_args
*args
,
1910 struct compound_hdr
*hdr
)
1914 encode_op_hdr(xdr
, OP_GETDEVICEINFO
, decode_getdeviceinfo_maxsz
, hdr
);
1915 p
= reserve_space(xdr
, NFS4_DEVICEID4_SIZE
+ 4 + 4);
1916 p
= xdr_encode_opaque_fixed(p
, args
->pdev
->dev_id
.data
,
1917 NFS4_DEVICEID4_SIZE
);
1918 *p
++ = cpu_to_be32(args
->pdev
->layout_type
);
1919 *p
++ = cpu_to_be32(args
->pdev
->maxcount
); /* gdia_maxcount */
1921 p
= reserve_space(xdr
, 4 + 4);
1922 *p
++ = cpu_to_be32(1); /* bitmap length */
1923 *p
++ = cpu_to_be32(args
->notify_types
);
1927 encode_layoutget(struct xdr_stream
*xdr
,
1928 const struct nfs4_layoutget_args
*args
,
1929 struct compound_hdr
*hdr
)
1933 encode_op_hdr(xdr
, OP_LAYOUTGET
, decode_layoutget_maxsz
, hdr
);
1934 p
= reserve_space(xdr
, 36);
1935 *p
++ = cpu_to_be32(0); /* Signal layout available */
1936 *p
++ = cpu_to_be32(args
->type
);
1937 *p
++ = cpu_to_be32(args
->range
.iomode
);
1938 p
= xdr_encode_hyper(p
, args
->range
.offset
);
1939 p
= xdr_encode_hyper(p
, args
->range
.length
);
1940 p
= xdr_encode_hyper(p
, args
->minlength
);
1941 encode_nfs4_stateid(xdr
, &args
->stateid
);
1942 encode_uint32(xdr
, args
->maxcount
);
1944 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1948 (unsigned long)args
->range
.offset
,
1949 (unsigned long)args
->range
.length
,
1954 encode_layoutcommit(struct xdr_stream
*xdr
,
1955 struct inode
*inode
,
1956 struct nfs4_layoutcommit_args
*args
,
1957 struct compound_hdr
*hdr
)
1961 dprintk("%s: lbw: %llu type: %d\n", __func__
, args
->lastbytewritten
,
1962 NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);
1964 encode_op_hdr(xdr
, OP_LAYOUTCOMMIT
, decode_layoutcommit_maxsz
, hdr
);
1965 p
= reserve_space(xdr
, 20);
1966 /* Only whole file layouts */
1967 p
= xdr_encode_hyper(p
, 0); /* offset */
1968 p
= xdr_encode_hyper(p
, args
->lastbytewritten
+ 1); /* length */
1969 *p
= cpu_to_be32(0); /* reclaim */
1970 encode_nfs4_stateid(xdr
, &args
->stateid
);
1971 p
= reserve_space(xdr
, 20);
1972 *p
++ = cpu_to_be32(1); /* newoffset = TRUE */
1973 p
= xdr_encode_hyper(p
, args
->lastbytewritten
);
1974 *p
++ = cpu_to_be32(0); /* Never send time_modify_changed */
1975 *p
++ = cpu_to_be32(NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);/* type */
1977 if (NFS_SERVER(inode
)->pnfs_curr_ld
->encode_layoutcommit
) {
1978 NFS_SERVER(inode
)->pnfs_curr_ld
->encode_layoutcommit(
1979 NFS_I(inode
)->layout
, xdr
, args
);
1981 encode_uint32(xdr
, args
->layoutupdate_len
);
1982 if (args
->layoutupdate_pages
) {
1983 xdr_write_pages(xdr
, args
->layoutupdate_pages
, 0,
1984 args
->layoutupdate_len
);
1992 encode_layoutreturn(struct xdr_stream
*xdr
,
1993 const struct nfs4_layoutreturn_args
*args
,
1994 struct compound_hdr
*hdr
)
1998 encode_op_hdr(xdr
, OP_LAYOUTRETURN
, decode_layoutreturn_maxsz
, hdr
);
1999 p
= reserve_space(xdr
, 16);
2000 *p
++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2001 *p
++ = cpu_to_be32(args
->layout_type
);
2002 *p
++ = cpu_to_be32(args
->range
.iomode
);
2003 *p
= cpu_to_be32(RETURN_FILE
);
2004 p
= reserve_space(xdr
, 16);
2005 p
= xdr_encode_hyper(p
, args
->range
.offset
);
2006 p
= xdr_encode_hyper(p
, args
->range
.length
);
2007 spin_lock(&args
->inode
->i_lock
);
2008 encode_nfs4_stateid(xdr
, &args
->stateid
);
2009 spin_unlock(&args
->inode
->i_lock
);
2010 if (NFS_SERVER(args
->inode
)->pnfs_curr_ld
->encode_layoutreturn
) {
2011 NFS_SERVER(args
->inode
)->pnfs_curr_ld
->encode_layoutreturn(
2012 NFS_I(args
->inode
)->layout
, xdr
, args
);
2014 encode_uint32(xdr
, 0);
2018 encode_secinfo_no_name(struct xdr_stream
*xdr
,
2019 const struct nfs41_secinfo_no_name_args
*args
,
2020 struct compound_hdr
*hdr
)
2022 encode_op_hdr(xdr
, OP_SECINFO_NO_NAME
, decode_secinfo_no_name_maxsz
, hdr
);
2023 encode_uint32(xdr
, args
->style
);
2027 static void encode_test_stateid(struct xdr_stream
*xdr
,
2028 struct nfs41_test_stateid_args
*args
,
2029 struct compound_hdr
*hdr
)
2031 encode_op_hdr(xdr
, OP_TEST_STATEID
, decode_test_stateid_maxsz
, hdr
);
2032 encode_uint32(xdr
, 1);
2033 encode_nfs4_stateid(xdr
, args
->stateid
);
2036 static void encode_free_stateid(struct xdr_stream
*xdr
,
2037 struct nfs41_free_stateid_args
*args
,
2038 struct compound_hdr
*hdr
)
2040 encode_op_hdr(xdr
, OP_FREE_STATEID
, decode_free_stateid_maxsz
, hdr
);
2041 encode_nfs4_stateid(xdr
, &args
->stateid
);
2043 #endif /* CONFIG_NFS_V4_1 */
2046 * END OF "GENERIC" ENCODE ROUTINES.
2049 static u32
nfs4_xdr_minorversion(const struct nfs4_sequence_args
*args
)
2051 #if defined(CONFIG_NFS_V4_1)
2052 struct nfs4_session
*session
= args
->sa_slot
->table
->session
;
2054 return session
->clp
->cl_mvops
->minor_version
;
2055 #endif /* CONFIG_NFS_V4_1 */
2060 * Encode an ACCESS request
2062 static void nfs4_xdr_enc_access(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2063 const struct nfs4_accessargs
*args
)
2065 struct compound_hdr hdr
= {
2066 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2069 encode_compound_hdr(xdr
, req
, &hdr
);
2070 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2071 encode_putfh(xdr
, args
->fh
, &hdr
);
2072 encode_access(xdr
, args
->access
, &hdr
);
2073 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2078 * Encode LOOKUP request
2080 static void nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2081 const struct nfs4_lookup_arg
*args
)
2083 struct compound_hdr hdr
= {
2084 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2087 encode_compound_hdr(xdr
, req
, &hdr
);
2088 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2089 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2090 encode_lookup(xdr
, args
->name
, &hdr
);
2091 encode_getfh(xdr
, &hdr
);
2092 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2097 * Encode LOOKUP_ROOT request
2099 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
,
2100 struct xdr_stream
*xdr
,
2101 const struct nfs4_lookup_root_arg
*args
)
2103 struct compound_hdr hdr
= {
2104 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2107 encode_compound_hdr(xdr
, req
, &hdr
);
2108 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2109 encode_putrootfh(xdr
, &hdr
);
2110 encode_getfh(xdr
, &hdr
);
2111 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2116 * Encode REMOVE request
2118 static void nfs4_xdr_enc_remove(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2119 const struct nfs_removeargs
*args
)
2121 struct compound_hdr hdr
= {
2122 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2125 encode_compound_hdr(xdr
, req
, &hdr
);
2126 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2127 encode_putfh(xdr
, args
->fh
, &hdr
);
2128 encode_remove(xdr
, &args
->name
, &hdr
);
2133 * Encode RENAME request
2135 static void nfs4_xdr_enc_rename(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2136 const struct nfs_renameargs
*args
)
2138 struct compound_hdr hdr
= {
2139 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2142 encode_compound_hdr(xdr
, req
, &hdr
);
2143 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2144 encode_putfh(xdr
, args
->old_dir
, &hdr
);
2145 encode_savefh(xdr
, &hdr
);
2146 encode_putfh(xdr
, args
->new_dir
, &hdr
);
2147 encode_rename(xdr
, args
->old_name
, args
->new_name
, &hdr
);
2152 * Encode LINK request
2154 static void nfs4_xdr_enc_link(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2155 const struct nfs4_link_arg
*args
)
2157 struct compound_hdr hdr
= {
2158 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2161 encode_compound_hdr(xdr
, req
, &hdr
);
2162 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2163 encode_putfh(xdr
, args
->fh
, &hdr
);
2164 encode_savefh(xdr
, &hdr
);
2165 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2166 encode_link(xdr
, args
->name
, &hdr
);
2167 encode_restorefh(xdr
, &hdr
);
2168 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2173 * Encode CREATE request
2175 static void nfs4_xdr_enc_create(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2176 const struct nfs4_create_arg
*args
)
2178 struct compound_hdr hdr
= {
2179 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2182 encode_compound_hdr(xdr
, req
, &hdr
);
2183 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2184 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2185 encode_create(xdr
, args
, &hdr
);
2186 encode_getfh(xdr
, &hdr
);
2187 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2192 * Encode SYMLINK request
2194 static void nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2195 const struct nfs4_create_arg
*args
)
2197 nfs4_xdr_enc_create(req
, xdr
, args
);
2201 * Encode GETATTR request
2203 static void nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2204 const struct nfs4_getattr_arg
*args
)
2206 struct compound_hdr hdr
= {
2207 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2210 encode_compound_hdr(xdr
, req
, &hdr
);
2211 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2212 encode_putfh(xdr
, args
->fh
, &hdr
);
2213 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2218 * Encode a CLOSE request
2220 static void nfs4_xdr_enc_close(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2221 struct nfs_closeargs
*args
)
2223 struct compound_hdr hdr
= {
2224 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2227 encode_compound_hdr(xdr
, req
, &hdr
);
2228 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2229 encode_putfh(xdr
, args
->fh
, &hdr
);
2230 encode_close(xdr
, args
, &hdr
);
2231 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2236 * Encode an OPEN request
2238 static void nfs4_xdr_enc_open(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2239 struct nfs_openargs
*args
)
2241 struct compound_hdr hdr
= {
2242 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2245 encode_compound_hdr(xdr
, req
, &hdr
);
2246 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2247 encode_putfh(xdr
, args
->fh
, &hdr
);
2248 encode_open(xdr
, args
, &hdr
);
2249 encode_getfh(xdr
, &hdr
);
2251 encode_access(xdr
, args
->access
, &hdr
);
2252 encode_getfattr_open(xdr
, args
->bitmask
, args
->open_bitmap
, &hdr
);
2257 * Encode an OPEN_CONFIRM request
2259 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
,
2260 struct xdr_stream
*xdr
,
2261 struct nfs_open_confirmargs
*args
)
2263 struct compound_hdr hdr
= {
2267 encode_compound_hdr(xdr
, req
, &hdr
);
2268 encode_putfh(xdr
, args
->fh
, &hdr
);
2269 encode_open_confirm(xdr
, args
, &hdr
);
2274 * Encode an OPEN request with no attributes.
2276 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
,
2277 struct xdr_stream
*xdr
,
2278 struct nfs_openargs
*args
)
2280 struct compound_hdr hdr
= {
2281 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2284 encode_compound_hdr(xdr
, req
, &hdr
);
2285 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2286 encode_putfh(xdr
, args
->fh
, &hdr
);
2287 encode_open(xdr
, args
, &hdr
);
2289 encode_access(xdr
, args
->access
, &hdr
);
2290 encode_getfattr_open(xdr
, args
->bitmask
, args
->open_bitmap
, &hdr
);
2295 * Encode an OPEN_DOWNGRADE request
2297 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
,
2298 struct xdr_stream
*xdr
,
2299 struct nfs_closeargs
*args
)
2301 struct compound_hdr hdr
= {
2302 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2305 encode_compound_hdr(xdr
, req
, &hdr
);
2306 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2307 encode_putfh(xdr
, args
->fh
, &hdr
);
2308 encode_open_downgrade(xdr
, args
, &hdr
);
2309 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2314 * Encode a LOCK request
2316 static void nfs4_xdr_enc_lock(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2317 struct nfs_lock_args
*args
)
2319 struct compound_hdr hdr
= {
2320 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2323 encode_compound_hdr(xdr
, req
, &hdr
);
2324 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2325 encode_putfh(xdr
, args
->fh
, &hdr
);
2326 encode_lock(xdr
, args
, &hdr
);
2331 * Encode a LOCKT request
2333 static void nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2334 struct nfs_lockt_args
*args
)
2336 struct compound_hdr hdr
= {
2337 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2340 encode_compound_hdr(xdr
, req
, &hdr
);
2341 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2342 encode_putfh(xdr
, args
->fh
, &hdr
);
2343 encode_lockt(xdr
, args
, &hdr
);
2348 * Encode a LOCKU request
2350 static void nfs4_xdr_enc_locku(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2351 struct nfs_locku_args
*args
)
2353 struct compound_hdr hdr
= {
2354 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2357 encode_compound_hdr(xdr
, req
, &hdr
);
2358 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2359 encode_putfh(xdr
, args
->fh
, &hdr
);
2360 encode_locku(xdr
, args
, &hdr
);
2364 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst
*req
,
2365 struct xdr_stream
*xdr
,
2366 struct nfs_release_lockowner_args
*args
)
2368 struct compound_hdr hdr
= {
2372 encode_compound_hdr(xdr
, req
, &hdr
);
2373 encode_release_lockowner(xdr
, &args
->lock_owner
, &hdr
);
2378 * Encode a READLINK request
2380 static void nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2381 const struct nfs4_readlink
*args
)
2383 struct compound_hdr hdr
= {
2384 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2387 encode_compound_hdr(xdr
, req
, &hdr
);
2388 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2389 encode_putfh(xdr
, args
->fh
, &hdr
);
2390 encode_readlink(xdr
, args
, req
, &hdr
);
2392 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2393 args
->pgbase
, args
->pglen
);
2398 * Encode a READDIR request
2400 static void nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2401 const struct nfs4_readdir_arg
*args
)
2403 struct compound_hdr hdr
= {
2404 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2407 encode_compound_hdr(xdr
, req
, &hdr
);
2408 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2409 encode_putfh(xdr
, args
->fh
, &hdr
);
2410 encode_readdir(xdr
, args
, req
, &hdr
);
2412 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2413 args
->pgbase
, args
->count
);
2414 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2415 __func__
, hdr
.replen
<< 2, args
->pages
,
2416 args
->pgbase
, args
->count
);
2421 * Encode a READ request
2423 static void nfs4_xdr_enc_read(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2424 struct nfs_pgio_args
*args
)
2426 struct compound_hdr hdr
= {
2427 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2430 encode_compound_hdr(xdr
, req
, &hdr
);
2431 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2432 encode_putfh(xdr
, args
->fh
, &hdr
);
2433 encode_read(xdr
, args
, &hdr
);
2435 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2436 args
->pages
, args
->pgbase
, args
->count
);
2437 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
2442 * Encode an SETATTR request
2444 static void nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2445 struct nfs_setattrargs
*args
)
2447 struct compound_hdr hdr
= {
2448 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2451 encode_compound_hdr(xdr
, req
, &hdr
);
2452 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2453 encode_putfh(xdr
, args
->fh
, &hdr
);
2454 encode_setattr(xdr
, args
, args
->server
, &hdr
);
2455 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2460 * Encode a GETACL request
2462 static void nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2463 struct nfs_getaclargs
*args
)
2465 struct compound_hdr hdr
= {
2466 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2470 encode_compound_hdr(xdr
, req
, &hdr
);
2471 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2472 encode_putfh(xdr
, args
->fh
, &hdr
);
2473 replen
= hdr
.replen
+ op_decode_hdr_maxsz
+ 1;
2474 encode_getattr_two(xdr
, FATTR4_WORD0_ACL
, 0, &hdr
);
2476 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2,
2477 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
2483 * Encode a WRITE request
2485 static void nfs4_xdr_enc_write(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2486 struct nfs_pgio_args
*args
)
2488 struct compound_hdr hdr
= {
2489 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2492 encode_compound_hdr(xdr
, req
, &hdr
);
2493 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2494 encode_putfh(xdr
, args
->fh
, &hdr
);
2495 encode_write(xdr
, args
, &hdr
);
2496 req
->rq_snd_buf
.flags
|= XDRBUF_WRITE
;
2498 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2505 static void nfs4_xdr_enc_commit(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2506 struct nfs_commitargs
*args
)
2508 struct compound_hdr hdr
= {
2509 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2512 encode_compound_hdr(xdr
, req
, &hdr
);
2513 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2514 encode_putfh(xdr
, args
->fh
, &hdr
);
2515 encode_commit(xdr
, args
, &hdr
);
2522 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2523 struct nfs4_fsinfo_arg
*args
)
2525 struct compound_hdr hdr
= {
2526 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2529 encode_compound_hdr(xdr
, req
, &hdr
);
2530 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2531 encode_putfh(xdr
, args
->fh
, &hdr
);
2532 encode_fsinfo(xdr
, args
->bitmask
, &hdr
);
2537 * a PATHCONF request
2539 static void nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2540 const struct nfs4_pathconf_arg
*args
)
2542 struct compound_hdr hdr
= {
2543 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2546 encode_compound_hdr(xdr
, req
, &hdr
);
2547 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2548 encode_putfh(xdr
, args
->fh
, &hdr
);
2549 encode_getattr_one(xdr
, args
->bitmask
[0] & nfs4_pathconf_bitmap
[0],
2557 static void nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2558 const struct nfs4_statfs_arg
*args
)
2560 struct compound_hdr hdr
= {
2561 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2564 encode_compound_hdr(xdr
, req
, &hdr
);
2565 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2566 encode_putfh(xdr
, args
->fh
, &hdr
);
2567 encode_getattr_two(xdr
, args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
2568 args
->bitmask
[1] & nfs4_statfs_bitmap
[1], &hdr
);
2573 * GETATTR_BITMAP request
2575 static void nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
,
2576 struct xdr_stream
*xdr
,
2577 struct nfs4_server_caps_arg
*args
)
2579 struct compound_hdr hdr
= {
2580 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2583 encode_compound_hdr(xdr
, req
, &hdr
);
2584 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2585 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2586 encode_getattr_one(xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
2587 FATTR4_WORD0_FH_EXPIRE_TYPE
|
2588 FATTR4_WORD0_LINK_SUPPORT
|
2589 FATTR4_WORD0_SYMLINK_SUPPORT
|
2590 FATTR4_WORD0_ACLSUPPORT
, &hdr
);
2597 static void nfs4_xdr_enc_renew(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2598 struct nfs_client
*clp
)
2600 struct compound_hdr hdr
= {
2604 encode_compound_hdr(xdr
, req
, &hdr
);
2605 encode_renew(xdr
, clp
->cl_clientid
, &hdr
);
2610 * a SETCLIENTID request
2612 static void nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
,
2613 struct xdr_stream
*xdr
,
2614 struct nfs4_setclientid
*sc
)
2616 struct compound_hdr hdr
= {
2620 encode_compound_hdr(xdr
, req
, &hdr
);
2621 encode_setclientid(xdr
, sc
, &hdr
);
2626 * a SETCLIENTID_CONFIRM request
2628 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
,
2629 struct xdr_stream
*xdr
,
2630 struct nfs4_setclientid_res
*arg
)
2632 struct compound_hdr hdr
= {
2636 encode_compound_hdr(xdr
, req
, &hdr
);
2637 encode_setclientid_confirm(xdr
, arg
, &hdr
);
2642 * DELEGRETURN request
2644 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
,
2645 struct xdr_stream
*xdr
,
2646 const struct nfs4_delegreturnargs
*args
)
2648 struct compound_hdr hdr
= {
2649 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2652 encode_compound_hdr(xdr
, req
, &hdr
);
2653 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2654 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2655 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2656 encode_delegreturn(xdr
, args
->stateid
, &hdr
);
2661 * Encode FS_LOCATIONS request
2663 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
,
2664 struct xdr_stream
*xdr
,
2665 struct nfs4_fs_locations_arg
*args
)
2667 struct compound_hdr hdr
= {
2668 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2672 encode_compound_hdr(xdr
, req
, &hdr
);
2673 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2674 if (args
->migration
) {
2675 encode_putfh(xdr
, args
->fh
, &hdr
);
2676 replen
= hdr
.replen
;
2677 encode_fs_locations(xdr
, args
->bitmask
, &hdr
);
2679 encode_renew(xdr
, args
->clientid
, &hdr
);
2681 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2682 encode_lookup(xdr
, args
->name
, &hdr
);
2683 replen
= hdr
.replen
;
2684 encode_fs_locations(xdr
, args
->bitmask
, &hdr
);
2687 /* Set up reply kvec to capture returned fs_locations array. */
2688 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, &args
->page
,
2694 * Encode SECINFO request
2696 static void nfs4_xdr_enc_secinfo(struct rpc_rqst
*req
,
2697 struct xdr_stream
*xdr
,
2698 struct nfs4_secinfo_arg
*args
)
2700 struct compound_hdr hdr
= {
2701 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2704 encode_compound_hdr(xdr
, req
, &hdr
);
2705 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2706 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2707 encode_secinfo(xdr
, args
->name
, &hdr
);
2712 * Encode FSID_PRESENT request
2714 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst
*req
,
2715 struct xdr_stream
*xdr
,
2716 struct nfs4_fsid_present_arg
*args
)
2718 struct compound_hdr hdr
= {
2719 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2722 encode_compound_hdr(xdr
, req
, &hdr
);
2723 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2724 encode_putfh(xdr
, args
->fh
, &hdr
);
2725 encode_getfh(xdr
, &hdr
);
2727 encode_renew(xdr
, args
->clientid
, &hdr
);
2731 #if defined(CONFIG_NFS_V4_1)
2733 * BIND_CONN_TO_SESSION request
2735 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst
*req
,
2736 struct xdr_stream
*xdr
,
2737 struct nfs41_bind_conn_to_session_args
*args
)
2739 struct compound_hdr hdr
= {
2740 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2743 encode_compound_hdr(xdr
, req
, &hdr
);
2744 encode_bind_conn_to_session(xdr
, args
, &hdr
);
2749 * EXCHANGE_ID request
2751 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst
*req
,
2752 struct xdr_stream
*xdr
,
2753 struct nfs41_exchange_id_args
*args
)
2755 struct compound_hdr hdr
= {
2756 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2759 encode_compound_hdr(xdr
, req
, &hdr
);
2760 encode_exchange_id(xdr
, args
, &hdr
);
2765 * a CREATE_SESSION request
2767 static void nfs4_xdr_enc_create_session(struct rpc_rqst
*req
,
2768 struct xdr_stream
*xdr
,
2769 struct nfs41_create_session_args
*args
)
2771 struct compound_hdr hdr
= {
2772 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2775 encode_compound_hdr(xdr
, req
, &hdr
);
2776 encode_create_session(xdr
, args
, &hdr
);
2781 * a DESTROY_SESSION request
2783 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst
*req
,
2784 struct xdr_stream
*xdr
,
2785 struct nfs4_session
*session
)
2787 struct compound_hdr hdr
= {
2788 .minorversion
= session
->clp
->cl_mvops
->minor_version
,
2791 encode_compound_hdr(xdr
, req
, &hdr
);
2792 encode_destroy_session(xdr
, session
, &hdr
);
2797 * a DESTROY_CLIENTID request
2799 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst
*req
,
2800 struct xdr_stream
*xdr
,
2801 struct nfs_client
*clp
)
2803 struct compound_hdr hdr
= {
2804 .minorversion
= clp
->cl_mvops
->minor_version
,
2807 encode_compound_hdr(xdr
, req
, &hdr
);
2808 encode_destroy_clientid(xdr
, clp
->cl_clientid
, &hdr
);
2813 * a SEQUENCE request
2815 static void nfs4_xdr_enc_sequence(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2816 struct nfs4_sequence_args
*args
)
2818 struct compound_hdr hdr
= {
2819 .minorversion
= nfs4_xdr_minorversion(args
),
2822 encode_compound_hdr(xdr
, req
, &hdr
);
2823 encode_sequence(xdr
, args
, &hdr
);
2828 * a GET_LEASE_TIME request
2830 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst
*req
,
2831 struct xdr_stream
*xdr
,
2832 struct nfs4_get_lease_time_args
*args
)
2834 struct compound_hdr hdr
= {
2835 .minorversion
= nfs4_xdr_minorversion(&args
->la_seq_args
),
2837 const u32 lease_bitmap
[3] = { FATTR4_WORD0_LEASE_TIME
};
2839 encode_compound_hdr(xdr
, req
, &hdr
);
2840 encode_sequence(xdr
, &args
->la_seq_args
, &hdr
);
2841 encode_putrootfh(xdr
, &hdr
);
2842 encode_fsinfo(xdr
, lease_bitmap
, &hdr
);
2847 * a RECLAIM_COMPLETE request
2849 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst
*req
,
2850 struct xdr_stream
*xdr
,
2851 struct nfs41_reclaim_complete_args
*args
)
2853 struct compound_hdr hdr
= {
2854 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
)
2857 encode_compound_hdr(xdr
, req
, &hdr
);
2858 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2859 encode_reclaim_complete(xdr
, args
, &hdr
);
2864 * Encode GETDEVICEINFO request
2866 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst
*req
,
2867 struct xdr_stream
*xdr
,
2868 struct nfs4_getdeviceinfo_args
*args
)
2870 struct compound_hdr hdr
= {
2871 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2874 encode_compound_hdr(xdr
, req
, &hdr
);
2875 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2876 encode_getdeviceinfo(xdr
, args
, &hdr
);
2878 /* set up reply kvec. Subtract notification bitmap max size (2)
2879 * so that notification bitmap is put in xdr_buf tail */
2880 xdr_inline_pages(&req
->rq_rcv_buf
, (hdr
.replen
- 2) << 2,
2881 args
->pdev
->pages
, args
->pdev
->pgbase
,
2888 * Encode LAYOUTGET request
2890 static void nfs4_xdr_enc_layoutget(struct rpc_rqst
*req
,
2891 struct xdr_stream
*xdr
,
2892 struct nfs4_layoutget_args
*args
)
2894 struct compound_hdr hdr
= {
2895 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2898 encode_compound_hdr(xdr
, req
, &hdr
);
2899 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2900 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2901 encode_layoutget(xdr
, args
, &hdr
);
2903 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2904 args
->layout
.pages
, 0, args
->layout
.pglen
);
2910 * Encode LAYOUTCOMMIT request
2912 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst
*req
,
2913 struct xdr_stream
*xdr
,
2914 struct nfs4_layoutcommit_args
*args
)
2916 struct nfs4_layoutcommit_data
*data
=
2917 container_of(args
, struct nfs4_layoutcommit_data
, args
);
2918 struct compound_hdr hdr
= {
2919 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2922 encode_compound_hdr(xdr
, req
, &hdr
);
2923 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2924 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2925 encode_layoutcommit(xdr
, data
->args
.inode
, args
, &hdr
);
2926 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2931 * Encode LAYOUTRETURN request
2933 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst
*req
,
2934 struct xdr_stream
*xdr
,
2935 struct nfs4_layoutreturn_args
*args
)
2937 struct compound_hdr hdr
= {
2938 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2941 encode_compound_hdr(xdr
, req
, &hdr
);
2942 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2943 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2944 encode_layoutreturn(xdr
, args
, &hdr
);
2949 * Encode SECINFO_NO_NAME request
2951 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst
*req
,
2952 struct xdr_stream
*xdr
,
2953 struct nfs41_secinfo_no_name_args
*args
)
2955 struct compound_hdr hdr
= {
2956 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2959 encode_compound_hdr(xdr
, req
, &hdr
);
2960 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2961 encode_putrootfh(xdr
, &hdr
);
2962 encode_secinfo_no_name(xdr
, args
, &hdr
);
2968 * Encode TEST_STATEID request
2970 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst
*req
,
2971 struct xdr_stream
*xdr
,
2972 struct nfs41_test_stateid_args
*args
)
2974 struct compound_hdr hdr
= {
2975 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2978 encode_compound_hdr(xdr
, req
, &hdr
);
2979 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2980 encode_test_stateid(xdr
, args
, &hdr
);
2985 * Encode FREE_STATEID request
2987 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst
*req
,
2988 struct xdr_stream
*xdr
,
2989 struct nfs41_free_stateid_args
*args
)
2991 struct compound_hdr hdr
= {
2992 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2995 encode_compound_hdr(xdr
, req
, &hdr
);
2996 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2997 encode_free_stateid(xdr
, args
, &hdr
);
3000 #endif /* CONFIG_NFS_V4_1 */
3002 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
3004 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3005 "Remaining buffer length is %tu words.\n",
3006 func
, xdr
->end
- xdr
->p
);
3009 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
3013 p
= xdr_inline_decode(xdr
, 4);
3016 *len
= be32_to_cpup(p
);
3017 p
= xdr_inline_decode(xdr
, *len
);
3020 *string
= (char *)p
;
3023 print_overflow_msg(__func__
, xdr
);
3027 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
3031 p
= xdr_inline_decode(xdr
, 8);
3034 hdr
->status
= be32_to_cpup(p
++);
3035 hdr
->taglen
= be32_to_cpup(p
);
3037 p
= xdr_inline_decode(xdr
, hdr
->taglen
+ 4);
3040 hdr
->tag
= (char *)p
;
3041 p
+= XDR_QUADLEN(hdr
->taglen
);
3042 hdr
->nops
= be32_to_cpup(p
);
3043 if (unlikely(hdr
->nops
< 1))
3044 return nfs4_stat_to_errno(hdr
->status
);
3047 print_overflow_msg(__func__
, xdr
);
3051 static bool __decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
,
3058 p
= xdr_inline_decode(xdr
, 8);
3061 opnum
= be32_to_cpup(p
++);
3062 if (unlikely(opnum
!= expected
))
3063 goto out_bad_operation
;
3064 nfserr
= be32_to_cpup(p
);
3065 if (nfserr
== NFS_OK
)
3068 *nfs_retval
= nfs4_stat_to_errno(nfserr
);
3071 dprintk("nfs: Server returned operation"
3072 " %d but we issued a request for %d\n",
3074 *nfs_retval
= -EREMOTEIO
;
3077 print_overflow_msg(__func__
, xdr
);
3082 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
3086 __decode_op_hdr(xdr
, expected
, &retval
);
3091 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
3094 unsigned int strlen
;
3097 p
= xdr_inline_decode(xdr
, 12);
3099 return decode_opaque_inline(xdr
, &strlen
, &str
);
3100 print_overflow_msg(__func__
, xdr
);
3104 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
3109 p
= xdr_inline_decode(xdr
, 4);
3112 bmlen
= be32_to_cpup(p
);
3114 bitmap
[0] = bitmap
[1] = bitmap
[2] = 0;
3115 p
= xdr_inline_decode(xdr
, (bmlen
<< 2));
3119 bitmap
[0] = be32_to_cpup(p
++);
3121 bitmap
[1] = be32_to_cpup(p
++);
3123 bitmap
[2] = be32_to_cpup(p
);
3128 print_overflow_msg(__func__
, xdr
);
3132 static int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, unsigned int *savep
)
3136 p
= xdr_inline_decode(xdr
, 4);
3139 *attrlen
= be32_to_cpup(p
);
3140 *savep
= xdr_stream_pos(xdr
);
3143 print_overflow_msg(__func__
, xdr
);
3147 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
3149 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
3151 ret
= decode_attr_bitmap(xdr
, bitmask
);
3152 if (unlikely(ret
< 0))
3154 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
3156 bitmask
[0] = bitmask
[1] = bitmask
[2] = 0;
3157 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__
,
3158 bitmask
[0], bitmask
[1], bitmask
[2]);
3162 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
3168 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
3170 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
3171 p
= xdr_inline_decode(xdr
, 4);
3174 *type
= be32_to_cpup(p
);
3175 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
3176 dprintk("%s: bad type %d\n", __func__
, *type
);
3179 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
3180 ret
= NFS_ATTR_FATTR_TYPE
;
3182 dprintk("%s: type=0%o\n", __func__
, nfs_type2fmt
[*type
]);
3185 print_overflow_msg(__func__
, xdr
);
3189 static int decode_attr_fh_expire_type(struct xdr_stream
*xdr
,
3190 uint32_t *bitmap
, uint32_t *type
)
3195 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE
- 1U)))
3197 if (likely(bitmap
[0] & FATTR4_WORD0_FH_EXPIRE_TYPE
)) {
3198 p
= xdr_inline_decode(xdr
, 4);
3201 *type
= be32_to_cpup(p
);
3202 bitmap
[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE
;
3204 dprintk("%s: expire type=0x%x\n", __func__
, *type
);
3207 print_overflow_msg(__func__
, xdr
);
3211 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
3217 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
3219 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
3220 p
= xdr_inline_decode(xdr
, 8);
3223 xdr_decode_hyper(p
, change
);
3224 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
3225 ret
= NFS_ATTR_FATTR_CHANGE
;
3227 dprintk("%s: change attribute=%Lu\n", __func__
,
3228 (unsigned long long)*change
);
3231 print_overflow_msg(__func__
, xdr
);
3235 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
3241 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
3243 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
3244 p
= xdr_inline_decode(xdr
, 8);
3247 xdr_decode_hyper(p
, size
);
3248 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
3249 ret
= NFS_ATTR_FATTR_SIZE
;
3251 dprintk("%s: file size=%Lu\n", __func__
, (unsigned long long)*size
);
3254 print_overflow_msg(__func__
, xdr
);
3258 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3263 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
3265 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
3266 p
= xdr_inline_decode(xdr
, 4);
3269 *res
= be32_to_cpup(p
);
3270 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
3272 dprintk("%s: link support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3275 print_overflow_msg(__func__
, xdr
);
3279 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3284 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
3286 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
3287 p
= xdr_inline_decode(xdr
, 4);
3290 *res
= be32_to_cpup(p
);
3291 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
3293 dprintk("%s: symlink support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3296 print_overflow_msg(__func__
, xdr
);
3300 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
3307 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
3309 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
3310 p
= xdr_inline_decode(xdr
, 16);
3313 p
= xdr_decode_hyper(p
, &fsid
->major
);
3314 xdr_decode_hyper(p
, &fsid
->minor
);
3315 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
3316 ret
= NFS_ATTR_FATTR_FSID
;
3318 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__
,
3319 (unsigned long long)fsid
->major
,
3320 (unsigned long long)fsid
->minor
);
3323 print_overflow_msg(__func__
, xdr
);
3327 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3332 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
3334 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
3335 p
= xdr_inline_decode(xdr
, 4);
3338 *res
= be32_to_cpup(p
);
3339 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
3341 dprintk("%s: file size=%u\n", __func__
, (unsigned int)*res
);
3344 print_overflow_msg(__func__
, xdr
);
3348 static int decode_attr_error(struct xdr_stream
*xdr
, uint32_t *bitmap
, int32_t *res
)
3352 if (unlikely(bitmap
[0] & (FATTR4_WORD0_RDATTR_ERROR
- 1U)))
3354 if (likely(bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
)) {
3355 p
= xdr_inline_decode(xdr
, 4);
3358 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
3359 *res
= -be32_to_cpup(p
);
3363 print_overflow_msg(__func__
, xdr
);
3367 static int decode_attr_filehandle(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fh
*fh
)
3373 memset(fh
, 0, sizeof(*fh
));
3375 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEHANDLE
- 1U)))
3377 if (likely(bitmap
[0] & FATTR4_WORD0_FILEHANDLE
)) {
3378 p
= xdr_inline_decode(xdr
, 4);
3381 len
= be32_to_cpup(p
);
3382 if (len
> NFS4_FHSIZE
)
3384 p
= xdr_inline_decode(xdr
, len
);
3388 memcpy(fh
->data
, p
, len
);
3391 bitmap
[0] &= ~FATTR4_WORD0_FILEHANDLE
;
3395 print_overflow_msg(__func__
, xdr
);
3399 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3404 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
3406 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
3407 p
= xdr_inline_decode(xdr
, 4);
3410 *res
= be32_to_cpup(p
);
3411 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
3413 dprintk("%s: ACLs supported=%u\n", __func__
, (unsigned int)*res
);
3416 print_overflow_msg(__func__
, xdr
);
3420 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3426 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
3428 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
3429 p
= xdr_inline_decode(xdr
, 8);
3432 xdr_decode_hyper(p
, fileid
);
3433 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
3434 ret
= NFS_ATTR_FATTR_FILEID
;
3436 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3439 print_overflow_msg(__func__
, xdr
);
3443 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3449 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
3451 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
3452 p
= xdr_inline_decode(xdr
, 8);
3455 xdr_decode_hyper(p
, fileid
);
3456 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
3457 ret
= NFS_ATTR_FATTR_MOUNTED_ON_FILEID
;
3459 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3462 print_overflow_msg(__func__
, xdr
);
3466 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3472 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
3474 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
3475 p
= xdr_inline_decode(xdr
, 8);
3478 xdr_decode_hyper(p
, res
);
3479 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
3481 dprintk("%s: files avail=%Lu\n", __func__
, (unsigned long long)*res
);
3484 print_overflow_msg(__func__
, xdr
);
3488 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3494 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
3496 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
3497 p
= xdr_inline_decode(xdr
, 8);
3500 xdr_decode_hyper(p
, res
);
3501 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
3503 dprintk("%s: files free=%Lu\n", __func__
, (unsigned long long)*res
);
3506 print_overflow_msg(__func__
, xdr
);
3510 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3516 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
3518 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
3519 p
= xdr_inline_decode(xdr
, 8);
3522 xdr_decode_hyper(p
, res
);
3523 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
3525 dprintk("%s: files total=%Lu\n", __func__
, (unsigned long long)*res
);
3528 print_overflow_msg(__func__
, xdr
);
3532 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
3538 p
= xdr_inline_decode(xdr
, 4);
3541 n
= be32_to_cpup(p
);
3544 dprintk("pathname4: ");
3545 if (n
> NFS4_PATHNAME_MAXCOMPONENTS
) {
3546 dprintk("cannot parse %d components in path\n", n
);
3549 for (path
->ncomponents
= 0; path
->ncomponents
< n
; path
->ncomponents
++) {
3550 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
3551 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
3552 if (unlikely(status
!= 0))
3556 (path
->ncomponents
!= n
? "/ " : ""),
3557 component
->len
, component
->data
);
3562 /* a root pathname is sent as a zero component4 */
3563 path
->ncomponents
= 1;
3564 path
->components
[0].len
=0;
3565 path
->components
[0].data
=NULL
;
3566 dprintk("pathname4: /\n");
3569 dprintk(" status %d", status
);
3573 print_overflow_msg(__func__
, xdr
);
3577 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
3583 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
3586 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
3589 /* Ignore borken servers that return unrequested attrs */
3590 if (unlikely(res
== NULL
))
3592 dprintk("%s: fsroot:\n", __func__
);
3593 status
= decode_pathname(xdr
, &res
->fs_path
);
3594 if (unlikely(status
!= 0))
3596 p
= xdr_inline_decode(xdr
, 4);
3599 n
= be32_to_cpup(p
);
3602 for (res
->nlocations
= 0; res
->nlocations
< n
; res
->nlocations
++) {
3604 struct nfs4_fs_location
*loc
;
3606 if (res
->nlocations
== NFS4_FS_LOCATIONS_MAXENTRIES
)
3608 loc
= &res
->locations
[res
->nlocations
];
3609 p
= xdr_inline_decode(xdr
, 4);
3612 m
= be32_to_cpup(p
);
3614 dprintk("%s: servers:\n", __func__
);
3615 for (loc
->nservers
= 0; loc
->nservers
< m
; loc
->nservers
++) {
3616 struct nfs4_string
*server
;
3618 if (loc
->nservers
== NFS4_FS_LOCATION_MAXSERVERS
) {
3620 dprintk("%s: using first %u of %u servers "
3621 "returned for location %u\n",
3623 NFS4_FS_LOCATION_MAXSERVERS
,
3624 m
, res
->nlocations
);
3625 for (i
= loc
->nservers
; i
< m
; i
++) {
3628 status
= decode_opaque_inline(xdr
, &len
, &data
);
3629 if (unlikely(status
!= 0))
3634 server
= &loc
->servers
[loc
->nservers
];
3635 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
3636 if (unlikely(status
!= 0))
3638 dprintk("%s ", server
->data
);
3640 status
= decode_pathname(xdr
, &loc
->rootpath
);
3641 if (unlikely(status
!= 0))
3644 if (res
->nlocations
!= 0)
3645 status
= NFS_ATTR_FATTR_V4_LOCATIONS
;
3647 dprintk("%s: fs_locations done, error = %d\n", __func__
, status
);
3650 print_overflow_msg(__func__
, xdr
);
3656 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3662 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
3664 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
3665 p
= xdr_inline_decode(xdr
, 8);
3668 xdr_decode_hyper(p
, res
);
3669 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
3671 dprintk("%s: maxfilesize=%Lu\n", __func__
, (unsigned long long)*res
);
3674 print_overflow_msg(__func__
, xdr
);
3678 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
3684 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
3686 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
3687 p
= xdr_inline_decode(xdr
, 4);
3690 *maxlink
= be32_to_cpup(p
);
3691 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
3693 dprintk("%s: maxlink=%u\n", __func__
, *maxlink
);
3696 print_overflow_msg(__func__
, xdr
);
3700 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
3706 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
3708 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
3709 p
= xdr_inline_decode(xdr
, 4);
3712 *maxname
= be32_to_cpup(p
);
3713 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
3715 dprintk("%s: maxname=%u\n", __func__
, *maxname
);
3718 print_overflow_msg(__func__
, xdr
);
3722 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3728 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
3730 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
3732 p
= xdr_inline_decode(xdr
, 8);
3735 xdr_decode_hyper(p
, &maxread
);
3736 if (maxread
> 0x7FFFFFFF)
3737 maxread
= 0x7FFFFFFF;
3738 *res
= (uint32_t)maxread
;
3739 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
3741 dprintk("%s: maxread=%lu\n", __func__
, (unsigned long)*res
);
3744 print_overflow_msg(__func__
, xdr
);
3748 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3754 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
3756 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
3758 p
= xdr_inline_decode(xdr
, 8);
3761 xdr_decode_hyper(p
, &maxwrite
);
3762 if (maxwrite
> 0x7FFFFFFF)
3763 maxwrite
= 0x7FFFFFFF;
3764 *res
= (uint32_t)maxwrite
;
3765 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
3767 dprintk("%s: maxwrite=%lu\n", __func__
, (unsigned long)*res
);
3770 print_overflow_msg(__func__
, xdr
);
3774 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, umode_t
*mode
)
3781 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
3783 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
3784 p
= xdr_inline_decode(xdr
, 4);
3787 tmp
= be32_to_cpup(p
);
3788 *mode
= tmp
& ~S_IFMT
;
3789 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
3790 ret
= NFS_ATTR_FATTR_MODE
;
3792 dprintk("%s: file mode=0%o\n", __func__
, (unsigned int)*mode
);
3795 print_overflow_msg(__func__
, xdr
);
3799 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
3805 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
3807 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
3808 p
= xdr_inline_decode(xdr
, 4);
3811 *nlink
= be32_to_cpup(p
);
3812 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
3813 ret
= NFS_ATTR_FATTR_NLINK
;
3815 dprintk("%s: nlink=%u\n", __func__
, (unsigned int)*nlink
);
3818 print_overflow_msg(__func__
, xdr
);
3822 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3823 const struct nfs_server
*server
, kuid_t
*uid
,
3824 struct nfs4_string
*owner_name
)
3830 *uid
= make_kuid(&init_user_ns
, -2);
3831 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
3833 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
3834 p
= xdr_inline_decode(xdr
, 4);
3837 len
= be32_to_cpup(p
);
3838 p
= xdr_inline_decode(xdr
, len
);
3841 if (owner_name
!= NULL
) {
3842 owner_name
->data
= kmemdup(p
, len
, GFP_NOWAIT
);
3843 if (owner_name
->data
!= NULL
) {
3844 owner_name
->len
= len
;
3845 ret
= NFS_ATTR_FATTR_OWNER_NAME
;
3847 } else if (len
< XDR_MAX_NETOBJ
) {
3848 if (nfs_map_name_to_uid(server
, (char *)p
, len
, uid
) == 0)
3849 ret
= NFS_ATTR_FATTR_OWNER
;
3851 dprintk("%s: nfs_map_name_to_uid failed!\n",
3854 dprintk("%s: name too long (%u)!\n",
3856 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
3858 dprintk("%s: uid=%d\n", __func__
, (int)from_kuid(&init_user_ns
, *uid
));
3861 print_overflow_msg(__func__
, xdr
);
3865 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3866 const struct nfs_server
*server
, kgid_t
*gid
,
3867 struct nfs4_string
*group_name
)
3873 *gid
= make_kgid(&init_user_ns
, -2);
3874 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
3876 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
3877 p
= xdr_inline_decode(xdr
, 4);
3880 len
= be32_to_cpup(p
);
3881 p
= xdr_inline_decode(xdr
, len
);
3884 if (group_name
!= NULL
) {
3885 group_name
->data
= kmemdup(p
, len
, GFP_NOWAIT
);
3886 if (group_name
->data
!= NULL
) {
3887 group_name
->len
= len
;
3888 ret
= NFS_ATTR_FATTR_GROUP_NAME
;
3890 } else if (len
< XDR_MAX_NETOBJ
) {
3891 if (nfs_map_group_to_gid(server
, (char *)p
, len
, gid
) == 0)
3892 ret
= NFS_ATTR_FATTR_GROUP
;
3894 dprintk("%s: nfs_map_group_to_gid failed!\n",
3897 dprintk("%s: name too long (%u)!\n",
3899 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
3901 dprintk("%s: gid=%d\n", __func__
, (int)from_kgid(&init_user_ns
, *gid
));
3904 print_overflow_msg(__func__
, xdr
);
3908 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
3910 uint32_t major
= 0, minor
= 0;
3915 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
3917 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
3920 p
= xdr_inline_decode(xdr
, 8);
3923 major
= be32_to_cpup(p
++);
3924 minor
= be32_to_cpup(p
);
3925 tmp
= MKDEV(major
, minor
);
3926 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
3928 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
3929 ret
= NFS_ATTR_FATTR_RDEV
;
3931 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__
, major
, minor
);
3934 print_overflow_msg(__func__
, xdr
);
3938 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3944 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
3946 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
3947 p
= xdr_inline_decode(xdr
, 8);
3950 xdr_decode_hyper(p
, res
);
3951 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
3953 dprintk("%s: space avail=%Lu\n", __func__
, (unsigned long long)*res
);
3956 print_overflow_msg(__func__
, xdr
);
3960 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3966 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
3968 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
3969 p
= xdr_inline_decode(xdr
, 8);
3972 xdr_decode_hyper(p
, res
);
3973 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
3975 dprintk("%s: space free=%Lu\n", __func__
, (unsigned long long)*res
);
3978 print_overflow_msg(__func__
, xdr
);
3982 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3988 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
3990 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
3991 p
= xdr_inline_decode(xdr
, 8);
3994 xdr_decode_hyper(p
, res
);
3995 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
3997 dprintk("%s: space total=%Lu\n", __func__
, (unsigned long long)*res
);
4000 print_overflow_msg(__func__
, xdr
);
4004 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
4010 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
4012 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
4013 p
= xdr_inline_decode(xdr
, 8);
4016 xdr_decode_hyper(p
, used
);
4017 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
4018 ret
= NFS_ATTR_FATTR_SPACE_USED
;
4020 dprintk("%s: space used=%Lu\n", __func__
,
4021 (unsigned long long)*used
);
4024 print_overflow_msg(__func__
, xdr
);
4028 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
4034 p
= xdr_inline_decode(xdr
, 12);
4037 p
= xdr_decode_hyper(p
, &sec
);
4038 nsec
= be32_to_cpup(p
);
4039 time
->tv_sec
= (time_t)sec
;
4040 time
->tv_nsec
= (long)nsec
;
4043 print_overflow_msg(__func__
, xdr
);
4047 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4053 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
4055 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
4056 status
= decode_attr_time(xdr
, time
);
4058 status
= NFS_ATTR_FATTR_ATIME
;
4059 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
4061 dprintk("%s: atime=%ld\n", __func__
, (long)time
->tv_sec
);
4065 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4071 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
4073 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
4074 status
= decode_attr_time(xdr
, time
);
4076 status
= NFS_ATTR_FATTR_CTIME
;
4077 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
4079 dprintk("%s: ctime=%ld\n", __func__
, (long)time
->tv_sec
);
4083 static int decode_attr_time_delta(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4084 struct timespec
*time
)
4090 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_DELTA
- 1U)))
4092 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_DELTA
)) {
4093 status
= decode_attr_time(xdr
, time
);
4094 bitmap
[1] &= ~FATTR4_WORD1_TIME_DELTA
;
4096 dprintk("%s: time_delta=%ld %ld\n", __func__
, (long)time
->tv_sec
,
4097 (long)time
->tv_nsec
);
4101 static int decode_attr_security_label(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4102 struct nfs4_label
*label
)
4110 if (unlikely(bitmap
[2] & (FATTR4_WORD2_SECURITY_LABEL
- 1U)))
4112 if (likely(bitmap
[2] & FATTR4_WORD2_SECURITY_LABEL
)) {
4113 p
= xdr_inline_decode(xdr
, 4);
4116 lfs
= be32_to_cpup(p
++);
4117 p
= xdr_inline_decode(xdr
, 4);
4120 pi
= be32_to_cpup(p
++);
4121 p
= xdr_inline_decode(xdr
, 4);
4124 len
= be32_to_cpup(p
++);
4125 p
= xdr_inline_decode(xdr
, len
);
4128 if (len
< NFS4_MAXLABELLEN
) {
4130 memcpy(label
->label
, p
, len
);
4134 status
= NFS_ATTR_FATTR_V4_SECURITY_LABEL
;
4136 bitmap
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
4138 printk(KERN_WARNING
"%s: label too long (%u)!\n",
4141 if (label
&& label
->label
)
4142 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__
,
4143 (char *)label
->label
, label
->len
, label
->pi
, label
->lfs
);
4147 print_overflow_msg(__func__
, xdr
);
4151 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4157 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
4159 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
4160 status
= decode_attr_time(xdr
, time
);
4162 status
= NFS_ATTR_FATTR_MTIME
;
4163 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
4165 dprintk("%s: mtime=%ld\n", __func__
, (long)time
->tv_sec
);
4169 static int verify_attr_len(struct xdr_stream
*xdr
, unsigned int savep
, uint32_t attrlen
)
4171 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
4172 unsigned int nwords
= (xdr_stream_pos(xdr
) - savep
) >> 2;
4174 if (unlikely(attrwords
!= nwords
)) {
4175 dprintk("%s: server returned incorrect attribute length: "
4179 (attrwords
< nwords
) ? '<' : '>',
4186 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4190 p
= xdr_inline_decode(xdr
, 20);
4193 cinfo
->atomic
= be32_to_cpup(p
++);
4194 p
= xdr_decode_hyper(p
, &cinfo
->before
);
4195 xdr_decode_hyper(p
, &cinfo
->after
);
4198 print_overflow_msg(__func__
, xdr
);
4202 static int decode_access(struct xdr_stream
*xdr
, u32
*supported
, u32
*access
)
4208 status
= decode_op_hdr(xdr
, OP_ACCESS
);
4211 p
= xdr_inline_decode(xdr
, 8);
4214 supp
= be32_to_cpup(p
++);
4215 acc
= be32_to_cpup(p
);
4220 print_overflow_msg(__func__
, xdr
);
4224 static int decode_opaque_fixed(struct xdr_stream
*xdr
, void *buf
, size_t len
)
4228 p
= xdr_inline_decode(xdr
, len
);
4230 memcpy(buf
, p
, len
);
4233 print_overflow_msg(__func__
, xdr
);
4237 static int decode_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
4239 return decode_opaque_fixed(xdr
, stateid
, NFS4_STATEID_SIZE
);
4242 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4246 status
= decode_op_hdr(xdr
, OP_CLOSE
);
4248 nfs_increment_open_seqid(status
, res
->seqid
);
4250 status
= decode_stateid(xdr
, &res
->stateid
);
4254 static int decode_verifier(struct xdr_stream
*xdr
, void *verifier
)
4256 return decode_opaque_fixed(xdr
, verifier
, NFS4_VERIFIER_SIZE
);
4259 static int decode_write_verifier(struct xdr_stream
*xdr
, struct nfs_write_verifier
*verifier
)
4261 return decode_opaque_fixed(xdr
, verifier
->data
, NFS4_VERIFIER_SIZE
);
4264 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_commitres
*res
)
4268 status
= decode_op_hdr(xdr
, OP_COMMIT
);
4270 status
= decode_write_verifier(xdr
, &res
->verf
->verifier
);
4274 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4280 status
= decode_op_hdr(xdr
, OP_CREATE
);
4283 if ((status
= decode_change_info(xdr
, cinfo
)))
4285 p
= xdr_inline_decode(xdr
, 4);
4288 bmlen
= be32_to_cpup(p
);
4289 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4293 print_overflow_msg(__func__
, xdr
);
4297 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
4300 uint32_t attrlen
, bitmap
[3] = {0};
4303 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4305 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4307 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4309 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
4311 if ((status
= decode_attr_fh_expire_type(xdr
, bitmap
,
4312 &res
->fh_expire_type
)) != 0)
4314 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
4316 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
4318 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
4320 status
= verify_attr_len(xdr
, savep
, attrlen
);
4322 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4326 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
4329 uint32_t attrlen
, bitmap
[3] = {0};
4332 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4334 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4336 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4339 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
4341 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
4343 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
4345 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
4347 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
4349 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
4352 status
= verify_attr_len(xdr
, savep
, attrlen
);
4354 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4358 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
4361 uint32_t attrlen
, bitmap
[3] = {0};
4364 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4366 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4368 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4371 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
4373 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
4376 status
= verify_attr_len(xdr
, savep
, attrlen
);
4378 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4382 static int decode_threshold_hint(struct xdr_stream
*xdr
,
4390 if (likely(bitmap
[0] & hint_bit
)) {
4391 p
= xdr_inline_decode(xdr
, 8);
4394 xdr_decode_hyper(p
, res
);
4398 print_overflow_msg(__func__
, xdr
);
4402 static int decode_first_threshold_item4(struct xdr_stream
*xdr
,
4403 struct nfs4_threshold
*res
)
4407 uint32_t bitmap
[3] = {0,}, attrlen
;
4411 p
= xdr_inline_decode(xdr
, 4);
4413 print_overflow_msg(__func__
, xdr
);
4416 res
->l_type
= be32_to_cpup(p
);
4418 /* thi_hintset bitmap */
4419 status
= decode_attr_bitmap(xdr
, bitmap
);
4423 /* thi_hintlist length */
4424 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
4428 status
= decode_threshold_hint(xdr
, bitmap
, &res
->rd_sz
, THRESHOLD_RD
);
4431 status
= decode_threshold_hint(xdr
, bitmap
, &res
->wr_sz
, THRESHOLD_WR
);
4434 status
= decode_threshold_hint(xdr
, bitmap
, &res
->rd_io_sz
,
4438 status
= decode_threshold_hint(xdr
, bitmap
, &res
->wr_io_sz
,
4443 status
= verify_attr_len(xdr
, savep
, attrlen
);
4444 res
->bm
= bitmap
[0];
4446 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4447 __func__
, res
->bm
, res
->rd_sz
, res
->wr_sz
, res
->rd_io_sz
,
4450 dprintk("%s ret=%d!\n", __func__
, status
);
4455 * Thresholds on pNFS direct I/O vrs MDS I/O
4457 static int decode_attr_mdsthreshold(struct xdr_stream
*xdr
,
4459 struct nfs4_threshold
*res
)
4465 if (unlikely(bitmap
[2] & (FATTR4_WORD2_MDSTHRESHOLD
- 1U)))
4467 if (bitmap
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
4468 /* Did the server return an unrequested attribute? */
4469 if (unlikely(res
== NULL
))
4471 p
= xdr_inline_decode(xdr
, 4);
4474 num
= be32_to_cpup(p
);
4478 printk(KERN_INFO
"%s: Warning: Multiple pNFS layout "
4479 "drivers per filesystem not supported\n",
4482 status
= decode_first_threshold_item4(xdr
, res
);
4483 bitmap
[2] &= ~FATTR4_WORD2_MDSTHRESHOLD
;
4487 print_overflow_msg(__func__
, xdr
);
4491 static int decode_getfattr_attrs(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4492 struct nfs_fattr
*fattr
, struct nfs_fh
*fh
,
4493 struct nfs4_fs_locations
*fs_loc
, struct nfs4_label
*label
,
4494 const struct nfs_server
*server
)
4501 status
= decode_attr_type(xdr
, bitmap
, &type
);
4506 fattr
->mode
|= nfs_type2fmt
[type
];
4507 fattr
->valid
|= status
;
4510 status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
);
4513 fattr
->valid
|= status
;
4515 status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
);
4518 fattr
->valid
|= status
;
4520 status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
);
4523 fattr
->valid
|= status
;
4526 status
= decode_attr_error(xdr
, bitmap
, &err
);
4530 status
= decode_attr_filehandle(xdr
, bitmap
, fh
);
4534 status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
);
4537 fattr
->valid
|= status
;
4539 status
= decode_attr_fs_locations(xdr
, bitmap
, fs_loc
);
4542 fattr
->valid
|= status
;
4544 status
= decode_attr_mode(xdr
, bitmap
, &fmode
);
4548 fattr
->mode
|= fmode
;
4549 fattr
->valid
|= status
;
4552 status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
);
4555 fattr
->valid
|= status
;
4557 status
= decode_attr_owner(xdr
, bitmap
, server
, &fattr
->uid
, fattr
->owner_name
);
4560 fattr
->valid
|= status
;
4562 status
= decode_attr_group(xdr
, bitmap
, server
, &fattr
->gid
, fattr
->group_name
);
4565 fattr
->valid
|= status
;
4567 status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
);
4570 fattr
->valid
|= status
;
4572 status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
);
4575 fattr
->valid
|= status
;
4577 status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
);
4580 fattr
->valid
|= status
;
4582 status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
);
4585 fattr
->valid
|= status
;
4587 status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
);
4590 fattr
->valid
|= status
;
4592 status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fattr
->mounted_on_fileid
);
4595 fattr
->valid
|= status
;
4597 status
= decode_attr_mdsthreshold(xdr
, bitmap
, fattr
->mdsthreshold
);
4602 status
= decode_attr_security_label(xdr
, bitmap
, label
);
4605 fattr
->valid
|= status
;
4609 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4613 static int decode_getfattr_generic(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4614 struct nfs_fh
*fh
, struct nfs4_fs_locations
*fs_loc
,
4615 struct nfs4_label
*label
, const struct nfs_server
*server
)
4622 status
= decode_op_hdr(xdr
, OP_GETATTR
);
4626 status
= decode_attr_bitmap(xdr
, bitmap
);
4630 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
4634 status
= decode_getfattr_attrs(xdr
, bitmap
, fattr
, fh
, fs_loc
,
4639 status
= verify_attr_len(xdr
, savep
, attrlen
);
4641 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4645 static int decode_getfattr_label(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4646 struct nfs4_label
*label
, const struct nfs_server
*server
)
4648 return decode_getfattr_generic(xdr
, fattr
, NULL
, NULL
, label
, server
);
4651 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4652 const struct nfs_server
*server
)
4654 return decode_getfattr_generic(xdr
, fattr
, NULL
, NULL
, NULL
, server
);
4658 * Decode potentially multiple layout types. Currently we only support
4659 * one layout driver per file system.
4661 static int decode_first_pnfs_layout_type(struct xdr_stream
*xdr
,
4662 uint32_t *layouttype
)
4667 p
= xdr_inline_decode(xdr
, 4);
4670 num
= be32_to_cpup(p
);
4672 /* pNFS is not supported by the underlying file system */
4678 printk(KERN_INFO
"NFS: %s: Warning: Multiple pNFS layout "
4679 "drivers per filesystem not supported\n", __func__
);
4681 /* Decode and set first layout type, move xdr->p past unused types */
4682 p
= xdr_inline_decode(xdr
, num
* 4);
4685 *layouttype
= be32_to_cpup(p
);
4688 print_overflow_msg(__func__
, xdr
);
4693 * The type of file system exported.
4694 * Note we must ensure that layouttype is set in any non-error case.
4696 static int decode_attr_pnfstype(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4697 uint32_t *layouttype
)
4701 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[1]);
4702 if (unlikely(bitmap
[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES
- 1U)))
4704 if (bitmap
[1] & FATTR4_WORD1_FS_LAYOUT_TYPES
) {
4705 status
= decode_first_pnfs_layout_type(xdr
, layouttype
);
4706 bitmap
[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES
;
4713 * The prefered block size for layout directed io
4715 static int decode_attr_layout_blksize(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4720 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[2]);
4722 if (bitmap
[2] & FATTR4_WORD2_LAYOUT_BLKSIZE
) {
4723 p
= xdr_inline_decode(xdr
, 4);
4725 print_overflow_msg(__func__
, xdr
);
4728 *res
= be32_to_cpup(p
);
4729 bitmap
[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE
;
4734 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
4737 uint32_t attrlen
, bitmap
[3];
4740 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4742 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4744 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4747 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
4749 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
4751 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
4753 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
4755 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
4756 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
4758 fsinfo
->wtpref
= fsinfo
->wtmax
;
4759 status
= decode_attr_time_delta(xdr
, bitmap
, &fsinfo
->time_delta
);
4762 status
= decode_attr_pnfstype(xdr
, bitmap
, &fsinfo
->layouttype
);
4765 status
= decode_attr_layout_blksize(xdr
, bitmap
, &fsinfo
->blksize
);
4769 status
= verify_attr_len(xdr
, savep
, attrlen
);
4771 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4775 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
4781 /* Zero handle first to allow comparisons */
4782 memset(fh
, 0, sizeof(*fh
));
4784 status
= decode_op_hdr(xdr
, OP_GETFH
);
4788 p
= xdr_inline_decode(xdr
, 4);
4791 len
= be32_to_cpup(p
);
4792 if (len
> NFS4_FHSIZE
)
4795 p
= xdr_inline_decode(xdr
, len
);
4798 memcpy(fh
->data
, p
, len
);
4801 print_overflow_msg(__func__
, xdr
);
4805 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4809 status
= decode_op_hdr(xdr
, OP_LINK
);
4812 return decode_change_info(xdr
, cinfo
);
4816 * We create the owner, so we know a proper owner.id length is 4.
4818 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
4820 uint64_t offset
, length
, clientid
;
4822 uint32_t namelen
, type
;
4824 p
= xdr_inline_decode(xdr
, 32); /* read 32 bytes */
4827 p
= xdr_decode_hyper(p
, &offset
); /* read 2 8-byte long words */
4828 p
= xdr_decode_hyper(p
, &length
);
4829 type
= be32_to_cpup(p
++); /* 4 byte read */
4830 if (fl
!= NULL
) { /* manipulate file lock */
4831 fl
->fl_start
= (loff_t
)offset
;
4832 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
4833 if (length
== ~(uint64_t)0)
4834 fl
->fl_end
= OFFSET_MAX
;
4835 fl
->fl_type
= F_WRLCK
;
4837 fl
->fl_type
= F_RDLCK
;
4840 p
= xdr_decode_hyper(p
, &clientid
); /* read 8 bytes */
4841 namelen
= be32_to_cpup(p
); /* read 4 bytes */ /* have read all 32 bytes now */
4842 p
= xdr_inline_decode(xdr
, namelen
); /* variable size field */
4844 return -NFS4ERR_DENIED
;
4846 print_overflow_msg(__func__
, xdr
);
4850 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
4854 status
= decode_op_hdr(xdr
, OP_LOCK
);
4858 status
= decode_stateid(xdr
, &res
->stateid
);
4859 if (unlikely(status
))
4861 } else if (status
== -NFS4ERR_DENIED
)
4862 status
= decode_lock_denied(xdr
, NULL
);
4863 if (res
->open_seqid
!= NULL
)
4864 nfs_increment_open_seqid(status
, res
->open_seqid
);
4865 nfs_increment_lock_seqid(status
, res
->lock_seqid
);
4870 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
4873 status
= decode_op_hdr(xdr
, OP_LOCKT
);
4874 if (status
== -NFS4ERR_DENIED
)
4875 return decode_lock_denied(xdr
, res
->denied
);
4879 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
4883 status
= decode_op_hdr(xdr
, OP_LOCKU
);
4885 nfs_increment_lock_seqid(status
, res
->seqid
);
4887 status
= decode_stateid(xdr
, &res
->stateid
);
4891 static int decode_release_lockowner(struct xdr_stream
*xdr
)
4893 return decode_op_hdr(xdr
, OP_RELEASE_LOCKOWNER
);
4896 static int decode_lookup(struct xdr_stream
*xdr
)
4898 return decode_op_hdr(xdr
, OP_LOOKUP
);
4901 /* This is too sick! */
4902 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
4905 uint32_t limit_type
, nblocks
, blocksize
;
4907 p
= xdr_inline_decode(xdr
, 12);
4910 limit_type
= be32_to_cpup(p
++);
4911 switch (limit_type
) {
4913 xdr_decode_hyper(p
, maxsize
);
4916 nblocks
= be32_to_cpup(p
++);
4917 blocksize
= be32_to_cpup(p
);
4918 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
4922 print_overflow_msg(__func__
, xdr
);
4926 static int decode_rw_delegation(struct xdr_stream
*xdr
,
4927 uint32_t delegation_type
,
4928 struct nfs_openres
*res
)
4933 status
= decode_stateid(xdr
, &res
->delegation
);
4934 if (unlikely(status
))
4936 p
= xdr_inline_decode(xdr
, 4);
4939 res
->do_recall
= be32_to_cpup(p
);
4941 switch (delegation_type
) {
4942 case NFS4_OPEN_DELEGATE_READ
:
4943 res
->delegation_type
= FMODE_READ
;
4945 case NFS4_OPEN_DELEGATE_WRITE
:
4946 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
4947 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
4950 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
4952 print_overflow_msg(__func__
, xdr
);
4956 static int decode_no_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4959 uint32_t why_no_delegation
;
4961 p
= xdr_inline_decode(xdr
, 4);
4964 why_no_delegation
= be32_to_cpup(p
);
4965 switch (why_no_delegation
) {
4966 case WND4_CONTENTION
:
4968 xdr_inline_decode(xdr
, 4);
4969 /* Ignore for now */
4973 print_overflow_msg(__func__
, xdr
);
4977 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4980 uint32_t delegation_type
;
4982 p
= xdr_inline_decode(xdr
, 4);
4985 delegation_type
= be32_to_cpup(p
);
4986 res
->delegation_type
= 0;
4987 switch (delegation_type
) {
4988 case NFS4_OPEN_DELEGATE_NONE
:
4990 case NFS4_OPEN_DELEGATE_READ
:
4991 case NFS4_OPEN_DELEGATE_WRITE
:
4992 return decode_rw_delegation(xdr
, delegation_type
, res
);
4993 case NFS4_OPEN_DELEGATE_NONE_EXT
:
4994 return decode_no_delegation(xdr
, res
);
4998 print_overflow_msg(__func__
, xdr
);
5002 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
5005 uint32_t savewords
, bmlen
, i
;
5008 if (!__decode_op_hdr(xdr
, OP_OPEN
, &status
))
5010 nfs_increment_open_seqid(status
, res
->seqid
);
5013 status
= decode_stateid(xdr
, &res
->stateid
);
5014 if (unlikely(status
))
5017 decode_change_info(xdr
, &res
->cinfo
);
5019 p
= xdr_inline_decode(xdr
, 8);
5022 res
->rflags
= be32_to_cpup(p
++);
5023 bmlen
= be32_to_cpup(p
);
5027 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
5030 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
5031 for (i
= 0; i
< savewords
; ++i
)
5032 res
->attrset
[i
] = be32_to_cpup(p
++);
5033 for (; i
< NFS4_BITMAP_SIZE
; i
++)
5034 res
->attrset
[i
] = 0;
5036 return decode_delegation(xdr
, res
);
5038 dprintk("%s: Bitmap too large! Length = %u\n", __func__
, bmlen
);
5041 print_overflow_msg(__func__
, xdr
);
5045 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
5049 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
5051 nfs_increment_open_seqid(status
, res
->seqid
);
5053 status
= decode_stateid(xdr
, &res
->stateid
);
5057 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
5061 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
5063 nfs_increment_open_seqid(status
, res
->seqid
);
5065 status
= decode_stateid(xdr
, &res
->stateid
);
5069 static int decode_putfh(struct xdr_stream
*xdr
)
5071 return decode_op_hdr(xdr
, OP_PUTFH
);
5074 static int decode_putrootfh(struct xdr_stream
*xdr
)
5076 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
5079 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5080 struct nfs_pgio_res
*res
)
5083 uint32_t count
, eof
, recvd
;
5086 status
= decode_op_hdr(xdr
, OP_READ
);
5089 p
= xdr_inline_decode(xdr
, 8);
5092 eof
= be32_to_cpup(p
++);
5093 count
= be32_to_cpup(p
);
5094 recvd
= xdr_read_pages(xdr
, count
);
5095 if (count
> recvd
) {
5096 dprintk("NFS: server cheating in read reply: "
5097 "count %u > recvd %u\n", count
, recvd
);
5105 print_overflow_msg(__func__
, xdr
);
5109 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
5114 status
= decode_op_hdr(xdr
, OP_READDIR
);
5116 status
= decode_verifier(xdr
, readdir
->verifier
.data
);
5117 if (unlikely(status
))
5119 memcpy(verf
, readdir
->verifier
.data
, sizeof(verf
));
5120 dprintk("%s: verifier = %08x:%08x\n",
5121 __func__
, verf
[0], verf
[1]);
5122 return xdr_read_pages(xdr
, xdr
->buf
->page_len
);
5125 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
5127 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
5132 status
= decode_op_hdr(xdr
, OP_READLINK
);
5136 /* Convert length of symlink */
5137 p
= xdr_inline_decode(xdr
, 4);
5140 len
= be32_to_cpup(p
);
5141 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
5142 dprintk("nfs: server returned giant symlink!\n");
5143 return -ENAMETOOLONG
;
5145 recvd
= xdr_read_pages(xdr
, len
);
5147 dprintk("NFS: server cheating in readlink reply: "
5148 "count %u > recvd %u\n", len
, recvd
);
5152 * The XDR encode routine has set things up so that
5153 * the link text will be copied directly into the
5154 * buffer. We just have to do overflow-checking,
5155 * and and null-terminate the text (the VFS expects
5156 * null-termination).
5158 xdr_terminate_string(rcvbuf
, len
);
5161 print_overflow_msg(__func__
, xdr
);
5165 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
5169 status
= decode_op_hdr(xdr
, OP_REMOVE
);
5172 status
= decode_change_info(xdr
, cinfo
);
5177 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
5178 struct nfs4_change_info
*new_cinfo
)
5182 status
= decode_op_hdr(xdr
, OP_RENAME
);
5185 if ((status
= decode_change_info(xdr
, old_cinfo
)))
5187 status
= decode_change_info(xdr
, new_cinfo
);
5192 static int decode_renew(struct xdr_stream
*xdr
)
5194 return decode_op_hdr(xdr
, OP_RENEW
);
5198 decode_restorefh(struct xdr_stream
*xdr
)
5200 return decode_op_hdr(xdr
, OP_RESTOREFH
);
5203 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5204 struct nfs_getaclres
*res
)
5210 unsigned int pg_offset
;
5213 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
5216 xdr_enter_page(xdr
, xdr
->buf
->page_len
);
5218 /* Calculate the offset of the page data */
5219 pg_offset
= xdr
->buf
->head
[0].iov_len
;
5221 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
5223 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
5226 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
5228 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
5230 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5231 * are stored with the acl data to handle the problem of
5232 * variable length bitmaps.*/
5233 res
->acl_data_offset
= xdr_stream_pos(xdr
) - pg_offset
;
5234 res
->acl_len
= attrlen
;
5236 /* Check for receive buffer overflow */
5237 if (res
->acl_len
> (xdr
->nwords
<< 2) ||
5238 res
->acl_len
+ res
->acl_data_offset
> xdr
->buf
->page_len
) {
5239 res
->acl_flags
|= NFS4_ACL_TRUNC
;
5240 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5241 attrlen
, xdr
->nwords
<< 2);
5244 status
= -EOPNOTSUPP
;
5251 decode_savefh(struct xdr_stream
*xdr
)
5253 return decode_op_hdr(xdr
, OP_SAVEFH
);
5256 static int decode_setattr(struct xdr_stream
*xdr
)
5262 status
= decode_op_hdr(xdr
, OP_SETATTR
);
5265 p
= xdr_inline_decode(xdr
, 4);
5268 bmlen
= be32_to_cpup(p
);
5269 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
5273 print_overflow_msg(__func__
, xdr
);
5277 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs4_setclientid_res
*res
)
5283 p
= xdr_inline_decode(xdr
, 8);
5286 opnum
= be32_to_cpup(p
++);
5287 if (opnum
!= OP_SETCLIENTID
) {
5288 dprintk("nfs: decode_setclientid: Server returned operation"
5292 nfserr
= be32_to_cpup(p
);
5293 if (nfserr
== NFS_OK
) {
5294 p
= xdr_inline_decode(xdr
, 8 + NFS4_VERIFIER_SIZE
);
5297 p
= xdr_decode_hyper(p
, &res
->clientid
);
5298 memcpy(res
->confirm
.data
, p
, NFS4_VERIFIER_SIZE
);
5299 } else if (nfserr
== NFSERR_CLID_INUSE
) {
5302 /* skip netid string */
5303 p
= xdr_inline_decode(xdr
, 4);
5306 len
= be32_to_cpup(p
);
5307 p
= xdr_inline_decode(xdr
, len
);
5311 /* skip uaddr string */
5312 p
= xdr_inline_decode(xdr
, 4);
5315 len
= be32_to_cpup(p
);
5316 p
= xdr_inline_decode(xdr
, len
);
5319 return -NFSERR_CLID_INUSE
;
5321 return nfs4_stat_to_errno(nfserr
);
5325 print_overflow_msg(__func__
, xdr
);
5329 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
5331 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
5334 static int decode_write(struct xdr_stream
*xdr
, struct nfs_pgio_res
*res
)
5339 status
= decode_op_hdr(xdr
, OP_WRITE
);
5343 p
= xdr_inline_decode(xdr
, 8);
5346 res
->count
= be32_to_cpup(p
++);
5347 res
->verf
->committed
= be32_to_cpup(p
++);
5348 return decode_write_verifier(xdr
, &res
->verf
->verifier
);
5350 print_overflow_msg(__func__
, xdr
);
5354 static int decode_delegreturn(struct xdr_stream
*xdr
)
5356 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
5359 static int decode_secinfo_gss(struct xdr_stream
*xdr
,
5360 struct nfs4_secinfo4
*flavor
)
5365 p
= xdr_inline_decode(xdr
, 4);
5368 oid_len
= be32_to_cpup(p
);
5369 if (oid_len
> GSS_OID_MAX_LEN
)
5372 p
= xdr_inline_decode(xdr
, oid_len
);
5375 memcpy(flavor
->flavor_info
.oid
.data
, p
, oid_len
);
5376 flavor
->flavor_info
.oid
.len
= oid_len
;
5378 p
= xdr_inline_decode(xdr
, 8);
5381 flavor
->flavor_info
.qop
= be32_to_cpup(p
++);
5382 flavor
->flavor_info
.service
= be32_to_cpup(p
);
5387 print_overflow_msg(__func__
, xdr
);
5393 static int decode_secinfo_common(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5395 struct nfs4_secinfo4
*sec_flavor
;
5396 unsigned int i
, num_flavors
;
5400 p
= xdr_inline_decode(xdr
, 4);
5404 res
->flavors
->num_flavors
= 0;
5405 num_flavors
= be32_to_cpup(p
);
5407 for (i
= 0; i
< num_flavors
; i
++) {
5408 sec_flavor
= &res
->flavors
->flavors
[i
];
5409 if ((char *)&sec_flavor
[1] - (char *)res
->flavors
> PAGE_SIZE
)
5412 p
= xdr_inline_decode(xdr
, 4);
5415 sec_flavor
->flavor
= be32_to_cpup(p
);
5417 if (sec_flavor
->flavor
== RPC_AUTH_GSS
) {
5418 status
= decode_secinfo_gss(xdr
, sec_flavor
);
5422 res
->flavors
->num_flavors
++;
5429 print_overflow_msg(__func__
, xdr
);
5433 static int decode_secinfo(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5435 int status
= decode_op_hdr(xdr
, OP_SECINFO
);
5438 return decode_secinfo_common(xdr
, res
);
5441 #if defined(CONFIG_NFS_V4_1)
5442 static int decode_secinfo_no_name(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5444 int status
= decode_op_hdr(xdr
, OP_SECINFO_NO_NAME
);
5447 return decode_secinfo_common(xdr
, res
);
5450 static int decode_op_map(struct xdr_stream
*xdr
, struct nfs4_op_map
*op_map
)
5453 uint32_t bitmap_words
;
5456 p
= xdr_inline_decode(xdr
, 4);
5457 bitmap_words
= be32_to_cpup(p
++);
5458 if (bitmap_words
> NFS4_OP_MAP_NUM_WORDS
)
5460 p
= xdr_inline_decode(xdr
, 4 * bitmap_words
);
5461 for (i
= 0; i
< bitmap_words
; i
++)
5462 op_map
->u
.words
[i
] = be32_to_cpup(p
++);
5467 static int decode_exchange_id(struct xdr_stream
*xdr
,
5468 struct nfs41_exchange_id_res
*res
)
5474 uint32_t impl_id_count
;
5476 status
= decode_op_hdr(xdr
, OP_EXCHANGE_ID
);
5480 p
= xdr_inline_decode(xdr
, 8);
5483 xdr_decode_hyper(p
, &res
->clientid
);
5484 p
= xdr_inline_decode(xdr
, 12);
5487 res
->seqid
= be32_to_cpup(p
++);
5488 res
->flags
= be32_to_cpup(p
++);
5490 res
->state_protect
.how
= be32_to_cpup(p
);
5491 switch (res
->state_protect
.how
) {
5495 status
= decode_op_map(xdr
, &res
->state_protect
.enforce
);
5498 status
= decode_op_map(xdr
, &res
->state_protect
.allow
);
5507 /* server_owner4.so_minor_id */
5508 p
= xdr_inline_decode(xdr
, 8);
5511 p
= xdr_decode_hyper(p
, &res
->server_owner
->minor_id
);
5513 /* server_owner4.so_major_id */
5514 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5515 if (unlikely(status
))
5517 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5519 memcpy(res
->server_owner
->major_id
, dummy_str
, dummy
);
5520 res
->server_owner
->major_id_sz
= dummy
;
5523 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5524 if (unlikely(status
))
5526 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5528 memcpy(res
->server_scope
->server_scope
, dummy_str
, dummy
);
5529 res
->server_scope
->server_scope_sz
= dummy
;
5531 /* Implementation Id */
5532 p
= xdr_inline_decode(xdr
, 4);
5535 impl_id_count
= be32_to_cpup(p
++);
5537 if (impl_id_count
) {
5539 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5540 if (unlikely(status
))
5542 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5544 memcpy(res
->impl_id
->domain
, dummy_str
, dummy
);
5547 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5548 if (unlikely(status
))
5550 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5552 memcpy(res
->impl_id
->name
, dummy_str
, dummy
);
5555 p
= xdr_inline_decode(xdr
, 12);
5558 p
= xdr_decode_hyper(p
, &res
->impl_id
->date
.seconds
);
5559 res
->impl_id
->date
.nseconds
= be32_to_cpup(p
);
5561 /* if there's more than one entry, ignore the rest */
5565 print_overflow_msg(__func__
, xdr
);
5569 static int decode_chan_attrs(struct xdr_stream
*xdr
,
5570 struct nfs4_channel_attrs
*attrs
)
5575 p
= xdr_inline_decode(xdr
, 28);
5578 val
= be32_to_cpup(p
++); /* headerpadsz */
5580 return -EINVAL
; /* no support for header padding yet */
5581 attrs
->max_rqst_sz
= be32_to_cpup(p
++);
5582 attrs
->max_resp_sz
= be32_to_cpup(p
++);
5583 attrs
->max_resp_sz_cached
= be32_to_cpup(p
++);
5584 attrs
->max_ops
= be32_to_cpup(p
++);
5585 attrs
->max_reqs
= be32_to_cpup(p
++);
5586 nr_attrs
= be32_to_cpup(p
);
5587 if (unlikely(nr_attrs
> 1)) {
5588 printk(KERN_WARNING
"NFS: %s: Invalid rdma channel attrs "
5589 "count %u\n", __func__
, nr_attrs
);
5592 if (nr_attrs
== 1) {
5593 p
= xdr_inline_decode(xdr
, 4); /* skip rdma_attrs */
5599 print_overflow_msg(__func__
, xdr
);
5603 static int decode_sessionid(struct xdr_stream
*xdr
, struct nfs4_sessionid
*sid
)
5605 return decode_opaque_fixed(xdr
, sid
->data
, NFS4_MAX_SESSIONID_LEN
);
5608 static int decode_bind_conn_to_session(struct xdr_stream
*xdr
,
5609 struct nfs41_bind_conn_to_session_res
*res
)
5614 status
= decode_op_hdr(xdr
, OP_BIND_CONN_TO_SESSION
);
5616 status
= decode_sessionid(xdr
, &res
->sessionid
);
5617 if (unlikely(status
))
5620 /* dir flags, rdma mode bool */
5621 p
= xdr_inline_decode(xdr
, 8);
5625 res
->dir
= be32_to_cpup(p
++);
5626 if (res
->dir
== 0 || res
->dir
> NFS4_CDFS4_BOTH
)
5628 if (be32_to_cpup(p
) == 0)
5629 res
->use_conn_in_rdma_mode
= false;
5631 res
->use_conn_in_rdma_mode
= true;
5635 print_overflow_msg(__func__
, xdr
);
5639 static int decode_create_session(struct xdr_stream
*xdr
,
5640 struct nfs41_create_session_res
*res
)
5645 status
= decode_op_hdr(xdr
, OP_CREATE_SESSION
);
5647 status
= decode_sessionid(xdr
, &res
->sessionid
);
5648 if (unlikely(status
))
5652 p
= xdr_inline_decode(xdr
, 8);
5655 res
->seqid
= be32_to_cpup(p
++);
5656 res
->flags
= be32_to_cpup(p
);
5658 /* Channel attributes */
5659 status
= decode_chan_attrs(xdr
, &res
->fc_attrs
);
5661 status
= decode_chan_attrs(xdr
, &res
->bc_attrs
);
5664 print_overflow_msg(__func__
, xdr
);
5668 static int decode_destroy_session(struct xdr_stream
*xdr
, void *dummy
)
5670 return decode_op_hdr(xdr
, OP_DESTROY_SESSION
);
5673 static int decode_destroy_clientid(struct xdr_stream
*xdr
, void *dummy
)
5675 return decode_op_hdr(xdr
, OP_DESTROY_CLIENTID
);
5678 static int decode_reclaim_complete(struct xdr_stream
*xdr
, void *dummy
)
5680 return decode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
);
5682 #endif /* CONFIG_NFS_V4_1 */
5684 static int decode_sequence(struct xdr_stream
*xdr
,
5685 struct nfs4_sequence_res
*res
,
5686 struct rpc_rqst
*rqstp
)
5688 #if defined(CONFIG_NFS_V4_1)
5689 struct nfs4_session
*session
;
5690 struct nfs4_sessionid id
;
5695 if (res
->sr_slot
== NULL
)
5697 if (!res
->sr_slot
->table
->session
)
5700 status
= decode_op_hdr(xdr
, OP_SEQUENCE
);
5702 status
= decode_sessionid(xdr
, &id
);
5703 if (unlikely(status
))
5707 * If the server returns different values for sessionID, slotID or
5708 * sequence number, the server is looney tunes.
5710 status
= -EREMOTEIO
;
5711 session
= res
->sr_slot
->table
->session
;
5713 if (memcmp(id
.data
, session
->sess_id
.data
,
5714 NFS4_MAX_SESSIONID_LEN
)) {
5715 dprintk("%s Invalid session id\n", __func__
);
5719 p
= xdr_inline_decode(xdr
, 20);
5724 dummy
= be32_to_cpup(p
++);
5725 if (dummy
!= res
->sr_slot
->seq_nr
) {
5726 dprintk("%s Invalid sequence number\n", __func__
);
5730 dummy
= be32_to_cpup(p
++);
5731 if (dummy
!= res
->sr_slot
->slot_nr
) {
5732 dprintk("%s Invalid slot id\n", __func__
);
5735 /* highest slot id */
5736 res
->sr_highest_slotid
= be32_to_cpup(p
++);
5737 /* target highest slot id */
5738 res
->sr_target_highest_slotid
= be32_to_cpup(p
++);
5740 res
->sr_status_flags
= be32_to_cpup(p
);
5743 res
->sr_status
= status
;
5746 print_overflow_msg(__func__
, xdr
);
5749 #else /* CONFIG_NFS_V4_1 */
5751 #endif /* CONFIG_NFS_V4_1 */
5754 #if defined(CONFIG_NFS_V4_1)
5755 static int decode_getdeviceinfo(struct xdr_stream
*xdr
,
5756 struct nfs4_getdeviceinfo_res
*res
)
5758 struct pnfs_device
*pdev
= res
->pdev
;
5763 status
= decode_op_hdr(xdr
, OP_GETDEVICEINFO
);
5765 if (status
== -ETOOSMALL
) {
5766 p
= xdr_inline_decode(xdr
, 4);
5769 pdev
->mincount
= be32_to_cpup(p
);
5770 dprintk("%s: Min count too small. mincnt = %u\n",
5771 __func__
, pdev
->mincount
);
5776 p
= xdr_inline_decode(xdr
, 8);
5779 type
= be32_to_cpup(p
++);
5780 if (type
!= pdev
->layout_type
) {
5781 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5782 __func__
, pdev
->layout_type
, type
);
5786 * Get the length of the opaque device_addr4. xdr_read_pages places
5787 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5788 * and places the remaining xdr data in xdr_buf->tail
5790 pdev
->mincount
= be32_to_cpup(p
);
5791 if (xdr_read_pages(xdr
, pdev
->mincount
) != pdev
->mincount
)
5794 /* Parse notification bitmap, verifying that it is zero. */
5795 p
= xdr_inline_decode(xdr
, 4);
5798 len
= be32_to_cpup(p
);
5802 p
= xdr_inline_decode(xdr
, 4 * len
);
5806 res
->notification
= be32_to_cpup(p
++);
5807 for (i
= 1; i
< len
; i
++) {
5808 if (be32_to_cpup(p
++)) {
5809 dprintk("%s: unsupported notification\n",
5817 print_overflow_msg(__func__
, xdr
);
5821 static int decode_layoutget(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5822 struct nfs4_layoutget_res
*res
)
5829 status
= decode_op_hdr(xdr
, OP_LAYOUTGET
);
5832 p
= xdr_inline_decode(xdr
, 4);
5835 res
->return_on_close
= be32_to_cpup(p
);
5836 decode_stateid(xdr
, &res
->stateid
);
5837 p
= xdr_inline_decode(xdr
, 4);
5840 layout_count
= be32_to_cpup(p
);
5841 if (!layout_count
) {
5842 dprintk("%s: server responded with empty layout array\n",
5847 p
= xdr_inline_decode(xdr
, 28);
5850 p
= xdr_decode_hyper(p
, &res
->range
.offset
);
5851 p
= xdr_decode_hyper(p
, &res
->range
.length
);
5852 res
->range
.iomode
= be32_to_cpup(p
++);
5853 res
->type
= be32_to_cpup(p
++);
5854 res
->layoutp
->len
= be32_to_cpup(p
);
5856 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5858 (unsigned long)res
->range
.offset
,
5859 (unsigned long)res
->range
.length
,
5864 recvd
= xdr_read_pages(xdr
, res
->layoutp
->len
);
5865 if (res
->layoutp
->len
> recvd
) {
5866 dprintk("NFS: server cheating in layoutget reply: "
5867 "layout len %u > recvd %u\n",
5868 res
->layoutp
->len
, recvd
);
5872 if (layout_count
> 1) {
5873 /* We only handle a length one array at the moment. Any
5874 * further entries are just ignored. Note that this means
5875 * the client may see a response that is less than the
5876 * minimum it requested.
5878 dprintk("%s: server responded with %d layouts, dropping tail\n",
5879 __func__
, layout_count
);
5884 print_overflow_msg(__func__
, xdr
);
5888 static int decode_layoutreturn(struct xdr_stream
*xdr
,
5889 struct nfs4_layoutreturn_res
*res
)
5894 status
= decode_op_hdr(xdr
, OP_LAYOUTRETURN
);
5897 p
= xdr_inline_decode(xdr
, 4);
5900 res
->lrs_present
= be32_to_cpup(p
);
5901 if (res
->lrs_present
)
5902 status
= decode_stateid(xdr
, &res
->stateid
);
5905 print_overflow_msg(__func__
, xdr
);
5909 static int decode_layoutcommit(struct xdr_stream
*xdr
,
5910 struct rpc_rqst
*req
,
5911 struct nfs4_layoutcommit_res
*res
)
5917 status
= decode_op_hdr(xdr
, OP_LAYOUTCOMMIT
);
5918 res
->status
= status
;
5922 p
= xdr_inline_decode(xdr
, 4);
5925 sizechanged
= be32_to_cpup(p
);
5928 /* throw away new size */
5929 p
= xdr_inline_decode(xdr
, 8);
5935 print_overflow_msg(__func__
, xdr
);
5939 static int decode_test_stateid(struct xdr_stream
*xdr
,
5940 struct nfs41_test_stateid_res
*res
)
5946 status
= decode_op_hdr(xdr
, OP_TEST_STATEID
);
5950 p
= xdr_inline_decode(xdr
, 4);
5953 num_res
= be32_to_cpup(p
++);
5957 p
= xdr_inline_decode(xdr
, 4);
5960 res
->status
= be32_to_cpup(p
++);
5964 print_overflow_msg(__func__
, xdr
);
5969 static int decode_free_stateid(struct xdr_stream
*xdr
,
5970 struct nfs41_free_stateid_res
*res
)
5972 res
->status
= decode_op_hdr(xdr
, OP_FREE_STATEID
);
5975 #endif /* CONFIG_NFS_V4_1 */
5978 * END OF "GENERIC" DECODE ROUTINES.
5982 * Decode OPEN_DOWNGRADE response
5984 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
,
5985 struct xdr_stream
*xdr
,
5986 struct nfs_closeres
*res
)
5988 struct compound_hdr hdr
;
5991 status
= decode_compound_hdr(xdr
, &hdr
);
5994 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5997 status
= decode_putfh(xdr
);
6000 status
= decode_open_downgrade(xdr
, res
);
6003 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6009 * Decode ACCESS response
6011 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6012 struct nfs4_accessres
*res
)
6014 struct compound_hdr hdr
;
6017 status
= decode_compound_hdr(xdr
, &hdr
);
6020 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6023 status
= decode_putfh(xdr
);
6026 status
= decode_access(xdr
, &res
->supported
, &res
->access
);
6029 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6035 * Decode LOOKUP response
6037 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6038 struct nfs4_lookup_res
*res
)
6040 struct compound_hdr hdr
;
6043 status
= decode_compound_hdr(xdr
, &hdr
);
6046 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6049 status
= decode_putfh(xdr
);
6052 status
= decode_lookup(xdr
);
6055 status
= decode_getfh(xdr
, res
->fh
);
6058 status
= decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6064 * Decode LOOKUP_ROOT response
6066 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
,
6067 struct xdr_stream
*xdr
,
6068 struct nfs4_lookup_res
*res
)
6070 struct compound_hdr hdr
;
6073 status
= decode_compound_hdr(xdr
, &hdr
);
6076 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6079 status
= decode_putrootfh(xdr
);
6082 status
= decode_getfh(xdr
, res
->fh
);
6084 status
= decode_getfattr_label(xdr
, res
->fattr
,
6085 res
->label
, res
->server
);
6091 * Decode REMOVE response
6093 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6094 struct nfs_removeres
*res
)
6096 struct compound_hdr hdr
;
6099 status
= decode_compound_hdr(xdr
, &hdr
);
6102 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6105 status
= decode_putfh(xdr
);
6108 status
= decode_remove(xdr
, &res
->cinfo
);
6114 * Decode RENAME response
6116 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6117 struct nfs_renameres
*res
)
6119 struct compound_hdr hdr
;
6122 status
= decode_compound_hdr(xdr
, &hdr
);
6125 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6128 status
= decode_putfh(xdr
);
6131 status
= decode_savefh(xdr
);
6134 status
= decode_putfh(xdr
);
6137 status
= decode_rename(xdr
, &res
->old_cinfo
, &res
->new_cinfo
);
6143 * Decode LINK response
6145 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6146 struct nfs4_link_res
*res
)
6148 struct compound_hdr hdr
;
6151 status
= decode_compound_hdr(xdr
, &hdr
);
6154 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6157 status
= decode_putfh(xdr
);
6160 status
= decode_savefh(xdr
);
6163 status
= decode_putfh(xdr
);
6166 status
= decode_link(xdr
, &res
->cinfo
);
6170 * Note order: OP_LINK leaves the directory as the current
6173 status
= decode_restorefh(xdr
);
6176 decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6182 * Decode CREATE response
6184 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6185 struct nfs4_create_res
*res
)
6187 struct compound_hdr hdr
;
6190 status
= decode_compound_hdr(xdr
, &hdr
);
6193 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6196 status
= decode_putfh(xdr
);
6199 status
= decode_create(xdr
, &res
->dir_cinfo
);
6202 status
= decode_getfh(xdr
, res
->fh
);
6205 decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6211 * Decode SYMLINK response
6213 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6214 struct nfs4_create_res
*res
)
6216 return nfs4_xdr_dec_create(rqstp
, xdr
, res
);
6220 * Decode GETATTR response
6222 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6223 struct nfs4_getattr_res
*res
)
6225 struct compound_hdr hdr
;
6228 status
= decode_compound_hdr(xdr
, &hdr
);
6231 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6234 status
= decode_putfh(xdr
);
6237 status
= decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6243 * Encode an SETACL request
6245 static void nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6246 struct nfs_setaclargs
*args
)
6248 struct compound_hdr hdr
= {
6249 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
6252 encode_compound_hdr(xdr
, req
, &hdr
);
6253 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
6254 encode_putfh(xdr
, args
->fh
, &hdr
);
6255 encode_setacl(xdr
, args
, &hdr
);
6260 * Decode SETACL response
6263 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6264 struct nfs_setaclres
*res
)
6266 struct compound_hdr hdr
;
6269 status
= decode_compound_hdr(xdr
, &hdr
);
6272 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6275 status
= decode_putfh(xdr
);
6278 status
= decode_setattr(xdr
);
6284 * Decode GETACL response
6287 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6288 struct nfs_getaclres
*res
)
6290 struct compound_hdr hdr
;
6293 if (res
->acl_scratch
!= NULL
) {
6294 void *p
= page_address(res
->acl_scratch
);
6295 xdr_set_scratch_buffer(xdr
, p
, PAGE_SIZE
);
6297 status
= decode_compound_hdr(xdr
, &hdr
);
6300 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6303 status
= decode_putfh(xdr
);
6306 status
= decode_getacl(xdr
, rqstp
, res
);
6313 * Decode CLOSE response
6315 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6316 struct nfs_closeres
*res
)
6318 struct compound_hdr hdr
;
6321 status
= decode_compound_hdr(xdr
, &hdr
);
6324 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6327 status
= decode_putfh(xdr
);
6330 status
= decode_close(xdr
, res
);
6334 * Note: Server may do delete on close for this file
6335 * in which case the getattr call will fail with
6336 * an ESTALE error. Shouldn't be a problem,
6337 * though, since fattr->valid will remain unset.
6339 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6345 * Decode OPEN response
6347 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6348 struct nfs_openres
*res
)
6350 struct compound_hdr hdr
;
6353 status
= decode_compound_hdr(xdr
, &hdr
);
6356 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6359 status
= decode_putfh(xdr
);
6362 status
= decode_open(xdr
, res
);
6365 status
= decode_getfh(xdr
, &res
->fh
);
6368 if (res
->access_request
)
6369 decode_access(xdr
, &res
->access_supported
, &res
->access_result
);
6370 decode_getfattr_label(xdr
, res
->f_attr
, res
->f_label
, res
->server
);
6376 * Decode OPEN_CONFIRM response
6378 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
,
6379 struct xdr_stream
*xdr
,
6380 struct nfs_open_confirmres
*res
)
6382 struct compound_hdr hdr
;
6385 status
= decode_compound_hdr(xdr
, &hdr
);
6388 status
= decode_putfh(xdr
);
6391 status
= decode_open_confirm(xdr
, res
);
6397 * Decode OPEN response
6399 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
,
6400 struct xdr_stream
*xdr
,
6401 struct nfs_openres
*res
)
6403 struct compound_hdr hdr
;
6406 status
= decode_compound_hdr(xdr
, &hdr
);
6409 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6412 status
= decode_putfh(xdr
);
6415 status
= decode_open(xdr
, res
);
6418 if (res
->access_request
)
6419 decode_access(xdr
, &res
->access_supported
, &res
->access_result
);
6420 decode_getfattr(xdr
, res
->f_attr
, res
->server
);
6426 * Decode SETATTR response
6428 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
,
6429 struct xdr_stream
*xdr
,
6430 struct nfs_setattrres
*res
)
6432 struct compound_hdr hdr
;
6435 status
= decode_compound_hdr(xdr
, &hdr
);
6438 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6441 status
= decode_putfh(xdr
);
6444 status
= decode_setattr(xdr
);
6447 decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6453 * Decode LOCK response
6455 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6456 struct nfs_lock_res
*res
)
6458 struct compound_hdr hdr
;
6461 status
= decode_compound_hdr(xdr
, &hdr
);
6464 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6467 status
= decode_putfh(xdr
);
6470 status
= decode_lock(xdr
, res
);
6476 * Decode LOCKT response
6478 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6479 struct nfs_lockt_res
*res
)
6481 struct compound_hdr hdr
;
6484 status
= decode_compound_hdr(xdr
, &hdr
);
6487 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6490 status
= decode_putfh(xdr
);
6493 status
= decode_lockt(xdr
, res
);
6499 * Decode LOCKU response
6501 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6502 struct nfs_locku_res
*res
)
6504 struct compound_hdr hdr
;
6507 status
= decode_compound_hdr(xdr
, &hdr
);
6510 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6513 status
= decode_putfh(xdr
);
6516 status
= decode_locku(xdr
, res
);
6521 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst
*rqstp
,
6522 struct xdr_stream
*xdr
, void *dummy
)
6524 struct compound_hdr hdr
;
6527 status
= decode_compound_hdr(xdr
, &hdr
);
6529 status
= decode_release_lockowner(xdr
);
6534 * Decode READLINK response
6536 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
,
6537 struct xdr_stream
*xdr
,
6538 struct nfs4_readlink_res
*res
)
6540 struct compound_hdr hdr
;
6543 status
= decode_compound_hdr(xdr
, &hdr
);
6546 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6549 status
= decode_putfh(xdr
);
6552 status
= decode_readlink(xdr
, rqstp
);
6558 * Decode READDIR response
6560 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6561 struct nfs4_readdir_res
*res
)
6563 struct compound_hdr hdr
;
6566 status
= decode_compound_hdr(xdr
, &hdr
);
6569 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6572 status
= decode_putfh(xdr
);
6575 status
= decode_readdir(xdr
, rqstp
, res
);
6581 * Decode Read response
6583 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6584 struct nfs_pgio_res
*res
)
6586 struct compound_hdr hdr
;
6589 status
= decode_compound_hdr(xdr
, &hdr
);
6590 res
->op_status
= hdr
.status
;
6593 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6596 status
= decode_putfh(xdr
);
6599 status
= decode_read(xdr
, rqstp
, res
);
6601 status
= res
->count
;
6607 * Decode WRITE response
6609 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6610 struct nfs_pgio_res
*res
)
6612 struct compound_hdr hdr
;
6615 status
= decode_compound_hdr(xdr
, &hdr
);
6616 res
->op_status
= hdr
.status
;
6619 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6622 status
= decode_putfh(xdr
);
6625 status
= decode_write(xdr
, res
);
6629 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6631 status
= res
->count
;
6637 * Decode COMMIT response
6639 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6640 struct nfs_commitres
*res
)
6642 struct compound_hdr hdr
;
6645 status
= decode_compound_hdr(xdr
, &hdr
);
6646 res
->op_status
= hdr
.status
;
6649 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6652 status
= decode_putfh(xdr
);
6655 status
= decode_commit(xdr
, res
);
6661 * Decode FSINFO response
6663 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6664 struct nfs4_fsinfo_res
*res
)
6666 struct compound_hdr hdr
;
6669 status
= decode_compound_hdr(xdr
, &hdr
);
6671 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6673 status
= decode_putfh(xdr
);
6675 status
= decode_fsinfo(xdr
, res
->fsinfo
);
6680 * Decode PATHCONF response
6682 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6683 struct nfs4_pathconf_res
*res
)
6685 struct compound_hdr hdr
;
6688 status
= decode_compound_hdr(xdr
, &hdr
);
6690 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6692 status
= decode_putfh(xdr
);
6694 status
= decode_pathconf(xdr
, res
->pathconf
);
6699 * Decode STATFS response
6701 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6702 struct nfs4_statfs_res
*res
)
6704 struct compound_hdr hdr
;
6707 status
= decode_compound_hdr(xdr
, &hdr
);
6709 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6711 status
= decode_putfh(xdr
);
6713 status
= decode_statfs(xdr
, res
->fsstat
);
6718 * Decode GETATTR_BITMAP response
6720 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
,
6721 struct xdr_stream
*xdr
,
6722 struct nfs4_server_caps_res
*res
)
6724 struct compound_hdr hdr
;
6727 status
= decode_compound_hdr(xdr
, &hdr
);
6730 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6733 status
= decode_putfh(xdr
);
6736 status
= decode_server_caps(xdr
, res
);
6742 * Decode RENEW response
6744 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6747 struct compound_hdr hdr
;
6750 status
= decode_compound_hdr(xdr
, &hdr
);
6752 status
= decode_renew(xdr
);
6757 * Decode SETCLIENTID response
6759 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
,
6760 struct xdr_stream
*xdr
,
6761 struct nfs4_setclientid_res
*res
)
6763 struct compound_hdr hdr
;
6766 status
= decode_compound_hdr(xdr
, &hdr
);
6768 status
= decode_setclientid(xdr
, res
);
6773 * Decode SETCLIENTID_CONFIRM response
6775 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
,
6776 struct xdr_stream
*xdr
)
6778 struct compound_hdr hdr
;
6781 status
= decode_compound_hdr(xdr
, &hdr
);
6783 status
= decode_setclientid_confirm(xdr
);
6788 * Decode DELEGRETURN response
6790 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
,
6791 struct xdr_stream
*xdr
,
6792 struct nfs4_delegreturnres
*res
)
6794 struct compound_hdr hdr
;
6797 status
= decode_compound_hdr(xdr
, &hdr
);
6800 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6803 status
= decode_putfh(xdr
);
6806 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
);
6809 status
= decode_delegreturn(xdr
);
6815 * Decode FS_LOCATIONS response
6817 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
,
6818 struct xdr_stream
*xdr
,
6819 struct nfs4_fs_locations_res
*res
)
6821 struct compound_hdr hdr
;
6824 status
= decode_compound_hdr(xdr
, &hdr
);
6827 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6830 status
= decode_putfh(xdr
);
6833 if (res
->migration
) {
6834 xdr_enter_page(xdr
, PAGE_SIZE
);
6835 status
= decode_getfattr_generic(xdr
,
6836 &res
->fs_locations
->fattr
,
6837 NULL
, res
->fs_locations
,
6838 NULL
, res
->fs_locations
->server
);
6842 status
= decode_renew(xdr
);
6844 status
= decode_lookup(xdr
);
6847 xdr_enter_page(xdr
, PAGE_SIZE
);
6848 status
= decode_getfattr_generic(xdr
,
6849 &res
->fs_locations
->fattr
,
6850 NULL
, res
->fs_locations
,
6851 NULL
, res
->fs_locations
->server
);
6858 * Decode SECINFO response
6860 static int nfs4_xdr_dec_secinfo(struct rpc_rqst
*rqstp
,
6861 struct xdr_stream
*xdr
,
6862 struct nfs4_secinfo_res
*res
)
6864 struct compound_hdr hdr
;
6867 status
= decode_compound_hdr(xdr
, &hdr
);
6870 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6873 status
= decode_putfh(xdr
);
6876 status
= decode_secinfo(xdr
, res
);
6882 * Decode FSID_PRESENT response
6884 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst
*rqstp
,
6885 struct xdr_stream
*xdr
,
6886 struct nfs4_fsid_present_res
*res
)
6888 struct compound_hdr hdr
;
6891 status
= decode_compound_hdr(xdr
, &hdr
);
6894 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6897 status
= decode_putfh(xdr
);
6900 status
= decode_getfh(xdr
, res
->fh
);
6904 status
= decode_renew(xdr
);
6909 #if defined(CONFIG_NFS_V4_1)
6911 * Decode BIND_CONN_TO_SESSION response
6913 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst
*rqstp
,
6914 struct xdr_stream
*xdr
,
6917 struct compound_hdr hdr
;
6920 status
= decode_compound_hdr(xdr
, &hdr
);
6922 status
= decode_bind_conn_to_session(xdr
, res
);
6927 * Decode EXCHANGE_ID response
6929 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst
*rqstp
,
6930 struct xdr_stream
*xdr
,
6933 struct compound_hdr hdr
;
6936 status
= decode_compound_hdr(xdr
, &hdr
);
6938 status
= decode_exchange_id(xdr
, res
);
6943 * Decode CREATE_SESSION response
6945 static int nfs4_xdr_dec_create_session(struct rpc_rqst
*rqstp
,
6946 struct xdr_stream
*xdr
,
6947 struct nfs41_create_session_res
*res
)
6949 struct compound_hdr hdr
;
6952 status
= decode_compound_hdr(xdr
, &hdr
);
6954 status
= decode_create_session(xdr
, res
);
6959 * Decode DESTROY_SESSION response
6961 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst
*rqstp
,
6962 struct xdr_stream
*xdr
,
6965 struct compound_hdr hdr
;
6968 status
= decode_compound_hdr(xdr
, &hdr
);
6970 status
= decode_destroy_session(xdr
, res
);
6975 * Decode DESTROY_CLIENTID response
6977 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst
*rqstp
,
6978 struct xdr_stream
*xdr
,
6981 struct compound_hdr hdr
;
6984 status
= decode_compound_hdr(xdr
, &hdr
);
6986 status
= decode_destroy_clientid(xdr
, res
);
6991 * Decode SEQUENCE response
6993 static int nfs4_xdr_dec_sequence(struct rpc_rqst
*rqstp
,
6994 struct xdr_stream
*xdr
,
6995 struct nfs4_sequence_res
*res
)
6997 struct compound_hdr hdr
;
7000 status
= decode_compound_hdr(xdr
, &hdr
);
7002 status
= decode_sequence(xdr
, res
, rqstp
);
7007 * Decode GET_LEASE_TIME response
7009 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst
*rqstp
,
7010 struct xdr_stream
*xdr
,
7011 struct nfs4_get_lease_time_res
*res
)
7013 struct compound_hdr hdr
;
7016 status
= decode_compound_hdr(xdr
, &hdr
);
7018 status
= decode_sequence(xdr
, &res
->lr_seq_res
, rqstp
);
7020 status
= decode_putrootfh(xdr
);
7022 status
= decode_fsinfo(xdr
, res
->lr_fsinfo
);
7027 * Decode RECLAIM_COMPLETE response
7029 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst
*rqstp
,
7030 struct xdr_stream
*xdr
,
7031 struct nfs41_reclaim_complete_res
*res
)
7033 struct compound_hdr hdr
;
7036 status
= decode_compound_hdr(xdr
, &hdr
);
7038 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7040 status
= decode_reclaim_complete(xdr
, NULL
);
7045 * Decode GETDEVINFO response
7047 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst
*rqstp
,
7048 struct xdr_stream
*xdr
,
7049 struct nfs4_getdeviceinfo_res
*res
)
7051 struct compound_hdr hdr
;
7054 status
= decode_compound_hdr(xdr
, &hdr
);
7057 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7060 status
= decode_getdeviceinfo(xdr
, res
);
7066 * Decode LAYOUTGET response
7068 static int nfs4_xdr_dec_layoutget(struct rpc_rqst
*rqstp
,
7069 struct xdr_stream
*xdr
,
7070 struct nfs4_layoutget_res
*res
)
7072 struct compound_hdr hdr
;
7075 status
= decode_compound_hdr(xdr
, &hdr
);
7078 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7081 status
= decode_putfh(xdr
);
7084 status
= decode_layoutget(xdr
, rqstp
, res
);
7090 * Decode LAYOUTRETURN response
7092 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst
*rqstp
,
7093 struct xdr_stream
*xdr
,
7094 struct nfs4_layoutreturn_res
*res
)
7096 struct compound_hdr hdr
;
7099 status
= decode_compound_hdr(xdr
, &hdr
);
7102 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7105 status
= decode_putfh(xdr
);
7108 status
= decode_layoutreturn(xdr
, res
);
7114 * Decode LAYOUTCOMMIT response
7116 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst
*rqstp
,
7117 struct xdr_stream
*xdr
,
7118 struct nfs4_layoutcommit_res
*res
)
7120 struct compound_hdr hdr
;
7123 status
= decode_compound_hdr(xdr
, &hdr
);
7126 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7129 status
= decode_putfh(xdr
);
7132 status
= decode_layoutcommit(xdr
, rqstp
, res
);
7135 decode_getfattr(xdr
, res
->fattr
, res
->server
);
7141 * Decode SECINFO_NO_NAME response
7143 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst
*rqstp
,
7144 struct xdr_stream
*xdr
,
7145 struct nfs4_secinfo_res
*res
)
7147 struct compound_hdr hdr
;
7150 status
= decode_compound_hdr(xdr
, &hdr
);
7153 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7156 status
= decode_putrootfh(xdr
);
7159 status
= decode_secinfo_no_name(xdr
, res
);
7165 * Decode TEST_STATEID response
7167 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst
*rqstp
,
7168 struct xdr_stream
*xdr
,
7169 struct nfs41_test_stateid_res
*res
)
7171 struct compound_hdr hdr
;
7174 status
= decode_compound_hdr(xdr
, &hdr
);
7177 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7180 status
= decode_test_stateid(xdr
, res
);
7186 * Decode FREE_STATEID response
7188 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst
*rqstp
,
7189 struct xdr_stream
*xdr
,
7190 struct nfs41_free_stateid_res
*res
)
7192 struct compound_hdr hdr
;
7195 status
= decode_compound_hdr(xdr
, &hdr
);
7198 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7201 status
= decode_free_stateid(xdr
, res
);
7205 #endif /* CONFIG_NFS_V4_1 */
7208 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7209 * the local page cache.
7210 * @xdr: XDR stream where entry resides
7211 * @entry: buffer to fill in with entry data
7212 * @plus: boolean indicating whether this should be a readdirplus entry
7214 * Returns zero if successful, otherwise a negative errno value is
7217 * This function is not invoked during READDIR reply decoding, but
7218 * rather whenever an application invokes the getdents(2) system call
7219 * on a directory already in our cache.
7221 int nfs4_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
7225 uint32_t bitmap
[3] = {0};
7227 __be32
*p
= xdr_inline_decode(xdr
, 4);
7230 if (*p
== xdr_zero
) {
7231 p
= xdr_inline_decode(xdr
, 4);
7240 p
= xdr_inline_decode(xdr
, 12);
7243 entry
->prev_cookie
= entry
->cookie
;
7244 p
= xdr_decode_hyper(p
, &entry
->cookie
);
7245 entry
->len
= be32_to_cpup(p
);
7247 p
= xdr_inline_decode(xdr
, entry
->len
);
7250 entry
->name
= (const char *) p
;
7253 * In case the server doesn't return an inode number,
7254 * we fake one here. (We don't use inode number 0,
7255 * since glibc seems to choke on it...)
7258 entry
->fattr
->valid
= 0;
7260 if (decode_attr_bitmap(xdr
, bitmap
) < 0)
7263 if (decode_attr_length(xdr
, &len
, &savep
) < 0)
7266 if (decode_getfattr_attrs(xdr
, bitmap
, entry
->fattr
, entry
->fh
,
7267 NULL
, entry
->label
, entry
->server
) < 0)
7269 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
)
7270 entry
->ino
= entry
->fattr
->mounted_on_fileid
;
7271 else if (entry
->fattr
->valid
& NFS_ATTR_FATTR_FILEID
)
7272 entry
->ino
= entry
->fattr
->fileid
;
7274 entry
->d_type
= DT_UNKNOWN
;
7275 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_TYPE
)
7276 entry
->d_type
= nfs_umode_to_dtype(entry
->fattr
->mode
);
7281 print_overflow_msg(__func__
, xdr
);
7286 * We need to translate between nfs status return values and
7287 * the local errno values which may not be the same.
7294 { NFS4ERR_PERM
, -EPERM
},
7295 { NFS4ERR_NOENT
, -ENOENT
},
7296 { NFS4ERR_IO
, -errno_NFSERR_IO
},
7297 { NFS4ERR_NXIO
, -ENXIO
},
7298 { NFS4ERR_ACCESS
, -EACCES
},
7299 { NFS4ERR_EXIST
, -EEXIST
},
7300 { NFS4ERR_XDEV
, -EXDEV
},
7301 { NFS4ERR_NOTDIR
, -ENOTDIR
},
7302 { NFS4ERR_ISDIR
, -EISDIR
},
7303 { NFS4ERR_INVAL
, -EINVAL
},
7304 { NFS4ERR_FBIG
, -EFBIG
},
7305 { NFS4ERR_NOSPC
, -ENOSPC
},
7306 { NFS4ERR_ROFS
, -EROFS
},
7307 { NFS4ERR_MLINK
, -EMLINK
},
7308 { NFS4ERR_NAMETOOLONG
, -ENAMETOOLONG
},
7309 { NFS4ERR_NOTEMPTY
, -ENOTEMPTY
},
7310 { NFS4ERR_DQUOT
, -EDQUOT
},
7311 { NFS4ERR_STALE
, -ESTALE
},
7312 { NFS4ERR_BADHANDLE
, -EBADHANDLE
},
7313 { NFS4ERR_BAD_COOKIE
, -EBADCOOKIE
},
7314 { NFS4ERR_NOTSUPP
, -ENOTSUPP
},
7315 { NFS4ERR_TOOSMALL
, -ETOOSMALL
},
7316 { NFS4ERR_SERVERFAULT
, -EREMOTEIO
},
7317 { NFS4ERR_BADTYPE
, -EBADTYPE
},
7318 { NFS4ERR_LOCKED
, -EAGAIN
},
7319 { NFS4ERR_SYMLINK
, -ELOOP
},
7320 { NFS4ERR_OP_ILLEGAL
, -EOPNOTSUPP
},
7321 { NFS4ERR_DEADLOCK
, -EDEADLK
},
7326 * Convert an NFS error code to a local one.
7327 * This one is used jointly by NFSv2 and NFSv3.
7330 nfs4_stat_to_errno(int stat
)
7333 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
7334 if (nfs_errtbl
[i
].stat
== stat
)
7335 return nfs_errtbl
[i
].errno
;
7337 if (stat
<= 10000 || stat
> 10100) {
7338 /* The server is looney tunes. */
7341 /* If we cannot translate the error, the recovery routines should
7343 * Note: remaining NFSv4 error codes have values > 10000, so should
7344 * not conflict with native Linux error codes.
7349 #ifdef CONFIG_NFS_V4_2
7350 #include "nfs42xdr.c"
7351 #endif /* CONFIG_NFS_V4_2 */
7353 #define PROC(proc, argtype, restype) \
7354 [NFSPROC4_CLNT_##proc] = { \
7355 .p_proc = NFSPROC4_COMPOUND, \
7356 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7357 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7358 .p_arglen = NFS4_##argtype##_sz, \
7359 .p_replen = NFS4_##restype##_sz, \
7360 .p_statidx = NFSPROC4_CLNT_##proc, \
7364 #define STUB(proc) \
7365 [NFSPROC4_CLNT_##proc] = { \
7369 struct rpc_procinfo nfs4_procedures
[] = {
7370 PROC(READ
, enc_read
, dec_read
),
7371 PROC(WRITE
, enc_write
, dec_write
),
7372 PROC(COMMIT
, enc_commit
, dec_commit
),
7373 PROC(OPEN
, enc_open
, dec_open
),
7374 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
7375 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
7376 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
7377 PROC(CLOSE
, enc_close
, dec_close
),
7378 PROC(SETATTR
, enc_setattr
, dec_setattr
),
7379 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
7380 PROC(RENEW
, enc_renew
, dec_renew
),
7381 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
7382 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
7383 PROC(LOCK
, enc_lock
, dec_lock
),
7384 PROC(LOCKT
, enc_lockt
, dec_lockt
),
7385 PROC(LOCKU
, enc_locku
, dec_locku
),
7386 PROC(ACCESS
, enc_access
, dec_access
),
7387 PROC(GETATTR
, enc_getattr
, dec_getattr
),
7388 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
7389 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
7390 PROC(REMOVE
, enc_remove
, dec_remove
),
7391 PROC(RENAME
, enc_rename
, dec_rename
),
7392 PROC(LINK
, enc_link
, dec_link
),
7393 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
7394 PROC(CREATE
, enc_create
, dec_create
),
7395 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
7396 PROC(STATFS
, enc_statfs
, dec_statfs
),
7397 PROC(READLINK
, enc_readlink
, dec_readlink
),
7398 PROC(READDIR
, enc_readdir
, dec_readdir
),
7399 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
7400 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
7401 PROC(GETACL
, enc_getacl
, dec_getacl
),
7402 PROC(SETACL
, enc_setacl
, dec_setacl
),
7403 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
7404 PROC(RELEASE_LOCKOWNER
, enc_release_lockowner
, dec_release_lockowner
),
7405 PROC(SECINFO
, enc_secinfo
, dec_secinfo
),
7406 PROC(FSID_PRESENT
, enc_fsid_present
, dec_fsid_present
),
7407 #if defined(CONFIG_NFS_V4_1)
7408 PROC(EXCHANGE_ID
, enc_exchange_id
, dec_exchange_id
),
7409 PROC(CREATE_SESSION
, enc_create_session
, dec_create_session
),
7410 PROC(DESTROY_SESSION
, enc_destroy_session
, dec_destroy_session
),
7411 PROC(SEQUENCE
, enc_sequence
, dec_sequence
),
7412 PROC(GET_LEASE_TIME
, enc_get_lease_time
, dec_get_lease_time
),
7413 PROC(RECLAIM_COMPLETE
, enc_reclaim_complete
, dec_reclaim_complete
),
7414 PROC(GETDEVICEINFO
, enc_getdeviceinfo
, dec_getdeviceinfo
),
7415 PROC(LAYOUTGET
, enc_layoutget
, dec_layoutget
),
7416 PROC(LAYOUTCOMMIT
, enc_layoutcommit
, dec_layoutcommit
),
7417 PROC(LAYOUTRETURN
, enc_layoutreturn
, dec_layoutreturn
),
7418 PROC(SECINFO_NO_NAME
, enc_secinfo_no_name
, dec_secinfo_no_name
),
7419 PROC(TEST_STATEID
, enc_test_stateid
, dec_test_stateid
),
7420 PROC(FREE_STATEID
, enc_free_stateid
, dec_free_stateid
),
7421 STUB(GETDEVICELIST
),
7422 PROC(BIND_CONN_TO_SESSION
,
7423 enc_bind_conn_to_session
, dec_bind_conn_to_session
),
7424 PROC(DESTROY_CLIENTID
, enc_destroy_clientid
, dec_destroy_clientid
),
7425 #endif /* CONFIG_NFS_V4_1 */
7426 #ifdef CONFIG_NFS_V4_2
7427 PROC(SEEK
, enc_seek
, dec_seek
),
7428 PROC(ALLOCATE
, enc_allocate
, dec_allocate
),
7429 PROC(DEALLOCATE
, enc_deallocate
, dec_deallocate
),
7430 #endif /* CONFIG_NFS_V4_2 */
7433 const struct rpc_version nfs_version4
= {
7435 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
7436 .procs
= nfs4_procedures