mmc: sdhci: move timeout_clk calculation farther down
[linux-2.6/next.git] / fs / nfs / nfs4xdr.c
blob1dce12f41a4f8d48ceedccf192f64fd7617f6713
1 /*
2 * fs/nfs/nfs4xdr.c
4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
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
14 * are met:
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>
40 #include <linux/mm.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
43 #include <linux/in.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/sunrpc/clnt.h>
48 #include <linux/sunrpc/msg_prot.h>
49 #include <linux/sunrpc/gss_api.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
54 #include "nfs4_fs.h"
55 #include "internal.h"
56 #include "pnfs.h"
58 #define NFSDBG_FACILITY NFSDBG_XDR
60 /* Mapping from NFS error code to "errno" error code. */
61 #define errno_NFSERR_IO EIO
63 static int nfs4_stat_to_errno(int);
65 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
66 #ifdef DEBUG
67 #define NFS4_MAXTAGLEN 20
68 #else
69 #define NFS4_MAXTAGLEN 0
70 #endif
72 /* lock,open owner id:
73 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
75 #define open_owner_id_maxsz (1 + 1 + 4)
76 #define lock_owner_id_maxsz (1 + 1 + 4)
77 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
78 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80 #define op_encode_hdr_maxsz (1)
81 #define op_decode_hdr_maxsz (2)
82 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
86 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
87 (NFS4_FHSIZE >> 2))
88 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
92 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
94 #define nfs4_fattr_bitmap_maxsz 4
95 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
96 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
98 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
100 /* This is based on getfattr, which uses the most attributes: */
101 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
103 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
106 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
107 1 + 2 + 1 + \
108 nfs4_owner_maxsz + \
109 nfs4_group_maxsz + \
110 4 + 4)
111 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
115 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
116 /* The 5 accounts for the PNFS attributes, and assumes that at most three
117 * layout types will be returned.
119 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
120 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
121 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
122 #define decode_renew_maxsz (op_decode_hdr_maxsz)
123 #define encode_setclientid_maxsz \
124 (op_encode_hdr_maxsz + \
125 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
126 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
127 1 /* sc_prog */ + \
128 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
129 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
130 1) /* sc_cb_ident */
131 #define decode_setclientid_maxsz \
132 (op_decode_hdr_maxsz + \
133 2 + \
134 1024) /* large value for CLID_INUSE */
135 #define encode_setclientid_confirm_maxsz \
136 (op_encode_hdr_maxsz + \
137 3 + (NFS4_VERIFIER_SIZE >> 2))
138 #define decode_setclientid_confirm_maxsz \
139 (op_decode_hdr_maxsz)
140 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
141 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
142 #define encode_share_access_maxsz \
144 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
145 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
146 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
147 #define encode_open_maxsz (op_encode_hdr_maxsz + \
148 2 + encode_share_access_maxsz + 2 + \
149 open_owner_id_maxsz + \
150 encode_opentype_maxsz + \
151 encode_claim_null_maxsz)
152 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
153 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
154 decode_ace_maxsz)
155 #define decode_change_info_maxsz (5)
156 #define decode_open_maxsz (op_decode_hdr_maxsz + \
157 decode_stateid_maxsz + \
158 decode_change_info_maxsz + 1 + \
159 nfs4_fattr_bitmap_maxsz + \
160 decode_delegation_maxsz)
161 #define encode_open_confirm_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1)
164 #define decode_open_confirm_maxsz \
165 (op_decode_hdr_maxsz + \
166 decode_stateid_maxsz)
167 #define encode_open_downgrade_maxsz \
168 (op_encode_hdr_maxsz + \
169 encode_stateid_maxsz + 1 + \
170 encode_share_access_maxsz)
171 #define decode_open_downgrade_maxsz \
172 (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174 #define encode_close_maxsz (op_encode_hdr_maxsz + \
175 1 + encode_stateid_maxsz)
176 #define decode_close_maxsz (op_decode_hdr_maxsz + \
177 decode_stateid_maxsz)
178 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + \
180 encode_attrs_maxsz)
181 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
182 nfs4_fattr_bitmap_maxsz)
183 #define encode_read_maxsz (op_encode_hdr_maxsz + \
184 encode_stateid_maxsz + 3)
185 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
186 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
187 2 + encode_verifier_maxsz + 5)
188 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
189 decode_verifier_maxsz)
190 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
191 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
192 #define encode_write_maxsz (op_encode_hdr_maxsz + \
193 encode_stateid_maxsz + 4)
194 #define decode_write_maxsz (op_decode_hdr_maxsz + \
195 2 + decode_verifier_maxsz)
196 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
197 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
198 decode_verifier_maxsz)
199 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
200 nfs4_name_maxsz)
201 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz)
203 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
204 2 * nfs4_name_maxsz)
205 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
206 decode_change_info_maxsz + \
207 decode_change_info_maxsz)
208 #define encode_link_maxsz (op_encode_hdr_maxsz + \
209 nfs4_name_maxsz)
210 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
211 #define encode_lockowner_maxsz (7)
212 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
213 7 + \
214 1 + encode_stateid_maxsz + 1 + \
215 encode_lockowner_maxsz)
216 #define decode_lock_denied_maxsz \
217 (8 + decode_lockowner_maxsz)
218 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
219 decode_lock_denied_maxsz)
220 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
221 encode_lockowner_maxsz)
222 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
223 decode_lock_denied_maxsz)
224 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
225 encode_stateid_maxsz + \
227 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
228 decode_stateid_maxsz)
229 #define encode_release_lockowner_maxsz \
230 (op_encode_hdr_maxsz + \
231 encode_lockowner_maxsz)
232 #define decode_release_lockowner_maxsz \
233 (op_decode_hdr_maxsz)
234 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
235 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
236 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
237 1 + nfs4_name_maxsz + \
238 1 + \
239 nfs4_fattr_maxsz)
240 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
241 #define encode_create_maxsz (op_encode_hdr_maxsz + \
242 1 + 2 + nfs4_name_maxsz + \
243 encode_attrs_maxsz)
244 #define decode_create_maxsz (op_decode_hdr_maxsz + \
245 decode_change_info_maxsz + \
246 nfs4_fattr_bitmap_maxsz)
247 #define encode_statfs_maxsz (encode_getattr_maxsz)
248 #define decode_statfs_maxsz (decode_getattr_maxsz)
249 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
250 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
251 #define encode_getacl_maxsz (encode_getattr_maxsz)
252 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
253 nfs4_fattr_bitmap_maxsz + 1)
254 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
255 encode_stateid_maxsz + 3)
256 #define decode_setacl_maxsz (decode_setattr_maxsz)
257 #define encode_fs_locations_maxsz \
258 (encode_getattr_maxsz)
259 #define decode_fs_locations_maxsz \
261 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
262 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
264 #if defined(CONFIG_NFS_V4_1)
265 #define NFS4_MAX_MACHINE_NAME_LEN (64)
267 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
268 encode_verifier_maxsz + \
269 1 /* co_ownerid.len */ + \
270 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
271 1 /* flags */ + \
272 1 /* spa_how */ + \
273 0 /* SP4_NONE (for now) */ + \
274 1 /* zero implemetation id array */)
275 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
276 2 /* eir_clientid */ + \
277 1 /* eir_sequenceid */ + \
278 1 /* eir_flags */ + \
279 1 /* spr_how */ + \
280 0 /* SP4_NONE (for now) */ + \
281 2 /* eir_server_owner.so_minor_id */ + \
282 /* eir_server_owner.so_major_id<> */ \
283 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
284 /* eir_server_scope<> */ \
285 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
286 1 /* eir_server_impl_id array length */ + \
287 0 /* ignored eir_server_impl_id contents */)
288 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
289 #define decode_channel_attrs_maxsz (6 + \
290 1 /* ca_rdma_ird.len */ + \
291 1 /* ca_rdma_ird */)
292 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
293 2 /* csa_clientid */ + \
294 1 /* csa_sequence */ + \
295 1 /* csa_flags */ + \
296 encode_channel_attrs_maxsz + \
297 encode_channel_attrs_maxsz + \
298 1 /* csa_cb_program */ + \
299 1 /* csa_sec_parms.len (1) */ + \
300 1 /* cb_secflavor (AUTH_SYS) */ + \
301 1 /* stamp */ + \
302 1 /* machinename.len */ + \
303 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
304 1 /* uid */ + \
305 1 /* gid */ + \
306 1 /* gids.len (0) */)
307 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
308 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
309 1 /* csr_sequence */ + \
310 1 /* csr_flags */ + \
311 decode_channel_attrs_maxsz + \
312 decode_channel_attrs_maxsz)
313 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
314 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
315 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
316 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
317 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
318 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
319 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
320 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
321 #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
322 encode_verifier_maxsz)
323 #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
324 2 /* nfs_cookie4 gdlr_cookie */ + \
325 decode_verifier_maxsz \
326 /* verifier4 gdlr_verifier */ + \
327 1 /* gdlr_deviceid_list count */ + \
328 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
329 NFS4_DEVICEID4_SIZE) \
330 /* gdlr_deviceid_list */ + \
331 1 /* bool gdlr_eof */)
332 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
333 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
334 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
335 1 /* layout type */ + \
336 1 /* opaque devaddr4 length */ + \
337 /* devaddr4 payload is read into page */ \
338 1 /* notification bitmap length */ + \
339 1 /* notification bitmap */)
340 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
341 encode_stateid_maxsz)
342 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
343 decode_stateid_maxsz + \
344 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
345 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
346 2 /* offset */ + \
347 2 /* length */ + \
348 1 /* reclaim */ + \
349 encode_stateid_maxsz + \
350 1 /* new offset (true) */ + \
351 2 /* last byte written */ + \
352 1 /* nt_timechanged (false) */ + \
353 1 /* layoutupdate4 layout type */ + \
354 1 /* NULL filelayout layoutupdate4 payload */)
355 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
356 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
357 encode_stateid_maxsz + \
358 1 /* FIXME: opaque lrf_body always empty at the moment */)
359 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
360 1 + decode_stateid_maxsz)
361 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
362 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
363 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
364 XDR_QUADLEN(NFS4_STATEID_SIZE))
365 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
366 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
367 XDR_QUADLEN(NFS4_STATEID_SIZE))
368 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
369 #else /* CONFIG_NFS_V4_1 */
370 #define encode_sequence_maxsz 0
371 #define decode_sequence_maxsz 0
372 #endif /* CONFIG_NFS_V4_1 */
374 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
375 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
376 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
377 encode_sequence_maxsz + \
378 encode_putfh_maxsz + \
379 encode_read_maxsz)
380 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
381 decode_sequence_maxsz + \
382 decode_putfh_maxsz + \
383 decode_read_maxsz)
384 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
385 encode_sequence_maxsz + \
386 encode_putfh_maxsz + \
387 encode_readlink_maxsz)
388 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
389 decode_sequence_maxsz + \
390 decode_putfh_maxsz + \
391 decode_readlink_maxsz)
392 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
393 encode_sequence_maxsz + \
394 encode_putfh_maxsz + \
395 encode_readdir_maxsz)
396 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
397 decode_sequence_maxsz + \
398 decode_putfh_maxsz + \
399 decode_readdir_maxsz)
400 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
401 encode_sequence_maxsz + \
402 encode_putfh_maxsz + \
403 encode_write_maxsz + \
404 encode_getattr_maxsz)
405 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
406 decode_sequence_maxsz + \
407 decode_putfh_maxsz + \
408 decode_write_maxsz + \
409 decode_getattr_maxsz)
410 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
411 encode_sequence_maxsz + \
412 encode_putfh_maxsz + \
413 encode_commit_maxsz + \
414 encode_getattr_maxsz)
415 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
416 decode_sequence_maxsz + \
417 decode_putfh_maxsz + \
418 decode_commit_maxsz + \
419 decode_getattr_maxsz)
420 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
421 encode_sequence_maxsz + \
422 encode_putfh_maxsz + \
423 encode_savefh_maxsz + \
424 encode_open_maxsz + \
425 encode_getfh_maxsz + \
426 encode_getattr_maxsz + \
427 encode_restorefh_maxsz + \
428 encode_getattr_maxsz)
429 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
430 decode_sequence_maxsz + \
431 decode_putfh_maxsz + \
432 decode_savefh_maxsz + \
433 decode_open_maxsz + \
434 decode_getfh_maxsz + \
435 decode_getattr_maxsz + \
436 decode_restorefh_maxsz + \
437 decode_getattr_maxsz)
438 #define NFS4_enc_open_confirm_sz \
439 (compound_encode_hdr_maxsz + \
440 encode_putfh_maxsz + \
441 encode_open_confirm_maxsz)
442 #define NFS4_dec_open_confirm_sz \
443 (compound_decode_hdr_maxsz + \
444 decode_putfh_maxsz + \
445 decode_open_confirm_maxsz)
446 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
447 encode_sequence_maxsz + \
448 encode_putfh_maxsz + \
449 encode_open_maxsz + \
450 encode_getattr_maxsz)
451 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
452 decode_sequence_maxsz + \
453 decode_putfh_maxsz + \
454 decode_open_maxsz + \
455 decode_getattr_maxsz)
456 #define NFS4_enc_open_downgrade_sz \
457 (compound_encode_hdr_maxsz + \
458 encode_sequence_maxsz + \
459 encode_putfh_maxsz + \
460 encode_open_downgrade_maxsz + \
461 encode_getattr_maxsz)
462 #define NFS4_dec_open_downgrade_sz \
463 (compound_decode_hdr_maxsz + \
464 decode_sequence_maxsz + \
465 decode_putfh_maxsz + \
466 decode_open_downgrade_maxsz + \
467 decode_getattr_maxsz)
468 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
469 encode_sequence_maxsz + \
470 encode_putfh_maxsz + \
471 encode_close_maxsz + \
472 encode_getattr_maxsz)
473 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
474 decode_sequence_maxsz + \
475 decode_putfh_maxsz + \
476 decode_close_maxsz + \
477 decode_getattr_maxsz)
478 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
479 encode_sequence_maxsz + \
480 encode_putfh_maxsz + \
481 encode_setattr_maxsz + \
482 encode_getattr_maxsz)
483 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
484 decode_sequence_maxsz + \
485 decode_putfh_maxsz + \
486 decode_setattr_maxsz + \
487 decode_getattr_maxsz)
488 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
489 encode_sequence_maxsz + \
490 encode_putfh_maxsz + \
491 encode_fsinfo_maxsz)
492 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
493 decode_sequence_maxsz + \
494 decode_putfh_maxsz + \
495 decode_fsinfo_maxsz)
496 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
497 encode_renew_maxsz)
498 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
499 decode_renew_maxsz)
500 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
501 encode_setclientid_maxsz)
502 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
503 decode_setclientid_maxsz)
504 #define NFS4_enc_setclientid_confirm_sz \
505 (compound_encode_hdr_maxsz + \
506 encode_setclientid_confirm_maxsz + \
507 encode_putrootfh_maxsz + \
508 encode_fsinfo_maxsz)
509 #define NFS4_dec_setclientid_confirm_sz \
510 (compound_decode_hdr_maxsz + \
511 decode_setclientid_confirm_maxsz + \
512 decode_putrootfh_maxsz + \
513 decode_fsinfo_maxsz)
514 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
515 encode_sequence_maxsz + \
516 encode_putfh_maxsz + \
517 encode_lock_maxsz)
518 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
519 decode_sequence_maxsz + \
520 decode_putfh_maxsz + \
521 decode_lock_maxsz)
522 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
523 encode_sequence_maxsz + \
524 encode_putfh_maxsz + \
525 encode_lockt_maxsz)
526 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
527 decode_sequence_maxsz + \
528 decode_putfh_maxsz + \
529 decode_lockt_maxsz)
530 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
531 encode_sequence_maxsz + \
532 encode_putfh_maxsz + \
533 encode_locku_maxsz)
534 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
535 decode_sequence_maxsz + \
536 decode_putfh_maxsz + \
537 decode_locku_maxsz)
538 #define NFS4_enc_release_lockowner_sz \
539 (compound_encode_hdr_maxsz + \
540 encode_lockowner_maxsz)
541 #define NFS4_dec_release_lockowner_sz \
542 (compound_decode_hdr_maxsz + \
543 decode_lockowner_maxsz)
544 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
545 encode_sequence_maxsz + \
546 encode_putfh_maxsz + \
547 encode_access_maxsz + \
548 encode_getattr_maxsz)
549 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
550 decode_sequence_maxsz + \
551 decode_putfh_maxsz + \
552 decode_access_maxsz + \
553 decode_getattr_maxsz)
554 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
555 encode_sequence_maxsz + \
556 encode_putfh_maxsz + \
557 encode_getattr_maxsz)
558 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
559 decode_sequence_maxsz + \
560 decode_putfh_maxsz + \
561 decode_getattr_maxsz)
562 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
563 encode_sequence_maxsz + \
564 encode_putfh_maxsz + \
565 encode_lookup_maxsz + \
566 encode_getattr_maxsz + \
567 encode_getfh_maxsz)
568 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
569 decode_sequence_maxsz + \
570 decode_putfh_maxsz + \
571 decode_lookup_maxsz + \
572 decode_getattr_maxsz + \
573 decode_getfh_maxsz)
574 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
575 encode_sequence_maxsz + \
576 encode_putrootfh_maxsz + \
577 encode_getattr_maxsz + \
578 encode_getfh_maxsz)
579 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
580 decode_sequence_maxsz + \
581 decode_putrootfh_maxsz + \
582 decode_getattr_maxsz + \
583 decode_getfh_maxsz)
584 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
585 encode_sequence_maxsz + \
586 encode_putfh_maxsz + \
587 encode_remove_maxsz + \
588 encode_getattr_maxsz)
589 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
590 decode_sequence_maxsz + \
591 decode_putfh_maxsz + \
592 decode_remove_maxsz + \
593 decode_getattr_maxsz)
594 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
595 encode_sequence_maxsz + \
596 encode_putfh_maxsz + \
597 encode_savefh_maxsz + \
598 encode_putfh_maxsz + \
599 encode_rename_maxsz + \
600 encode_getattr_maxsz + \
601 encode_restorefh_maxsz + \
602 encode_getattr_maxsz)
603 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
604 decode_sequence_maxsz + \
605 decode_putfh_maxsz + \
606 decode_savefh_maxsz + \
607 decode_putfh_maxsz + \
608 decode_rename_maxsz + \
609 decode_getattr_maxsz + \
610 decode_restorefh_maxsz + \
611 decode_getattr_maxsz)
612 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
613 encode_sequence_maxsz + \
614 encode_putfh_maxsz + \
615 encode_savefh_maxsz + \
616 encode_putfh_maxsz + \
617 encode_link_maxsz + \
618 decode_getattr_maxsz + \
619 encode_restorefh_maxsz + \
620 decode_getattr_maxsz)
621 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
622 decode_sequence_maxsz + \
623 decode_putfh_maxsz + \
624 decode_savefh_maxsz + \
625 decode_putfh_maxsz + \
626 decode_link_maxsz + \
627 decode_getattr_maxsz + \
628 decode_restorefh_maxsz + \
629 decode_getattr_maxsz)
630 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
631 encode_sequence_maxsz + \
632 encode_putfh_maxsz + \
633 encode_symlink_maxsz + \
634 encode_getattr_maxsz + \
635 encode_getfh_maxsz)
636 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
637 decode_sequence_maxsz + \
638 decode_putfh_maxsz + \
639 decode_symlink_maxsz + \
640 decode_getattr_maxsz + \
641 decode_getfh_maxsz)
642 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
643 encode_sequence_maxsz + \
644 encode_putfh_maxsz + \
645 encode_savefh_maxsz + \
646 encode_create_maxsz + \
647 encode_getfh_maxsz + \
648 encode_getattr_maxsz + \
649 encode_restorefh_maxsz + \
650 encode_getattr_maxsz)
651 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
652 decode_sequence_maxsz + \
653 decode_putfh_maxsz + \
654 decode_savefh_maxsz + \
655 decode_create_maxsz + \
656 decode_getfh_maxsz + \
657 decode_getattr_maxsz + \
658 decode_restorefh_maxsz + \
659 decode_getattr_maxsz)
660 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
661 encode_sequence_maxsz + \
662 encode_putfh_maxsz + \
663 encode_getattr_maxsz)
664 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
665 decode_sequence_maxsz + \
666 decode_putfh_maxsz + \
667 decode_getattr_maxsz)
668 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
669 encode_sequence_maxsz + \
670 encode_putfh_maxsz + \
671 encode_statfs_maxsz)
672 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
673 decode_sequence_maxsz + \
674 decode_putfh_maxsz + \
675 decode_statfs_maxsz)
676 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
677 encode_sequence_maxsz + \
678 encode_putfh_maxsz + \
679 encode_getattr_maxsz)
680 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
681 decode_sequence_maxsz + \
682 decode_putfh_maxsz + \
683 decode_getattr_maxsz)
684 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
685 encode_sequence_maxsz + \
686 encode_putfh_maxsz + \
687 encode_delegreturn_maxsz + \
688 encode_getattr_maxsz)
689 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
690 decode_sequence_maxsz + \
691 decode_delegreturn_maxsz + \
692 decode_getattr_maxsz)
693 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
694 encode_sequence_maxsz + \
695 encode_putfh_maxsz + \
696 encode_getacl_maxsz)
697 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
698 decode_sequence_maxsz + \
699 decode_putfh_maxsz + \
700 decode_getacl_maxsz)
701 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
702 encode_sequence_maxsz + \
703 encode_putfh_maxsz + \
704 encode_setacl_maxsz)
705 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
706 decode_sequence_maxsz + \
707 decode_putfh_maxsz + \
708 decode_setacl_maxsz)
709 #define NFS4_enc_fs_locations_sz \
710 (compound_encode_hdr_maxsz + \
711 encode_sequence_maxsz + \
712 encode_putfh_maxsz + \
713 encode_lookup_maxsz + \
714 encode_fs_locations_maxsz)
715 #define NFS4_dec_fs_locations_sz \
716 (compound_decode_hdr_maxsz + \
717 decode_sequence_maxsz + \
718 decode_putfh_maxsz + \
719 decode_lookup_maxsz + \
720 decode_fs_locations_maxsz)
721 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
722 encode_sequence_maxsz + \
723 encode_putfh_maxsz + \
724 encode_secinfo_maxsz)
725 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
726 decode_sequence_maxsz + \
727 decode_putfh_maxsz + \
728 decode_secinfo_maxsz)
729 #if defined(CONFIG_NFS_V4_1)
730 #define NFS4_enc_exchange_id_sz \
731 (compound_encode_hdr_maxsz + \
732 encode_exchange_id_maxsz)
733 #define NFS4_dec_exchange_id_sz \
734 (compound_decode_hdr_maxsz + \
735 decode_exchange_id_maxsz)
736 #define NFS4_enc_create_session_sz \
737 (compound_encode_hdr_maxsz + \
738 encode_create_session_maxsz)
739 #define NFS4_dec_create_session_sz \
740 (compound_decode_hdr_maxsz + \
741 decode_create_session_maxsz)
742 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
743 encode_destroy_session_maxsz)
744 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
745 decode_destroy_session_maxsz)
746 #define NFS4_enc_sequence_sz \
747 (compound_decode_hdr_maxsz + \
748 encode_sequence_maxsz)
749 #define NFS4_dec_sequence_sz \
750 (compound_decode_hdr_maxsz + \
751 decode_sequence_maxsz)
752 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
753 encode_sequence_maxsz + \
754 encode_putrootfh_maxsz + \
755 encode_fsinfo_maxsz)
756 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
757 decode_sequence_maxsz + \
758 decode_putrootfh_maxsz + \
759 decode_fsinfo_maxsz)
760 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
761 encode_sequence_maxsz + \
762 encode_reclaim_complete_maxsz)
763 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
764 decode_sequence_maxsz + \
765 decode_reclaim_complete_maxsz)
766 #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
767 encode_sequence_maxsz + \
768 encode_putfh_maxsz + \
769 encode_getdevicelist_maxsz)
770 #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
771 decode_sequence_maxsz + \
772 decode_putfh_maxsz + \
773 decode_getdevicelist_maxsz)
774 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
775 encode_sequence_maxsz +\
776 encode_getdeviceinfo_maxsz)
777 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
778 decode_sequence_maxsz + \
779 decode_getdeviceinfo_maxsz)
780 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
781 encode_sequence_maxsz + \
782 encode_putfh_maxsz + \
783 encode_layoutget_maxsz)
784 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
785 decode_sequence_maxsz + \
786 decode_putfh_maxsz + \
787 decode_layoutget_maxsz)
788 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
789 encode_sequence_maxsz +\
790 encode_putfh_maxsz + \
791 encode_layoutcommit_maxsz + \
792 encode_getattr_maxsz)
793 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
794 decode_sequence_maxsz + \
795 decode_putfh_maxsz + \
796 decode_layoutcommit_maxsz + \
797 decode_getattr_maxsz)
798 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
799 encode_sequence_maxsz + \
800 encode_putfh_maxsz + \
801 encode_layoutreturn_maxsz)
802 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
803 decode_sequence_maxsz + \
804 decode_putfh_maxsz + \
805 decode_layoutreturn_maxsz)
806 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
807 encode_sequence_maxsz + \
808 encode_putrootfh_maxsz +\
809 encode_secinfo_no_name_maxsz)
810 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_putrootfh_maxsz + \
813 decode_secinfo_no_name_maxsz)
814 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
815 encode_sequence_maxsz + \
816 encode_test_stateid_maxsz)
817 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
818 decode_sequence_maxsz + \
819 decode_test_stateid_maxsz)
820 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
821 encode_sequence_maxsz + \
822 encode_free_stateid_maxsz)
823 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_free_stateid_maxsz)
827 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
828 compound_encode_hdr_maxsz +
829 encode_sequence_maxsz +
830 encode_putfh_maxsz +
831 encode_getattr_maxsz) *
832 XDR_UNIT);
834 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
835 compound_decode_hdr_maxsz +
836 decode_sequence_maxsz +
837 decode_putfh_maxsz) *
838 XDR_UNIT);
839 #endif /* CONFIG_NFS_V4_1 */
841 static const umode_t nfs_type2fmt[] = {
842 [NF4BAD] = 0,
843 [NF4REG] = S_IFREG,
844 [NF4DIR] = S_IFDIR,
845 [NF4BLK] = S_IFBLK,
846 [NF4CHR] = S_IFCHR,
847 [NF4LNK] = S_IFLNK,
848 [NF4SOCK] = S_IFSOCK,
849 [NF4FIFO] = S_IFIFO,
850 [NF4ATTRDIR] = 0,
851 [NF4NAMEDATTR] = 0,
854 struct compound_hdr {
855 int32_t status;
856 uint32_t nops;
857 __be32 * nops_p;
858 uint32_t taglen;
859 char * tag;
860 uint32_t replen; /* expected reply words */
861 u32 minorversion;
864 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
866 __be32 *p = xdr_reserve_space(xdr, nbytes);
867 BUG_ON(!p);
868 return p;
871 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
873 __be32 *p;
875 p = xdr_reserve_space(xdr, 4 + len);
876 BUG_ON(p == NULL);
877 xdr_encode_opaque(p, str, len);
880 static void encode_compound_hdr(struct xdr_stream *xdr,
881 struct rpc_rqst *req,
882 struct compound_hdr *hdr)
884 __be32 *p;
885 struct rpc_auth *auth = req->rq_cred->cr_auth;
887 /* initialize running count of expected bytes in reply.
888 * NOTE: the replied tag SHOULD be the same is the one sent,
889 * but this is not required as a MUST for the server to do so. */
890 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
892 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
893 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
894 p = reserve_space(xdr, 4 + hdr->taglen + 8);
895 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
896 *p++ = cpu_to_be32(hdr->minorversion);
897 hdr->nops_p = p;
898 *p = cpu_to_be32(hdr->nops);
901 static void encode_nops(struct compound_hdr *hdr)
903 BUG_ON(hdr->nops > NFS4_MAX_OPS);
904 *hdr->nops_p = htonl(hdr->nops);
907 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
909 __be32 *p;
911 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
912 BUG_ON(p == NULL);
913 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
916 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
918 char owner_name[IDMAP_NAMESZ];
919 char owner_group[IDMAP_NAMESZ];
920 int owner_namelen = 0;
921 int owner_grouplen = 0;
922 __be32 *p;
923 __be32 *q;
924 int len;
925 uint32_t bmval0 = 0;
926 uint32_t bmval1 = 0;
929 * We reserve enough space to write the entire attribute buffer at once.
930 * In the worst-case, this would be
931 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
932 * = 36 bytes, plus any contribution from variable-length fields
933 * such as owner/group.
935 len = 16;
937 /* Sigh */
938 if (iap->ia_valid & ATTR_SIZE)
939 len += 8;
940 if (iap->ia_valid & ATTR_MODE)
941 len += 4;
942 if (iap->ia_valid & ATTR_UID) {
943 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
944 if (owner_namelen < 0) {
945 dprintk("nfs: couldn't resolve uid %d to string\n",
946 iap->ia_uid);
947 /* XXX */
948 strcpy(owner_name, "nobody");
949 owner_namelen = sizeof("nobody") - 1;
950 /* goto out; */
952 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
954 if (iap->ia_valid & ATTR_GID) {
955 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
956 if (owner_grouplen < 0) {
957 dprintk("nfs: couldn't resolve gid %d to string\n",
958 iap->ia_gid);
959 strcpy(owner_group, "nobody");
960 owner_grouplen = sizeof("nobody") - 1;
961 /* goto out; */
963 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
965 if (iap->ia_valid & ATTR_ATIME_SET)
966 len += 16;
967 else if (iap->ia_valid & ATTR_ATIME)
968 len += 4;
969 if (iap->ia_valid & ATTR_MTIME_SET)
970 len += 16;
971 else if (iap->ia_valid & ATTR_MTIME)
972 len += 4;
973 p = reserve_space(xdr, len);
976 * We write the bitmap length now, but leave the bitmap and the attribute
977 * buffer length to be backfilled at the end of this routine.
979 *p++ = cpu_to_be32(2);
980 q = p;
981 p += 3;
983 if (iap->ia_valid & ATTR_SIZE) {
984 bmval0 |= FATTR4_WORD0_SIZE;
985 p = xdr_encode_hyper(p, iap->ia_size);
987 if (iap->ia_valid & ATTR_MODE) {
988 bmval1 |= FATTR4_WORD1_MODE;
989 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
991 if (iap->ia_valid & ATTR_UID) {
992 bmval1 |= FATTR4_WORD1_OWNER;
993 p = xdr_encode_opaque(p, owner_name, owner_namelen);
995 if (iap->ia_valid & ATTR_GID) {
996 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
997 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
999 if (iap->ia_valid & ATTR_ATIME_SET) {
1000 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1001 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1002 *p++ = cpu_to_be32(0);
1003 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1004 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1006 else if (iap->ia_valid & ATTR_ATIME) {
1007 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1008 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1010 if (iap->ia_valid & ATTR_MTIME_SET) {
1011 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1012 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1013 *p++ = cpu_to_be32(0);
1014 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1015 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1017 else if (iap->ia_valid & ATTR_MTIME) {
1018 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1019 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1023 * Now we backfill the bitmap and the attribute buffer length.
1025 if (len != ((char *)p - (char *)q) + 4) {
1026 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
1027 len, ((char *)p - (char *)q) + 4);
1028 BUG();
1030 len = (char *)p - (char *)q - 12;
1031 *q++ = htonl(bmval0);
1032 *q++ = htonl(bmval1);
1033 *q = htonl(len);
1035 /* out: */
1038 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1040 __be32 *p;
1042 p = reserve_space(xdr, 8);
1043 *p++ = cpu_to_be32(OP_ACCESS);
1044 *p = cpu_to_be32(access);
1045 hdr->nops++;
1046 hdr->replen += decode_access_maxsz;
1049 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1051 __be32 *p;
1053 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
1054 *p++ = cpu_to_be32(OP_CLOSE);
1055 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
1056 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1057 hdr->nops++;
1058 hdr->replen += decode_close_maxsz;
1061 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1063 __be32 *p;
1065 p = reserve_space(xdr, 16);
1066 *p++ = cpu_to_be32(OP_COMMIT);
1067 p = xdr_encode_hyper(p, args->offset);
1068 *p = cpu_to_be32(args->count);
1069 hdr->nops++;
1070 hdr->replen += decode_commit_maxsz;
1073 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1075 __be32 *p;
1077 p = reserve_space(xdr, 8);
1078 *p++ = cpu_to_be32(OP_CREATE);
1079 *p = cpu_to_be32(create->ftype);
1081 switch (create->ftype) {
1082 case NF4LNK:
1083 p = reserve_space(xdr, 4);
1084 *p = cpu_to_be32(create->u.symlink.len);
1085 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1086 break;
1088 case NF4BLK: case NF4CHR:
1089 p = reserve_space(xdr, 8);
1090 *p++ = cpu_to_be32(create->u.device.specdata1);
1091 *p = cpu_to_be32(create->u.device.specdata2);
1092 break;
1094 default:
1095 break;
1098 encode_string(xdr, create->name->len, create->name->name);
1099 hdr->nops++;
1100 hdr->replen += decode_create_maxsz;
1102 encode_attrs(xdr, create->attrs, create->server);
1105 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1107 __be32 *p;
1109 p = reserve_space(xdr, 12);
1110 *p++ = cpu_to_be32(OP_GETATTR);
1111 *p++ = cpu_to_be32(1);
1112 *p = cpu_to_be32(bitmap);
1113 hdr->nops++;
1114 hdr->replen += decode_getattr_maxsz;
1117 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1119 __be32 *p;
1121 p = reserve_space(xdr, 16);
1122 *p++ = cpu_to_be32(OP_GETATTR);
1123 *p++ = cpu_to_be32(2);
1124 *p++ = cpu_to_be32(bm0);
1125 *p = cpu_to_be32(bm1);
1126 hdr->nops++;
1127 hdr->replen += decode_getattr_maxsz;
1130 static void
1131 encode_getattr_three(struct xdr_stream *xdr,
1132 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1133 struct compound_hdr *hdr)
1135 __be32 *p;
1137 p = reserve_space(xdr, 4);
1138 *p = cpu_to_be32(OP_GETATTR);
1139 if (bm2) {
1140 p = reserve_space(xdr, 16);
1141 *p++ = cpu_to_be32(3);
1142 *p++ = cpu_to_be32(bm0);
1143 *p++ = cpu_to_be32(bm1);
1144 *p = cpu_to_be32(bm2);
1145 } else if (bm1) {
1146 p = reserve_space(xdr, 12);
1147 *p++ = cpu_to_be32(2);
1148 *p++ = cpu_to_be32(bm0);
1149 *p = cpu_to_be32(bm1);
1150 } else {
1151 p = reserve_space(xdr, 8);
1152 *p++ = cpu_to_be32(1);
1153 *p = cpu_to_be32(bm0);
1155 hdr->nops++;
1156 hdr->replen += decode_getattr_maxsz;
1159 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1161 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1162 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1165 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1167 encode_getattr_three(xdr,
1168 bitmask[0] & nfs4_fsinfo_bitmap[0],
1169 bitmask[1] & nfs4_fsinfo_bitmap[1],
1170 bitmask[2] & nfs4_fsinfo_bitmap[2],
1171 hdr);
1174 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1176 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1177 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1180 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1182 __be32 *p;
1184 p = reserve_space(xdr, 4);
1185 *p = cpu_to_be32(OP_GETFH);
1186 hdr->nops++;
1187 hdr->replen += decode_getfh_maxsz;
1190 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1192 __be32 *p;
1194 p = reserve_space(xdr, 8 + name->len);
1195 *p++ = cpu_to_be32(OP_LINK);
1196 xdr_encode_opaque(p, name->name, name->len);
1197 hdr->nops++;
1198 hdr->replen += decode_link_maxsz;
1201 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1203 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1204 return block ? NFS4_READW_LT : NFS4_READ_LT;
1205 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1208 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1210 if (fl->fl_end == OFFSET_MAX)
1211 return ~(uint64_t)0;
1212 return fl->fl_end - fl->fl_start + 1;
1215 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1217 __be32 *p;
1219 p = reserve_space(xdr, 32);
1220 p = xdr_encode_hyper(p, lowner->clientid);
1221 *p++ = cpu_to_be32(20);
1222 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1223 *p++ = cpu_to_be32(lowner->s_dev);
1224 xdr_encode_hyper(p, lowner->id);
1228 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1229 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1231 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1233 __be32 *p;
1235 p = reserve_space(xdr, 32);
1236 *p++ = cpu_to_be32(OP_LOCK);
1237 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1238 *p++ = cpu_to_be32(args->reclaim);
1239 p = xdr_encode_hyper(p, args->fl->fl_start);
1240 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1241 *p = cpu_to_be32(args->new_lock_owner);
1242 if (args->new_lock_owner){
1243 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1244 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
1245 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1246 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1247 encode_lockowner(xdr, &args->lock_owner);
1249 else {
1250 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
1251 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
1252 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1254 hdr->nops++;
1255 hdr->replen += decode_lock_maxsz;
1258 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1260 __be32 *p;
1262 p = reserve_space(xdr, 24);
1263 *p++ = cpu_to_be32(OP_LOCKT);
1264 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1265 p = xdr_encode_hyper(p, args->fl->fl_start);
1266 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1267 encode_lockowner(xdr, &args->lock_owner);
1268 hdr->nops++;
1269 hdr->replen += decode_lockt_maxsz;
1272 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1274 __be32 *p;
1276 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1277 *p++ = cpu_to_be32(OP_LOCKU);
1278 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1279 *p++ = cpu_to_be32(args->seqid->sequence->counter);
1280 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1281 p = xdr_encode_hyper(p, args->fl->fl_start);
1282 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1283 hdr->nops++;
1284 hdr->replen += decode_locku_maxsz;
1287 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1289 __be32 *p;
1291 p = reserve_space(xdr, 4);
1292 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1293 encode_lockowner(xdr, lowner);
1294 hdr->nops++;
1295 hdr->replen += decode_release_lockowner_maxsz;
1298 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1300 int len = name->len;
1301 __be32 *p;
1303 p = reserve_space(xdr, 8 + len);
1304 *p++ = cpu_to_be32(OP_LOOKUP);
1305 xdr_encode_opaque(p, name->name, len);
1306 hdr->nops++;
1307 hdr->replen += decode_lookup_maxsz;
1310 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1312 __be32 *p;
1314 p = reserve_space(xdr, 8);
1315 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1316 case FMODE_READ:
1317 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1318 break;
1319 case FMODE_WRITE:
1320 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1321 break;
1322 case FMODE_READ|FMODE_WRITE:
1323 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1324 break;
1325 default:
1326 *p++ = cpu_to_be32(0);
1328 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1331 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1333 __be32 *p;
1335 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1336 * owner 4 = 32
1338 p = reserve_space(xdr, 8);
1339 *p++ = cpu_to_be32(OP_OPEN);
1340 *p = cpu_to_be32(arg->seqid->sequence->counter);
1341 encode_share_access(xdr, arg->fmode);
1342 p = reserve_space(xdr, 32);
1343 p = xdr_encode_hyper(p, arg->clientid);
1344 *p++ = cpu_to_be32(20);
1345 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1346 *p++ = cpu_to_be32(arg->server->s_dev);
1347 xdr_encode_hyper(p, arg->id);
1350 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1352 __be32 *p;
1353 struct nfs_client *clp;
1355 p = reserve_space(xdr, 4);
1356 switch(arg->open_flags & O_EXCL) {
1357 case 0:
1358 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1359 encode_attrs(xdr, arg->u.attrs, arg->server);
1360 break;
1361 default:
1362 clp = arg->server->nfs_client;
1363 if (clp->cl_mvops->minor_version > 0) {
1364 if (nfs4_has_persistent_session(clp)) {
1365 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1366 encode_attrs(xdr, arg->u.attrs, arg->server);
1367 } else {
1368 struct iattr dummy;
1370 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1371 encode_nfs4_verifier(xdr, &arg->u.verifier);
1372 dummy.ia_valid = 0;
1373 encode_attrs(xdr, &dummy, arg->server);
1375 } else {
1376 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1377 encode_nfs4_verifier(xdr, &arg->u.verifier);
1382 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1384 __be32 *p;
1386 p = reserve_space(xdr, 4);
1387 switch (arg->open_flags & O_CREAT) {
1388 case 0:
1389 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1390 break;
1391 default:
1392 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1393 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1394 encode_createmode(xdr, arg);
1398 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1400 __be32 *p;
1402 p = reserve_space(xdr, 4);
1403 switch (delegation_type) {
1404 case 0:
1405 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1406 break;
1407 case FMODE_READ:
1408 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1409 break;
1410 case FMODE_WRITE|FMODE_READ:
1411 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1412 break;
1413 default:
1414 BUG();
1418 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1420 __be32 *p;
1422 p = reserve_space(xdr, 4);
1423 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1424 encode_string(xdr, name->len, name->name);
1427 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1429 __be32 *p;
1431 p = reserve_space(xdr, 4);
1432 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1433 encode_delegation_type(xdr, type);
1436 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1438 __be32 *p;
1440 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1441 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1442 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1443 encode_string(xdr, name->len, name->name);
1446 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1448 encode_openhdr(xdr, arg);
1449 encode_opentype(xdr, arg);
1450 switch (arg->claim) {
1451 case NFS4_OPEN_CLAIM_NULL:
1452 encode_claim_null(xdr, arg->name);
1453 break;
1454 case NFS4_OPEN_CLAIM_PREVIOUS:
1455 encode_claim_previous(xdr, arg->u.delegation_type);
1456 break;
1457 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1458 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1459 break;
1460 default:
1461 BUG();
1463 hdr->nops++;
1464 hdr->replen += decode_open_maxsz;
1467 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1469 __be32 *p;
1471 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1472 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1473 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1474 *p = cpu_to_be32(arg->seqid->sequence->counter);
1475 hdr->nops++;
1476 hdr->replen += decode_open_confirm_maxsz;
1479 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1481 __be32 *p;
1483 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1484 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1485 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1486 *p = cpu_to_be32(arg->seqid->sequence->counter);
1487 encode_share_access(xdr, arg->fmode);
1488 hdr->nops++;
1489 hdr->replen += decode_open_downgrade_maxsz;
1492 static void
1493 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1495 int len = fh->size;
1496 __be32 *p;
1498 p = reserve_space(xdr, 8 + len);
1499 *p++ = cpu_to_be32(OP_PUTFH);
1500 xdr_encode_opaque(p, fh->data, len);
1501 hdr->nops++;
1502 hdr->replen += decode_putfh_maxsz;
1505 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1507 __be32 *p;
1509 p = reserve_space(xdr, 4);
1510 *p = cpu_to_be32(OP_PUTROOTFH);
1511 hdr->nops++;
1512 hdr->replen += decode_putrootfh_maxsz;
1515 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
1517 nfs4_stateid stateid;
1518 __be32 *p;
1520 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1521 if (ctx->state != NULL) {
1522 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
1523 if (zero_seqid)
1524 stateid.stateid.seqid = 0;
1525 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1526 } else
1527 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1530 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1532 __be32 *p;
1534 p = reserve_space(xdr, 4);
1535 *p = cpu_to_be32(OP_READ);
1537 encode_stateid(xdr, args->context, args->lock_context,
1538 hdr->minorversion);
1540 p = reserve_space(xdr, 12);
1541 p = xdr_encode_hyper(p, args->offset);
1542 *p = cpu_to_be32(args->count);
1543 hdr->nops++;
1544 hdr->replen += decode_read_maxsz;
1547 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1549 uint32_t attrs[2] = {
1550 FATTR4_WORD0_RDATTR_ERROR,
1551 FATTR4_WORD1_MOUNTED_ON_FILEID,
1553 uint32_t dircount = readdir->count >> 1;
1554 __be32 *p;
1556 if (readdir->plus) {
1557 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1558 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1559 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1560 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1561 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1562 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1563 dircount >>= 1;
1565 /* Use mounted_on_fileid only if the server supports it */
1566 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1567 attrs[0] |= FATTR4_WORD0_FILEID;
1569 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
1570 *p++ = cpu_to_be32(OP_READDIR);
1571 p = xdr_encode_hyper(p, readdir->cookie);
1572 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
1573 *p++ = cpu_to_be32(dircount);
1574 *p++ = cpu_to_be32(readdir->count);
1575 *p++ = cpu_to_be32(2);
1577 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1578 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1579 hdr->nops++;
1580 hdr->replen += decode_readdir_maxsz;
1581 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1582 __func__,
1583 (unsigned long long)readdir->cookie,
1584 ((u32 *)readdir->verifier.data)[0],
1585 ((u32 *)readdir->verifier.data)[1],
1586 attrs[0] & readdir->bitmask[0],
1587 attrs[1] & readdir->bitmask[1]);
1590 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1592 __be32 *p;
1594 p = reserve_space(xdr, 4);
1595 *p = cpu_to_be32(OP_READLINK);
1596 hdr->nops++;
1597 hdr->replen += decode_readlink_maxsz;
1600 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1602 __be32 *p;
1604 p = reserve_space(xdr, 8 + name->len);
1605 *p++ = cpu_to_be32(OP_REMOVE);
1606 xdr_encode_opaque(p, name->name, name->len);
1607 hdr->nops++;
1608 hdr->replen += decode_remove_maxsz;
1611 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1613 __be32 *p;
1615 p = reserve_space(xdr, 4);
1616 *p = cpu_to_be32(OP_RENAME);
1617 encode_string(xdr, oldname->len, oldname->name);
1618 encode_string(xdr, newname->len, newname->name);
1619 hdr->nops++;
1620 hdr->replen += decode_rename_maxsz;
1623 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1625 __be32 *p;
1627 p = reserve_space(xdr, 12);
1628 *p++ = cpu_to_be32(OP_RENEW);
1629 xdr_encode_hyper(p, client_stateid->cl_clientid);
1630 hdr->nops++;
1631 hdr->replen += decode_renew_maxsz;
1634 static void
1635 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1637 __be32 *p;
1639 p = reserve_space(xdr, 4);
1640 *p = cpu_to_be32(OP_RESTOREFH);
1641 hdr->nops++;
1642 hdr->replen += decode_restorefh_maxsz;
1645 static void
1646 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1648 __be32 *p;
1650 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1651 *p++ = cpu_to_be32(OP_SETATTR);
1652 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1653 p = reserve_space(xdr, 2*4);
1654 *p++ = cpu_to_be32(1);
1655 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1656 BUG_ON(arg->acl_len % 4);
1657 p = reserve_space(xdr, 4);
1658 *p = cpu_to_be32(arg->acl_len);
1659 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1660 hdr->nops++;
1661 hdr->replen += decode_setacl_maxsz;
1664 static void
1665 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1667 __be32 *p;
1669 p = reserve_space(xdr, 4);
1670 *p = cpu_to_be32(OP_SAVEFH);
1671 hdr->nops++;
1672 hdr->replen += decode_savefh_maxsz;
1675 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1677 __be32 *p;
1679 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1680 *p++ = cpu_to_be32(OP_SETATTR);
1681 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1682 hdr->nops++;
1683 hdr->replen += decode_setattr_maxsz;
1684 encode_attrs(xdr, arg->iap, server);
1687 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1689 __be32 *p;
1691 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1692 *p++ = cpu_to_be32(OP_SETCLIENTID);
1693 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1695 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1696 p = reserve_space(xdr, 4);
1697 *p = cpu_to_be32(setclientid->sc_prog);
1698 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1699 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1700 p = reserve_space(xdr, 4);
1701 *p = cpu_to_be32(setclientid->sc_cb_ident);
1702 hdr->nops++;
1703 hdr->replen += decode_setclientid_maxsz;
1706 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1708 __be32 *p;
1710 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1711 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1712 p = xdr_encode_hyper(p, arg->clientid);
1713 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1714 hdr->nops++;
1715 hdr->replen += decode_setclientid_confirm_maxsz;
1718 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1720 __be32 *p;
1722 p = reserve_space(xdr, 4);
1723 *p = cpu_to_be32(OP_WRITE);
1725 encode_stateid(xdr, args->context, args->lock_context,
1726 hdr->minorversion);
1728 p = reserve_space(xdr, 16);
1729 p = xdr_encode_hyper(p, args->offset);
1730 *p++ = cpu_to_be32(args->stable);
1731 *p = cpu_to_be32(args->count);
1733 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1734 hdr->nops++;
1735 hdr->replen += decode_write_maxsz;
1738 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1740 __be32 *p;
1742 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1744 *p++ = cpu_to_be32(OP_DELEGRETURN);
1745 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1746 hdr->nops++;
1747 hdr->replen += decode_delegreturn_maxsz;
1750 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1752 int len = name->len;
1753 __be32 *p;
1755 p = reserve_space(xdr, 8 + len);
1756 *p++ = cpu_to_be32(OP_SECINFO);
1757 xdr_encode_opaque(p, name->name, len);
1758 hdr->nops++;
1759 hdr->replen += decode_secinfo_maxsz;
1762 #if defined(CONFIG_NFS_V4_1)
1763 /* NFSv4.1 operations */
1764 static void encode_exchange_id(struct xdr_stream *xdr,
1765 struct nfs41_exchange_id_args *args,
1766 struct compound_hdr *hdr)
1768 __be32 *p;
1770 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1771 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
1772 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1774 encode_string(xdr, args->id_len, args->id);
1776 p = reserve_space(xdr, 12);
1777 *p++ = cpu_to_be32(args->flags);
1778 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1779 *p = cpu_to_be32(0); /* zero length implementation id array */
1780 hdr->nops++;
1781 hdr->replen += decode_exchange_id_maxsz;
1784 static void encode_create_session(struct xdr_stream *xdr,
1785 struct nfs41_create_session_args *args,
1786 struct compound_hdr *hdr)
1788 __be32 *p;
1789 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1790 uint32_t len;
1791 struct nfs_client *clp = args->client;
1792 u32 max_resp_sz_cached;
1795 * Assumes OPEN is the biggest non-idempotent compound.
1796 * 2 is the verifier.
1798 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1799 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1801 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1802 clp->cl_ipaddr);
1804 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1805 *p++ = cpu_to_be32(OP_CREATE_SESSION);
1806 p = xdr_encode_hyper(p, clp->cl_clientid);
1807 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1808 *p++ = cpu_to_be32(args->flags); /*flags */
1810 /* Fore Channel */
1811 *p++ = cpu_to_be32(0); /* header padding size */
1812 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1813 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1814 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1815 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1816 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1817 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1819 /* Back Channel */
1820 *p++ = cpu_to_be32(0); /* header padding size */
1821 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1822 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1823 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1824 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1825 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1826 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1828 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1829 *p++ = cpu_to_be32(1);
1830 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1832 /* authsys_parms rfc1831 */
1833 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1834 p = xdr_encode_opaque(p, machine_name, len);
1835 *p++ = cpu_to_be32(0); /* UID */
1836 *p++ = cpu_to_be32(0); /* GID */
1837 *p = cpu_to_be32(0); /* No more gids */
1838 hdr->nops++;
1839 hdr->replen += decode_create_session_maxsz;
1842 static void encode_destroy_session(struct xdr_stream *xdr,
1843 struct nfs4_session *session,
1844 struct compound_hdr *hdr)
1846 __be32 *p;
1847 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1848 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1849 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1850 hdr->nops++;
1851 hdr->replen += decode_destroy_session_maxsz;
1854 static void encode_reclaim_complete(struct xdr_stream *xdr,
1855 struct nfs41_reclaim_complete_args *args,
1856 struct compound_hdr *hdr)
1858 __be32 *p;
1860 p = reserve_space(xdr, 8);
1861 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1862 *p++ = cpu_to_be32(args->one_fs);
1863 hdr->nops++;
1864 hdr->replen += decode_reclaim_complete_maxsz;
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 = args->sa_session;
1874 struct nfs4_slot_table *tp;
1875 struct nfs4_slot *slot;
1876 __be32 *p;
1878 if (!session)
1879 return;
1881 tp = &session->fc_slot_table;
1883 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1884 slot = tp->slots + args->sa_slotid;
1886 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1887 *p++ = cpu_to_be32(OP_SEQUENCE);
1890 * Sessionid + seqid + slotid + max slotid + cache_this
1892 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1893 "max_slotid=%d cache_this=%d\n",
1894 __func__,
1895 ((u32 *)session->sess_id.data)[0],
1896 ((u32 *)session->sess_id.data)[1],
1897 ((u32 *)session->sess_id.data)[2],
1898 ((u32 *)session->sess_id.data)[3],
1899 slot->seq_nr, args->sa_slotid,
1900 tp->highest_used_slotid, args->sa_cache_this);
1901 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1902 *p++ = cpu_to_be32(slot->seq_nr);
1903 *p++ = cpu_to_be32(args->sa_slotid);
1904 *p++ = cpu_to_be32(tp->highest_used_slotid);
1905 *p = cpu_to_be32(args->sa_cache_this);
1906 hdr->nops++;
1907 hdr->replen += decode_sequence_maxsz;
1908 #endif /* CONFIG_NFS_V4_1 */
1911 #ifdef CONFIG_NFS_V4_1
1912 static void
1913 encode_getdevicelist(struct xdr_stream *xdr,
1914 const struct nfs4_getdevicelist_args *args,
1915 struct compound_hdr *hdr)
1917 __be32 *p;
1918 nfs4_verifier dummy = {
1919 .data = "dummmmmy",
1922 p = reserve_space(xdr, 20);
1923 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1924 *p++ = cpu_to_be32(args->layoutclass);
1925 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1926 xdr_encode_hyper(p, 0ULL); /* cookie */
1927 encode_nfs4_verifier(xdr, &dummy);
1928 hdr->nops++;
1929 hdr->replen += decode_getdevicelist_maxsz;
1932 static void
1933 encode_getdeviceinfo(struct xdr_stream *xdr,
1934 const struct nfs4_getdeviceinfo_args *args,
1935 struct compound_hdr *hdr)
1937 __be32 *p;
1939 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1940 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1941 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1942 NFS4_DEVICEID4_SIZE);
1943 *p++ = cpu_to_be32(args->pdev->layout_type);
1944 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1945 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1946 hdr->nops++;
1947 hdr->replen += decode_getdeviceinfo_maxsz;
1950 static void
1951 encode_layoutget(struct xdr_stream *xdr,
1952 const struct nfs4_layoutget_args *args,
1953 struct compound_hdr *hdr)
1955 __be32 *p;
1957 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1958 *p++ = cpu_to_be32(OP_LAYOUTGET);
1959 *p++ = cpu_to_be32(0); /* Signal layout available */
1960 *p++ = cpu_to_be32(args->type);
1961 *p++ = cpu_to_be32(args->range.iomode);
1962 p = xdr_encode_hyper(p, args->range.offset);
1963 p = xdr_encode_hyper(p, args->range.length);
1964 p = xdr_encode_hyper(p, args->minlength);
1965 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1966 *p = cpu_to_be32(args->maxcount);
1968 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1969 __func__,
1970 args->type,
1971 args->range.iomode,
1972 (unsigned long)args->range.offset,
1973 (unsigned long)args->range.length,
1974 args->maxcount);
1975 hdr->nops++;
1976 hdr->replen += decode_layoutget_maxsz;
1979 static int
1980 encode_layoutcommit(struct xdr_stream *xdr,
1981 struct inode *inode,
1982 const struct nfs4_layoutcommit_args *args,
1983 struct compound_hdr *hdr)
1985 __be32 *p;
1987 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1988 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1990 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1991 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1992 /* Only whole file layouts */
1993 p = xdr_encode_hyper(p, 0); /* offset */
1994 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1995 *p++ = cpu_to_be32(0); /* reclaim */
1996 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1997 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1998 p = xdr_encode_hyper(p, args->lastbytewritten);
1999 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2000 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2002 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2003 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2004 NFS_I(inode)->layout, xdr, args);
2005 else {
2006 p = reserve_space(xdr, 4);
2007 *p = cpu_to_be32(0); /* no layout-type payload */
2010 hdr->nops++;
2011 hdr->replen += decode_layoutcommit_maxsz;
2012 return 0;
2015 static void
2016 encode_layoutreturn(struct xdr_stream *xdr,
2017 const struct nfs4_layoutreturn_args *args,
2018 struct compound_hdr *hdr)
2020 __be32 *p;
2022 p = reserve_space(xdr, 20);
2023 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2024 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2025 *p++ = cpu_to_be32(args->layout_type);
2026 *p++ = cpu_to_be32(IOMODE_ANY);
2027 *p = cpu_to_be32(RETURN_FILE);
2028 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2029 p = xdr_encode_hyper(p, 0);
2030 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2031 spin_lock(&args->inode->i_lock);
2032 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2033 spin_unlock(&args->inode->i_lock);
2034 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2035 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2036 NFS_I(args->inode)->layout, xdr, args);
2037 } else {
2038 p = reserve_space(xdr, 4);
2039 *p = cpu_to_be32(0);
2041 hdr->nops++;
2042 hdr->replen += decode_layoutreturn_maxsz;
2045 static int
2046 encode_secinfo_no_name(struct xdr_stream *xdr,
2047 const struct nfs41_secinfo_no_name_args *args,
2048 struct compound_hdr *hdr)
2050 __be32 *p;
2051 p = reserve_space(xdr, 8);
2052 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2053 *p++ = cpu_to_be32(args->style);
2054 hdr->nops++;
2055 hdr->replen += decode_secinfo_no_name_maxsz;
2056 return 0;
2059 static void encode_test_stateid(struct xdr_stream *xdr,
2060 struct nfs41_test_stateid_args *args,
2061 struct compound_hdr *hdr)
2063 __be32 *p;
2065 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2066 *p++ = cpu_to_be32(OP_TEST_STATEID);
2067 *p++ = cpu_to_be32(1);
2068 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2069 hdr->nops++;
2070 hdr->replen += decode_test_stateid_maxsz;
2073 static void encode_free_stateid(struct xdr_stream *xdr,
2074 struct nfs41_free_stateid_args *args,
2075 struct compound_hdr *hdr)
2077 __be32 *p;
2078 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2079 *p++ = cpu_to_be32(OP_FREE_STATEID);
2080 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2081 hdr->nops++;
2082 hdr->replen += decode_free_stateid_maxsz;
2084 #endif /* CONFIG_NFS_V4_1 */
2087 * END OF "GENERIC" ENCODE ROUTINES.
2090 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2092 #if defined(CONFIG_NFS_V4_1)
2093 if (args->sa_session)
2094 return args->sa_session->clp->cl_mvops->minor_version;
2095 #endif /* CONFIG_NFS_V4_1 */
2096 return 0;
2100 * Encode an ACCESS request
2102 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2103 const struct nfs4_accessargs *args)
2105 struct compound_hdr hdr = {
2106 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2109 encode_compound_hdr(xdr, req, &hdr);
2110 encode_sequence(xdr, &args->seq_args, &hdr);
2111 encode_putfh(xdr, args->fh, &hdr);
2112 encode_access(xdr, args->access, &hdr);
2113 encode_getfattr(xdr, args->bitmask, &hdr);
2114 encode_nops(&hdr);
2118 * Encode LOOKUP request
2120 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2121 const struct nfs4_lookup_arg *args)
2123 struct compound_hdr hdr = {
2124 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2127 encode_compound_hdr(xdr, req, &hdr);
2128 encode_sequence(xdr, &args->seq_args, &hdr);
2129 encode_putfh(xdr, args->dir_fh, &hdr);
2130 encode_lookup(xdr, args->name, &hdr);
2131 encode_getfh(xdr, &hdr);
2132 encode_getfattr(xdr, args->bitmask, &hdr);
2133 encode_nops(&hdr);
2137 * Encode LOOKUP_ROOT request
2139 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2140 struct xdr_stream *xdr,
2141 const struct nfs4_lookup_root_arg *args)
2143 struct compound_hdr hdr = {
2144 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2147 encode_compound_hdr(xdr, req, &hdr);
2148 encode_sequence(xdr, &args->seq_args, &hdr);
2149 encode_putrootfh(xdr, &hdr);
2150 encode_getfh(xdr, &hdr);
2151 encode_getfattr(xdr, args->bitmask, &hdr);
2152 encode_nops(&hdr);
2156 * Encode REMOVE request
2158 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2159 const struct nfs_removeargs *args)
2161 struct compound_hdr hdr = {
2162 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_sequence(xdr, &args->seq_args, &hdr);
2167 encode_putfh(xdr, args->fh, &hdr);
2168 encode_remove(xdr, &args->name, &hdr);
2169 encode_getfattr(xdr, args->bitmask, &hdr);
2170 encode_nops(&hdr);
2174 * Encode RENAME request
2176 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2177 const struct nfs_renameargs *args)
2179 struct compound_hdr hdr = {
2180 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2183 encode_compound_hdr(xdr, req, &hdr);
2184 encode_sequence(xdr, &args->seq_args, &hdr);
2185 encode_putfh(xdr, args->old_dir, &hdr);
2186 encode_savefh(xdr, &hdr);
2187 encode_putfh(xdr, args->new_dir, &hdr);
2188 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2189 encode_getfattr(xdr, args->bitmask, &hdr);
2190 encode_restorefh(xdr, &hdr);
2191 encode_getfattr(xdr, args->bitmask, &hdr);
2192 encode_nops(&hdr);
2196 * Encode LINK request
2198 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2199 const struct nfs4_link_arg *args)
2201 struct compound_hdr hdr = {
2202 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2205 encode_compound_hdr(xdr, req, &hdr);
2206 encode_sequence(xdr, &args->seq_args, &hdr);
2207 encode_putfh(xdr, args->fh, &hdr);
2208 encode_savefh(xdr, &hdr);
2209 encode_putfh(xdr, args->dir_fh, &hdr);
2210 encode_link(xdr, args->name, &hdr);
2211 encode_getfattr(xdr, args->bitmask, &hdr);
2212 encode_restorefh(xdr, &hdr);
2213 encode_getfattr(xdr, args->bitmask, &hdr);
2214 encode_nops(&hdr);
2218 * Encode CREATE request
2220 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2221 const struct nfs4_create_arg *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->dir_fh, &hdr);
2230 encode_savefh(xdr, &hdr);
2231 encode_create(xdr, args, &hdr);
2232 encode_getfh(xdr, &hdr);
2233 encode_getfattr(xdr, args->bitmask, &hdr);
2234 encode_restorefh(xdr, &hdr);
2235 encode_getfattr(xdr, args->bitmask, &hdr);
2236 encode_nops(&hdr);
2240 * Encode SYMLINK request
2242 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2243 const struct nfs4_create_arg *args)
2245 nfs4_xdr_enc_create(req, xdr, args);
2249 * Encode GETATTR request
2251 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2252 const struct nfs4_getattr_arg *args)
2254 struct compound_hdr hdr = {
2255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2258 encode_compound_hdr(xdr, req, &hdr);
2259 encode_sequence(xdr, &args->seq_args, &hdr);
2260 encode_putfh(xdr, args->fh, &hdr);
2261 encode_getfattr(xdr, args->bitmask, &hdr);
2262 encode_nops(&hdr);
2266 * Encode a CLOSE request
2268 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2269 struct nfs_closeargs *args)
2271 struct compound_hdr hdr = {
2272 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2275 encode_compound_hdr(xdr, req, &hdr);
2276 encode_sequence(xdr, &args->seq_args, &hdr);
2277 encode_putfh(xdr, args->fh, &hdr);
2278 encode_close(xdr, args, &hdr);
2279 encode_getfattr(xdr, args->bitmask, &hdr);
2280 encode_nops(&hdr);
2284 * Encode an OPEN request
2286 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2287 struct nfs_openargs *args)
2289 struct compound_hdr hdr = {
2290 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2293 encode_compound_hdr(xdr, req, &hdr);
2294 encode_sequence(xdr, &args->seq_args, &hdr);
2295 encode_putfh(xdr, args->fh, &hdr);
2296 encode_savefh(xdr, &hdr);
2297 encode_open(xdr, args, &hdr);
2298 encode_getfh(xdr, &hdr);
2299 encode_getfattr(xdr, args->bitmask, &hdr);
2300 encode_restorefh(xdr, &hdr);
2301 encode_getfattr(xdr, args->bitmask, &hdr);
2302 encode_nops(&hdr);
2306 * Encode an OPEN_CONFIRM request
2308 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2309 struct xdr_stream *xdr,
2310 struct nfs_open_confirmargs *args)
2312 struct compound_hdr hdr = {
2313 .nops = 0,
2316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_putfh(xdr, args->fh, &hdr);
2318 encode_open_confirm(xdr, args, &hdr);
2319 encode_nops(&hdr);
2323 * Encode an OPEN request with no attributes.
2325 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2326 struct xdr_stream *xdr,
2327 struct nfs_openargs *args)
2329 struct compound_hdr hdr = {
2330 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2333 encode_compound_hdr(xdr, req, &hdr);
2334 encode_sequence(xdr, &args->seq_args, &hdr);
2335 encode_putfh(xdr, args->fh, &hdr);
2336 encode_open(xdr, args, &hdr);
2337 encode_getfattr(xdr, args->bitmask, &hdr);
2338 encode_nops(&hdr);
2342 * Encode an OPEN_DOWNGRADE request
2344 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2345 struct xdr_stream *xdr,
2346 struct nfs_closeargs *args)
2348 struct compound_hdr hdr = {
2349 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2352 encode_compound_hdr(xdr, req, &hdr);
2353 encode_sequence(xdr, &args->seq_args, &hdr);
2354 encode_putfh(xdr, args->fh, &hdr);
2355 encode_open_downgrade(xdr, args, &hdr);
2356 encode_getfattr(xdr, args->bitmask, &hdr);
2357 encode_nops(&hdr);
2361 * Encode a LOCK request
2363 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2364 struct nfs_lock_args *args)
2366 struct compound_hdr hdr = {
2367 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2370 encode_compound_hdr(xdr, req, &hdr);
2371 encode_sequence(xdr, &args->seq_args, &hdr);
2372 encode_putfh(xdr, args->fh, &hdr);
2373 encode_lock(xdr, args, &hdr);
2374 encode_nops(&hdr);
2378 * Encode a LOCKT request
2380 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2381 struct nfs_lockt_args *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_lockt(xdr, args, &hdr);
2391 encode_nops(&hdr);
2395 * Encode a LOCKU request
2397 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2398 struct nfs_locku_args *args)
2400 struct compound_hdr hdr = {
2401 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2404 encode_compound_hdr(xdr, req, &hdr);
2405 encode_sequence(xdr, &args->seq_args, &hdr);
2406 encode_putfh(xdr, args->fh, &hdr);
2407 encode_locku(xdr, args, &hdr);
2408 encode_nops(&hdr);
2411 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2412 struct xdr_stream *xdr,
2413 struct nfs_release_lockowner_args *args)
2415 struct compound_hdr hdr = {
2416 .minorversion = 0,
2419 encode_compound_hdr(xdr, req, &hdr);
2420 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2421 encode_nops(&hdr);
2425 * Encode a READLINK request
2427 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2428 const struct nfs4_readlink *args)
2430 struct compound_hdr hdr = {
2431 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2434 encode_compound_hdr(xdr, req, &hdr);
2435 encode_sequence(xdr, &args->seq_args, &hdr);
2436 encode_putfh(xdr, args->fh, &hdr);
2437 encode_readlink(xdr, args, req, &hdr);
2439 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2440 args->pgbase, args->pglen);
2441 encode_nops(&hdr);
2445 * Encode a READDIR request
2447 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2448 const struct nfs4_readdir_arg *args)
2450 struct compound_hdr hdr = {
2451 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2454 encode_compound_hdr(xdr, req, &hdr);
2455 encode_sequence(xdr, &args->seq_args, &hdr);
2456 encode_putfh(xdr, args->fh, &hdr);
2457 encode_readdir(xdr, args, req, &hdr);
2459 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2460 args->pgbase, args->count);
2461 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2462 __func__, hdr.replen << 2, args->pages,
2463 args->pgbase, args->count);
2464 encode_nops(&hdr);
2468 * Encode a READ request
2470 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2471 struct nfs_readargs *args)
2473 struct compound_hdr hdr = {
2474 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2477 encode_compound_hdr(xdr, req, &hdr);
2478 encode_sequence(xdr, &args->seq_args, &hdr);
2479 encode_putfh(xdr, args->fh, &hdr);
2480 encode_read(xdr, args, &hdr);
2482 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2483 args->pages, args->pgbase, args->count);
2484 req->rq_rcv_buf.flags |= XDRBUF_READ;
2485 encode_nops(&hdr);
2489 * Encode an SETATTR request
2491 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2492 struct nfs_setattrargs *args)
2494 struct compound_hdr hdr = {
2495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_setattr(xdr, args, args->server, &hdr);
2502 encode_getfattr(xdr, args->bitmask, &hdr);
2503 encode_nops(&hdr);
2507 * Encode a GETACL request
2509 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2510 struct nfs_getaclargs *args)
2512 struct compound_hdr hdr = {
2513 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2515 uint32_t replen;
2517 encode_compound_hdr(xdr, req, &hdr);
2518 encode_sequence(xdr, &args->seq_args, &hdr);
2519 encode_putfh(xdr, args->fh, &hdr);
2520 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
2521 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2523 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2524 args->acl_pages, args->acl_pgbase, args->acl_len);
2525 encode_nops(&hdr);
2529 * Encode a WRITE request
2531 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2532 struct nfs_writeargs *args)
2534 struct compound_hdr hdr = {
2535 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2538 encode_compound_hdr(xdr, req, &hdr);
2539 encode_sequence(xdr, &args->seq_args, &hdr);
2540 encode_putfh(xdr, args->fh, &hdr);
2541 encode_write(xdr, args, &hdr);
2542 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2543 if (args->bitmask)
2544 encode_getfattr(xdr, args->bitmask, &hdr);
2545 encode_nops(&hdr);
2549 * a COMMIT request
2551 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2552 struct nfs_writeargs *args)
2554 struct compound_hdr hdr = {
2555 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2558 encode_compound_hdr(xdr, req, &hdr);
2559 encode_sequence(xdr, &args->seq_args, &hdr);
2560 encode_putfh(xdr, args->fh, &hdr);
2561 encode_commit(xdr, args, &hdr);
2562 if (args->bitmask)
2563 encode_getfattr(xdr, args->bitmask, &hdr);
2564 encode_nops(&hdr);
2568 * FSINFO request
2570 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2571 struct nfs4_fsinfo_arg *args)
2573 struct compound_hdr hdr = {
2574 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2577 encode_compound_hdr(xdr, req, &hdr);
2578 encode_sequence(xdr, &args->seq_args, &hdr);
2579 encode_putfh(xdr, args->fh, &hdr);
2580 encode_fsinfo(xdr, args->bitmask, &hdr);
2581 encode_nops(&hdr);
2585 * a PATHCONF request
2587 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2588 const struct nfs4_pathconf_arg *args)
2590 struct compound_hdr hdr = {
2591 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2594 encode_compound_hdr(xdr, req, &hdr);
2595 encode_sequence(xdr, &args->seq_args, &hdr);
2596 encode_putfh(xdr, args->fh, &hdr);
2597 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2598 &hdr);
2599 encode_nops(&hdr);
2603 * a STATFS request
2605 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2606 const struct nfs4_statfs_arg *args)
2608 struct compound_hdr hdr = {
2609 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2612 encode_compound_hdr(xdr, req, &hdr);
2613 encode_sequence(xdr, &args->seq_args, &hdr);
2614 encode_putfh(xdr, args->fh, &hdr);
2615 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2616 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2617 encode_nops(&hdr);
2621 * GETATTR_BITMAP request
2623 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2624 struct xdr_stream *xdr,
2625 struct nfs4_server_caps_arg *args)
2627 struct compound_hdr hdr = {
2628 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_sequence(xdr, &args->seq_args, &hdr);
2633 encode_putfh(xdr, args->fhandle, &hdr);
2634 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2635 FATTR4_WORD0_LINK_SUPPORT|
2636 FATTR4_WORD0_SYMLINK_SUPPORT|
2637 FATTR4_WORD0_ACLSUPPORT, &hdr);
2638 encode_nops(&hdr);
2642 * a RENEW request
2644 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2645 struct nfs_client *clp)
2647 struct compound_hdr hdr = {
2648 .nops = 0,
2651 encode_compound_hdr(xdr, req, &hdr);
2652 encode_renew(xdr, clp, &hdr);
2653 encode_nops(&hdr);
2657 * a SETCLIENTID request
2659 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2660 struct xdr_stream *xdr,
2661 struct nfs4_setclientid *sc)
2663 struct compound_hdr hdr = {
2664 .nops = 0,
2667 encode_compound_hdr(xdr, req, &hdr);
2668 encode_setclientid(xdr, sc, &hdr);
2669 encode_nops(&hdr);
2673 * a SETCLIENTID_CONFIRM request
2675 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2676 struct xdr_stream *xdr,
2677 struct nfs4_setclientid_res *arg)
2679 struct compound_hdr hdr = {
2680 .nops = 0,
2682 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2684 encode_compound_hdr(xdr, req, &hdr);
2685 encode_setclientid_confirm(xdr, arg, &hdr);
2686 encode_putrootfh(xdr, &hdr);
2687 encode_fsinfo(xdr, lease_bitmap, &hdr);
2688 encode_nops(&hdr);
2692 * DELEGRETURN request
2694 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2695 struct xdr_stream *xdr,
2696 const struct nfs4_delegreturnargs *args)
2698 struct compound_hdr hdr = {
2699 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2702 encode_compound_hdr(xdr, req, &hdr);
2703 encode_sequence(xdr, &args->seq_args, &hdr);
2704 encode_putfh(xdr, args->fhandle, &hdr);
2705 encode_delegreturn(xdr, args->stateid, &hdr);
2706 encode_getfattr(xdr, args->bitmask, &hdr);
2707 encode_nops(&hdr);
2711 * Encode FS_LOCATIONS request
2713 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2714 struct xdr_stream *xdr,
2715 struct nfs4_fs_locations_arg *args)
2717 struct compound_hdr hdr = {
2718 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2720 uint32_t replen;
2722 encode_compound_hdr(xdr, req, &hdr);
2723 encode_sequence(xdr, &args->seq_args, &hdr);
2724 encode_putfh(xdr, args->dir_fh, &hdr);
2725 encode_lookup(xdr, args->name, &hdr);
2726 replen = hdr.replen; /* get the attribute into args->page */
2727 encode_fs_locations(xdr, args->bitmask, &hdr);
2729 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2730 0, PAGE_SIZE);
2731 encode_nops(&hdr);
2735 * Encode SECINFO request
2737 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2738 struct xdr_stream *xdr,
2739 struct nfs4_secinfo_arg *args)
2741 struct compound_hdr hdr = {
2742 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2745 encode_compound_hdr(xdr, req, &hdr);
2746 encode_sequence(xdr, &args->seq_args, &hdr);
2747 encode_putfh(xdr, args->dir_fh, &hdr);
2748 encode_secinfo(xdr, args->name, &hdr);
2749 encode_nops(&hdr);
2752 #if defined(CONFIG_NFS_V4_1)
2754 * EXCHANGE_ID request
2756 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2757 struct xdr_stream *xdr,
2758 struct nfs41_exchange_id_args *args)
2760 struct compound_hdr hdr = {
2761 .minorversion = args->client->cl_mvops->minor_version,
2764 encode_compound_hdr(xdr, req, &hdr);
2765 encode_exchange_id(xdr, args, &hdr);
2766 encode_nops(&hdr);
2770 * a CREATE_SESSION request
2772 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2773 struct xdr_stream *xdr,
2774 struct nfs41_create_session_args *args)
2776 struct compound_hdr hdr = {
2777 .minorversion = args->client->cl_mvops->minor_version,
2780 encode_compound_hdr(xdr, req, &hdr);
2781 encode_create_session(xdr, args, &hdr);
2782 encode_nops(&hdr);
2786 * a DESTROY_SESSION request
2788 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2789 struct xdr_stream *xdr,
2790 struct nfs4_session *session)
2792 struct compound_hdr hdr = {
2793 .minorversion = session->clp->cl_mvops->minor_version,
2796 encode_compound_hdr(xdr, req, &hdr);
2797 encode_destroy_session(xdr, session, &hdr);
2798 encode_nops(&hdr);
2802 * a SEQUENCE request
2804 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2805 struct nfs4_sequence_args *args)
2807 struct compound_hdr hdr = {
2808 .minorversion = nfs4_xdr_minorversion(args),
2811 encode_compound_hdr(xdr, req, &hdr);
2812 encode_sequence(xdr, args, &hdr);
2813 encode_nops(&hdr);
2817 * a GET_LEASE_TIME request
2819 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2820 struct xdr_stream *xdr,
2821 struct nfs4_get_lease_time_args *args)
2823 struct compound_hdr hdr = {
2824 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2826 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2828 encode_compound_hdr(xdr, req, &hdr);
2829 encode_sequence(xdr, &args->la_seq_args, &hdr);
2830 encode_putrootfh(xdr, &hdr);
2831 encode_fsinfo(xdr, lease_bitmap, &hdr);
2832 encode_nops(&hdr);
2836 * a RECLAIM_COMPLETE request
2838 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2839 struct xdr_stream *xdr,
2840 struct nfs41_reclaim_complete_args *args)
2842 struct compound_hdr hdr = {
2843 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2846 encode_compound_hdr(xdr, req, &hdr);
2847 encode_sequence(xdr, &args->seq_args, &hdr);
2848 encode_reclaim_complete(xdr, args, &hdr);
2849 encode_nops(&hdr);
2853 * Encode GETDEVICELIST request
2855 static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2856 struct xdr_stream *xdr,
2857 struct nfs4_getdevicelist_args *args)
2859 struct compound_hdr hdr = {
2860 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2863 encode_compound_hdr(xdr, req, &hdr);
2864 encode_sequence(xdr, &args->seq_args, &hdr);
2865 encode_putfh(xdr, args->fh, &hdr);
2866 encode_getdevicelist(xdr, args, &hdr);
2867 encode_nops(&hdr);
2871 * Encode GETDEVICEINFO request
2873 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2874 struct xdr_stream *xdr,
2875 struct nfs4_getdeviceinfo_args *args)
2877 struct compound_hdr hdr = {
2878 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2881 encode_compound_hdr(xdr, req, &hdr);
2882 encode_sequence(xdr, &args->seq_args, &hdr);
2883 encode_getdeviceinfo(xdr, args, &hdr);
2885 /* set up reply kvec. Subtract notification bitmap max size (2)
2886 * so that notification bitmap is put in xdr_buf tail */
2887 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2888 args->pdev->pages, args->pdev->pgbase,
2889 args->pdev->pglen);
2891 encode_nops(&hdr);
2895 * Encode LAYOUTGET request
2897 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2898 struct xdr_stream *xdr,
2899 struct nfs4_layoutget_args *args)
2901 struct compound_hdr hdr = {
2902 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2905 encode_compound_hdr(xdr, req, &hdr);
2906 encode_sequence(xdr, &args->seq_args, &hdr);
2907 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2908 encode_layoutget(xdr, args, &hdr);
2910 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2911 args->layout.pages, 0, args->layout.pglen);
2913 encode_nops(&hdr);
2917 * Encode LAYOUTCOMMIT request
2919 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2920 struct xdr_stream *xdr,
2921 struct nfs4_layoutcommit_args *args)
2923 struct nfs4_layoutcommit_data *data =
2924 container_of(args, struct nfs4_layoutcommit_data, args);
2925 struct compound_hdr hdr = {
2926 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2929 encode_compound_hdr(xdr, req, &hdr);
2930 encode_sequence(xdr, &args->seq_args, &hdr);
2931 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2932 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2933 encode_getfattr(xdr, args->bitmask, &hdr);
2934 encode_nops(&hdr);
2938 * Encode LAYOUTRETURN request
2940 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2941 struct xdr_stream *xdr,
2942 struct nfs4_layoutreturn_args *args)
2944 struct compound_hdr hdr = {
2945 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2948 encode_compound_hdr(xdr, req, &hdr);
2949 encode_sequence(xdr, &args->seq_args, &hdr);
2950 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2951 encode_layoutreturn(xdr, args, &hdr);
2952 encode_nops(&hdr);
2956 * Encode SECINFO_NO_NAME request
2958 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2959 struct xdr_stream *xdr,
2960 struct nfs41_secinfo_no_name_args *args)
2962 struct compound_hdr hdr = {
2963 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2966 encode_compound_hdr(xdr, req, &hdr);
2967 encode_sequence(xdr, &args->seq_args, &hdr);
2968 encode_putrootfh(xdr, &hdr);
2969 encode_secinfo_no_name(xdr, args, &hdr);
2970 encode_nops(&hdr);
2971 return 0;
2975 * Encode TEST_STATEID request
2977 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2978 struct xdr_stream *xdr,
2979 struct nfs41_test_stateid_args *args)
2981 struct compound_hdr hdr = {
2982 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2985 encode_compound_hdr(xdr, req, &hdr);
2986 encode_sequence(xdr, &args->seq_args, &hdr);
2987 encode_test_stateid(xdr, args, &hdr);
2988 encode_nops(&hdr);
2992 * Encode FREE_STATEID request
2994 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2995 struct xdr_stream *xdr,
2996 struct nfs41_free_stateid_args *args)
2998 struct compound_hdr hdr = {
2999 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3002 encode_compound_hdr(xdr, req, &hdr);
3003 encode_sequence(xdr, &args->seq_args, &hdr);
3004 encode_free_stateid(xdr, args, &hdr);
3005 encode_nops(&hdr);
3007 #endif /* CONFIG_NFS_V4_1 */
3009 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3011 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3012 "Remaining buffer length is %tu words.\n",
3013 func, xdr->end - xdr->p);
3016 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3018 __be32 *p;
3020 p = xdr_inline_decode(xdr, 4);
3021 if (unlikely(!p))
3022 goto out_overflow;
3023 *len = be32_to_cpup(p);
3024 p = xdr_inline_decode(xdr, *len);
3025 if (unlikely(!p))
3026 goto out_overflow;
3027 *string = (char *)p;
3028 return 0;
3029 out_overflow:
3030 print_overflow_msg(__func__, xdr);
3031 return -EIO;
3034 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3036 __be32 *p;
3038 p = xdr_inline_decode(xdr, 8);
3039 if (unlikely(!p))
3040 goto out_overflow;
3041 hdr->status = be32_to_cpup(p++);
3042 hdr->taglen = be32_to_cpup(p);
3044 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3045 if (unlikely(!p))
3046 goto out_overflow;
3047 hdr->tag = (char *)p;
3048 p += XDR_QUADLEN(hdr->taglen);
3049 hdr->nops = be32_to_cpup(p);
3050 if (unlikely(hdr->nops < 1))
3051 return nfs4_stat_to_errno(hdr->status);
3052 return 0;
3053 out_overflow:
3054 print_overflow_msg(__func__, xdr);
3055 return -EIO;
3058 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3060 __be32 *p;
3061 uint32_t opnum;
3062 int32_t nfserr;
3064 p = xdr_inline_decode(xdr, 8);
3065 if (unlikely(!p))
3066 goto out_overflow;
3067 opnum = be32_to_cpup(p++);
3068 if (opnum != expected) {
3069 dprintk("nfs: Server returned operation"
3070 " %d but we issued a request for %d\n",
3071 opnum, expected);
3072 return -EIO;
3074 nfserr = be32_to_cpup(p);
3075 if (nfserr != NFS_OK)
3076 return nfs4_stat_to_errno(nfserr);
3077 return 0;
3078 out_overflow:
3079 print_overflow_msg(__func__, xdr);
3080 return -EIO;
3083 /* Dummy routine */
3084 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
3086 __be32 *p;
3087 unsigned int strlen;
3088 char *str;
3090 p = xdr_inline_decode(xdr, 12);
3091 if (likely(p))
3092 return decode_opaque_inline(xdr, &strlen, &str);
3093 print_overflow_msg(__func__, xdr);
3094 return -EIO;
3097 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3099 uint32_t bmlen;
3100 __be32 *p;
3102 p = xdr_inline_decode(xdr, 4);
3103 if (unlikely(!p))
3104 goto out_overflow;
3105 bmlen = be32_to_cpup(p);
3107 bitmap[0] = bitmap[1] = bitmap[2] = 0;
3108 p = xdr_inline_decode(xdr, (bmlen << 2));
3109 if (unlikely(!p))
3110 goto out_overflow;
3111 if (bmlen > 0) {
3112 bitmap[0] = be32_to_cpup(p++);
3113 if (bmlen > 1) {
3114 bitmap[1] = be32_to_cpup(p++);
3115 if (bmlen > 2)
3116 bitmap[2] = be32_to_cpup(p);
3119 return 0;
3120 out_overflow:
3121 print_overflow_msg(__func__, xdr);
3122 return -EIO;
3125 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
3127 __be32 *p;
3129 p = xdr_inline_decode(xdr, 4);
3130 if (unlikely(!p))
3131 goto out_overflow;
3132 *attrlen = be32_to_cpup(p);
3133 *savep = xdr->p;
3134 return 0;
3135 out_overflow:
3136 print_overflow_msg(__func__, xdr);
3137 return -EIO;
3140 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3142 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3143 int ret;
3144 ret = decode_attr_bitmap(xdr, bitmask);
3145 if (unlikely(ret < 0))
3146 return ret;
3147 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3148 } else
3149 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3150 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3151 bitmask[0], bitmask[1], bitmask[2]);
3152 return 0;
3155 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3157 __be32 *p;
3158 int ret = 0;
3160 *type = 0;
3161 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3162 return -EIO;
3163 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3164 p = xdr_inline_decode(xdr, 4);
3165 if (unlikely(!p))
3166 goto out_overflow;
3167 *type = be32_to_cpup(p);
3168 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3169 dprintk("%s: bad type %d\n", __func__, *type);
3170 return -EIO;
3172 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3173 ret = NFS_ATTR_FATTR_TYPE;
3175 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3176 return ret;
3177 out_overflow:
3178 print_overflow_msg(__func__, xdr);
3179 return -EIO;
3182 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3184 __be32 *p;
3185 int ret = 0;
3187 *change = 0;
3188 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3189 return -EIO;
3190 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3191 p = xdr_inline_decode(xdr, 8);
3192 if (unlikely(!p))
3193 goto out_overflow;
3194 xdr_decode_hyper(p, change);
3195 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3196 ret = NFS_ATTR_FATTR_CHANGE;
3198 dprintk("%s: change attribute=%Lu\n", __func__,
3199 (unsigned long long)*change);
3200 return ret;
3201 out_overflow:
3202 print_overflow_msg(__func__, xdr);
3203 return -EIO;
3206 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3208 __be32 *p;
3209 int ret = 0;
3211 *size = 0;
3212 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3213 return -EIO;
3214 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3215 p = xdr_inline_decode(xdr, 8);
3216 if (unlikely(!p))
3217 goto out_overflow;
3218 xdr_decode_hyper(p, size);
3219 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3220 ret = NFS_ATTR_FATTR_SIZE;
3222 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3223 return ret;
3224 out_overflow:
3225 print_overflow_msg(__func__, xdr);
3226 return -EIO;
3229 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3231 __be32 *p;
3233 *res = 0;
3234 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3235 return -EIO;
3236 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3237 p = xdr_inline_decode(xdr, 4);
3238 if (unlikely(!p))
3239 goto out_overflow;
3240 *res = be32_to_cpup(p);
3241 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3243 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3244 return 0;
3245 out_overflow:
3246 print_overflow_msg(__func__, xdr);
3247 return -EIO;
3250 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3252 __be32 *p;
3254 *res = 0;
3255 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3256 return -EIO;
3257 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3258 p = xdr_inline_decode(xdr, 4);
3259 if (unlikely(!p))
3260 goto out_overflow;
3261 *res = be32_to_cpup(p);
3262 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3264 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3265 return 0;
3266 out_overflow:
3267 print_overflow_msg(__func__, xdr);
3268 return -EIO;
3271 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3273 __be32 *p;
3274 int ret = 0;
3276 fsid->major = 0;
3277 fsid->minor = 0;
3278 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3279 return -EIO;
3280 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3281 p = xdr_inline_decode(xdr, 16);
3282 if (unlikely(!p))
3283 goto out_overflow;
3284 p = xdr_decode_hyper(p, &fsid->major);
3285 xdr_decode_hyper(p, &fsid->minor);
3286 bitmap[0] &= ~FATTR4_WORD0_FSID;
3287 ret = NFS_ATTR_FATTR_FSID;
3289 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3290 (unsigned long long)fsid->major,
3291 (unsigned long long)fsid->minor);
3292 return ret;
3293 out_overflow:
3294 print_overflow_msg(__func__, xdr);
3295 return -EIO;
3298 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3300 __be32 *p;
3302 *res = 60;
3303 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3304 return -EIO;
3305 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3306 p = xdr_inline_decode(xdr, 4);
3307 if (unlikely(!p))
3308 goto out_overflow;
3309 *res = be32_to_cpup(p);
3310 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3312 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3313 return 0;
3314 out_overflow:
3315 print_overflow_msg(__func__, xdr);
3316 return -EIO;
3319 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3321 __be32 *p;
3323 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3324 return -EIO;
3325 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3326 p = xdr_inline_decode(xdr, 4);
3327 if (unlikely(!p))
3328 goto out_overflow;
3329 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3330 *res = -be32_to_cpup(p);
3332 return 0;
3333 out_overflow:
3334 print_overflow_msg(__func__, xdr);
3335 return -EIO;
3338 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3340 __be32 *p;
3341 int len;
3343 if (fh != NULL)
3344 memset(fh, 0, sizeof(*fh));
3346 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3347 return -EIO;
3348 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3349 p = xdr_inline_decode(xdr, 4);
3350 if (unlikely(!p))
3351 goto out_overflow;
3352 len = be32_to_cpup(p);
3353 if (len > NFS4_FHSIZE)
3354 return -EIO;
3355 p = xdr_inline_decode(xdr, len);
3356 if (unlikely(!p))
3357 goto out_overflow;
3358 if (fh != NULL) {
3359 memcpy(fh->data, p, len);
3360 fh->size = len;
3362 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3364 return 0;
3365 out_overflow:
3366 print_overflow_msg(__func__, xdr);
3367 return -EIO;
3370 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3372 __be32 *p;
3374 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3375 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3376 return -EIO;
3377 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3378 p = xdr_inline_decode(xdr, 4);
3379 if (unlikely(!p))
3380 goto out_overflow;
3381 *res = be32_to_cpup(p);
3382 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3384 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3385 return 0;
3386 out_overflow:
3387 print_overflow_msg(__func__, xdr);
3388 return -EIO;
3391 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3393 __be32 *p;
3394 int ret = 0;
3396 *fileid = 0;
3397 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3398 return -EIO;
3399 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3400 p = xdr_inline_decode(xdr, 8);
3401 if (unlikely(!p))
3402 goto out_overflow;
3403 xdr_decode_hyper(p, fileid);
3404 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3405 ret = NFS_ATTR_FATTR_FILEID;
3407 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3408 return ret;
3409 out_overflow:
3410 print_overflow_msg(__func__, xdr);
3411 return -EIO;
3414 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3416 __be32 *p;
3417 int ret = 0;
3419 *fileid = 0;
3420 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3421 return -EIO;
3422 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3423 p = xdr_inline_decode(xdr, 8);
3424 if (unlikely(!p))
3425 goto out_overflow;
3426 xdr_decode_hyper(p, fileid);
3427 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3428 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3430 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3431 return ret;
3432 out_overflow:
3433 print_overflow_msg(__func__, xdr);
3434 return -EIO;
3437 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3439 __be32 *p;
3440 int status = 0;
3442 *res = 0;
3443 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3444 return -EIO;
3445 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3446 p = xdr_inline_decode(xdr, 8);
3447 if (unlikely(!p))
3448 goto out_overflow;
3449 xdr_decode_hyper(p, res);
3450 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3452 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3453 return status;
3454 out_overflow:
3455 print_overflow_msg(__func__, xdr);
3456 return -EIO;
3459 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3461 __be32 *p;
3462 int status = 0;
3464 *res = 0;
3465 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3466 return -EIO;
3467 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3468 p = xdr_inline_decode(xdr, 8);
3469 if (unlikely(!p))
3470 goto out_overflow;
3471 xdr_decode_hyper(p, res);
3472 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3474 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3475 return status;
3476 out_overflow:
3477 print_overflow_msg(__func__, xdr);
3478 return -EIO;
3481 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3483 __be32 *p;
3484 int status = 0;
3486 *res = 0;
3487 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3488 return -EIO;
3489 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3490 p = xdr_inline_decode(xdr, 8);
3491 if (unlikely(!p))
3492 goto out_overflow;
3493 xdr_decode_hyper(p, res);
3494 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3496 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3497 return status;
3498 out_overflow:
3499 print_overflow_msg(__func__, xdr);
3500 return -EIO;
3503 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3505 u32 n;
3506 __be32 *p;
3507 int status = 0;
3509 p = xdr_inline_decode(xdr, 4);
3510 if (unlikely(!p))
3511 goto out_overflow;
3512 n = be32_to_cpup(p);
3513 if (n == 0)
3514 goto root_path;
3515 dprintk("path ");
3516 path->ncomponents = 0;
3517 while (path->ncomponents < n) {
3518 struct nfs4_string *component = &path->components[path->ncomponents];
3519 status = decode_opaque_inline(xdr, &component->len, &component->data);
3520 if (unlikely(status != 0))
3521 goto out_eio;
3522 if (path->ncomponents != n)
3523 dprintk("/");
3524 dprintk("%s", component->data);
3525 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3526 path->ncomponents++;
3527 else {
3528 dprintk("cannot parse %d components in path\n", n);
3529 goto out_eio;
3532 out:
3533 dprintk("\n");
3534 return status;
3535 root_path:
3536 /* a root pathname is sent as a zero component4 */
3537 path->ncomponents = 1;
3538 path->components[0].len=0;
3539 path->components[0].data=NULL;
3540 dprintk("path /\n");
3541 goto out;
3542 out_eio:
3543 dprintk(" status %d", status);
3544 status = -EIO;
3545 goto out;
3546 out_overflow:
3547 print_overflow_msg(__func__, xdr);
3548 return -EIO;
3551 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3553 int n;
3554 __be32 *p;
3555 int status = -EIO;
3557 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3558 goto out;
3559 status = 0;
3560 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3561 goto out;
3562 dprintk("%s: fsroot ", __func__);
3563 status = decode_pathname(xdr, &res->fs_path);
3564 if (unlikely(status != 0))
3565 goto out;
3566 p = xdr_inline_decode(xdr, 4);
3567 if (unlikely(!p))
3568 goto out_overflow;
3569 n = be32_to_cpup(p);
3570 if (n <= 0)
3571 goto out_eio;
3572 res->nlocations = 0;
3573 while (res->nlocations < n) {
3574 u32 m;
3575 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3577 p = xdr_inline_decode(xdr, 4);
3578 if (unlikely(!p))
3579 goto out_overflow;
3580 m = be32_to_cpup(p);
3582 loc->nservers = 0;
3583 dprintk("%s: servers ", __func__);
3584 while (loc->nservers < m) {
3585 struct nfs4_string *server = &loc->servers[loc->nservers];
3586 status = decode_opaque_inline(xdr, &server->len, &server->data);
3587 if (unlikely(status != 0))
3588 goto out_eio;
3589 dprintk("%s ", server->data);
3590 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3591 loc->nservers++;
3592 else {
3593 unsigned int i;
3594 dprintk("%s: using first %u of %u servers "
3595 "returned for location %u\n",
3596 __func__,
3597 NFS4_FS_LOCATION_MAXSERVERS,
3598 m, res->nlocations);
3599 for (i = loc->nservers; i < m; i++) {
3600 unsigned int len;
3601 char *data;
3602 status = decode_opaque_inline(xdr, &len, &data);
3603 if (unlikely(status != 0))
3604 goto out_eio;
3608 status = decode_pathname(xdr, &loc->rootpath);
3609 if (unlikely(status != 0))
3610 goto out_eio;
3611 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3612 res->nlocations++;
3614 if (res->nlocations != 0)
3615 status = NFS_ATTR_FATTR_V4_REFERRAL;
3616 out:
3617 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3618 return status;
3619 out_overflow:
3620 print_overflow_msg(__func__, xdr);
3621 out_eio:
3622 status = -EIO;
3623 goto out;
3626 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3628 __be32 *p;
3629 int status = 0;
3631 *res = 0;
3632 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3633 return -EIO;
3634 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3635 p = xdr_inline_decode(xdr, 8);
3636 if (unlikely(!p))
3637 goto out_overflow;
3638 xdr_decode_hyper(p, res);
3639 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3641 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3642 return status;
3643 out_overflow:
3644 print_overflow_msg(__func__, xdr);
3645 return -EIO;
3648 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3650 __be32 *p;
3651 int status = 0;
3653 *maxlink = 1;
3654 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3655 return -EIO;
3656 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3657 p = xdr_inline_decode(xdr, 4);
3658 if (unlikely(!p))
3659 goto out_overflow;
3660 *maxlink = be32_to_cpup(p);
3661 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3663 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3664 return status;
3665 out_overflow:
3666 print_overflow_msg(__func__, xdr);
3667 return -EIO;
3670 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3672 __be32 *p;
3673 int status = 0;
3675 *maxname = 1024;
3676 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3677 return -EIO;
3678 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3679 p = xdr_inline_decode(xdr, 4);
3680 if (unlikely(!p))
3681 goto out_overflow;
3682 *maxname = be32_to_cpup(p);
3683 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3685 dprintk("%s: maxname=%u\n", __func__, *maxname);
3686 return status;
3687 out_overflow:
3688 print_overflow_msg(__func__, xdr);
3689 return -EIO;
3692 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3694 __be32 *p;
3695 int status = 0;
3697 *res = 1024;
3698 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3699 return -EIO;
3700 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3701 uint64_t maxread;
3702 p = xdr_inline_decode(xdr, 8);
3703 if (unlikely(!p))
3704 goto out_overflow;
3705 xdr_decode_hyper(p, &maxread);
3706 if (maxread > 0x7FFFFFFF)
3707 maxread = 0x7FFFFFFF;
3708 *res = (uint32_t)maxread;
3709 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3711 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3712 return status;
3713 out_overflow:
3714 print_overflow_msg(__func__, xdr);
3715 return -EIO;
3718 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3720 __be32 *p;
3721 int status = 0;
3723 *res = 1024;
3724 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3725 return -EIO;
3726 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3727 uint64_t maxwrite;
3728 p = xdr_inline_decode(xdr, 8);
3729 if (unlikely(!p))
3730 goto out_overflow;
3731 xdr_decode_hyper(p, &maxwrite);
3732 if (maxwrite > 0x7FFFFFFF)
3733 maxwrite = 0x7FFFFFFF;
3734 *res = (uint32_t)maxwrite;
3735 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3737 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3738 return status;
3739 out_overflow:
3740 print_overflow_msg(__func__, xdr);
3741 return -EIO;
3744 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3746 uint32_t tmp;
3747 __be32 *p;
3748 int ret = 0;
3750 *mode = 0;
3751 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3752 return -EIO;
3753 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3754 p = xdr_inline_decode(xdr, 4);
3755 if (unlikely(!p))
3756 goto out_overflow;
3757 tmp = be32_to_cpup(p);
3758 *mode = tmp & ~S_IFMT;
3759 bitmap[1] &= ~FATTR4_WORD1_MODE;
3760 ret = NFS_ATTR_FATTR_MODE;
3762 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3763 return ret;
3764 out_overflow:
3765 print_overflow_msg(__func__, xdr);
3766 return -EIO;
3769 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3771 __be32 *p;
3772 int ret = 0;
3774 *nlink = 1;
3775 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3776 return -EIO;
3777 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3778 p = xdr_inline_decode(xdr, 4);
3779 if (unlikely(!p))
3780 goto out_overflow;
3781 *nlink = be32_to_cpup(p);
3782 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3783 ret = NFS_ATTR_FATTR_NLINK;
3785 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3786 return ret;
3787 out_overflow:
3788 print_overflow_msg(__func__, xdr);
3789 return -EIO;
3792 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3793 const struct nfs_server *server, uint32_t *uid, int may_sleep)
3795 uint32_t len;
3796 __be32 *p;
3797 int ret = 0;
3799 *uid = -2;
3800 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3801 return -EIO;
3802 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3803 p = xdr_inline_decode(xdr, 4);
3804 if (unlikely(!p))
3805 goto out_overflow;
3806 len = be32_to_cpup(p);
3807 p = xdr_inline_decode(xdr, len);
3808 if (unlikely(!p))
3809 goto out_overflow;
3810 if (!may_sleep) {
3811 /* do nothing */
3812 } else if (len < XDR_MAX_NETOBJ) {
3813 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3814 ret = NFS_ATTR_FATTR_OWNER;
3815 else
3816 dprintk("%s: nfs_map_name_to_uid failed!\n",
3817 __func__);
3818 } else
3819 dprintk("%s: name too long (%u)!\n",
3820 __func__, len);
3821 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3823 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3824 return ret;
3825 out_overflow:
3826 print_overflow_msg(__func__, xdr);
3827 return -EIO;
3830 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3831 const struct nfs_server *server, uint32_t *gid, int may_sleep)
3833 uint32_t len;
3834 __be32 *p;
3835 int ret = 0;
3837 *gid = -2;
3838 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3839 return -EIO;
3840 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3841 p = xdr_inline_decode(xdr, 4);
3842 if (unlikely(!p))
3843 goto out_overflow;
3844 len = be32_to_cpup(p);
3845 p = xdr_inline_decode(xdr, len);
3846 if (unlikely(!p))
3847 goto out_overflow;
3848 if (!may_sleep) {
3849 /* do nothing */
3850 } else if (len < XDR_MAX_NETOBJ) {
3851 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3852 ret = NFS_ATTR_FATTR_GROUP;
3853 else
3854 dprintk("%s: nfs_map_group_to_gid failed!\n",
3855 __func__);
3856 } else
3857 dprintk("%s: name too long (%u)!\n",
3858 __func__, len);
3859 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3861 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3862 return ret;
3863 out_overflow:
3864 print_overflow_msg(__func__, xdr);
3865 return -EIO;
3868 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3870 uint32_t major = 0, minor = 0;
3871 __be32 *p;
3872 int ret = 0;
3874 *rdev = MKDEV(0,0);
3875 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3876 return -EIO;
3877 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3878 dev_t tmp;
3880 p = xdr_inline_decode(xdr, 8);
3881 if (unlikely(!p))
3882 goto out_overflow;
3883 major = be32_to_cpup(p++);
3884 minor = be32_to_cpup(p);
3885 tmp = MKDEV(major, minor);
3886 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3887 *rdev = tmp;
3888 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3889 ret = NFS_ATTR_FATTR_RDEV;
3891 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3892 return ret;
3893 out_overflow:
3894 print_overflow_msg(__func__, xdr);
3895 return -EIO;
3898 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3900 __be32 *p;
3901 int status = 0;
3903 *res = 0;
3904 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3905 return -EIO;
3906 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3907 p = xdr_inline_decode(xdr, 8);
3908 if (unlikely(!p))
3909 goto out_overflow;
3910 xdr_decode_hyper(p, res);
3911 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3913 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3914 return status;
3915 out_overflow:
3916 print_overflow_msg(__func__, xdr);
3917 return -EIO;
3920 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3922 __be32 *p;
3923 int status = 0;
3925 *res = 0;
3926 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3927 return -EIO;
3928 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3929 p = xdr_inline_decode(xdr, 8);
3930 if (unlikely(!p))
3931 goto out_overflow;
3932 xdr_decode_hyper(p, res);
3933 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3935 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3936 return status;
3937 out_overflow:
3938 print_overflow_msg(__func__, xdr);
3939 return -EIO;
3942 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3944 __be32 *p;
3945 int status = 0;
3947 *res = 0;
3948 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3949 return -EIO;
3950 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3951 p = xdr_inline_decode(xdr, 8);
3952 if (unlikely(!p))
3953 goto out_overflow;
3954 xdr_decode_hyper(p, res);
3955 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3957 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3958 return status;
3959 out_overflow:
3960 print_overflow_msg(__func__, xdr);
3961 return -EIO;
3964 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3966 __be32 *p;
3967 int ret = 0;
3969 *used = 0;
3970 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3971 return -EIO;
3972 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3973 p = xdr_inline_decode(xdr, 8);
3974 if (unlikely(!p))
3975 goto out_overflow;
3976 xdr_decode_hyper(p, used);
3977 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3978 ret = NFS_ATTR_FATTR_SPACE_USED;
3980 dprintk("%s: space used=%Lu\n", __func__,
3981 (unsigned long long)*used);
3982 return ret;
3983 out_overflow:
3984 print_overflow_msg(__func__, xdr);
3985 return -EIO;
3988 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3990 __be32 *p;
3991 uint64_t sec;
3992 uint32_t nsec;
3994 p = xdr_inline_decode(xdr, 12);
3995 if (unlikely(!p))
3996 goto out_overflow;
3997 p = xdr_decode_hyper(p, &sec);
3998 nsec = be32_to_cpup(p);
3999 time->tv_sec = (time_t)sec;
4000 time->tv_nsec = (long)nsec;
4001 return 0;
4002 out_overflow:
4003 print_overflow_msg(__func__, xdr);
4004 return -EIO;
4007 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4009 int status = 0;
4011 time->tv_sec = 0;
4012 time->tv_nsec = 0;
4013 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4014 return -EIO;
4015 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4016 status = decode_attr_time(xdr, time);
4017 if (status == 0)
4018 status = NFS_ATTR_FATTR_ATIME;
4019 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4021 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
4022 return status;
4025 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4027 int status = 0;
4029 time->tv_sec = 0;
4030 time->tv_nsec = 0;
4031 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4032 return -EIO;
4033 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4034 status = decode_attr_time(xdr, time);
4035 if (status == 0)
4036 status = NFS_ATTR_FATTR_CTIME;
4037 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4039 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
4040 return status;
4043 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4044 struct timespec *time)
4046 int status = 0;
4048 time->tv_sec = 0;
4049 time->tv_nsec = 0;
4050 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4051 return -EIO;
4052 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4053 status = decode_attr_time(xdr, time);
4054 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4056 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4057 (long)time->tv_nsec);
4058 return status;
4061 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4063 int status = 0;
4065 time->tv_sec = 0;
4066 time->tv_nsec = 0;
4067 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4068 return -EIO;
4069 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4070 status = decode_attr_time(xdr, time);
4071 if (status == 0)
4072 status = NFS_ATTR_FATTR_MTIME;
4073 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4075 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
4076 return status;
4079 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
4081 unsigned int attrwords = XDR_QUADLEN(attrlen);
4082 unsigned int nwords = xdr->p - savep;
4084 if (unlikely(attrwords != nwords)) {
4085 dprintk("%s: server returned incorrect attribute length: "
4086 "%u %c %u\n",
4087 __func__,
4088 attrwords << 2,
4089 (attrwords < nwords) ? '<' : '>',
4090 nwords << 2);
4091 return -EIO;
4093 return 0;
4096 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4098 __be32 *p;
4100 p = xdr_inline_decode(xdr, 20);
4101 if (unlikely(!p))
4102 goto out_overflow;
4103 cinfo->atomic = be32_to_cpup(p++);
4104 p = xdr_decode_hyper(p, &cinfo->before);
4105 xdr_decode_hyper(p, &cinfo->after);
4106 return 0;
4107 out_overflow:
4108 print_overflow_msg(__func__, xdr);
4109 return -EIO;
4112 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4114 __be32 *p;
4115 uint32_t supp, acc;
4116 int status;
4118 status = decode_op_hdr(xdr, OP_ACCESS);
4119 if (status)
4120 return status;
4121 p = xdr_inline_decode(xdr, 8);
4122 if (unlikely(!p))
4123 goto out_overflow;
4124 supp = be32_to_cpup(p++);
4125 acc = be32_to_cpup(p);
4126 access->supported = supp;
4127 access->access = acc;
4128 return 0;
4129 out_overflow:
4130 print_overflow_msg(__func__, xdr);
4131 return -EIO;
4134 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4136 __be32 *p;
4138 p = xdr_inline_decode(xdr, len);
4139 if (likely(p)) {
4140 memcpy(buf, p, len);
4141 return 0;
4143 print_overflow_msg(__func__, xdr);
4144 return -EIO;
4147 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4149 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
4152 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4154 int status;
4156 status = decode_op_hdr(xdr, OP_CLOSE);
4157 if (status != -EIO)
4158 nfs_increment_open_seqid(status, res->seqid);
4159 if (!status)
4160 status = decode_stateid(xdr, &res->stateid);
4161 return status;
4164 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4166 return decode_opaque_fixed(xdr, verifier, 8);
4169 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4171 int status;
4173 status = decode_op_hdr(xdr, OP_COMMIT);
4174 if (!status)
4175 status = decode_verifier(xdr, res->verf->verifier);
4176 return status;
4179 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4181 __be32 *p;
4182 uint32_t bmlen;
4183 int status;
4185 status = decode_op_hdr(xdr, OP_CREATE);
4186 if (status)
4187 return status;
4188 if ((status = decode_change_info(xdr, cinfo)))
4189 return status;
4190 p = xdr_inline_decode(xdr, 4);
4191 if (unlikely(!p))
4192 goto out_overflow;
4193 bmlen = be32_to_cpup(p);
4194 p = xdr_inline_decode(xdr, bmlen << 2);
4195 if (likely(p))
4196 return 0;
4197 out_overflow:
4198 print_overflow_msg(__func__, xdr);
4199 return -EIO;
4202 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4204 __be32 *savep;
4205 uint32_t attrlen, bitmap[3] = {0};
4206 int status;
4208 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4209 goto xdr_error;
4210 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4211 goto xdr_error;
4212 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4213 goto xdr_error;
4214 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4215 goto xdr_error;
4216 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4217 goto xdr_error;
4218 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4219 goto xdr_error;
4220 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4221 goto xdr_error;
4222 status = verify_attr_len(xdr, savep, attrlen);
4223 xdr_error:
4224 dprintk("%s: xdr returned %d!\n", __func__, -status);
4225 return status;
4228 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4230 __be32 *savep;
4231 uint32_t attrlen, bitmap[3] = {0};
4232 int status;
4234 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4235 goto xdr_error;
4236 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4237 goto xdr_error;
4238 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4239 goto xdr_error;
4241 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4242 goto xdr_error;
4243 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4244 goto xdr_error;
4245 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4246 goto xdr_error;
4247 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4248 goto xdr_error;
4249 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4250 goto xdr_error;
4251 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4252 goto xdr_error;
4254 status = verify_attr_len(xdr, savep, attrlen);
4255 xdr_error:
4256 dprintk("%s: xdr returned %d!\n", __func__, -status);
4257 return status;
4260 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4262 __be32 *savep;
4263 uint32_t attrlen, bitmap[3] = {0};
4264 int status;
4266 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4267 goto xdr_error;
4268 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4269 goto xdr_error;
4270 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4271 goto xdr_error;
4273 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4274 goto xdr_error;
4275 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4276 goto xdr_error;
4278 status = verify_attr_len(xdr, savep, attrlen);
4279 xdr_error:
4280 dprintk("%s: xdr returned %d!\n", __func__, -status);
4281 return status;
4284 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4285 struct nfs_fattr *fattr, struct nfs_fh *fh,
4286 const struct nfs_server *server, int may_sleep)
4288 int status;
4289 umode_t fmode = 0;
4290 uint32_t type;
4291 int32_t err;
4293 status = decode_attr_type(xdr, bitmap, &type);
4294 if (status < 0)
4295 goto xdr_error;
4296 fattr->mode = 0;
4297 if (status != 0) {
4298 fattr->mode |= nfs_type2fmt[type];
4299 fattr->valid |= status;
4302 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4303 if (status < 0)
4304 goto xdr_error;
4305 fattr->valid |= status;
4307 status = decode_attr_size(xdr, bitmap, &fattr->size);
4308 if (status < 0)
4309 goto xdr_error;
4310 fattr->valid |= status;
4312 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4313 if (status < 0)
4314 goto xdr_error;
4315 fattr->valid |= status;
4317 err = 0;
4318 status = decode_attr_error(xdr, bitmap, &err);
4319 if (status < 0)
4320 goto xdr_error;
4321 if (err == -NFS4ERR_WRONGSEC)
4322 nfs_fixup_secinfo_attributes(fattr, fh);
4324 status = decode_attr_filehandle(xdr, bitmap, fh);
4325 if (status < 0)
4326 goto xdr_error;
4328 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4329 if (status < 0)
4330 goto xdr_error;
4331 fattr->valid |= status;
4333 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
4334 struct nfs4_fs_locations,
4335 fattr));
4336 if (status < 0)
4337 goto xdr_error;
4338 fattr->valid |= status;
4340 status = decode_attr_mode(xdr, bitmap, &fmode);
4341 if (status < 0)
4342 goto xdr_error;
4343 if (status != 0) {
4344 fattr->mode |= fmode;
4345 fattr->valid |= status;
4348 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4349 if (status < 0)
4350 goto xdr_error;
4351 fattr->valid |= status;
4353 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
4354 if (status < 0)
4355 goto xdr_error;
4356 fattr->valid |= status;
4358 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
4359 if (status < 0)
4360 goto xdr_error;
4361 fattr->valid |= status;
4363 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4364 if (status < 0)
4365 goto xdr_error;
4366 fattr->valid |= status;
4368 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4369 if (status < 0)
4370 goto xdr_error;
4371 fattr->valid |= status;
4373 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4374 if (status < 0)
4375 goto xdr_error;
4376 fattr->valid |= status;
4378 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4379 if (status < 0)
4380 goto xdr_error;
4381 fattr->valid |= status;
4383 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4384 if (status < 0)
4385 goto xdr_error;
4386 fattr->valid |= status;
4388 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4389 if (status < 0)
4390 goto xdr_error;
4391 fattr->valid |= status;
4393 xdr_error:
4394 dprintk("%s: xdr returned %d\n", __func__, -status);
4395 return status;
4398 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4399 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4401 __be32 *savep;
4402 uint32_t attrlen,
4403 bitmap[3] = {0};
4404 int status;
4406 status = decode_op_hdr(xdr, OP_GETATTR);
4407 if (status < 0)
4408 goto xdr_error;
4410 status = decode_attr_bitmap(xdr, bitmap);
4411 if (status < 0)
4412 goto xdr_error;
4414 status = decode_attr_length(xdr, &attrlen, &savep);
4415 if (status < 0)
4416 goto xdr_error;
4418 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4419 if (status < 0)
4420 goto xdr_error;
4422 status = verify_attr_len(xdr, savep, attrlen);
4423 xdr_error:
4424 dprintk("%s: xdr returned %d\n", __func__, -status);
4425 return status;
4428 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4429 const struct nfs_server *server, int may_sleep)
4431 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4435 * Decode potentially multiple layout types. Currently we only support
4436 * one layout driver per file system.
4438 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4439 uint32_t *layouttype)
4441 uint32_t *p;
4442 int num;
4444 p = xdr_inline_decode(xdr, 4);
4445 if (unlikely(!p))
4446 goto out_overflow;
4447 num = be32_to_cpup(p);
4449 /* pNFS is not supported by the underlying file system */
4450 if (num == 0) {
4451 *layouttype = 0;
4452 return 0;
4454 if (num > 1)
4455 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4456 "per filesystem not supported\n", __func__);
4458 /* Decode and set first layout type, move xdr->p past unused types */
4459 p = xdr_inline_decode(xdr, num * 4);
4460 if (unlikely(!p))
4461 goto out_overflow;
4462 *layouttype = be32_to_cpup(p);
4463 return 0;
4464 out_overflow:
4465 print_overflow_msg(__func__, xdr);
4466 return -EIO;
4470 * The type of file system exported.
4471 * Note we must ensure that layouttype is set in any non-error case.
4473 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4474 uint32_t *layouttype)
4476 int status = 0;
4478 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4479 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4480 return -EIO;
4481 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4482 status = decode_first_pnfs_layout_type(xdr, layouttype);
4483 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4484 } else
4485 *layouttype = 0;
4486 return status;
4490 * The prefered block size for layout directed io
4492 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4493 uint32_t *res)
4495 __be32 *p;
4497 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4498 *res = 0;
4499 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4500 p = xdr_inline_decode(xdr, 4);
4501 if (unlikely(!p)) {
4502 print_overflow_msg(__func__, xdr);
4503 return -EIO;
4505 *res = be32_to_cpup(p);
4506 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4508 return 0;
4511 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4513 __be32 *savep;
4514 uint32_t attrlen, bitmap[3];
4515 int status;
4517 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4518 goto xdr_error;
4519 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4520 goto xdr_error;
4521 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4522 goto xdr_error;
4524 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4526 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4527 goto xdr_error;
4528 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4529 goto xdr_error;
4530 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4531 goto xdr_error;
4532 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4533 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4534 goto xdr_error;
4535 fsinfo->wtpref = fsinfo->wtmax;
4536 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4537 if (status != 0)
4538 goto xdr_error;
4539 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4540 if (status != 0)
4541 goto xdr_error;
4542 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4543 if (status)
4544 goto xdr_error;
4546 status = verify_attr_len(xdr, savep, attrlen);
4547 xdr_error:
4548 dprintk("%s: xdr returned %d!\n", __func__, -status);
4549 return status;
4552 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4554 __be32 *p;
4555 uint32_t len;
4556 int status;
4558 /* Zero handle first to allow comparisons */
4559 memset(fh, 0, sizeof(*fh));
4561 status = decode_op_hdr(xdr, OP_GETFH);
4562 if (status)
4563 return status;
4565 p = xdr_inline_decode(xdr, 4);
4566 if (unlikely(!p))
4567 goto out_overflow;
4568 len = be32_to_cpup(p);
4569 if (len > NFS4_FHSIZE)
4570 return -EIO;
4571 fh->size = len;
4572 p = xdr_inline_decode(xdr, len);
4573 if (unlikely(!p))
4574 goto out_overflow;
4575 memcpy(fh->data, p, len);
4576 return 0;
4577 out_overflow:
4578 print_overflow_msg(__func__, xdr);
4579 return -EIO;
4582 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4584 int status;
4586 status = decode_op_hdr(xdr, OP_LINK);
4587 if (status)
4588 return status;
4589 return decode_change_info(xdr, cinfo);
4593 * We create the owner, so we know a proper owner.id length is 4.
4595 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4597 uint64_t offset, length, clientid;
4598 __be32 *p;
4599 uint32_t namelen, type;
4601 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4602 if (unlikely(!p))
4603 goto out_overflow;
4604 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4605 p = xdr_decode_hyper(p, &length);
4606 type = be32_to_cpup(p++); /* 4 byte read */
4607 if (fl != NULL) { /* manipulate file lock */
4608 fl->fl_start = (loff_t)offset;
4609 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4610 if (length == ~(uint64_t)0)
4611 fl->fl_end = OFFSET_MAX;
4612 fl->fl_type = F_WRLCK;
4613 if (type & 1)
4614 fl->fl_type = F_RDLCK;
4615 fl->fl_pid = 0;
4617 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4618 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4619 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4620 if (likely(p))
4621 return -NFS4ERR_DENIED;
4622 out_overflow:
4623 print_overflow_msg(__func__, xdr);
4624 return -EIO;
4627 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4629 int status;
4631 status = decode_op_hdr(xdr, OP_LOCK);
4632 if (status == -EIO)
4633 goto out;
4634 if (status == 0) {
4635 status = decode_stateid(xdr, &res->stateid);
4636 if (unlikely(status))
4637 goto out;
4638 } else if (status == -NFS4ERR_DENIED)
4639 status = decode_lock_denied(xdr, NULL);
4640 if (res->open_seqid != NULL)
4641 nfs_increment_open_seqid(status, res->open_seqid);
4642 nfs_increment_lock_seqid(status, res->lock_seqid);
4643 out:
4644 return status;
4647 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4649 int status;
4650 status = decode_op_hdr(xdr, OP_LOCKT);
4651 if (status == -NFS4ERR_DENIED)
4652 return decode_lock_denied(xdr, res->denied);
4653 return status;
4656 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4658 int status;
4660 status = decode_op_hdr(xdr, OP_LOCKU);
4661 if (status != -EIO)
4662 nfs_increment_lock_seqid(status, res->seqid);
4663 if (status == 0)
4664 status = decode_stateid(xdr, &res->stateid);
4665 return status;
4668 static int decode_release_lockowner(struct xdr_stream *xdr)
4670 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4673 static int decode_lookup(struct xdr_stream *xdr)
4675 return decode_op_hdr(xdr, OP_LOOKUP);
4678 /* This is too sick! */
4679 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4681 __be32 *p;
4682 uint32_t limit_type, nblocks, blocksize;
4684 p = xdr_inline_decode(xdr, 12);
4685 if (unlikely(!p))
4686 goto out_overflow;
4687 limit_type = be32_to_cpup(p++);
4688 switch (limit_type) {
4689 case 1:
4690 xdr_decode_hyper(p, maxsize);
4691 break;
4692 case 2:
4693 nblocks = be32_to_cpup(p++);
4694 blocksize = be32_to_cpup(p);
4695 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4697 return 0;
4698 out_overflow:
4699 print_overflow_msg(__func__, xdr);
4700 return -EIO;
4703 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4705 __be32 *p;
4706 uint32_t delegation_type;
4707 int status;
4709 p = xdr_inline_decode(xdr, 4);
4710 if (unlikely(!p))
4711 goto out_overflow;
4712 delegation_type = be32_to_cpup(p);
4713 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4714 res->delegation_type = 0;
4715 return 0;
4717 status = decode_stateid(xdr, &res->delegation);
4718 if (unlikely(status))
4719 return status;
4720 p = xdr_inline_decode(xdr, 4);
4721 if (unlikely(!p))
4722 goto out_overflow;
4723 res->do_recall = be32_to_cpup(p);
4725 switch (delegation_type) {
4726 case NFS4_OPEN_DELEGATE_READ:
4727 res->delegation_type = FMODE_READ;
4728 break;
4729 case NFS4_OPEN_DELEGATE_WRITE:
4730 res->delegation_type = FMODE_WRITE|FMODE_READ;
4731 if (decode_space_limit(xdr, &res->maxsize) < 0)
4732 return -EIO;
4734 return decode_ace(xdr, NULL, res->server->nfs_client);
4735 out_overflow:
4736 print_overflow_msg(__func__, xdr);
4737 return -EIO;
4740 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4742 __be32 *p;
4743 uint32_t savewords, bmlen, i;
4744 int status;
4746 status = decode_op_hdr(xdr, OP_OPEN);
4747 if (status != -EIO)
4748 nfs_increment_open_seqid(status, res->seqid);
4749 if (!status)
4750 status = decode_stateid(xdr, &res->stateid);
4751 if (unlikely(status))
4752 return status;
4754 decode_change_info(xdr, &res->cinfo);
4756 p = xdr_inline_decode(xdr, 8);
4757 if (unlikely(!p))
4758 goto out_overflow;
4759 res->rflags = be32_to_cpup(p++);
4760 bmlen = be32_to_cpup(p);
4761 if (bmlen > 10)
4762 goto xdr_error;
4764 p = xdr_inline_decode(xdr, bmlen << 2);
4765 if (unlikely(!p))
4766 goto out_overflow;
4767 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4768 for (i = 0; i < savewords; ++i)
4769 res->attrset[i] = be32_to_cpup(p++);
4770 for (; i < NFS4_BITMAP_SIZE; i++)
4771 res->attrset[i] = 0;
4773 return decode_delegation(xdr, res);
4774 xdr_error:
4775 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
4776 return -EIO;
4777 out_overflow:
4778 print_overflow_msg(__func__, xdr);
4779 return -EIO;
4782 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4784 int status;
4786 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4787 if (status != -EIO)
4788 nfs_increment_open_seqid(status, res->seqid);
4789 if (!status)
4790 status = decode_stateid(xdr, &res->stateid);
4791 return status;
4794 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4796 int status;
4798 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4799 if (status != -EIO)
4800 nfs_increment_open_seqid(status, res->seqid);
4801 if (!status)
4802 status = decode_stateid(xdr, &res->stateid);
4803 return status;
4806 static int decode_putfh(struct xdr_stream *xdr)
4808 return decode_op_hdr(xdr, OP_PUTFH);
4811 static int decode_putrootfh(struct xdr_stream *xdr)
4813 return decode_op_hdr(xdr, OP_PUTROOTFH);
4816 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4818 struct kvec *iov = req->rq_rcv_buf.head;
4819 __be32 *p;
4820 uint32_t count, eof, recvd, hdrlen;
4821 int status;
4823 status = decode_op_hdr(xdr, OP_READ);
4824 if (status)
4825 return status;
4826 p = xdr_inline_decode(xdr, 8);
4827 if (unlikely(!p))
4828 goto out_overflow;
4829 eof = be32_to_cpup(p++);
4830 count = be32_to_cpup(p);
4831 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
4832 recvd = req->rq_rcv_buf.len - hdrlen;
4833 if (count > recvd) {
4834 dprintk("NFS: server cheating in read reply: "
4835 "count %u > recvd %u\n", count, recvd);
4836 count = recvd;
4837 eof = 0;
4839 xdr_read_pages(xdr, count);
4840 res->eof = eof;
4841 res->count = count;
4842 return 0;
4843 out_overflow:
4844 print_overflow_msg(__func__, xdr);
4845 return -EIO;
4848 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4850 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4851 struct kvec *iov = rcvbuf->head;
4852 size_t hdrlen;
4853 u32 recvd, pglen = rcvbuf->page_len;
4854 int status;
4856 status = decode_op_hdr(xdr, OP_READDIR);
4857 if (!status)
4858 status = decode_verifier(xdr, readdir->verifier.data);
4859 if (unlikely(status))
4860 return status;
4861 dprintk("%s: verifier = %08x:%08x\n",
4862 __func__,
4863 ((u32 *)readdir->verifier.data)[0],
4864 ((u32 *)readdir->verifier.data)[1]);
4867 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4868 recvd = rcvbuf->len - hdrlen;
4869 if (pglen > recvd)
4870 pglen = recvd;
4871 xdr_read_pages(xdr, pglen);
4874 return pglen;
4877 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4879 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4880 struct kvec *iov = rcvbuf->head;
4881 size_t hdrlen;
4882 u32 len, recvd;
4883 __be32 *p;
4884 int status;
4886 status = decode_op_hdr(xdr, OP_READLINK);
4887 if (status)
4888 return status;
4890 /* Convert length of symlink */
4891 p = xdr_inline_decode(xdr, 4);
4892 if (unlikely(!p))
4893 goto out_overflow;
4894 len = be32_to_cpup(p);
4895 if (len >= rcvbuf->page_len || len <= 0) {
4896 dprintk("nfs: server returned giant symlink!\n");
4897 return -ENAMETOOLONG;
4899 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4900 recvd = req->rq_rcv_buf.len - hdrlen;
4901 if (recvd < len) {
4902 dprintk("NFS: server cheating in readlink reply: "
4903 "count %u > recvd %u\n", len, recvd);
4904 return -EIO;
4906 xdr_read_pages(xdr, len);
4908 * The XDR encode routine has set things up so that
4909 * the link text will be copied directly into the
4910 * buffer. We just have to do overflow-checking,
4911 * and and null-terminate the text (the VFS expects
4912 * null-termination).
4914 xdr_terminate_string(rcvbuf, len);
4915 return 0;
4916 out_overflow:
4917 print_overflow_msg(__func__, xdr);
4918 return -EIO;
4921 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4923 int status;
4925 status = decode_op_hdr(xdr, OP_REMOVE);
4926 if (status)
4927 goto out;
4928 status = decode_change_info(xdr, cinfo);
4929 out:
4930 return status;
4933 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4934 struct nfs4_change_info *new_cinfo)
4936 int status;
4938 status = decode_op_hdr(xdr, OP_RENAME);
4939 if (status)
4940 goto out;
4941 if ((status = decode_change_info(xdr, old_cinfo)))
4942 goto out;
4943 status = decode_change_info(xdr, new_cinfo);
4944 out:
4945 return status;
4948 static int decode_renew(struct xdr_stream *xdr)
4950 return decode_op_hdr(xdr, OP_RENEW);
4953 static int
4954 decode_restorefh(struct xdr_stream *xdr)
4956 return decode_op_hdr(xdr, OP_RESTOREFH);
4959 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4960 size_t *acl_len)
4962 __be32 *savep;
4963 uint32_t attrlen,
4964 bitmap[3] = {0};
4965 struct kvec *iov = req->rq_rcv_buf.head;
4966 int status;
4968 *acl_len = 0;
4969 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4970 goto out;
4971 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4972 goto out;
4973 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4974 goto out;
4976 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4977 return -EIO;
4978 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
4979 size_t hdrlen;
4980 u32 recvd;
4982 /* We ignore &savep and don't do consistency checks on
4983 * the attr length. Let userspace figure it out.... */
4984 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4985 recvd = req->rq_rcv_buf.len - hdrlen;
4986 if (attrlen > recvd) {
4987 dprintk("NFS: server cheating in getattr"
4988 " acl reply: attrlen %u > recvd %u\n",
4989 attrlen, recvd);
4990 return -EINVAL;
4992 xdr_read_pages(xdr, attrlen);
4993 *acl_len = attrlen;
4994 } else
4995 status = -EOPNOTSUPP;
4997 out:
4998 return status;
5001 static int
5002 decode_savefh(struct xdr_stream *xdr)
5004 return decode_op_hdr(xdr, OP_SAVEFH);
5007 static int decode_setattr(struct xdr_stream *xdr)
5009 __be32 *p;
5010 uint32_t bmlen;
5011 int status;
5013 status = decode_op_hdr(xdr, OP_SETATTR);
5014 if (status)
5015 return status;
5016 p = xdr_inline_decode(xdr, 4);
5017 if (unlikely(!p))
5018 goto out_overflow;
5019 bmlen = be32_to_cpup(p);
5020 p = xdr_inline_decode(xdr, bmlen << 2);
5021 if (likely(p))
5022 return 0;
5023 out_overflow:
5024 print_overflow_msg(__func__, xdr);
5025 return -EIO;
5028 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5030 __be32 *p;
5031 uint32_t opnum;
5032 int32_t nfserr;
5034 p = xdr_inline_decode(xdr, 8);
5035 if (unlikely(!p))
5036 goto out_overflow;
5037 opnum = be32_to_cpup(p++);
5038 if (opnum != OP_SETCLIENTID) {
5039 dprintk("nfs: decode_setclientid: Server returned operation"
5040 " %d\n", opnum);
5041 return -EIO;
5043 nfserr = be32_to_cpup(p);
5044 if (nfserr == NFS_OK) {
5045 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5046 if (unlikely(!p))
5047 goto out_overflow;
5048 p = xdr_decode_hyper(p, &res->clientid);
5049 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5050 } else if (nfserr == NFSERR_CLID_INUSE) {
5051 uint32_t len;
5053 /* skip netid string */
5054 p = xdr_inline_decode(xdr, 4);
5055 if (unlikely(!p))
5056 goto out_overflow;
5057 len = be32_to_cpup(p);
5058 p = xdr_inline_decode(xdr, len);
5059 if (unlikely(!p))
5060 goto out_overflow;
5062 /* skip uaddr string */
5063 p = xdr_inline_decode(xdr, 4);
5064 if (unlikely(!p))
5065 goto out_overflow;
5066 len = be32_to_cpup(p);
5067 p = xdr_inline_decode(xdr, len);
5068 if (unlikely(!p))
5069 goto out_overflow;
5070 return -NFSERR_CLID_INUSE;
5071 } else
5072 return nfs4_stat_to_errno(nfserr);
5074 return 0;
5075 out_overflow:
5076 print_overflow_msg(__func__, xdr);
5077 return -EIO;
5080 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5082 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5085 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5087 __be32 *p;
5088 int status;
5090 status = decode_op_hdr(xdr, OP_WRITE);
5091 if (status)
5092 return status;
5094 p = xdr_inline_decode(xdr, 16);
5095 if (unlikely(!p))
5096 goto out_overflow;
5097 res->count = be32_to_cpup(p++);
5098 res->verf->committed = be32_to_cpup(p++);
5099 memcpy(res->verf->verifier, p, 8);
5100 return 0;
5101 out_overflow:
5102 print_overflow_msg(__func__, xdr);
5103 return -EIO;
5106 static int decode_delegreturn(struct xdr_stream *xdr)
5108 return decode_op_hdr(xdr, OP_DELEGRETURN);
5111 static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5113 __be32 *p;
5115 p = xdr_inline_decode(xdr, 4);
5116 if (unlikely(!p))
5117 goto out_overflow;
5118 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5119 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5120 goto out_err;
5122 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5123 if (unlikely(!p))
5124 goto out_overflow;
5125 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5127 p = xdr_inline_decode(xdr, 8);
5128 if (unlikely(!p))
5129 goto out_overflow;
5130 flavor->gss.qop4 = be32_to_cpup(p++);
5131 flavor->gss.service = be32_to_cpup(p);
5133 return 0;
5135 out_overflow:
5136 print_overflow_msg(__func__, xdr);
5137 return -EIO;
5138 out_err:
5139 return -EINVAL;
5142 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5144 struct nfs4_secinfo_flavor *sec_flavor;
5145 int status;
5146 __be32 *p;
5147 int i, num_flavors;
5149 status = decode_op_hdr(xdr, OP_SECINFO);
5150 if (status)
5151 goto out;
5152 p = xdr_inline_decode(xdr, 4);
5153 if (unlikely(!p))
5154 goto out_overflow;
5156 res->flavors->num_flavors = 0;
5157 num_flavors = be32_to_cpup(p);
5159 for (i = 0; i < num_flavors; i++) {
5160 sec_flavor = &res->flavors->flavors[i];
5161 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5162 break;
5164 p = xdr_inline_decode(xdr, 4);
5165 if (unlikely(!p))
5166 goto out_overflow;
5167 sec_flavor->flavor = be32_to_cpup(p);
5169 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5170 status = decode_secinfo_gss(xdr, sec_flavor);
5171 if (status)
5172 goto out;
5174 res->flavors->num_flavors++;
5177 out:
5178 return status;
5179 out_overflow:
5180 print_overflow_msg(__func__, xdr);
5181 return -EIO;
5184 #if defined(CONFIG_NFS_V4_1)
5185 static int decode_exchange_id(struct xdr_stream *xdr,
5186 struct nfs41_exchange_id_res *res)
5188 __be32 *p;
5189 uint32_t dummy;
5190 char *dummy_str;
5191 int status;
5192 struct nfs_client *clp = res->client;
5194 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5195 if (status)
5196 return status;
5198 p = xdr_inline_decode(xdr, 8);
5199 if (unlikely(!p))
5200 goto out_overflow;
5201 xdr_decode_hyper(p, &clp->cl_clientid);
5202 p = xdr_inline_decode(xdr, 12);
5203 if (unlikely(!p))
5204 goto out_overflow;
5205 clp->cl_seqid = be32_to_cpup(p++);
5206 clp->cl_exchange_flags = be32_to_cpup(p++);
5208 /* We ask for SP4_NONE */
5209 dummy = be32_to_cpup(p);
5210 if (dummy != SP4_NONE)
5211 return -EIO;
5213 /* Throw away minor_id */
5214 p = xdr_inline_decode(xdr, 8);
5215 if (unlikely(!p))
5216 goto out_overflow;
5218 /* Throw away Major id */
5219 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5220 if (unlikely(status))
5221 return status;
5223 /* Save server_scope */
5224 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5225 if (unlikely(status))
5226 return status;
5228 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5229 return -EIO;
5231 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5232 res->server_scope->server_scope_sz = dummy;
5234 /* Throw away Implementation id array */
5235 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5236 if (unlikely(status))
5237 return status;
5239 return 0;
5240 out_overflow:
5241 print_overflow_msg(__func__, xdr);
5242 return -EIO;
5245 static int decode_chan_attrs(struct xdr_stream *xdr,
5246 struct nfs4_channel_attrs *attrs)
5248 __be32 *p;
5249 u32 nr_attrs, val;
5251 p = xdr_inline_decode(xdr, 28);
5252 if (unlikely(!p))
5253 goto out_overflow;
5254 val = be32_to_cpup(p++); /* headerpadsz */
5255 if (val)
5256 return -EINVAL; /* no support for header padding yet */
5257 attrs->max_rqst_sz = be32_to_cpup(p++);
5258 attrs->max_resp_sz = be32_to_cpup(p++);
5259 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5260 attrs->max_ops = be32_to_cpup(p++);
5261 attrs->max_reqs = be32_to_cpup(p++);
5262 nr_attrs = be32_to_cpup(p);
5263 if (unlikely(nr_attrs > 1)) {
5264 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5265 __func__, nr_attrs);
5266 return -EINVAL;
5268 if (nr_attrs == 1) {
5269 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5270 if (unlikely(!p))
5271 goto out_overflow;
5273 return 0;
5274 out_overflow:
5275 print_overflow_msg(__func__, xdr);
5276 return -EIO;
5279 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5281 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5284 static int decode_create_session(struct xdr_stream *xdr,
5285 struct nfs41_create_session_res *res)
5287 __be32 *p;
5288 int status;
5289 struct nfs_client *clp = res->client;
5290 struct nfs4_session *session = clp->cl_session;
5292 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5293 if (!status)
5294 status = decode_sessionid(xdr, &session->sess_id);
5295 if (unlikely(status))
5296 return status;
5298 /* seqid, flags */
5299 p = xdr_inline_decode(xdr, 8);
5300 if (unlikely(!p))
5301 goto out_overflow;
5302 clp->cl_seqid = be32_to_cpup(p++);
5303 session->flags = be32_to_cpup(p);
5305 /* Channel attributes */
5306 status = decode_chan_attrs(xdr, &session->fc_attrs);
5307 if (!status)
5308 status = decode_chan_attrs(xdr, &session->bc_attrs);
5309 return status;
5310 out_overflow:
5311 print_overflow_msg(__func__, xdr);
5312 return -EIO;
5315 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5317 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5320 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5322 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5324 #endif /* CONFIG_NFS_V4_1 */
5326 static int decode_sequence(struct xdr_stream *xdr,
5327 struct nfs4_sequence_res *res,
5328 struct rpc_rqst *rqstp)
5330 #if defined(CONFIG_NFS_V4_1)
5331 struct nfs4_sessionid id;
5332 u32 dummy;
5333 int status;
5334 __be32 *p;
5336 if (!res->sr_session)
5337 return 0;
5339 status = decode_op_hdr(xdr, OP_SEQUENCE);
5340 if (!status)
5341 status = decode_sessionid(xdr, &id);
5342 if (unlikely(status))
5343 goto out_err;
5346 * If the server returns different values for sessionID, slotID or
5347 * sequence number, the server is looney tunes.
5349 status = -EREMOTEIO;
5351 if (memcmp(id.data, res->sr_session->sess_id.data,
5352 NFS4_MAX_SESSIONID_LEN)) {
5353 dprintk("%s Invalid session id\n", __func__);
5354 goto out_err;
5357 p = xdr_inline_decode(xdr, 20);
5358 if (unlikely(!p))
5359 goto out_overflow;
5361 /* seqid */
5362 dummy = be32_to_cpup(p++);
5363 if (dummy != res->sr_slot->seq_nr) {
5364 dprintk("%s Invalid sequence number\n", __func__);
5365 goto out_err;
5367 /* slot id */
5368 dummy = be32_to_cpup(p++);
5369 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
5370 dprintk("%s Invalid slot id\n", __func__);
5371 goto out_err;
5373 /* highest slot id - currently not processed */
5374 dummy = be32_to_cpup(p++);
5375 /* target highest slot id - currently not processed */
5376 dummy = be32_to_cpup(p++);
5377 /* result flags */
5378 res->sr_status_flags = be32_to_cpup(p);
5379 status = 0;
5380 out_err:
5381 res->sr_status = status;
5382 return status;
5383 out_overflow:
5384 print_overflow_msg(__func__, xdr);
5385 status = -EIO;
5386 goto out_err;
5387 #else /* CONFIG_NFS_V4_1 */
5388 return 0;
5389 #endif /* CONFIG_NFS_V4_1 */
5392 #if defined(CONFIG_NFS_V4_1)
5394 * TODO: Need to handle case when EOF != true;
5396 static int decode_getdevicelist(struct xdr_stream *xdr,
5397 struct pnfs_devicelist *res)
5399 __be32 *p;
5400 int status, i;
5401 struct nfs_writeverf verftemp;
5403 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5404 if (status)
5405 return status;
5407 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5408 if (unlikely(!p))
5409 goto out_overflow;
5411 /* TODO: Skip cookie for now */
5412 p += 2;
5414 /* Read verifier */
5415 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5417 res->num_devs = be32_to_cpup(p);
5419 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5421 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5422 printk(KERN_ERR "%s too many result dev_num %u\n",
5423 __func__, res->num_devs);
5424 return -EIO;
5427 p = xdr_inline_decode(xdr,
5428 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5429 if (unlikely(!p))
5430 goto out_overflow;
5431 for (i = 0; i < res->num_devs; i++)
5432 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5433 NFS4_DEVICEID4_SIZE);
5434 res->eof = be32_to_cpup(p);
5435 return 0;
5436 out_overflow:
5437 print_overflow_msg(__func__, xdr);
5438 return -EIO;
5441 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5442 struct pnfs_device *pdev)
5444 __be32 *p;
5445 uint32_t len, type;
5446 int status;
5448 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5449 if (status) {
5450 if (status == -ETOOSMALL) {
5451 p = xdr_inline_decode(xdr, 4);
5452 if (unlikely(!p))
5453 goto out_overflow;
5454 pdev->mincount = be32_to_cpup(p);
5455 dprintk("%s: Min count too small. mincnt = %u\n",
5456 __func__, pdev->mincount);
5458 return status;
5461 p = xdr_inline_decode(xdr, 8);
5462 if (unlikely(!p))
5463 goto out_overflow;
5464 type = be32_to_cpup(p++);
5465 if (type != pdev->layout_type) {
5466 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5467 __func__, pdev->layout_type, type);
5468 return -EINVAL;
5471 * Get the length of the opaque device_addr4. xdr_read_pages places
5472 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5473 * and places the remaining xdr data in xdr_buf->tail
5475 pdev->mincount = be32_to_cpup(p);
5476 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5478 /* Parse notification bitmap, verifying that it is zero. */
5479 p = xdr_inline_decode(xdr, 4);
5480 if (unlikely(!p))
5481 goto out_overflow;
5482 len = be32_to_cpup(p);
5483 if (len) {
5484 uint32_t i;
5486 p = xdr_inline_decode(xdr, 4 * len);
5487 if (unlikely(!p))
5488 goto out_overflow;
5489 for (i = 0; i < len; i++, p++) {
5490 if (be32_to_cpup(p)) {
5491 dprintk("%s: notifications not supported\n",
5492 __func__);
5493 return -EIO;
5497 return 0;
5498 out_overflow:
5499 print_overflow_msg(__func__, xdr);
5500 return -EIO;
5503 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5504 struct nfs4_layoutget_res *res)
5506 __be32 *p;
5507 int status;
5508 u32 layout_count;
5509 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5510 struct kvec *iov = rcvbuf->head;
5511 u32 hdrlen, recvd;
5513 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5514 if (status)
5515 return status;
5516 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5517 if (unlikely(!p))
5518 goto out_overflow;
5519 res->return_on_close = be32_to_cpup(p++);
5520 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5521 layout_count = be32_to_cpup(p);
5522 if (!layout_count) {
5523 dprintk("%s: server responded with empty layout array\n",
5524 __func__);
5525 return -EINVAL;
5528 p = xdr_inline_decode(xdr, 28);
5529 if (unlikely(!p))
5530 goto out_overflow;
5531 p = xdr_decode_hyper(p, &res->range.offset);
5532 p = xdr_decode_hyper(p, &res->range.length);
5533 res->range.iomode = be32_to_cpup(p++);
5534 res->type = be32_to_cpup(p++);
5535 res->layoutp->len = be32_to_cpup(p);
5537 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5538 __func__,
5539 (unsigned long)res->range.offset,
5540 (unsigned long)res->range.length,
5541 res->range.iomode,
5542 res->type,
5543 res->layoutp->len);
5545 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5546 recvd = req->rq_rcv_buf.len - hdrlen;
5547 if (res->layoutp->len > recvd) {
5548 dprintk("NFS: server cheating in layoutget reply: "
5549 "layout len %u > recvd %u\n",
5550 res->layoutp->len, recvd);
5551 return -EINVAL;
5554 xdr_read_pages(xdr, res->layoutp->len);
5556 if (layout_count > 1) {
5557 /* We only handle a length one array at the moment. Any
5558 * further entries are just ignored. Note that this means
5559 * the client may see a response that is less than the
5560 * minimum it requested.
5562 dprintk("%s: server responded with %d layouts, dropping tail\n",
5563 __func__, layout_count);
5566 return 0;
5567 out_overflow:
5568 print_overflow_msg(__func__, xdr);
5569 return -EIO;
5572 static int decode_layoutreturn(struct xdr_stream *xdr,
5573 struct nfs4_layoutreturn_res *res)
5575 __be32 *p;
5576 int status;
5578 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5579 if (status)
5580 return status;
5581 p = xdr_inline_decode(xdr, 4);
5582 if (unlikely(!p))
5583 goto out_overflow;
5584 res->lrs_present = be32_to_cpup(p);
5585 if (res->lrs_present)
5586 status = decode_stateid(xdr, &res->stateid);
5587 return status;
5588 out_overflow:
5589 print_overflow_msg(__func__, xdr);
5590 return -EIO;
5593 static int decode_layoutcommit(struct xdr_stream *xdr,
5594 struct rpc_rqst *req,
5595 struct nfs4_layoutcommit_res *res)
5597 __be32 *p;
5598 __u32 sizechanged;
5599 int status;
5601 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5602 res->status = status;
5603 if (status)
5604 return status;
5606 p = xdr_inline_decode(xdr, 4);
5607 if (unlikely(!p))
5608 goto out_overflow;
5609 sizechanged = be32_to_cpup(p);
5611 if (sizechanged) {
5612 /* throw away new size */
5613 p = xdr_inline_decode(xdr, 8);
5614 if (unlikely(!p))
5615 goto out_overflow;
5617 return 0;
5618 out_overflow:
5619 print_overflow_msg(__func__, xdr);
5620 return -EIO;
5623 static int decode_test_stateid(struct xdr_stream *xdr,
5624 struct nfs41_test_stateid_res *res)
5626 __be32 *p;
5627 int status;
5628 int num_res;
5630 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5631 if (status)
5632 return status;
5634 p = xdr_inline_decode(xdr, 4);
5635 if (unlikely(!p))
5636 goto out_overflow;
5637 num_res = be32_to_cpup(p++);
5638 if (num_res != 1)
5639 goto out;
5641 p = xdr_inline_decode(xdr, 4);
5642 if (unlikely(!p))
5643 goto out_overflow;
5644 res->status = be32_to_cpup(p++);
5645 return res->status;
5646 out_overflow:
5647 print_overflow_msg(__func__, xdr);
5648 out:
5649 return -EIO;
5652 static int decode_free_stateid(struct xdr_stream *xdr,
5653 struct nfs41_free_stateid_res *res)
5655 __be32 *p;
5656 int status;
5658 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5659 if (status)
5660 return status;
5662 p = xdr_inline_decode(xdr, 4);
5663 if (unlikely(!p))
5664 goto out_overflow;
5665 res->status = be32_to_cpup(p++);
5666 return res->status;
5667 out_overflow:
5668 print_overflow_msg(__func__, xdr);
5669 return -EIO;
5671 #endif /* CONFIG_NFS_V4_1 */
5674 * END OF "GENERIC" DECODE ROUTINES.
5678 * Decode OPEN_DOWNGRADE response
5680 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5681 struct xdr_stream *xdr,
5682 struct nfs_closeres *res)
5684 struct compound_hdr hdr;
5685 int status;
5687 status = decode_compound_hdr(xdr, &hdr);
5688 if (status)
5689 goto out;
5690 status = decode_sequence(xdr, &res->seq_res, rqstp);
5691 if (status)
5692 goto out;
5693 status = decode_putfh(xdr);
5694 if (status)
5695 goto out;
5696 status = decode_open_downgrade(xdr, res);
5697 if (status != 0)
5698 goto out;
5699 decode_getfattr(xdr, res->fattr, res->server,
5700 !RPC_IS_ASYNC(rqstp->rq_task));
5701 out:
5702 return status;
5706 * Decode ACCESS response
5708 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5709 struct nfs4_accessres *res)
5711 struct compound_hdr hdr;
5712 int status;
5714 status = decode_compound_hdr(xdr, &hdr);
5715 if (status)
5716 goto out;
5717 status = decode_sequence(xdr, &res->seq_res, rqstp);
5718 if (status)
5719 goto out;
5720 status = decode_putfh(xdr);
5721 if (status != 0)
5722 goto out;
5723 status = decode_access(xdr, res);
5724 if (status != 0)
5725 goto out;
5726 decode_getfattr(xdr, res->fattr, res->server,
5727 !RPC_IS_ASYNC(rqstp->rq_task));
5728 out:
5729 return status;
5733 * Decode LOOKUP response
5735 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5736 struct nfs4_lookup_res *res)
5738 struct compound_hdr hdr;
5739 int status;
5741 status = decode_compound_hdr(xdr, &hdr);
5742 if (status)
5743 goto out;
5744 status = decode_sequence(xdr, &res->seq_res, rqstp);
5745 if (status)
5746 goto out;
5747 status = decode_putfh(xdr);
5748 if (status)
5749 goto out;
5750 status = decode_lookup(xdr);
5751 if (status)
5752 goto out;
5753 status = decode_getfh(xdr, res->fh);
5754 if (status)
5755 goto out;
5756 status = decode_getfattr(xdr, res->fattr, res->server
5757 ,!RPC_IS_ASYNC(rqstp->rq_task));
5758 out:
5759 return status;
5763 * Decode LOOKUP_ROOT response
5765 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5766 struct xdr_stream *xdr,
5767 struct nfs4_lookup_res *res)
5769 struct compound_hdr hdr;
5770 int status;
5772 status = decode_compound_hdr(xdr, &hdr);
5773 if (status)
5774 goto out;
5775 status = decode_sequence(xdr, &res->seq_res, rqstp);
5776 if (status)
5777 goto out;
5778 status = decode_putrootfh(xdr);
5779 if (status)
5780 goto out;
5781 status = decode_getfh(xdr, res->fh);
5782 if (status == 0)
5783 status = decode_getfattr(xdr, res->fattr, res->server,
5784 !RPC_IS_ASYNC(rqstp->rq_task));
5785 out:
5786 return status;
5790 * Decode REMOVE response
5792 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5793 struct nfs_removeres *res)
5795 struct compound_hdr hdr;
5796 int status;
5798 status = decode_compound_hdr(xdr, &hdr);
5799 if (status)
5800 goto out;
5801 status = decode_sequence(xdr, &res->seq_res, rqstp);
5802 if (status)
5803 goto out;
5804 status = decode_putfh(xdr);
5805 if (status)
5806 goto out;
5807 status = decode_remove(xdr, &res->cinfo);
5808 if (status)
5809 goto out;
5810 decode_getfattr(xdr, res->dir_attr, res->server,
5811 !RPC_IS_ASYNC(rqstp->rq_task));
5812 out:
5813 return status;
5817 * Decode RENAME response
5819 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5820 struct nfs_renameres *res)
5822 struct compound_hdr hdr;
5823 int status;
5825 status = decode_compound_hdr(xdr, &hdr);
5826 if (status)
5827 goto out;
5828 status = decode_sequence(xdr, &res->seq_res, rqstp);
5829 if (status)
5830 goto out;
5831 status = decode_putfh(xdr);
5832 if (status)
5833 goto out;
5834 status = decode_savefh(xdr);
5835 if (status)
5836 goto out;
5837 status = decode_putfh(xdr);
5838 if (status)
5839 goto out;
5840 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5841 if (status)
5842 goto out;
5843 /* Current FH is target directory */
5844 if (decode_getfattr(xdr, res->new_fattr, res->server,
5845 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5846 goto out;
5847 status = decode_restorefh(xdr);
5848 if (status)
5849 goto out;
5850 decode_getfattr(xdr, res->old_fattr, res->server,
5851 !RPC_IS_ASYNC(rqstp->rq_task));
5852 out:
5853 return status;
5857 * Decode LINK response
5859 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5860 struct nfs4_link_res *res)
5862 struct compound_hdr hdr;
5863 int status;
5865 status = decode_compound_hdr(xdr, &hdr);
5866 if (status)
5867 goto out;
5868 status = decode_sequence(xdr, &res->seq_res, rqstp);
5869 if (status)
5870 goto out;
5871 status = decode_putfh(xdr);
5872 if (status)
5873 goto out;
5874 status = decode_savefh(xdr);
5875 if (status)
5876 goto out;
5877 status = decode_putfh(xdr);
5878 if (status)
5879 goto out;
5880 status = decode_link(xdr, &res->cinfo);
5881 if (status)
5882 goto out;
5884 * Note order: OP_LINK leaves the directory as the current
5885 * filehandle.
5887 if (decode_getfattr(xdr, res->dir_attr, res->server,
5888 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5889 goto out;
5890 status = decode_restorefh(xdr);
5891 if (status)
5892 goto out;
5893 decode_getfattr(xdr, res->fattr, res->server,
5894 !RPC_IS_ASYNC(rqstp->rq_task));
5895 out:
5896 return status;
5900 * Decode CREATE response
5902 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5903 struct nfs4_create_res *res)
5905 struct compound_hdr hdr;
5906 int status;
5908 status = decode_compound_hdr(xdr, &hdr);
5909 if (status)
5910 goto out;
5911 status = decode_sequence(xdr, &res->seq_res, rqstp);
5912 if (status)
5913 goto out;
5914 status = decode_putfh(xdr);
5915 if (status)
5916 goto out;
5917 status = decode_savefh(xdr);
5918 if (status)
5919 goto out;
5920 status = decode_create(xdr, &res->dir_cinfo);
5921 if (status)
5922 goto out;
5923 status = decode_getfh(xdr, res->fh);
5924 if (status)
5925 goto out;
5926 if (decode_getfattr(xdr, res->fattr, res->server,
5927 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5928 goto out;
5929 status = decode_restorefh(xdr);
5930 if (status)
5931 goto out;
5932 decode_getfattr(xdr, res->dir_fattr, res->server,
5933 !RPC_IS_ASYNC(rqstp->rq_task));
5934 out:
5935 return status;
5939 * Decode SYMLINK response
5941 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5942 struct nfs4_create_res *res)
5944 return nfs4_xdr_dec_create(rqstp, xdr, res);
5948 * Decode GETATTR response
5950 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5951 struct nfs4_getattr_res *res)
5953 struct compound_hdr hdr;
5954 int status;
5956 status = decode_compound_hdr(xdr, &hdr);
5957 if (status)
5958 goto out;
5959 status = decode_sequence(xdr, &res->seq_res, rqstp);
5960 if (status)
5961 goto out;
5962 status = decode_putfh(xdr);
5963 if (status)
5964 goto out;
5965 status = decode_getfattr(xdr, res->fattr, res->server,
5966 !RPC_IS_ASYNC(rqstp->rq_task));
5967 out:
5968 return status;
5972 * Encode an SETACL request
5974 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5975 struct nfs_setaclargs *args)
5977 struct compound_hdr hdr = {
5978 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
5981 encode_compound_hdr(xdr, req, &hdr);
5982 encode_sequence(xdr, &args->seq_args, &hdr);
5983 encode_putfh(xdr, args->fh, &hdr);
5984 encode_setacl(xdr, args, &hdr);
5985 encode_nops(&hdr);
5989 * Decode SETACL response
5991 static int
5992 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5993 struct nfs_setaclres *res)
5995 struct compound_hdr hdr;
5996 int status;
5998 status = decode_compound_hdr(xdr, &hdr);
5999 if (status)
6000 goto out;
6001 status = decode_sequence(xdr, &res->seq_res, rqstp);
6002 if (status)
6003 goto out;
6004 status = decode_putfh(xdr);
6005 if (status)
6006 goto out;
6007 status = decode_setattr(xdr);
6008 out:
6009 return status;
6013 * Decode GETACL response
6015 static int
6016 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6017 struct nfs_getaclres *res)
6019 struct compound_hdr hdr;
6020 int status;
6022 status = decode_compound_hdr(xdr, &hdr);
6023 if (status)
6024 goto out;
6025 status = decode_sequence(xdr, &res->seq_res, rqstp);
6026 if (status)
6027 goto out;
6028 status = decode_putfh(xdr);
6029 if (status)
6030 goto out;
6031 status = decode_getacl(xdr, rqstp, &res->acl_len);
6033 out:
6034 return status;
6038 * Decode CLOSE response
6040 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6041 struct nfs_closeres *res)
6043 struct compound_hdr hdr;
6044 int status;
6046 status = decode_compound_hdr(xdr, &hdr);
6047 if (status)
6048 goto out;
6049 status = decode_sequence(xdr, &res->seq_res, rqstp);
6050 if (status)
6051 goto out;
6052 status = decode_putfh(xdr);
6053 if (status)
6054 goto out;
6055 status = decode_close(xdr, res);
6056 if (status != 0)
6057 goto out;
6059 * Note: Server may do delete on close for this file
6060 * in which case the getattr call will fail with
6061 * an ESTALE error. Shouldn't be a problem,
6062 * though, since fattr->valid will remain unset.
6064 decode_getfattr(xdr, res->fattr, res->server,
6065 !RPC_IS_ASYNC(rqstp->rq_task));
6066 out:
6067 return status;
6071 * Decode OPEN response
6073 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6074 struct nfs_openres *res)
6076 struct compound_hdr hdr;
6077 int status;
6079 status = decode_compound_hdr(xdr, &hdr);
6080 if (status)
6081 goto out;
6082 status = decode_sequence(xdr, &res->seq_res, rqstp);
6083 if (status)
6084 goto out;
6085 status = decode_putfh(xdr);
6086 if (status)
6087 goto out;
6088 status = decode_savefh(xdr);
6089 if (status)
6090 goto out;
6091 status = decode_open(xdr, res);
6092 if (status)
6093 goto out;
6094 if (decode_getfh(xdr, &res->fh) != 0)
6095 goto out;
6096 if (decode_getfattr(xdr, res->f_attr, res->server,
6097 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
6098 goto out;
6099 if (decode_restorefh(xdr) != 0)
6100 goto out;
6101 decode_getfattr(xdr, res->dir_attr, res->server,
6102 !RPC_IS_ASYNC(rqstp->rq_task));
6103 out:
6104 return status;
6108 * Decode OPEN_CONFIRM response
6110 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6111 struct xdr_stream *xdr,
6112 struct nfs_open_confirmres *res)
6114 struct compound_hdr hdr;
6115 int status;
6117 status = decode_compound_hdr(xdr, &hdr);
6118 if (status)
6119 goto out;
6120 status = decode_putfh(xdr);
6121 if (status)
6122 goto out;
6123 status = decode_open_confirm(xdr, res);
6124 out:
6125 return status;
6129 * Decode OPEN response
6131 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6132 struct xdr_stream *xdr,
6133 struct nfs_openres *res)
6135 struct compound_hdr hdr;
6136 int status;
6138 status = decode_compound_hdr(xdr, &hdr);
6139 if (status)
6140 goto out;
6141 status = decode_sequence(xdr, &res->seq_res, rqstp);
6142 if (status)
6143 goto out;
6144 status = decode_putfh(xdr);
6145 if (status)
6146 goto out;
6147 status = decode_open(xdr, res);
6148 if (status)
6149 goto out;
6150 decode_getfattr(xdr, res->f_attr, res->server,
6151 !RPC_IS_ASYNC(rqstp->rq_task));
6152 out:
6153 return status;
6157 * Decode SETATTR response
6159 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6160 struct xdr_stream *xdr,
6161 struct nfs_setattrres *res)
6163 struct compound_hdr hdr;
6164 int status;
6166 status = decode_compound_hdr(xdr, &hdr);
6167 if (status)
6168 goto out;
6169 status = decode_sequence(xdr, &res->seq_res, rqstp);
6170 if (status)
6171 goto out;
6172 status = decode_putfh(xdr);
6173 if (status)
6174 goto out;
6175 status = decode_setattr(xdr);
6176 if (status)
6177 goto out;
6178 decode_getfattr(xdr, res->fattr, res->server,
6179 !RPC_IS_ASYNC(rqstp->rq_task));
6180 out:
6181 return status;
6185 * Decode LOCK response
6187 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6188 struct nfs_lock_res *res)
6190 struct compound_hdr hdr;
6191 int status;
6193 status = decode_compound_hdr(xdr, &hdr);
6194 if (status)
6195 goto out;
6196 status = decode_sequence(xdr, &res->seq_res, rqstp);
6197 if (status)
6198 goto out;
6199 status = decode_putfh(xdr);
6200 if (status)
6201 goto out;
6202 status = decode_lock(xdr, res);
6203 out:
6204 return status;
6208 * Decode LOCKT response
6210 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6211 struct nfs_lockt_res *res)
6213 struct compound_hdr hdr;
6214 int status;
6216 status = decode_compound_hdr(xdr, &hdr);
6217 if (status)
6218 goto out;
6219 status = decode_sequence(xdr, &res->seq_res, rqstp);
6220 if (status)
6221 goto out;
6222 status = decode_putfh(xdr);
6223 if (status)
6224 goto out;
6225 status = decode_lockt(xdr, res);
6226 out:
6227 return status;
6231 * Decode LOCKU response
6233 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6234 struct nfs_locku_res *res)
6236 struct compound_hdr hdr;
6237 int status;
6239 status = decode_compound_hdr(xdr, &hdr);
6240 if (status)
6241 goto out;
6242 status = decode_sequence(xdr, &res->seq_res, rqstp);
6243 if (status)
6244 goto out;
6245 status = decode_putfh(xdr);
6246 if (status)
6247 goto out;
6248 status = decode_locku(xdr, res);
6249 out:
6250 return status;
6253 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6254 struct xdr_stream *xdr, void *dummy)
6256 struct compound_hdr hdr;
6257 int status;
6259 status = decode_compound_hdr(xdr, &hdr);
6260 if (!status)
6261 status = decode_release_lockowner(xdr);
6262 return status;
6266 * Decode READLINK response
6268 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6269 struct xdr_stream *xdr,
6270 struct nfs4_readlink_res *res)
6272 struct compound_hdr hdr;
6273 int status;
6275 status = decode_compound_hdr(xdr, &hdr);
6276 if (status)
6277 goto out;
6278 status = decode_sequence(xdr, &res->seq_res, rqstp);
6279 if (status)
6280 goto out;
6281 status = decode_putfh(xdr);
6282 if (status)
6283 goto out;
6284 status = decode_readlink(xdr, rqstp);
6285 out:
6286 return status;
6290 * Decode READDIR response
6292 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6293 struct nfs4_readdir_res *res)
6295 struct compound_hdr hdr;
6296 int status;
6298 status = decode_compound_hdr(xdr, &hdr);
6299 if (status)
6300 goto out;
6301 status = decode_sequence(xdr, &res->seq_res, rqstp);
6302 if (status)
6303 goto out;
6304 status = decode_putfh(xdr);
6305 if (status)
6306 goto out;
6307 status = decode_readdir(xdr, rqstp, res);
6308 out:
6309 return status;
6313 * Decode Read response
6315 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6316 struct nfs_readres *res)
6318 struct compound_hdr hdr;
6319 int status;
6321 status = decode_compound_hdr(xdr, &hdr);
6322 if (status)
6323 goto out;
6324 status = decode_sequence(xdr, &res->seq_res, rqstp);
6325 if (status)
6326 goto out;
6327 status = decode_putfh(xdr);
6328 if (status)
6329 goto out;
6330 status = decode_read(xdr, rqstp, res);
6331 if (!status)
6332 status = res->count;
6333 out:
6334 return status;
6338 * Decode WRITE response
6340 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6341 struct nfs_writeres *res)
6343 struct compound_hdr hdr;
6344 int status;
6346 status = decode_compound_hdr(xdr, &hdr);
6347 if (status)
6348 goto out;
6349 status = decode_sequence(xdr, &res->seq_res, rqstp);
6350 if (status)
6351 goto out;
6352 status = decode_putfh(xdr);
6353 if (status)
6354 goto out;
6355 status = decode_write(xdr, res);
6356 if (status)
6357 goto out;
6358 if (res->fattr)
6359 decode_getfattr(xdr, res->fattr, res->server,
6360 !RPC_IS_ASYNC(rqstp->rq_task));
6361 if (!status)
6362 status = res->count;
6363 out:
6364 return status;
6368 * Decode COMMIT response
6370 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6371 struct nfs_writeres *res)
6373 struct compound_hdr hdr;
6374 int status;
6376 status = decode_compound_hdr(xdr, &hdr);
6377 if (status)
6378 goto out;
6379 status = decode_sequence(xdr, &res->seq_res, rqstp);
6380 if (status)
6381 goto out;
6382 status = decode_putfh(xdr);
6383 if (status)
6384 goto out;
6385 status = decode_commit(xdr, res);
6386 if (status)
6387 goto out;
6388 if (res->fattr)
6389 decode_getfattr(xdr, res->fattr, res->server,
6390 !RPC_IS_ASYNC(rqstp->rq_task));
6391 out:
6392 return status;
6396 * Decode FSINFO response
6398 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6399 struct nfs4_fsinfo_res *res)
6401 struct compound_hdr hdr;
6402 int status;
6404 status = decode_compound_hdr(xdr, &hdr);
6405 if (!status)
6406 status = decode_sequence(xdr, &res->seq_res, req);
6407 if (!status)
6408 status = decode_putfh(xdr);
6409 if (!status)
6410 status = decode_fsinfo(xdr, res->fsinfo);
6411 return status;
6415 * Decode PATHCONF response
6417 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6418 struct nfs4_pathconf_res *res)
6420 struct compound_hdr hdr;
6421 int status;
6423 status = decode_compound_hdr(xdr, &hdr);
6424 if (!status)
6425 status = decode_sequence(xdr, &res->seq_res, req);
6426 if (!status)
6427 status = decode_putfh(xdr);
6428 if (!status)
6429 status = decode_pathconf(xdr, res->pathconf);
6430 return status;
6434 * Decode STATFS response
6436 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6437 struct nfs4_statfs_res *res)
6439 struct compound_hdr hdr;
6440 int status;
6442 status = decode_compound_hdr(xdr, &hdr);
6443 if (!status)
6444 status = decode_sequence(xdr, &res->seq_res, req);
6445 if (!status)
6446 status = decode_putfh(xdr);
6447 if (!status)
6448 status = decode_statfs(xdr, res->fsstat);
6449 return status;
6453 * Decode GETATTR_BITMAP response
6455 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6456 struct xdr_stream *xdr,
6457 struct nfs4_server_caps_res *res)
6459 struct compound_hdr hdr;
6460 int status;
6462 status = decode_compound_hdr(xdr, &hdr);
6463 if (status)
6464 goto out;
6465 status = decode_sequence(xdr, &res->seq_res, req);
6466 if (status)
6467 goto out;
6468 status = decode_putfh(xdr);
6469 if (status)
6470 goto out;
6471 status = decode_server_caps(xdr, res);
6472 out:
6473 return status;
6477 * Decode RENEW response
6479 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6480 void *__unused)
6482 struct compound_hdr hdr;
6483 int status;
6485 status = decode_compound_hdr(xdr, &hdr);
6486 if (!status)
6487 status = decode_renew(xdr);
6488 return status;
6492 * Decode SETCLIENTID response
6494 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6495 struct xdr_stream *xdr,
6496 struct nfs4_setclientid_res *res)
6498 struct compound_hdr hdr;
6499 int status;
6501 status = decode_compound_hdr(xdr, &hdr);
6502 if (!status)
6503 status = decode_setclientid(xdr, res);
6504 return status;
6508 * Decode SETCLIENTID_CONFIRM response
6510 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6511 struct xdr_stream *xdr,
6512 struct nfs_fsinfo *fsinfo)
6514 struct compound_hdr hdr;
6515 int status;
6517 status = decode_compound_hdr(xdr, &hdr);
6518 if (!status)
6519 status = decode_setclientid_confirm(xdr);
6520 if (!status)
6521 status = decode_putrootfh(xdr);
6522 if (!status)
6523 status = decode_fsinfo(xdr, fsinfo);
6524 return status;
6528 * Decode DELEGRETURN response
6530 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6531 struct xdr_stream *xdr,
6532 struct nfs4_delegreturnres *res)
6534 struct compound_hdr hdr;
6535 int status;
6537 status = decode_compound_hdr(xdr, &hdr);
6538 if (status)
6539 goto out;
6540 status = decode_sequence(xdr, &res->seq_res, rqstp);
6541 if (status)
6542 goto out;
6543 status = decode_putfh(xdr);
6544 if (status != 0)
6545 goto out;
6546 status = decode_delegreturn(xdr);
6547 if (status != 0)
6548 goto out;
6549 decode_getfattr(xdr, res->fattr, res->server,
6550 !RPC_IS_ASYNC(rqstp->rq_task));
6551 out:
6552 return status;
6556 * Decode FS_LOCATIONS response
6558 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6559 struct xdr_stream *xdr,
6560 struct nfs4_fs_locations_res *res)
6562 struct compound_hdr hdr;
6563 int status;
6565 status = decode_compound_hdr(xdr, &hdr);
6566 if (status)
6567 goto out;
6568 status = decode_sequence(xdr, &res->seq_res, req);
6569 if (status)
6570 goto out;
6571 status = decode_putfh(xdr);
6572 if (status)
6573 goto out;
6574 status = decode_lookup(xdr);
6575 if (status)
6576 goto out;
6577 xdr_enter_page(xdr, PAGE_SIZE);
6578 status = decode_getfattr(xdr, &res->fs_locations->fattr,
6579 res->fs_locations->server,
6580 !RPC_IS_ASYNC(req->rq_task));
6581 out:
6582 return status;
6586 * Decode SECINFO response
6588 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6589 struct xdr_stream *xdr,
6590 struct nfs4_secinfo_res *res)
6592 struct compound_hdr hdr;
6593 int status;
6595 status = decode_compound_hdr(xdr, &hdr);
6596 if (status)
6597 goto out;
6598 status = decode_sequence(xdr, &res->seq_res, rqstp);
6599 if (status)
6600 goto out;
6601 status = decode_putfh(xdr);
6602 if (status)
6603 goto out;
6604 status = decode_secinfo(xdr, res);
6605 if (status)
6606 goto out;
6607 out:
6608 return status;
6611 #if defined(CONFIG_NFS_V4_1)
6613 * Decode EXCHANGE_ID response
6615 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6616 struct xdr_stream *xdr,
6617 void *res)
6619 struct compound_hdr hdr;
6620 int status;
6622 status = decode_compound_hdr(xdr, &hdr);
6623 if (!status)
6624 status = decode_exchange_id(xdr, res);
6625 return status;
6629 * Decode CREATE_SESSION response
6631 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6632 struct xdr_stream *xdr,
6633 struct nfs41_create_session_res *res)
6635 struct compound_hdr hdr;
6636 int status;
6638 status = decode_compound_hdr(xdr, &hdr);
6639 if (!status)
6640 status = decode_create_session(xdr, res);
6641 return status;
6645 * Decode DESTROY_SESSION response
6647 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6648 struct xdr_stream *xdr,
6649 void *res)
6651 struct compound_hdr hdr;
6652 int status;
6654 status = decode_compound_hdr(xdr, &hdr);
6655 if (!status)
6656 status = decode_destroy_session(xdr, res);
6657 return status;
6661 * Decode SEQUENCE response
6663 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6664 struct xdr_stream *xdr,
6665 struct nfs4_sequence_res *res)
6667 struct compound_hdr hdr;
6668 int status;
6670 status = decode_compound_hdr(xdr, &hdr);
6671 if (!status)
6672 status = decode_sequence(xdr, res, rqstp);
6673 return status;
6677 * Decode GET_LEASE_TIME response
6679 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6680 struct xdr_stream *xdr,
6681 struct nfs4_get_lease_time_res *res)
6683 struct compound_hdr hdr;
6684 int status;
6686 status = decode_compound_hdr(xdr, &hdr);
6687 if (!status)
6688 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
6689 if (!status)
6690 status = decode_putrootfh(xdr);
6691 if (!status)
6692 status = decode_fsinfo(xdr, res->lr_fsinfo);
6693 return status;
6697 * Decode RECLAIM_COMPLETE response
6699 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6700 struct xdr_stream *xdr,
6701 struct nfs41_reclaim_complete_res *res)
6703 struct compound_hdr hdr;
6704 int status;
6706 status = decode_compound_hdr(xdr, &hdr);
6707 if (!status)
6708 status = decode_sequence(xdr, &res->seq_res, rqstp);
6709 if (!status)
6710 status = decode_reclaim_complete(xdr, (void *)NULL);
6711 return status;
6715 * Decode GETDEVICELIST response
6717 static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6718 struct xdr_stream *xdr,
6719 struct nfs4_getdevicelist_res *res)
6721 struct compound_hdr hdr;
6722 int status;
6724 dprintk("encoding getdevicelist!\n");
6726 status = decode_compound_hdr(xdr, &hdr);
6727 if (status != 0)
6728 goto out;
6729 status = decode_sequence(xdr, &res->seq_res, rqstp);
6730 if (status != 0)
6731 goto out;
6732 status = decode_putfh(xdr);
6733 if (status != 0)
6734 goto out;
6735 status = decode_getdevicelist(xdr, res->devlist);
6736 out:
6737 return status;
6741 * Decode GETDEVINFO response
6743 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6744 struct xdr_stream *xdr,
6745 struct nfs4_getdeviceinfo_res *res)
6747 struct compound_hdr hdr;
6748 int status;
6750 status = decode_compound_hdr(xdr, &hdr);
6751 if (status != 0)
6752 goto out;
6753 status = decode_sequence(xdr, &res->seq_res, rqstp);
6754 if (status != 0)
6755 goto out;
6756 status = decode_getdeviceinfo(xdr, res->pdev);
6757 out:
6758 return status;
6762 * Decode LAYOUTGET response
6764 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6765 struct xdr_stream *xdr,
6766 struct nfs4_layoutget_res *res)
6768 struct compound_hdr hdr;
6769 int status;
6771 status = decode_compound_hdr(xdr, &hdr);
6772 if (status)
6773 goto out;
6774 status = decode_sequence(xdr, &res->seq_res, rqstp);
6775 if (status)
6776 goto out;
6777 status = decode_putfh(xdr);
6778 if (status)
6779 goto out;
6780 status = decode_layoutget(xdr, rqstp, res);
6781 out:
6782 return status;
6786 * Decode LAYOUTRETURN response
6788 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6789 struct xdr_stream *xdr,
6790 struct nfs4_layoutreturn_res *res)
6792 struct compound_hdr hdr;
6793 int status;
6795 status = decode_compound_hdr(xdr, &hdr);
6796 if (status)
6797 goto out;
6798 status = decode_sequence(xdr, &res->seq_res, rqstp);
6799 if (status)
6800 goto out;
6801 status = decode_putfh(xdr);
6802 if (status)
6803 goto out;
6804 status = decode_layoutreturn(xdr, res);
6805 out:
6806 return status;
6810 * Decode LAYOUTCOMMIT response
6812 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6813 struct xdr_stream *xdr,
6814 struct nfs4_layoutcommit_res *res)
6816 struct compound_hdr hdr;
6817 int status;
6819 status = decode_compound_hdr(xdr, &hdr);
6820 if (status)
6821 goto out;
6822 status = decode_sequence(xdr, &res->seq_res, rqstp);
6823 if (status)
6824 goto out;
6825 status = decode_putfh(xdr);
6826 if (status)
6827 goto out;
6828 status = decode_layoutcommit(xdr, rqstp, res);
6829 if (status)
6830 goto out;
6831 decode_getfattr(xdr, res->fattr, res->server,
6832 !RPC_IS_ASYNC(rqstp->rq_task));
6833 out:
6834 return status;
6838 * Decode SECINFO_NO_NAME response
6840 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6841 struct xdr_stream *xdr,
6842 struct nfs4_secinfo_res *res)
6844 struct compound_hdr hdr;
6845 int status;
6847 status = decode_compound_hdr(xdr, &hdr);
6848 if (status)
6849 goto out;
6850 status = decode_sequence(xdr, &res->seq_res, rqstp);
6851 if (status)
6852 goto out;
6853 status = decode_putrootfh(xdr);
6854 if (status)
6855 goto out;
6856 status = decode_secinfo(xdr, res);
6857 out:
6858 return status;
6862 * Decode TEST_STATEID response
6864 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6865 struct xdr_stream *xdr,
6866 struct nfs41_test_stateid_res *res)
6868 struct compound_hdr hdr;
6869 int status;
6871 status = decode_compound_hdr(xdr, &hdr);
6872 if (status)
6873 goto out;
6874 status = decode_sequence(xdr, &res->seq_res, rqstp);
6875 if (status)
6876 goto out;
6877 status = decode_test_stateid(xdr, res);
6878 out:
6879 return status;
6883 * Decode FREE_STATEID response
6885 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6886 struct xdr_stream *xdr,
6887 struct nfs41_free_stateid_res *res)
6889 struct compound_hdr hdr;
6890 int status;
6892 status = decode_compound_hdr(xdr, &hdr);
6893 if (status)
6894 goto out;
6895 status = decode_sequence(xdr, &res->seq_res, rqstp);
6896 if (status)
6897 goto out;
6898 status = decode_free_stateid(xdr, res);
6899 out:
6900 return status;
6902 #endif /* CONFIG_NFS_V4_1 */
6905 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6906 * the local page cache.
6907 * @xdr: XDR stream where entry resides
6908 * @entry: buffer to fill in with entry data
6909 * @plus: boolean indicating whether this should be a readdirplus entry
6911 * Returns zero if successful, otherwise a negative errno value is
6912 * returned.
6914 * This function is not invoked during READDIR reply decoding, but
6915 * rather whenever an application invokes the getdents(2) system call
6916 * on a directory already in our cache.
6918 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6919 int plus)
6921 uint32_t bitmap[3] = {0};
6922 uint32_t len;
6923 __be32 *p = xdr_inline_decode(xdr, 4);
6924 if (unlikely(!p))
6925 goto out_overflow;
6926 if (*p == xdr_zero) {
6927 p = xdr_inline_decode(xdr, 4);
6928 if (unlikely(!p))
6929 goto out_overflow;
6930 if (*p == xdr_zero)
6931 return -EAGAIN;
6932 entry->eof = 1;
6933 return -EBADCOOKIE;
6936 p = xdr_inline_decode(xdr, 12);
6937 if (unlikely(!p))
6938 goto out_overflow;
6939 entry->prev_cookie = entry->cookie;
6940 p = xdr_decode_hyper(p, &entry->cookie);
6941 entry->len = be32_to_cpup(p);
6943 p = xdr_inline_decode(xdr, entry->len);
6944 if (unlikely(!p))
6945 goto out_overflow;
6946 entry->name = (const char *) p;
6949 * In case the server doesn't return an inode number,
6950 * we fake one here. (We don't use inode number 0,
6951 * since glibc seems to choke on it...)
6953 entry->ino = 1;
6954 entry->fattr->valid = 0;
6956 if (decode_attr_bitmap(xdr, bitmap) < 0)
6957 goto out_overflow;
6959 if (decode_attr_length(xdr, &len, &p) < 0)
6960 goto out_overflow;
6962 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6963 entry->server, 1) < 0)
6964 goto out_overflow;
6965 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6966 entry->ino = entry->fattr->mounted_on_fileid;
6967 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6968 entry->ino = entry->fattr->fileid;
6970 entry->d_type = DT_UNKNOWN;
6971 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6972 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6974 return 0;
6976 out_overflow:
6977 print_overflow_msg(__func__, xdr);
6978 return -EAGAIN;
6982 * We need to translate between nfs status return values and
6983 * the local errno values which may not be the same.
6985 static struct {
6986 int stat;
6987 int errno;
6988 } nfs_errtbl[] = {
6989 { NFS4_OK, 0 },
6990 { NFS4ERR_PERM, -EPERM },
6991 { NFS4ERR_NOENT, -ENOENT },
6992 { NFS4ERR_IO, -errno_NFSERR_IO},
6993 { NFS4ERR_NXIO, -ENXIO },
6994 { NFS4ERR_ACCESS, -EACCES },
6995 { NFS4ERR_EXIST, -EEXIST },
6996 { NFS4ERR_XDEV, -EXDEV },
6997 { NFS4ERR_NOTDIR, -ENOTDIR },
6998 { NFS4ERR_ISDIR, -EISDIR },
6999 { NFS4ERR_INVAL, -EINVAL },
7000 { NFS4ERR_FBIG, -EFBIG },
7001 { NFS4ERR_NOSPC, -ENOSPC },
7002 { NFS4ERR_ROFS, -EROFS },
7003 { NFS4ERR_MLINK, -EMLINK },
7004 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7005 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7006 { NFS4ERR_DQUOT, -EDQUOT },
7007 { NFS4ERR_STALE, -ESTALE },
7008 { NFS4ERR_BADHANDLE, -EBADHANDLE },
7009 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7010 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7011 { NFS4ERR_TOOSMALL, -ETOOSMALL },
7012 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7013 { NFS4ERR_BADTYPE, -EBADTYPE },
7014 { NFS4ERR_LOCKED, -EAGAIN },
7015 { NFS4ERR_SYMLINK, -ELOOP },
7016 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7017 { NFS4ERR_DEADLOCK, -EDEADLK },
7018 { -1, -EIO }
7022 * Convert an NFS error code to a local one.
7023 * This one is used jointly by NFSv2 and NFSv3.
7025 static int
7026 nfs4_stat_to_errno(int stat)
7028 int i;
7029 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7030 if (nfs_errtbl[i].stat == stat)
7031 return nfs_errtbl[i].errno;
7033 if (stat <= 10000 || stat > 10100) {
7034 /* The server is looney tunes. */
7035 return -EREMOTEIO;
7037 /* If we cannot translate the error, the recovery routines should
7038 * handle it.
7039 * Note: remaining NFSv4 error codes have values > 10000, so should
7040 * not conflict with native Linux error codes.
7042 return -stat;
7045 #define PROC(proc, argtype, restype) \
7046 [NFSPROC4_CLNT_##proc] = { \
7047 .p_proc = NFSPROC4_COMPOUND, \
7048 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7049 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7050 .p_arglen = NFS4_##argtype##_sz, \
7051 .p_replen = NFS4_##restype##_sz, \
7052 .p_statidx = NFSPROC4_CLNT_##proc, \
7053 .p_name = #proc, \
7056 struct rpc_procinfo nfs4_procedures[] = {
7057 PROC(READ, enc_read, dec_read),
7058 PROC(WRITE, enc_write, dec_write),
7059 PROC(COMMIT, enc_commit, dec_commit),
7060 PROC(OPEN, enc_open, dec_open),
7061 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7062 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7063 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7064 PROC(CLOSE, enc_close, dec_close),
7065 PROC(SETATTR, enc_setattr, dec_setattr),
7066 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7067 PROC(RENEW, enc_renew, dec_renew),
7068 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7069 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7070 PROC(LOCK, enc_lock, dec_lock),
7071 PROC(LOCKT, enc_lockt, dec_lockt),
7072 PROC(LOCKU, enc_locku, dec_locku),
7073 PROC(ACCESS, enc_access, dec_access),
7074 PROC(GETATTR, enc_getattr, dec_getattr),
7075 PROC(LOOKUP, enc_lookup, dec_lookup),
7076 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7077 PROC(REMOVE, enc_remove, dec_remove),
7078 PROC(RENAME, enc_rename, dec_rename),
7079 PROC(LINK, enc_link, dec_link),
7080 PROC(SYMLINK, enc_symlink, dec_symlink),
7081 PROC(CREATE, enc_create, dec_create),
7082 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7083 PROC(STATFS, enc_statfs, dec_statfs),
7084 PROC(READLINK, enc_readlink, dec_readlink),
7085 PROC(READDIR, enc_readdir, dec_readdir),
7086 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7087 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7088 PROC(GETACL, enc_getacl, dec_getacl),
7089 PROC(SETACL, enc_setacl, dec_setacl),
7090 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7091 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7092 PROC(SECINFO, enc_secinfo, dec_secinfo),
7093 #if defined(CONFIG_NFS_V4_1)
7094 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7095 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7096 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7097 PROC(SEQUENCE, enc_sequence, dec_sequence),
7098 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7099 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7100 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7101 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7102 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7103 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7104 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7105 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7106 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7107 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
7108 #endif /* CONFIG_NFS_V4_1 */
7111 struct rpc_version nfs_version4 = {
7112 .number = 4,
7113 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7114 .procs = nfs4_procedures
7118 * Local variables:
7119 * c-basic-offset: 8
7120 * End: