4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/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>
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 */
67 #define NFS4_MAXTAGLEN 20
69 #define NFS4_MAXTAGLEN 0
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 + \
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 + \
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) + \
128 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
129 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
131 #define decode_setclientid_maxsz \
132 (op_decode_hdr_maxsz + \
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 + \
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 + \
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 + \
201 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz)
203 #define encode_rename_maxsz (op_encode_hdr_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 + \
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 + \
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 + \
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 + \
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) + \
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 */ + \
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 */ + \
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) */ + \
302 1 /* machinename.len */ + \
303 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
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 + \
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 + \
380 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
381 decode_sequence_maxsz + \
382 decode_putfh_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 + \
492 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
493 decode_sequence_maxsz + \
494 decode_putfh_maxsz + \
496 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
498 #define NFS4_dec_renew_sz (compound_decode_hdr_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 + \
509 #define NFS4_dec_setclientid_confirm_sz \
510 (compound_decode_hdr_maxsz + \
511 decode_setclientid_confirm_maxsz + \
512 decode_putrootfh_maxsz + \
514 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
515 encode_sequence_maxsz + \
516 encode_putfh_maxsz + \
518 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
519 decode_sequence_maxsz + \
520 decode_putfh_maxsz + \
522 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
523 encode_sequence_maxsz + \
524 encode_putfh_maxsz + \
526 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
527 decode_sequence_maxsz + \
528 decode_putfh_maxsz + \
530 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
531 encode_sequence_maxsz + \
532 encode_putfh_maxsz + \
534 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
535 decode_sequence_maxsz + \
536 decode_putfh_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 + \
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 + \
574 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
575 encode_sequence_maxsz + \
576 encode_putrootfh_maxsz + \
577 encode_getattr_maxsz + \
579 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
580 decode_sequence_maxsz + \
581 decode_putrootfh_maxsz + \
582 decode_getattr_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 + \
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 + \
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 + \
672 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
673 decode_sequence_maxsz + \
674 decode_putfh_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 + \
697 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
698 decode_sequence_maxsz + \
699 decode_putfh_maxsz + \
701 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
702 encode_sequence_maxsz + \
703 encode_putfh_maxsz + \
705 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
706 decode_sequence_maxsz + \
707 decode_putfh_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 + \
756 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
757 decode_sequence_maxsz + \
758 decode_putrootfh_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
+
831 encode_getattr_maxsz
) *
834 const u32 nfs41_maxread_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
835 compound_decode_hdr_maxsz
+
836 decode_sequence_maxsz
+
837 decode_putfh_maxsz
) *
839 #endif /* CONFIG_NFS_V4_1 */
841 static const umode_t nfs_type2fmt
[] = {
848 [NF4SOCK
] = S_IFSOCK
,
854 struct compound_hdr
{
860 uint32_t replen
; /* expected reply words */
864 static __be32
*reserve_space(struct xdr_stream
*xdr
, size_t nbytes
)
866 __be32
*p
= xdr_reserve_space(xdr
, nbytes
);
871 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
875 p
= xdr_reserve_space(xdr
, 4 + len
);
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
)
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
);
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
)
911 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
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;
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.
938 if (iap
->ia_valid
& ATTR_SIZE
)
940 if (iap
->ia_valid
& ATTR_MODE
)
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",
948 strcpy(owner_name
, "nobody");
949 owner_namelen
= sizeof("nobody") - 1;
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",
959 strcpy(owner_group
, "nobody");
960 owner_grouplen
= sizeof("nobody") - 1;
963 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
965 if (iap
->ia_valid
& ATTR_ATIME_SET
)
967 else if (iap
->ia_valid
& ATTR_ATIME
)
969 if (iap
->ia_valid
& ATTR_MTIME_SET
)
971 else if (iap
->ia_valid
& ATTR_MTIME
)
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);
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);
1030 len
= (char *)p
- (char *)q
- 12;
1031 *q
++ = htonl(bmval0
);
1032 *q
++ = htonl(bmval1
);
1038 static void encode_access(struct xdr_stream
*xdr
, u32 access
, struct compound_hdr
*hdr
)
1042 p
= reserve_space(xdr
, 8);
1043 *p
++ = cpu_to_be32(OP_ACCESS
);
1044 *p
= cpu_to_be32(access
);
1046 hdr
->replen
+= decode_access_maxsz
;
1049 static void encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
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
);
1058 hdr
->replen
+= decode_close_maxsz
;
1061 static void encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
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
);
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
)
1077 p
= reserve_space(xdr
, 8);
1078 *p
++ = cpu_to_be32(OP_CREATE
);
1079 *p
= cpu_to_be32(create
->ftype
);
1081 switch (create
->ftype
) {
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
);
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
);
1098 encode_string(xdr
, create
->name
->len
, create
->name
->name
);
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
)
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
);
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
)
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
);
1127 hdr
->replen
+= decode_getattr_maxsz
;
1131 encode_getattr_three(struct xdr_stream
*xdr
,
1132 uint32_t bm0
, uint32_t bm1
, uint32_t bm2
,
1133 struct compound_hdr
*hdr
)
1137 p
= reserve_space(xdr
, 4);
1138 *p
= cpu_to_be32(OP_GETATTR
);
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
);
1146 p
= reserve_space(xdr
, 12);
1147 *p
++ = cpu_to_be32(2);
1148 *p
++ = cpu_to_be32(bm0
);
1149 *p
= cpu_to_be32(bm1
);
1151 p
= reserve_space(xdr
, 8);
1152 *p
++ = cpu_to_be32(1);
1153 *p
= cpu_to_be32(bm0
);
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],
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
)
1184 p
= reserve_space(xdr
, 4);
1185 *p
= cpu_to_be32(OP_GETFH
);
1187 hdr
->replen
+= decode_getfh_maxsz
;
1190 static void encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1194 p
= reserve_space(xdr
, 8 + name
->len
);
1195 *p
++ = cpu_to_be32(OP_LINK
);
1196 xdr_encode_opaque(p
, name
->name
, name
->len
);
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
)
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
)
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
);
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
);
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
)
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
);
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
)
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
));
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
)
1291 p
= reserve_space(xdr
, 4);
1292 *p
= cpu_to_be32(OP_RELEASE_LOCKOWNER
);
1293 encode_lockowner(xdr
, lowner
);
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
;
1303 p
= reserve_space(xdr
, 8 + len
);
1304 *p
++ = cpu_to_be32(OP_LOOKUP
);
1305 xdr_encode_opaque(p
, name
->name
, len
);
1307 hdr
->replen
+= decode_lookup_maxsz
;
1310 static void encode_share_access(struct xdr_stream
*xdr
, fmode_t fmode
)
1314 p
= reserve_space(xdr
, 8);
1315 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1317 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ
);
1320 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE
);
1322 case FMODE_READ
|FMODE_WRITE
:
1323 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH
);
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
)
1335 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
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
)
1353 struct nfs_client
*clp
;
1355 p
= reserve_space(xdr
, 4);
1356 switch(arg
->open_flags
& O_EXCL
) {
1358 *p
= cpu_to_be32(NFS4_CREATE_UNCHECKED
);
1359 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
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
);
1370 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1
);
1371 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1373 encode_attrs(xdr
, &dummy
, arg
->server
);
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
)
1386 p
= reserve_space(xdr
, 4);
1387 switch (arg
->open_flags
& O_CREAT
) {
1389 *p
= cpu_to_be32(NFS4_OPEN_NOCREATE
);
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
)
1402 p
= reserve_space(xdr
, 4);
1403 switch (delegation_type
) {
1405 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_NONE
);
1408 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_READ
);
1410 case FMODE_WRITE
|FMODE_READ
:
1411 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE
);
1418 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
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
)
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
)
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
);
1454 case NFS4_OPEN_CLAIM_PREVIOUS
:
1455 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
1457 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1458 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
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
)
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
);
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
)
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
);
1489 hdr
->replen
+= decode_open_downgrade_maxsz
;
1493 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
, struct compound_hdr
*hdr
)
1498 p
= reserve_space(xdr
, 8 + len
);
1499 *p
++ = cpu_to_be32(OP_PUTFH
);
1500 xdr_encode_opaque(p
, fh
->data
, len
);
1502 hdr
->replen
+= decode_putfh_maxsz
;
1505 static void encode_putrootfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1509 p
= reserve_space(xdr
, 4);
1510 *p
= cpu_to_be32(OP_PUTROOTFH
);
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
;
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
);
1524 stateid
.stateid
.seqid
= 0;
1525 xdr_encode_opaque_fixed(p
, stateid
.data
, NFS4_STATEID_SIZE
);
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
)
1534 p
= reserve_space(xdr
, 4);
1535 *p
= cpu_to_be32(OP_READ
);
1537 encode_stateid(xdr
, args
->context
, args
->lock_context
,
1540 p
= reserve_space(xdr
, 12);
1541 p
= xdr_encode_hyper(p
, args
->offset
);
1542 *p
= cpu_to_be32(args
->count
);
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;
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
;
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]);
1580 hdr
->replen
+= decode_readdir_maxsz
;
1581 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
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
)
1594 p
= reserve_space(xdr
, 4);
1595 *p
= cpu_to_be32(OP_READLINK
);
1597 hdr
->replen
+= decode_readlink_maxsz
;
1600 static void encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1604 p
= reserve_space(xdr
, 8 + name
->len
);
1605 *p
++ = cpu_to_be32(OP_REMOVE
);
1606 xdr_encode_opaque(p
, name
->name
, name
->len
);
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
)
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
);
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
)
1627 p
= reserve_space(xdr
, 12);
1628 *p
++ = cpu_to_be32(OP_RENEW
);
1629 xdr_encode_hyper(p
, client_stateid
->cl_clientid
);
1631 hdr
->replen
+= decode_renew_maxsz
;
1635 encode_restorefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1639 p
= reserve_space(xdr
, 4);
1640 *p
= cpu_to_be32(OP_RESTOREFH
);
1642 hdr
->replen
+= decode_restorefh_maxsz
;
1646 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
, struct compound_hdr
*hdr
)
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
);
1661 hdr
->replen
+= decode_setacl_maxsz
;
1665 encode_savefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1669 p
= reserve_space(xdr
, 4);
1670 *p
= cpu_to_be32(OP_SAVEFH
);
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
)
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
);
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
)
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
);
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
)
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
);
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
)
1722 p
= reserve_space(xdr
, 4);
1723 *p
= cpu_to_be32(OP_WRITE
);
1725 encode_stateid(xdr
, args
->context
, args
->lock_context
,
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
);
1735 hdr
->replen
+= decode_write_maxsz
;
1738 static void encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
, struct compound_hdr
*hdr
)
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
);
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
;
1755 p
= reserve_space(xdr
, 8 + len
);
1756 *p
++ = cpu_to_be32(OP_SECINFO
);
1757 xdr_encode_opaque(p
, name
->name
, len
);
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
)
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 */
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
)
1789 char machine_name
[NFS4_MAX_MACHINE_NAME_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",
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 */
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 */
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 */
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
)
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
);
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
)
1860 p
= reserve_space(xdr
, 8);
1861 *p
++ = cpu_to_be32(OP_RECLAIM_COMPLETE
);
1862 *p
++ = cpu_to_be32(args
->one_fs
);
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
;
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",
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
);
1907 hdr
->replen
+= decode_sequence_maxsz
;
1908 #endif /* CONFIG_NFS_V4_1 */
1911 #ifdef CONFIG_NFS_V4_1
1913 encode_getdevicelist(struct xdr_stream
*xdr
,
1914 const struct nfs4_getdevicelist_args
*args
,
1915 struct compound_hdr
*hdr
)
1918 nfs4_verifier dummy
= {
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
);
1929 hdr
->replen
+= decode_getdevicelist_maxsz
;
1933 encode_getdeviceinfo(struct xdr_stream
*xdr
,
1934 const struct nfs4_getdeviceinfo_args
*args
,
1935 struct compound_hdr
*hdr
)
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 */
1947 hdr
->replen
+= decode_getdeviceinfo_maxsz
;
1951 encode_layoutget(struct xdr_stream
*xdr
,
1952 const struct nfs4_layoutget_args
*args
,
1953 struct compound_hdr
*hdr
)
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",
1972 (unsigned long)args
->range
.offset
,
1973 (unsigned long)args
->range
.length
,
1976 hdr
->replen
+= decode_layoutget_maxsz
;
1980 encode_layoutcommit(struct xdr_stream
*xdr
,
1981 struct inode
*inode
,
1982 const struct nfs4_layoutcommit_args
*args
,
1983 struct compound_hdr
*hdr
)
1987 dprintk("%s: lbw: %llu type: %d\n", __func__
, args
->lastbytewritten
,
1988 NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);
1990 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
);
2006 p
= reserve_space(xdr
, 4);
2007 *p
= cpu_to_be32(0); /* no layout-type payload */
2011 hdr
->replen
+= decode_layoutcommit_maxsz
;
2016 encode_layoutreturn(struct xdr_stream
*xdr
,
2017 const struct nfs4_layoutreturn_args
*args
,
2018 struct compound_hdr
*hdr
)
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
);
2038 p
= reserve_space(xdr
, 4);
2039 *p
= cpu_to_be32(0);
2042 hdr
->replen
+= decode_layoutreturn_maxsz
;
2046 encode_secinfo_no_name(struct xdr_stream
*xdr
,
2047 const struct nfs41_secinfo_no_name_args
*args
,
2048 struct compound_hdr
*hdr
)
2051 p
= reserve_space(xdr
, 8);
2052 *p
++ = cpu_to_be32(OP_SECINFO_NO_NAME
);
2053 *p
++ = cpu_to_be32(args
->style
);
2055 hdr
->replen
+= decode_secinfo_no_name_maxsz
;
2059 static void encode_test_stateid(struct xdr_stream
*xdr
,
2060 struct nfs41_test_stateid_args
*args
,
2061 struct compound_hdr
*hdr
)
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
);
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
)
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
);
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 */
2100 * Encode an ACCESS request
2102 static void nfs4_xdr_enc_access(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2103 const struct nfs4_accessargs
*args
)
2105 struct compound_hdr hdr
= {
2106 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2109 encode_compound_hdr(xdr
, req
, &hdr
);
2110 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2111 encode_putfh(xdr
, args
->fh
, &hdr
);
2112 encode_access(xdr
, args
->access
, &hdr
);
2113 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2118 * Encode LOOKUP request
2120 static void nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2121 const struct nfs4_lookup_arg
*args
)
2123 struct compound_hdr hdr
= {
2124 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2127 encode_compound_hdr(xdr
, req
, &hdr
);
2128 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2129 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2130 encode_lookup(xdr
, args
->name
, &hdr
);
2131 encode_getfh(xdr
, &hdr
);
2132 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2137 * Encode LOOKUP_ROOT request
2139 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
,
2140 struct xdr_stream
*xdr
,
2141 const struct nfs4_lookup_root_arg
*args
)
2143 struct compound_hdr hdr
= {
2144 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2147 encode_compound_hdr(xdr
, req
, &hdr
);
2148 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2149 encode_putrootfh(xdr
, &hdr
);
2150 encode_getfh(xdr
, &hdr
);
2151 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2156 * Encode REMOVE request
2158 static void nfs4_xdr_enc_remove(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2159 const struct nfs_removeargs
*args
)
2161 struct compound_hdr hdr
= {
2162 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2165 encode_compound_hdr(xdr
, req
, &hdr
);
2166 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2167 encode_putfh(xdr
, args
->fh
, &hdr
);
2168 encode_remove(xdr
, &args
->name
, &hdr
);
2169 encode_getfattr(xdr
, args
->bitmask
, &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
);
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
);
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
);
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
);
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
);
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
->dir_bitmask
, &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
= {
2316 encode_compound_hdr(xdr
, req
, &hdr
);
2317 encode_putfh(xdr
, args
->fh
, &hdr
);
2318 encode_open_confirm(xdr
, args
, &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
);
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
);
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
);
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
);
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
);
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
= {
2419 encode_compound_hdr(xdr
, req
, &hdr
);
2420 encode_release_lockowner(xdr
, &args
->lock_owner
, &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
);
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
);
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
;
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
);
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
),
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
+ 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
);
2530 * Encode a WRITE request
2532 static void nfs4_xdr_enc_write(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2533 struct nfs_writeargs
*args
)
2535 struct compound_hdr hdr
= {
2536 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2539 encode_compound_hdr(xdr
, req
, &hdr
);
2540 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2541 encode_putfh(xdr
, args
->fh
, &hdr
);
2542 encode_write(xdr
, args
, &hdr
);
2543 req
->rq_snd_buf
.flags
|= XDRBUF_WRITE
;
2545 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2552 static void nfs4_xdr_enc_commit(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2553 struct nfs_writeargs
*args
)
2555 struct compound_hdr hdr
= {
2556 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2559 encode_compound_hdr(xdr
, req
, &hdr
);
2560 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2561 encode_putfh(xdr
, args
->fh
, &hdr
);
2562 encode_commit(xdr
, args
, &hdr
);
2564 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2571 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2572 struct nfs4_fsinfo_arg
*args
)
2574 struct compound_hdr hdr
= {
2575 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2578 encode_compound_hdr(xdr
, req
, &hdr
);
2579 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2580 encode_putfh(xdr
, args
->fh
, &hdr
);
2581 encode_fsinfo(xdr
, args
->bitmask
, &hdr
);
2586 * a PATHCONF request
2588 static void nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2589 const struct nfs4_pathconf_arg
*args
)
2591 struct compound_hdr hdr
= {
2592 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2595 encode_compound_hdr(xdr
, req
, &hdr
);
2596 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2597 encode_putfh(xdr
, args
->fh
, &hdr
);
2598 encode_getattr_one(xdr
, args
->bitmask
[0] & nfs4_pathconf_bitmap
[0],
2606 static void nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2607 const struct nfs4_statfs_arg
*args
)
2609 struct compound_hdr hdr
= {
2610 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2613 encode_compound_hdr(xdr
, req
, &hdr
);
2614 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2615 encode_putfh(xdr
, args
->fh
, &hdr
);
2616 encode_getattr_two(xdr
, args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
2617 args
->bitmask
[1] & nfs4_statfs_bitmap
[1], &hdr
);
2622 * GETATTR_BITMAP request
2624 static void nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
,
2625 struct xdr_stream
*xdr
,
2626 struct nfs4_server_caps_arg
*args
)
2628 struct compound_hdr hdr
= {
2629 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2632 encode_compound_hdr(xdr
, req
, &hdr
);
2633 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2634 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2635 encode_getattr_one(xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
2636 FATTR4_WORD0_LINK_SUPPORT
|
2637 FATTR4_WORD0_SYMLINK_SUPPORT
|
2638 FATTR4_WORD0_ACLSUPPORT
, &hdr
);
2645 static void nfs4_xdr_enc_renew(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2646 struct nfs_client
*clp
)
2648 struct compound_hdr hdr
= {
2652 encode_compound_hdr(xdr
, req
, &hdr
);
2653 encode_renew(xdr
, clp
, &hdr
);
2658 * a SETCLIENTID request
2660 static void nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
,
2661 struct xdr_stream
*xdr
,
2662 struct nfs4_setclientid
*sc
)
2664 struct compound_hdr hdr
= {
2668 encode_compound_hdr(xdr
, req
, &hdr
);
2669 encode_setclientid(xdr
, sc
, &hdr
);
2674 * a SETCLIENTID_CONFIRM request
2676 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
,
2677 struct xdr_stream
*xdr
,
2678 struct nfs4_setclientid_res
*arg
)
2680 struct compound_hdr hdr
= {
2683 const u32 lease_bitmap
[3] = { FATTR4_WORD0_LEASE_TIME
};
2685 encode_compound_hdr(xdr
, req
, &hdr
);
2686 encode_setclientid_confirm(xdr
, arg
, &hdr
);
2687 encode_putrootfh(xdr
, &hdr
);
2688 encode_fsinfo(xdr
, lease_bitmap
, &hdr
);
2693 * DELEGRETURN request
2695 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
,
2696 struct xdr_stream
*xdr
,
2697 const struct nfs4_delegreturnargs
*args
)
2699 struct compound_hdr hdr
= {
2700 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2703 encode_compound_hdr(xdr
, req
, &hdr
);
2704 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2705 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2706 encode_delegreturn(xdr
, args
->stateid
, &hdr
);
2707 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2712 * Encode FS_LOCATIONS request
2714 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
,
2715 struct xdr_stream
*xdr
,
2716 struct nfs4_fs_locations_arg
*args
)
2718 struct compound_hdr hdr
= {
2719 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2723 encode_compound_hdr(xdr
, req
, &hdr
);
2724 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2725 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2726 encode_lookup(xdr
, args
->name
, &hdr
);
2727 replen
= hdr
.replen
; /* get the attribute into args->page */
2728 encode_fs_locations(xdr
, args
->bitmask
, &hdr
);
2730 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, &args
->page
,
2736 * Encode SECINFO request
2738 static void nfs4_xdr_enc_secinfo(struct rpc_rqst
*req
,
2739 struct xdr_stream
*xdr
,
2740 struct nfs4_secinfo_arg
*args
)
2742 struct compound_hdr hdr
= {
2743 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2746 encode_compound_hdr(xdr
, req
, &hdr
);
2747 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2748 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2749 encode_secinfo(xdr
, args
->name
, &hdr
);
2753 #if defined(CONFIG_NFS_V4_1)
2755 * EXCHANGE_ID request
2757 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst
*req
,
2758 struct xdr_stream
*xdr
,
2759 struct nfs41_exchange_id_args
*args
)
2761 struct compound_hdr hdr
= {
2762 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2765 encode_compound_hdr(xdr
, req
, &hdr
);
2766 encode_exchange_id(xdr
, args
, &hdr
);
2771 * a CREATE_SESSION request
2773 static void nfs4_xdr_enc_create_session(struct rpc_rqst
*req
,
2774 struct xdr_stream
*xdr
,
2775 struct nfs41_create_session_args
*args
)
2777 struct compound_hdr hdr
= {
2778 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2781 encode_compound_hdr(xdr
, req
, &hdr
);
2782 encode_create_session(xdr
, args
, &hdr
);
2787 * a DESTROY_SESSION request
2789 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst
*req
,
2790 struct xdr_stream
*xdr
,
2791 struct nfs4_session
*session
)
2793 struct compound_hdr hdr
= {
2794 .minorversion
= session
->clp
->cl_mvops
->minor_version
,
2797 encode_compound_hdr(xdr
, req
, &hdr
);
2798 encode_destroy_session(xdr
, session
, &hdr
);
2803 * a SEQUENCE request
2805 static void nfs4_xdr_enc_sequence(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2806 struct nfs4_sequence_args
*args
)
2808 struct compound_hdr hdr
= {
2809 .minorversion
= nfs4_xdr_minorversion(args
),
2812 encode_compound_hdr(xdr
, req
, &hdr
);
2813 encode_sequence(xdr
, args
, &hdr
);
2818 * a GET_LEASE_TIME request
2820 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst
*req
,
2821 struct xdr_stream
*xdr
,
2822 struct nfs4_get_lease_time_args
*args
)
2824 struct compound_hdr hdr
= {
2825 .minorversion
= nfs4_xdr_minorversion(&args
->la_seq_args
),
2827 const u32 lease_bitmap
[3] = { FATTR4_WORD0_LEASE_TIME
};
2829 encode_compound_hdr(xdr
, req
, &hdr
);
2830 encode_sequence(xdr
, &args
->la_seq_args
, &hdr
);
2831 encode_putrootfh(xdr
, &hdr
);
2832 encode_fsinfo(xdr
, lease_bitmap
, &hdr
);
2837 * a RECLAIM_COMPLETE request
2839 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst
*req
,
2840 struct xdr_stream
*xdr
,
2841 struct nfs41_reclaim_complete_args
*args
)
2843 struct compound_hdr hdr
= {
2844 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
)
2847 encode_compound_hdr(xdr
, req
, &hdr
);
2848 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2849 encode_reclaim_complete(xdr
, args
, &hdr
);
2854 * Encode GETDEVICELIST request
2856 static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst
*req
,
2857 struct xdr_stream
*xdr
,
2858 struct nfs4_getdevicelist_args
*args
)
2860 struct compound_hdr hdr
= {
2861 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2864 encode_compound_hdr(xdr
, req
, &hdr
);
2865 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2866 encode_putfh(xdr
, args
->fh
, &hdr
);
2867 encode_getdevicelist(xdr
, args
, &hdr
);
2872 * Encode GETDEVICEINFO request
2874 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst
*req
,
2875 struct xdr_stream
*xdr
,
2876 struct nfs4_getdeviceinfo_args
*args
)
2878 struct compound_hdr hdr
= {
2879 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2882 encode_compound_hdr(xdr
, req
, &hdr
);
2883 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2884 encode_getdeviceinfo(xdr
, args
, &hdr
);
2886 /* set up reply kvec. Subtract notification bitmap max size (2)
2887 * so that notification bitmap is put in xdr_buf tail */
2888 xdr_inline_pages(&req
->rq_rcv_buf
, (hdr
.replen
- 2) << 2,
2889 args
->pdev
->pages
, args
->pdev
->pgbase
,
2896 * Encode LAYOUTGET request
2898 static void nfs4_xdr_enc_layoutget(struct rpc_rqst
*req
,
2899 struct xdr_stream
*xdr
,
2900 struct nfs4_layoutget_args
*args
)
2902 struct compound_hdr hdr
= {
2903 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2906 encode_compound_hdr(xdr
, req
, &hdr
);
2907 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2908 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2909 encode_layoutget(xdr
, args
, &hdr
);
2911 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2912 args
->layout
.pages
, 0, args
->layout
.pglen
);
2918 * Encode LAYOUTCOMMIT request
2920 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst
*req
,
2921 struct xdr_stream
*xdr
,
2922 struct nfs4_layoutcommit_args
*args
)
2924 struct nfs4_layoutcommit_data
*data
=
2925 container_of(args
, struct nfs4_layoutcommit_data
, args
);
2926 struct compound_hdr hdr
= {
2927 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2930 encode_compound_hdr(xdr
, req
, &hdr
);
2931 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2932 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2933 encode_layoutcommit(xdr
, data
->args
.inode
, args
, &hdr
);
2934 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2939 * Encode LAYOUTRETURN request
2941 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst
*req
,
2942 struct xdr_stream
*xdr
,
2943 struct nfs4_layoutreturn_args
*args
)
2945 struct compound_hdr hdr
= {
2946 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2949 encode_compound_hdr(xdr
, req
, &hdr
);
2950 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2951 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2952 encode_layoutreturn(xdr
, args
, &hdr
);
2957 * Encode SECINFO_NO_NAME request
2959 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst
*req
,
2960 struct xdr_stream
*xdr
,
2961 struct nfs41_secinfo_no_name_args
*args
)
2963 struct compound_hdr hdr
= {
2964 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2967 encode_compound_hdr(xdr
, req
, &hdr
);
2968 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2969 encode_putrootfh(xdr
, &hdr
);
2970 encode_secinfo_no_name(xdr
, args
, &hdr
);
2976 * Encode TEST_STATEID request
2978 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst
*req
,
2979 struct xdr_stream
*xdr
,
2980 struct nfs41_test_stateid_args
*args
)
2982 struct compound_hdr hdr
= {
2983 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2986 encode_compound_hdr(xdr
, req
, &hdr
);
2987 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2988 encode_test_stateid(xdr
, args
, &hdr
);
2993 * Encode FREE_STATEID request
2995 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst
*req
,
2996 struct xdr_stream
*xdr
,
2997 struct nfs41_free_stateid_args
*args
)
2999 struct compound_hdr hdr
= {
3000 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
3003 encode_compound_hdr(xdr
, req
, &hdr
);
3004 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
3005 encode_free_stateid(xdr
, args
, &hdr
);
3008 #endif /* CONFIG_NFS_V4_1 */
3010 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
3012 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3013 "Remaining buffer length is %tu words.\n",
3014 func
, xdr
->end
- xdr
->p
);
3017 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
3021 p
= xdr_inline_decode(xdr
, 4);
3024 *len
= be32_to_cpup(p
);
3025 p
= xdr_inline_decode(xdr
, *len
);
3028 *string
= (char *)p
;
3031 print_overflow_msg(__func__
, xdr
);
3035 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
3039 p
= xdr_inline_decode(xdr
, 8);
3042 hdr
->status
= be32_to_cpup(p
++);
3043 hdr
->taglen
= be32_to_cpup(p
);
3045 p
= xdr_inline_decode(xdr
, hdr
->taglen
+ 4);
3048 hdr
->tag
= (char *)p
;
3049 p
+= XDR_QUADLEN(hdr
->taglen
);
3050 hdr
->nops
= be32_to_cpup(p
);
3051 if (unlikely(hdr
->nops
< 1))
3052 return nfs4_stat_to_errno(hdr
->status
);
3055 print_overflow_msg(__func__
, xdr
);
3059 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
3065 p
= xdr_inline_decode(xdr
, 8);
3068 opnum
= be32_to_cpup(p
++);
3069 if (opnum
!= expected
) {
3070 dprintk("nfs: Server returned operation"
3071 " %d but we issued a request for %d\n",
3075 nfserr
= be32_to_cpup(p
);
3076 if (nfserr
!= NFS_OK
)
3077 return nfs4_stat_to_errno(nfserr
);
3080 print_overflow_msg(__func__
, xdr
);
3085 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
3088 unsigned int strlen
;
3091 p
= xdr_inline_decode(xdr
, 12);
3093 return decode_opaque_inline(xdr
, &strlen
, &str
);
3094 print_overflow_msg(__func__
, xdr
);
3098 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
3103 p
= xdr_inline_decode(xdr
, 4);
3106 bmlen
= be32_to_cpup(p
);
3108 bitmap
[0] = bitmap
[1] = bitmap
[2] = 0;
3109 p
= xdr_inline_decode(xdr
, (bmlen
<< 2));
3113 bitmap
[0] = be32_to_cpup(p
++);
3115 bitmap
[1] = be32_to_cpup(p
++);
3117 bitmap
[2] = be32_to_cpup(p
);
3122 print_overflow_msg(__func__
, xdr
);
3126 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, __be32
**savep
)
3130 p
= xdr_inline_decode(xdr
, 4);
3133 *attrlen
= be32_to_cpup(p
);
3137 print_overflow_msg(__func__
, xdr
);
3141 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
3143 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
3145 ret
= decode_attr_bitmap(xdr
, bitmask
);
3146 if (unlikely(ret
< 0))
3148 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
3150 bitmask
[0] = bitmask
[1] = bitmask
[2] = 0;
3151 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__
,
3152 bitmask
[0], bitmask
[1], bitmask
[2]);
3156 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
3162 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
3164 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
3165 p
= xdr_inline_decode(xdr
, 4);
3168 *type
= be32_to_cpup(p
);
3169 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
3170 dprintk("%s: bad type %d\n", __func__
, *type
);
3173 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
3174 ret
= NFS_ATTR_FATTR_TYPE
;
3176 dprintk("%s: type=0%o\n", __func__
, nfs_type2fmt
[*type
]);
3179 print_overflow_msg(__func__
, xdr
);
3183 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
3189 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
3191 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
3192 p
= xdr_inline_decode(xdr
, 8);
3195 xdr_decode_hyper(p
, change
);
3196 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
3197 ret
= NFS_ATTR_FATTR_CHANGE
;
3199 dprintk("%s: change attribute=%Lu\n", __func__
,
3200 (unsigned long long)*change
);
3203 print_overflow_msg(__func__
, xdr
);
3207 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
3213 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
3215 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
3216 p
= xdr_inline_decode(xdr
, 8);
3219 xdr_decode_hyper(p
, size
);
3220 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
3221 ret
= NFS_ATTR_FATTR_SIZE
;
3223 dprintk("%s: file size=%Lu\n", __func__
, (unsigned long long)*size
);
3226 print_overflow_msg(__func__
, xdr
);
3230 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3235 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
3237 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
3238 p
= xdr_inline_decode(xdr
, 4);
3241 *res
= be32_to_cpup(p
);
3242 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
3244 dprintk("%s: link support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3247 print_overflow_msg(__func__
, xdr
);
3251 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3256 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
3258 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
3259 p
= xdr_inline_decode(xdr
, 4);
3262 *res
= be32_to_cpup(p
);
3263 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
3265 dprintk("%s: symlink support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3268 print_overflow_msg(__func__
, xdr
);
3272 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
3279 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
3281 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
3282 p
= xdr_inline_decode(xdr
, 16);
3285 p
= xdr_decode_hyper(p
, &fsid
->major
);
3286 xdr_decode_hyper(p
, &fsid
->minor
);
3287 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
3288 ret
= NFS_ATTR_FATTR_FSID
;
3290 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__
,
3291 (unsigned long long)fsid
->major
,
3292 (unsigned long long)fsid
->minor
);
3295 print_overflow_msg(__func__
, xdr
);
3299 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3304 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
3306 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
3307 p
= xdr_inline_decode(xdr
, 4);
3310 *res
= be32_to_cpup(p
);
3311 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
3313 dprintk("%s: file size=%u\n", __func__
, (unsigned int)*res
);
3316 print_overflow_msg(__func__
, xdr
);
3320 static int decode_attr_error(struct xdr_stream
*xdr
, uint32_t *bitmap
, int32_t *res
)
3324 if (unlikely(bitmap
[0] & (FATTR4_WORD0_RDATTR_ERROR
- 1U)))
3326 if (likely(bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
)) {
3327 p
= xdr_inline_decode(xdr
, 4);
3330 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
3331 *res
= -be32_to_cpup(p
);
3335 print_overflow_msg(__func__
, xdr
);
3339 static int decode_attr_filehandle(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fh
*fh
)
3345 memset(fh
, 0, sizeof(*fh
));
3347 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEHANDLE
- 1U)))
3349 if (likely(bitmap
[0] & FATTR4_WORD0_FILEHANDLE
)) {
3350 p
= xdr_inline_decode(xdr
, 4);
3353 len
= be32_to_cpup(p
);
3354 if (len
> NFS4_FHSIZE
)
3356 p
= xdr_inline_decode(xdr
, len
);
3360 memcpy(fh
->data
, p
, len
);
3363 bitmap
[0] &= ~FATTR4_WORD0_FILEHANDLE
;
3367 print_overflow_msg(__func__
, xdr
);
3371 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3375 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
3376 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
3378 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
3379 p
= xdr_inline_decode(xdr
, 4);
3382 *res
= be32_to_cpup(p
);
3383 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
3385 dprintk("%s: ACLs supported=%u\n", __func__
, (unsigned int)*res
);
3388 print_overflow_msg(__func__
, xdr
);
3392 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3398 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
3400 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
3401 p
= xdr_inline_decode(xdr
, 8);
3404 xdr_decode_hyper(p
, fileid
);
3405 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
3406 ret
= NFS_ATTR_FATTR_FILEID
;
3408 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3411 print_overflow_msg(__func__
, xdr
);
3415 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3421 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
3423 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
3424 p
= xdr_inline_decode(xdr
, 8);
3427 xdr_decode_hyper(p
, fileid
);
3428 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
3429 ret
= NFS_ATTR_FATTR_MOUNTED_ON_FILEID
;
3431 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3434 print_overflow_msg(__func__
, xdr
);
3438 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3444 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
3446 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
3447 p
= xdr_inline_decode(xdr
, 8);
3450 xdr_decode_hyper(p
, res
);
3451 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
3453 dprintk("%s: files avail=%Lu\n", __func__
, (unsigned long long)*res
);
3456 print_overflow_msg(__func__
, xdr
);
3460 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3466 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
3468 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
3469 p
= xdr_inline_decode(xdr
, 8);
3472 xdr_decode_hyper(p
, res
);
3473 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
3475 dprintk("%s: files free=%Lu\n", __func__
, (unsigned long long)*res
);
3478 print_overflow_msg(__func__
, xdr
);
3482 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3488 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
3490 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
3491 p
= xdr_inline_decode(xdr
, 8);
3494 xdr_decode_hyper(p
, res
);
3495 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
3497 dprintk("%s: files total=%Lu\n", __func__
, (unsigned long long)*res
);
3500 print_overflow_msg(__func__
, xdr
);
3504 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
3510 p
= xdr_inline_decode(xdr
, 4);
3513 n
= be32_to_cpup(p
);
3517 path
->ncomponents
= 0;
3518 while (path
->ncomponents
< n
) {
3519 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
3520 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
3521 if (unlikely(status
!= 0))
3523 if (path
->ncomponents
!= n
)
3525 dprintk("%s", component
->data
);
3526 if (path
->ncomponents
< NFS4_PATHNAME_MAXCOMPONENTS
)
3527 path
->ncomponents
++;
3529 dprintk("cannot parse %d components in path\n", n
);
3537 /* a root pathname is sent as a zero component4 */
3538 path
->ncomponents
= 1;
3539 path
->components
[0].len
=0;
3540 path
->components
[0].data
=NULL
;
3541 dprintk("path /\n");
3544 dprintk(" status %d", status
);
3548 print_overflow_msg(__func__
, xdr
);
3552 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
3558 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
3561 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
3563 dprintk("%s: fsroot ", __func__
);
3564 status
= decode_pathname(xdr
, &res
->fs_path
);
3565 if (unlikely(status
!= 0))
3567 p
= xdr_inline_decode(xdr
, 4);
3570 n
= be32_to_cpup(p
);
3573 res
->nlocations
= 0;
3574 while (res
->nlocations
< n
) {
3576 struct nfs4_fs_location
*loc
= &res
->locations
[res
->nlocations
];
3578 p
= xdr_inline_decode(xdr
, 4);
3581 m
= be32_to_cpup(p
);
3584 dprintk("%s: servers ", __func__
);
3585 while (loc
->nservers
< m
) {
3586 struct nfs4_string
*server
= &loc
->servers
[loc
->nservers
];
3587 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
3588 if (unlikely(status
!= 0))
3590 dprintk("%s ", server
->data
);
3591 if (loc
->nservers
< NFS4_FS_LOCATION_MAXSERVERS
)
3595 dprintk("%s: using first %u of %u servers "
3596 "returned for location %u\n",
3598 NFS4_FS_LOCATION_MAXSERVERS
,
3599 m
, res
->nlocations
);
3600 for (i
= loc
->nservers
; i
< m
; i
++) {
3603 status
= decode_opaque_inline(xdr
, &len
, &data
);
3604 if (unlikely(status
!= 0))
3609 status
= decode_pathname(xdr
, &loc
->rootpath
);
3610 if (unlikely(status
!= 0))
3612 if (res
->nlocations
< NFS4_FS_LOCATIONS_MAXENTRIES
)
3615 if (res
->nlocations
!= 0)
3616 status
= NFS_ATTR_FATTR_V4_REFERRAL
;
3618 dprintk("%s: fs_locations done, error = %d\n", __func__
, status
);
3621 print_overflow_msg(__func__
, xdr
);
3627 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3633 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
3635 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
3636 p
= xdr_inline_decode(xdr
, 8);
3639 xdr_decode_hyper(p
, res
);
3640 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
3642 dprintk("%s: maxfilesize=%Lu\n", __func__
, (unsigned long long)*res
);
3645 print_overflow_msg(__func__
, xdr
);
3649 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
3655 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
3657 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
3658 p
= xdr_inline_decode(xdr
, 4);
3661 *maxlink
= be32_to_cpup(p
);
3662 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
3664 dprintk("%s: maxlink=%u\n", __func__
, *maxlink
);
3667 print_overflow_msg(__func__
, xdr
);
3671 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
3677 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
3679 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
3680 p
= xdr_inline_decode(xdr
, 4);
3683 *maxname
= be32_to_cpup(p
);
3684 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
3686 dprintk("%s: maxname=%u\n", __func__
, *maxname
);
3689 print_overflow_msg(__func__
, xdr
);
3693 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3699 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
3701 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
3703 p
= xdr_inline_decode(xdr
, 8);
3706 xdr_decode_hyper(p
, &maxread
);
3707 if (maxread
> 0x7FFFFFFF)
3708 maxread
= 0x7FFFFFFF;
3709 *res
= (uint32_t)maxread
;
3710 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
3712 dprintk("%s: maxread=%lu\n", __func__
, (unsigned long)*res
);
3715 print_overflow_msg(__func__
, xdr
);
3719 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3725 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
3727 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
3729 p
= xdr_inline_decode(xdr
, 8);
3732 xdr_decode_hyper(p
, &maxwrite
);
3733 if (maxwrite
> 0x7FFFFFFF)
3734 maxwrite
= 0x7FFFFFFF;
3735 *res
= (uint32_t)maxwrite
;
3736 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
3738 dprintk("%s: maxwrite=%lu\n", __func__
, (unsigned long)*res
);
3741 print_overflow_msg(__func__
, xdr
);
3745 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, umode_t
*mode
)
3752 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
3754 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
3755 p
= xdr_inline_decode(xdr
, 4);
3758 tmp
= be32_to_cpup(p
);
3759 *mode
= tmp
& ~S_IFMT
;
3760 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
3761 ret
= NFS_ATTR_FATTR_MODE
;
3763 dprintk("%s: file mode=0%o\n", __func__
, (unsigned int)*mode
);
3766 print_overflow_msg(__func__
, xdr
);
3770 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
3776 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
3778 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
3779 p
= xdr_inline_decode(xdr
, 4);
3782 *nlink
= be32_to_cpup(p
);
3783 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
3784 ret
= NFS_ATTR_FATTR_NLINK
;
3786 dprintk("%s: nlink=%u\n", __func__
, (unsigned int)*nlink
);
3789 print_overflow_msg(__func__
, xdr
);
3793 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3794 const struct nfs_server
*server
, uint32_t *uid
,
3795 struct nfs4_string
*owner_name
)
3802 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
3804 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
3805 p
= xdr_inline_decode(xdr
, 4);
3808 len
= be32_to_cpup(p
);
3809 p
= xdr_inline_decode(xdr
, len
);
3812 if (owner_name
!= NULL
) {
3813 owner_name
->data
= kmemdup(p
, len
, GFP_NOWAIT
);
3814 if (owner_name
->data
!= NULL
) {
3815 owner_name
->len
= len
;
3816 ret
= NFS_ATTR_FATTR_OWNER_NAME
;
3818 } else if (len
< XDR_MAX_NETOBJ
) {
3819 if (nfs_map_name_to_uid(server
, (char *)p
, len
, uid
) == 0)
3820 ret
= NFS_ATTR_FATTR_OWNER
;
3822 dprintk("%s: nfs_map_name_to_uid failed!\n",
3825 dprintk("%s: name too long (%u)!\n",
3827 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
3829 dprintk("%s: uid=%d\n", __func__
, (int)*uid
);
3832 print_overflow_msg(__func__
, xdr
);
3836 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3837 const struct nfs_server
*server
, uint32_t *gid
,
3838 struct nfs4_string
*group_name
)
3845 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
3847 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
3848 p
= xdr_inline_decode(xdr
, 4);
3851 len
= be32_to_cpup(p
);
3852 p
= xdr_inline_decode(xdr
, len
);
3855 if (group_name
!= NULL
) {
3856 group_name
->data
= kmemdup(p
, len
, GFP_NOWAIT
);
3857 if (group_name
->data
!= NULL
) {
3858 group_name
->len
= len
;
3859 ret
= NFS_ATTR_FATTR_GROUP_NAME
;
3861 } else if (len
< XDR_MAX_NETOBJ
) {
3862 if (nfs_map_group_to_gid(server
, (char *)p
, len
, gid
) == 0)
3863 ret
= NFS_ATTR_FATTR_GROUP
;
3865 dprintk("%s: nfs_map_group_to_gid failed!\n",
3868 dprintk("%s: name too long (%u)!\n",
3870 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
3872 dprintk("%s: gid=%d\n", __func__
, (int)*gid
);
3875 print_overflow_msg(__func__
, xdr
);
3879 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
3881 uint32_t major
= 0, minor
= 0;
3886 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
3888 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
3891 p
= xdr_inline_decode(xdr
, 8);
3894 major
= be32_to_cpup(p
++);
3895 minor
= be32_to_cpup(p
);
3896 tmp
= MKDEV(major
, minor
);
3897 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
3899 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
3900 ret
= NFS_ATTR_FATTR_RDEV
;
3902 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__
, major
, minor
);
3905 print_overflow_msg(__func__
, xdr
);
3909 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3915 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
3917 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
3918 p
= xdr_inline_decode(xdr
, 8);
3921 xdr_decode_hyper(p
, res
);
3922 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
3924 dprintk("%s: space avail=%Lu\n", __func__
, (unsigned long long)*res
);
3927 print_overflow_msg(__func__
, xdr
);
3931 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3937 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
3939 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
3940 p
= xdr_inline_decode(xdr
, 8);
3943 xdr_decode_hyper(p
, res
);
3944 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
3946 dprintk("%s: space free=%Lu\n", __func__
, (unsigned long long)*res
);
3949 print_overflow_msg(__func__
, xdr
);
3953 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3959 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
3961 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
3962 p
= xdr_inline_decode(xdr
, 8);
3965 xdr_decode_hyper(p
, res
);
3966 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
3968 dprintk("%s: space total=%Lu\n", __func__
, (unsigned long long)*res
);
3971 print_overflow_msg(__func__
, xdr
);
3975 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
3981 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
3983 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
3984 p
= xdr_inline_decode(xdr
, 8);
3987 xdr_decode_hyper(p
, used
);
3988 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
3989 ret
= NFS_ATTR_FATTR_SPACE_USED
;
3991 dprintk("%s: space used=%Lu\n", __func__
,
3992 (unsigned long long)*used
);
3995 print_overflow_msg(__func__
, xdr
);
3999 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
4005 p
= xdr_inline_decode(xdr
, 12);
4008 p
= xdr_decode_hyper(p
, &sec
);
4009 nsec
= be32_to_cpup(p
);
4010 time
->tv_sec
= (time_t)sec
;
4011 time
->tv_nsec
= (long)nsec
;
4014 print_overflow_msg(__func__
, xdr
);
4018 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4024 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
4026 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
4027 status
= decode_attr_time(xdr
, time
);
4029 status
= NFS_ATTR_FATTR_ATIME
;
4030 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
4032 dprintk("%s: atime=%ld\n", __func__
, (long)time
->tv_sec
);
4036 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4042 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
4044 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
4045 status
= decode_attr_time(xdr
, time
);
4047 status
= NFS_ATTR_FATTR_CTIME
;
4048 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
4050 dprintk("%s: ctime=%ld\n", __func__
, (long)time
->tv_sec
);
4054 static int decode_attr_time_delta(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4055 struct timespec
*time
)
4061 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_DELTA
- 1U)))
4063 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_DELTA
)) {
4064 status
= decode_attr_time(xdr
, time
);
4065 bitmap
[1] &= ~FATTR4_WORD1_TIME_DELTA
;
4067 dprintk("%s: time_delta=%ld %ld\n", __func__
, (long)time
->tv_sec
,
4068 (long)time
->tv_nsec
);
4072 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4078 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
4080 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
4081 status
= decode_attr_time(xdr
, time
);
4083 status
= NFS_ATTR_FATTR_MTIME
;
4084 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
4086 dprintk("%s: mtime=%ld\n", __func__
, (long)time
->tv_sec
);
4090 static int verify_attr_len(struct xdr_stream
*xdr
, __be32
*savep
, uint32_t attrlen
)
4092 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
4093 unsigned int nwords
= xdr
->p
- savep
;
4095 if (unlikely(attrwords
!= nwords
)) {
4096 dprintk("%s: server returned incorrect attribute length: "
4100 (attrwords
< nwords
) ? '<' : '>',
4107 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4111 p
= xdr_inline_decode(xdr
, 20);
4114 cinfo
->atomic
= be32_to_cpup(p
++);
4115 p
= xdr_decode_hyper(p
, &cinfo
->before
);
4116 xdr_decode_hyper(p
, &cinfo
->after
);
4119 print_overflow_msg(__func__
, xdr
);
4123 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
4129 status
= decode_op_hdr(xdr
, OP_ACCESS
);
4132 p
= xdr_inline_decode(xdr
, 8);
4135 supp
= be32_to_cpup(p
++);
4136 acc
= be32_to_cpup(p
);
4137 access
->supported
= supp
;
4138 access
->access
= acc
;
4141 print_overflow_msg(__func__
, xdr
);
4145 static int decode_opaque_fixed(struct xdr_stream
*xdr
, void *buf
, size_t len
)
4149 p
= xdr_inline_decode(xdr
, len
);
4151 memcpy(buf
, p
, len
);
4154 print_overflow_msg(__func__
, xdr
);
4158 static int decode_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
4160 return decode_opaque_fixed(xdr
, stateid
->data
, NFS4_STATEID_SIZE
);
4163 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4167 status
= decode_op_hdr(xdr
, OP_CLOSE
);
4169 nfs_increment_open_seqid(status
, res
->seqid
);
4171 status
= decode_stateid(xdr
, &res
->stateid
);
4175 static int decode_verifier(struct xdr_stream
*xdr
, void *verifier
)
4177 return decode_opaque_fixed(xdr
, verifier
, 8);
4180 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
4184 status
= decode_op_hdr(xdr
, OP_COMMIT
);
4186 status
= decode_verifier(xdr
, res
->verf
->verifier
);
4190 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4196 status
= decode_op_hdr(xdr
, OP_CREATE
);
4199 if ((status
= decode_change_info(xdr
, cinfo
)))
4201 p
= xdr_inline_decode(xdr
, 4);
4204 bmlen
= be32_to_cpup(p
);
4205 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4209 print_overflow_msg(__func__
, xdr
);
4213 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
4216 uint32_t attrlen
, bitmap
[3] = {0};
4219 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4221 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4223 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4225 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
4227 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
4229 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
4231 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
4233 status
= verify_attr_len(xdr
, savep
, attrlen
);
4235 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4239 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
4242 uint32_t attrlen
, bitmap
[3] = {0};
4245 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4247 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4249 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4252 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
4254 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
4256 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
4258 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
4260 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
4262 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
4265 status
= verify_attr_len(xdr
, savep
, attrlen
);
4267 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4271 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
4274 uint32_t attrlen
, bitmap
[3] = {0};
4277 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4279 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4281 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4284 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
4286 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
4289 status
= verify_attr_len(xdr
, savep
, attrlen
);
4291 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4295 static int decode_getfattr_attrs(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4296 struct nfs_fattr
*fattr
, struct nfs_fh
*fh
,
4297 const struct nfs_server
*server
)
4304 status
= decode_attr_type(xdr
, bitmap
, &type
);
4309 fattr
->mode
|= nfs_type2fmt
[type
];
4310 fattr
->valid
|= status
;
4313 status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
);
4316 fattr
->valid
|= status
;
4318 status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
);
4321 fattr
->valid
|= status
;
4323 status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
);
4326 fattr
->valid
|= status
;
4329 status
= decode_attr_error(xdr
, bitmap
, &err
);
4332 if (err
== -NFS4ERR_WRONGSEC
)
4333 nfs_fixup_secinfo_attributes(fattr
, fh
);
4335 status
= decode_attr_filehandle(xdr
, bitmap
, fh
);
4339 status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
);
4342 fattr
->valid
|= status
;
4344 status
= decode_attr_fs_locations(xdr
, bitmap
, container_of(fattr
,
4345 struct nfs4_fs_locations
,
4349 fattr
->valid
|= status
;
4351 status
= decode_attr_mode(xdr
, bitmap
, &fmode
);
4355 fattr
->mode
|= fmode
;
4356 fattr
->valid
|= status
;
4359 status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
);
4362 fattr
->valid
|= status
;
4364 status
= decode_attr_owner(xdr
, bitmap
, server
, &fattr
->uid
, fattr
->owner_name
);
4367 fattr
->valid
|= status
;
4369 status
= decode_attr_group(xdr
, bitmap
, server
, &fattr
->gid
, fattr
->group_name
);
4372 fattr
->valid
|= status
;
4374 status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
);
4377 fattr
->valid
|= status
;
4379 status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
);
4382 fattr
->valid
|= status
;
4384 status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
);
4387 fattr
->valid
|= status
;
4389 status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
);
4392 fattr
->valid
|= status
;
4394 status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
);
4397 fattr
->valid
|= status
;
4399 status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fattr
->mounted_on_fileid
);
4402 fattr
->valid
|= status
;
4405 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4409 static int decode_getfattr_generic(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4410 struct nfs_fh
*fh
, const struct nfs_server
*server
)
4417 status
= decode_op_hdr(xdr
, OP_GETATTR
);
4421 status
= decode_attr_bitmap(xdr
, bitmap
);
4425 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
4429 status
= decode_getfattr_attrs(xdr
, bitmap
, fattr
, fh
, server
);
4433 status
= verify_attr_len(xdr
, savep
, attrlen
);
4435 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4439 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4440 const struct nfs_server
*server
)
4442 return decode_getfattr_generic(xdr
, fattr
, NULL
, server
);
4446 * Decode potentially multiple layout types. Currently we only support
4447 * one layout driver per file system.
4449 static int decode_first_pnfs_layout_type(struct xdr_stream
*xdr
,
4450 uint32_t *layouttype
)
4455 p
= xdr_inline_decode(xdr
, 4);
4458 num
= be32_to_cpup(p
);
4460 /* pNFS is not supported by the underlying file system */
4466 printk(KERN_INFO
"%s: Warning: Multiple pNFS layout drivers "
4467 "per filesystem not supported\n", __func__
);
4469 /* Decode and set first layout type, move xdr->p past unused types */
4470 p
= xdr_inline_decode(xdr
, num
* 4);
4473 *layouttype
= be32_to_cpup(p
);
4476 print_overflow_msg(__func__
, xdr
);
4481 * The type of file system exported.
4482 * Note we must ensure that layouttype is set in any non-error case.
4484 static int decode_attr_pnfstype(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4485 uint32_t *layouttype
)
4489 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[1]);
4490 if (unlikely(bitmap
[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES
- 1U)))
4492 if (bitmap
[1] & FATTR4_WORD1_FS_LAYOUT_TYPES
) {
4493 status
= decode_first_pnfs_layout_type(xdr
, layouttype
);
4494 bitmap
[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES
;
4501 * The prefered block size for layout directed io
4503 static int decode_attr_layout_blksize(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4508 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[2]);
4510 if (bitmap
[2] & FATTR4_WORD2_LAYOUT_BLKSIZE
) {
4511 p
= xdr_inline_decode(xdr
, 4);
4513 print_overflow_msg(__func__
, xdr
);
4516 *res
= be32_to_cpup(p
);
4517 bitmap
[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE
;
4522 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
4525 uint32_t attrlen
, bitmap
[3];
4528 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4530 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4532 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4535 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
4537 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
4539 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
4541 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
4543 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
4544 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
4546 fsinfo
->wtpref
= fsinfo
->wtmax
;
4547 status
= decode_attr_time_delta(xdr
, bitmap
, &fsinfo
->time_delta
);
4550 status
= decode_attr_pnfstype(xdr
, bitmap
, &fsinfo
->layouttype
);
4553 status
= decode_attr_layout_blksize(xdr
, bitmap
, &fsinfo
->blksize
);
4557 status
= verify_attr_len(xdr
, savep
, attrlen
);
4559 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4563 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
4569 /* Zero handle first to allow comparisons */
4570 memset(fh
, 0, sizeof(*fh
));
4572 status
= decode_op_hdr(xdr
, OP_GETFH
);
4576 p
= xdr_inline_decode(xdr
, 4);
4579 len
= be32_to_cpup(p
);
4580 if (len
> NFS4_FHSIZE
)
4583 p
= xdr_inline_decode(xdr
, len
);
4586 memcpy(fh
->data
, p
, len
);
4589 print_overflow_msg(__func__
, xdr
);
4593 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4597 status
= decode_op_hdr(xdr
, OP_LINK
);
4600 return decode_change_info(xdr
, cinfo
);
4604 * We create the owner, so we know a proper owner.id length is 4.
4606 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
4608 uint64_t offset
, length
, clientid
;
4610 uint32_t namelen
, type
;
4612 p
= xdr_inline_decode(xdr
, 32); /* read 32 bytes */
4615 p
= xdr_decode_hyper(p
, &offset
); /* read 2 8-byte long words */
4616 p
= xdr_decode_hyper(p
, &length
);
4617 type
= be32_to_cpup(p
++); /* 4 byte read */
4618 if (fl
!= NULL
) { /* manipulate file lock */
4619 fl
->fl_start
= (loff_t
)offset
;
4620 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
4621 if (length
== ~(uint64_t)0)
4622 fl
->fl_end
= OFFSET_MAX
;
4623 fl
->fl_type
= F_WRLCK
;
4625 fl
->fl_type
= F_RDLCK
;
4628 p
= xdr_decode_hyper(p
, &clientid
); /* read 8 bytes */
4629 namelen
= be32_to_cpup(p
); /* read 4 bytes */ /* have read all 32 bytes now */
4630 p
= xdr_inline_decode(xdr
, namelen
); /* variable size field */
4632 return -NFS4ERR_DENIED
;
4634 print_overflow_msg(__func__
, xdr
);
4638 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
4642 status
= decode_op_hdr(xdr
, OP_LOCK
);
4646 status
= decode_stateid(xdr
, &res
->stateid
);
4647 if (unlikely(status
))
4649 } else if (status
== -NFS4ERR_DENIED
)
4650 status
= decode_lock_denied(xdr
, NULL
);
4651 if (res
->open_seqid
!= NULL
)
4652 nfs_increment_open_seqid(status
, res
->open_seqid
);
4653 nfs_increment_lock_seqid(status
, res
->lock_seqid
);
4658 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
4661 status
= decode_op_hdr(xdr
, OP_LOCKT
);
4662 if (status
== -NFS4ERR_DENIED
)
4663 return decode_lock_denied(xdr
, res
->denied
);
4667 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
4671 status
= decode_op_hdr(xdr
, OP_LOCKU
);
4673 nfs_increment_lock_seqid(status
, res
->seqid
);
4675 status
= decode_stateid(xdr
, &res
->stateid
);
4679 static int decode_release_lockowner(struct xdr_stream
*xdr
)
4681 return decode_op_hdr(xdr
, OP_RELEASE_LOCKOWNER
);
4684 static int decode_lookup(struct xdr_stream
*xdr
)
4686 return decode_op_hdr(xdr
, OP_LOOKUP
);
4689 /* This is too sick! */
4690 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
4693 uint32_t limit_type
, nblocks
, blocksize
;
4695 p
= xdr_inline_decode(xdr
, 12);
4698 limit_type
= be32_to_cpup(p
++);
4699 switch (limit_type
) {
4701 xdr_decode_hyper(p
, maxsize
);
4704 nblocks
= be32_to_cpup(p
++);
4705 blocksize
= be32_to_cpup(p
);
4706 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
4710 print_overflow_msg(__func__
, xdr
);
4714 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4717 uint32_t delegation_type
;
4720 p
= xdr_inline_decode(xdr
, 4);
4723 delegation_type
= be32_to_cpup(p
);
4724 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
4725 res
->delegation_type
= 0;
4728 status
= decode_stateid(xdr
, &res
->delegation
);
4729 if (unlikely(status
))
4731 p
= xdr_inline_decode(xdr
, 4);
4734 res
->do_recall
= be32_to_cpup(p
);
4736 switch (delegation_type
) {
4737 case NFS4_OPEN_DELEGATE_READ
:
4738 res
->delegation_type
= FMODE_READ
;
4740 case NFS4_OPEN_DELEGATE_WRITE
:
4741 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
4742 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
4745 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
4747 print_overflow_msg(__func__
, xdr
);
4751 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4754 uint32_t savewords
, bmlen
, i
;
4757 status
= decode_op_hdr(xdr
, OP_OPEN
);
4759 nfs_increment_open_seqid(status
, res
->seqid
);
4761 status
= decode_stateid(xdr
, &res
->stateid
);
4762 if (unlikely(status
))
4765 decode_change_info(xdr
, &res
->cinfo
);
4767 p
= xdr_inline_decode(xdr
, 8);
4770 res
->rflags
= be32_to_cpup(p
++);
4771 bmlen
= be32_to_cpup(p
);
4775 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4778 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
4779 for (i
= 0; i
< savewords
; ++i
)
4780 res
->attrset
[i
] = be32_to_cpup(p
++);
4781 for (; i
< NFS4_BITMAP_SIZE
; i
++)
4782 res
->attrset
[i
] = 0;
4784 return decode_delegation(xdr
, res
);
4786 dprintk("%s: Bitmap too large! Length = %u\n", __func__
, bmlen
);
4789 print_overflow_msg(__func__
, xdr
);
4793 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
4797 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
4799 nfs_increment_open_seqid(status
, res
->seqid
);
4801 status
= decode_stateid(xdr
, &res
->stateid
);
4805 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4809 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
4811 nfs_increment_open_seqid(status
, res
->seqid
);
4813 status
= decode_stateid(xdr
, &res
->stateid
);
4817 static int decode_putfh(struct xdr_stream
*xdr
)
4819 return decode_op_hdr(xdr
, OP_PUTFH
);
4822 static int decode_putrootfh(struct xdr_stream
*xdr
)
4824 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
4827 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
4829 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4831 uint32_t count
, eof
, recvd
, hdrlen
;
4834 status
= decode_op_hdr(xdr
, OP_READ
);
4837 p
= xdr_inline_decode(xdr
, 8);
4840 eof
= be32_to_cpup(p
++);
4841 count
= be32_to_cpup(p
);
4842 hdrlen
= (u8
*) xdr
->p
- (u8
*) iov
->iov_base
;
4843 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4844 if (count
> recvd
) {
4845 dprintk("NFS: server cheating in read reply: "
4846 "count %u > recvd %u\n", count
, recvd
);
4850 xdr_read_pages(xdr
, count
);
4855 print_overflow_msg(__func__
, xdr
);
4859 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
4861 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4862 struct kvec
*iov
= rcvbuf
->head
;
4864 u32 recvd
, pglen
= rcvbuf
->page_len
;
4867 status
= decode_op_hdr(xdr
, OP_READDIR
);
4869 status
= decode_verifier(xdr
, readdir
->verifier
.data
);
4870 if (unlikely(status
))
4872 dprintk("%s: verifier = %08x:%08x\n",
4874 ((u32
*)readdir
->verifier
.data
)[0],
4875 ((u32
*)readdir
->verifier
.data
)[1]);
4878 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4879 recvd
= rcvbuf
->len
- hdrlen
;
4882 xdr_read_pages(xdr
, pglen
);
4888 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
4890 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4891 struct kvec
*iov
= rcvbuf
->head
;
4897 status
= decode_op_hdr(xdr
, OP_READLINK
);
4901 /* Convert length of symlink */
4902 p
= xdr_inline_decode(xdr
, 4);
4905 len
= be32_to_cpup(p
);
4906 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
4907 dprintk("nfs: server returned giant symlink!\n");
4908 return -ENAMETOOLONG
;
4910 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4911 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4913 dprintk("NFS: server cheating in readlink reply: "
4914 "count %u > recvd %u\n", len
, recvd
);
4917 xdr_read_pages(xdr
, len
);
4919 * The XDR encode routine has set things up so that
4920 * the link text will be copied directly into the
4921 * buffer. We just have to do overflow-checking,
4922 * and and null-terminate the text (the VFS expects
4923 * null-termination).
4925 xdr_terminate_string(rcvbuf
, len
);
4928 print_overflow_msg(__func__
, xdr
);
4932 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4936 status
= decode_op_hdr(xdr
, OP_REMOVE
);
4939 status
= decode_change_info(xdr
, cinfo
);
4944 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
4945 struct nfs4_change_info
*new_cinfo
)
4949 status
= decode_op_hdr(xdr
, OP_RENAME
);
4952 if ((status
= decode_change_info(xdr
, old_cinfo
)))
4954 status
= decode_change_info(xdr
, new_cinfo
);
4959 static int decode_renew(struct xdr_stream
*xdr
)
4961 return decode_op_hdr(xdr
, OP_RENEW
);
4965 decode_restorefh(struct xdr_stream
*xdr
)
4967 return decode_op_hdr(xdr
, OP_RESTOREFH
);
4970 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
4971 struct nfs_getaclres
*res
)
4973 __be32
*savep
, *bm_p
;
4976 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4978 size_t page_len
= xdr
->buf
->page_len
;
4981 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4985 res
->acl_data_offset
= be32_to_cpup(bm_p
) + 2;
4986 res
->acl_data_offset
<<= 2;
4987 /* Check if the acl data starts beyond the allocated buffer */
4988 if (res
->acl_data_offset
> page_len
)
4991 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4993 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4996 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
4998 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
5001 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5002 * are stored with the acl data to handle the problem of
5003 * variable length bitmaps.*/
5006 /* We ignore &savep and don't do consistency checks on
5007 * the attr length. Let userspace figure it out.... */
5008 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
5009 attrlen
+= res
->acl_data_offset
;
5010 if (attrlen
> page_len
) {
5011 if (res
->acl_flags
& NFS4_ACL_LEN_REQUEST
) {
5012 /* getxattr interface called with a NULL buf */
5013 res
->acl_len
= attrlen
;
5016 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
5020 xdr_read_pages(xdr
, attrlen
);
5021 res
->acl_len
= attrlen
;
5023 status
= -EOPNOTSUPP
;
5030 decode_savefh(struct xdr_stream
*xdr
)
5032 return decode_op_hdr(xdr
, OP_SAVEFH
);
5035 static int decode_setattr(struct xdr_stream
*xdr
)
5041 status
= decode_op_hdr(xdr
, OP_SETATTR
);
5044 p
= xdr_inline_decode(xdr
, 4);
5047 bmlen
= be32_to_cpup(p
);
5048 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
5052 print_overflow_msg(__func__
, xdr
);
5056 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs4_setclientid_res
*res
)
5062 p
= xdr_inline_decode(xdr
, 8);
5065 opnum
= be32_to_cpup(p
++);
5066 if (opnum
!= OP_SETCLIENTID
) {
5067 dprintk("nfs: decode_setclientid: Server returned operation"
5071 nfserr
= be32_to_cpup(p
);
5072 if (nfserr
== NFS_OK
) {
5073 p
= xdr_inline_decode(xdr
, 8 + NFS4_VERIFIER_SIZE
);
5076 p
= xdr_decode_hyper(p
, &res
->clientid
);
5077 memcpy(res
->confirm
.data
, p
, NFS4_VERIFIER_SIZE
);
5078 } else if (nfserr
== NFSERR_CLID_INUSE
) {
5081 /* skip netid string */
5082 p
= xdr_inline_decode(xdr
, 4);
5085 len
= be32_to_cpup(p
);
5086 p
= xdr_inline_decode(xdr
, len
);
5090 /* skip uaddr string */
5091 p
= xdr_inline_decode(xdr
, 4);
5094 len
= be32_to_cpup(p
);
5095 p
= xdr_inline_decode(xdr
, len
);
5098 return -NFSERR_CLID_INUSE
;
5100 return nfs4_stat_to_errno(nfserr
);
5104 print_overflow_msg(__func__
, xdr
);
5108 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
5110 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
5113 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
5118 status
= decode_op_hdr(xdr
, OP_WRITE
);
5122 p
= xdr_inline_decode(xdr
, 16);
5125 res
->count
= be32_to_cpup(p
++);
5126 res
->verf
->committed
= be32_to_cpup(p
++);
5127 memcpy(res
->verf
->verifier
, p
, 8);
5130 print_overflow_msg(__func__
, xdr
);
5134 static int decode_delegreturn(struct xdr_stream
*xdr
)
5136 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
5139 static int decode_secinfo_gss(struct xdr_stream
*xdr
, struct nfs4_secinfo_flavor
*flavor
)
5143 p
= xdr_inline_decode(xdr
, 4);
5146 flavor
->gss
.sec_oid4
.len
= be32_to_cpup(p
);
5147 if (flavor
->gss
.sec_oid4
.len
> GSS_OID_MAX_LEN
)
5150 p
= xdr_inline_decode(xdr
, flavor
->gss
.sec_oid4
.len
);
5153 memcpy(flavor
->gss
.sec_oid4
.data
, p
, flavor
->gss
.sec_oid4
.len
);
5155 p
= xdr_inline_decode(xdr
, 8);
5158 flavor
->gss
.qop4
= be32_to_cpup(p
++);
5159 flavor
->gss
.service
= be32_to_cpup(p
);
5164 print_overflow_msg(__func__
, xdr
);
5170 static int decode_secinfo(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5172 struct nfs4_secinfo_flavor
*sec_flavor
;
5177 status
= decode_op_hdr(xdr
, OP_SECINFO
);
5180 p
= xdr_inline_decode(xdr
, 4);
5184 res
->flavors
->num_flavors
= 0;
5185 num_flavors
= be32_to_cpup(p
);
5187 for (i
= 0; i
< num_flavors
; i
++) {
5188 sec_flavor
= &res
->flavors
->flavors
[i
];
5189 if ((char *)&sec_flavor
[1] - (char *)res
->flavors
> PAGE_SIZE
)
5192 p
= xdr_inline_decode(xdr
, 4);
5195 sec_flavor
->flavor
= be32_to_cpup(p
);
5197 if (sec_flavor
->flavor
== RPC_AUTH_GSS
) {
5198 status
= decode_secinfo_gss(xdr
, sec_flavor
);
5202 res
->flavors
->num_flavors
++;
5208 print_overflow_msg(__func__
, xdr
);
5212 #if defined(CONFIG_NFS_V4_1)
5213 static int decode_exchange_id(struct xdr_stream
*xdr
,
5214 struct nfs41_exchange_id_res
*res
)
5220 struct nfs_client
*clp
= res
->client
;
5222 status
= decode_op_hdr(xdr
, OP_EXCHANGE_ID
);
5226 p
= xdr_inline_decode(xdr
, 8);
5229 xdr_decode_hyper(p
, &clp
->cl_clientid
);
5230 p
= xdr_inline_decode(xdr
, 12);
5233 clp
->cl_seqid
= be32_to_cpup(p
++);
5234 clp
->cl_exchange_flags
= be32_to_cpup(p
++);
5236 /* We ask for SP4_NONE */
5237 dummy
= be32_to_cpup(p
);
5238 if (dummy
!= SP4_NONE
)
5241 /* Throw away minor_id */
5242 p
= xdr_inline_decode(xdr
, 8);
5246 /* Throw away Major id */
5247 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5248 if (unlikely(status
))
5251 /* Save server_scope */
5252 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5253 if (unlikely(status
))
5256 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5259 memcpy(res
->server_scope
->server_scope
, dummy_str
, dummy
);
5260 res
->server_scope
->server_scope_sz
= dummy
;
5262 /* Throw away Implementation id array */
5263 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5264 if (unlikely(status
))
5269 print_overflow_msg(__func__
, xdr
);
5273 static int decode_chan_attrs(struct xdr_stream
*xdr
,
5274 struct nfs4_channel_attrs
*attrs
)
5279 p
= xdr_inline_decode(xdr
, 28);
5282 val
= be32_to_cpup(p
++); /* headerpadsz */
5284 return -EINVAL
; /* no support for header padding yet */
5285 attrs
->max_rqst_sz
= be32_to_cpup(p
++);
5286 attrs
->max_resp_sz
= be32_to_cpup(p
++);
5287 attrs
->max_resp_sz_cached
= be32_to_cpup(p
++);
5288 attrs
->max_ops
= be32_to_cpup(p
++);
5289 attrs
->max_reqs
= be32_to_cpup(p
++);
5290 nr_attrs
= be32_to_cpup(p
);
5291 if (unlikely(nr_attrs
> 1)) {
5292 printk(KERN_WARNING
"%s: Invalid rdma channel attrs count %u\n",
5293 __func__
, nr_attrs
);
5296 if (nr_attrs
== 1) {
5297 p
= xdr_inline_decode(xdr
, 4); /* skip rdma_attrs */
5303 print_overflow_msg(__func__
, xdr
);
5307 static int decode_sessionid(struct xdr_stream
*xdr
, struct nfs4_sessionid
*sid
)
5309 return decode_opaque_fixed(xdr
, sid
->data
, NFS4_MAX_SESSIONID_LEN
);
5312 static int decode_create_session(struct xdr_stream
*xdr
,
5313 struct nfs41_create_session_res
*res
)
5317 struct nfs_client
*clp
= res
->client
;
5318 struct nfs4_session
*session
= clp
->cl_session
;
5320 status
= decode_op_hdr(xdr
, OP_CREATE_SESSION
);
5322 status
= decode_sessionid(xdr
, &session
->sess_id
);
5323 if (unlikely(status
))
5327 p
= xdr_inline_decode(xdr
, 8);
5330 clp
->cl_seqid
= be32_to_cpup(p
++);
5331 session
->flags
= be32_to_cpup(p
);
5333 /* Channel attributes */
5334 status
= decode_chan_attrs(xdr
, &session
->fc_attrs
);
5336 status
= decode_chan_attrs(xdr
, &session
->bc_attrs
);
5339 print_overflow_msg(__func__
, xdr
);
5343 static int decode_destroy_session(struct xdr_stream
*xdr
, void *dummy
)
5345 return decode_op_hdr(xdr
, OP_DESTROY_SESSION
);
5348 static int decode_reclaim_complete(struct xdr_stream
*xdr
, void *dummy
)
5350 return decode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
);
5352 #endif /* CONFIG_NFS_V4_1 */
5354 static int decode_sequence(struct xdr_stream
*xdr
,
5355 struct nfs4_sequence_res
*res
,
5356 struct rpc_rqst
*rqstp
)
5358 #if defined(CONFIG_NFS_V4_1)
5359 struct nfs4_sessionid id
;
5364 if (!res
->sr_session
)
5367 status
= decode_op_hdr(xdr
, OP_SEQUENCE
);
5369 status
= decode_sessionid(xdr
, &id
);
5370 if (unlikely(status
))
5374 * If the server returns different values for sessionID, slotID or
5375 * sequence number, the server is looney tunes.
5377 status
= -EREMOTEIO
;
5379 if (memcmp(id
.data
, res
->sr_session
->sess_id
.data
,
5380 NFS4_MAX_SESSIONID_LEN
)) {
5381 dprintk("%s Invalid session id\n", __func__
);
5385 p
= xdr_inline_decode(xdr
, 20);
5390 dummy
= be32_to_cpup(p
++);
5391 if (dummy
!= res
->sr_slot
->seq_nr
) {
5392 dprintk("%s Invalid sequence number\n", __func__
);
5396 dummy
= be32_to_cpup(p
++);
5397 if (dummy
!= res
->sr_slot
- res
->sr_session
->fc_slot_table
.slots
) {
5398 dprintk("%s Invalid slot id\n", __func__
);
5401 /* highest slot id - currently not processed */
5402 dummy
= be32_to_cpup(p
++);
5403 /* target highest slot id - currently not processed */
5404 dummy
= be32_to_cpup(p
++);
5406 res
->sr_status_flags
= be32_to_cpup(p
);
5409 res
->sr_status
= status
;
5412 print_overflow_msg(__func__
, xdr
);
5415 #else /* CONFIG_NFS_V4_1 */
5417 #endif /* CONFIG_NFS_V4_1 */
5420 #if defined(CONFIG_NFS_V4_1)
5422 * TODO: Need to handle case when EOF != true;
5424 static int decode_getdevicelist(struct xdr_stream
*xdr
,
5425 struct pnfs_devicelist
*res
)
5429 struct nfs_writeverf verftemp
;
5431 status
= decode_op_hdr(xdr
, OP_GETDEVICELIST
);
5435 p
= xdr_inline_decode(xdr
, 8 + 8 + 4);
5439 /* TODO: Skip cookie for now */
5443 p
= xdr_decode_opaque_fixed(p
, verftemp
.verifier
, 8);
5445 res
->num_devs
= be32_to_cpup(p
);
5447 dprintk("%s: num_dev %d\n", __func__
, res
->num_devs
);
5449 if (res
->num_devs
> NFS4_PNFS_GETDEVLIST_MAXNUM
) {
5450 printk(KERN_ERR
"%s too many result dev_num %u\n",
5451 __func__
, res
->num_devs
);
5455 p
= xdr_inline_decode(xdr
,
5456 res
->num_devs
* NFS4_DEVICEID4_SIZE
+ 4);
5459 for (i
= 0; i
< res
->num_devs
; i
++)
5460 p
= xdr_decode_opaque_fixed(p
, res
->dev_id
[i
].data
,
5461 NFS4_DEVICEID4_SIZE
);
5462 res
->eof
= be32_to_cpup(p
);
5465 print_overflow_msg(__func__
, xdr
);
5469 static int decode_getdeviceinfo(struct xdr_stream
*xdr
,
5470 struct pnfs_device
*pdev
)
5476 status
= decode_op_hdr(xdr
, OP_GETDEVICEINFO
);
5478 if (status
== -ETOOSMALL
) {
5479 p
= xdr_inline_decode(xdr
, 4);
5482 pdev
->mincount
= be32_to_cpup(p
);
5483 dprintk("%s: Min count too small. mincnt = %u\n",
5484 __func__
, pdev
->mincount
);
5489 p
= xdr_inline_decode(xdr
, 8);
5492 type
= be32_to_cpup(p
++);
5493 if (type
!= pdev
->layout_type
) {
5494 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5495 __func__
, pdev
->layout_type
, type
);
5499 * Get the length of the opaque device_addr4. xdr_read_pages places
5500 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5501 * and places the remaining xdr data in xdr_buf->tail
5503 pdev
->mincount
= be32_to_cpup(p
);
5504 xdr_read_pages(xdr
, pdev
->mincount
); /* include space for the length */
5506 /* Parse notification bitmap, verifying that it is zero. */
5507 p
= xdr_inline_decode(xdr
, 4);
5510 len
= be32_to_cpup(p
);
5514 p
= xdr_inline_decode(xdr
, 4 * len
);
5517 for (i
= 0; i
< len
; i
++, p
++) {
5518 if (be32_to_cpup(p
)) {
5519 dprintk("%s: notifications not supported\n",
5527 print_overflow_msg(__func__
, xdr
);
5531 static int decode_layoutget(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5532 struct nfs4_layoutget_res
*res
)
5537 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
5538 struct kvec
*iov
= rcvbuf
->head
;
5541 status
= decode_op_hdr(xdr
, OP_LAYOUTGET
);
5544 p
= xdr_inline_decode(xdr
, 8 + NFS4_STATEID_SIZE
);
5547 res
->return_on_close
= be32_to_cpup(p
++);
5548 p
= xdr_decode_opaque_fixed(p
, res
->stateid
.data
, NFS4_STATEID_SIZE
);
5549 layout_count
= be32_to_cpup(p
);
5550 if (!layout_count
) {
5551 dprintk("%s: server responded with empty layout array\n",
5556 p
= xdr_inline_decode(xdr
, 28);
5559 p
= xdr_decode_hyper(p
, &res
->range
.offset
);
5560 p
= xdr_decode_hyper(p
, &res
->range
.length
);
5561 res
->range
.iomode
= be32_to_cpup(p
++);
5562 res
->type
= be32_to_cpup(p
++);
5563 res
->layoutp
->len
= be32_to_cpup(p
);
5565 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5567 (unsigned long)res
->range
.offset
,
5568 (unsigned long)res
->range
.length
,
5573 hdrlen
= (u8
*) xdr
->p
- (u8
*) iov
->iov_base
;
5574 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
5575 if (res
->layoutp
->len
> recvd
) {
5576 dprintk("NFS: server cheating in layoutget reply: "
5577 "layout len %u > recvd %u\n",
5578 res
->layoutp
->len
, recvd
);
5582 xdr_read_pages(xdr
, res
->layoutp
->len
);
5584 if (layout_count
> 1) {
5585 /* We only handle a length one array at the moment. Any
5586 * further entries are just ignored. Note that this means
5587 * the client may see a response that is less than the
5588 * minimum it requested.
5590 dprintk("%s: server responded with %d layouts, dropping tail\n",
5591 __func__
, layout_count
);
5596 print_overflow_msg(__func__
, xdr
);
5600 static int decode_layoutreturn(struct xdr_stream
*xdr
,
5601 struct nfs4_layoutreturn_res
*res
)
5606 status
= decode_op_hdr(xdr
, OP_LAYOUTRETURN
);
5609 p
= xdr_inline_decode(xdr
, 4);
5612 res
->lrs_present
= be32_to_cpup(p
);
5613 if (res
->lrs_present
)
5614 status
= decode_stateid(xdr
, &res
->stateid
);
5617 print_overflow_msg(__func__
, xdr
);
5621 static int decode_layoutcommit(struct xdr_stream
*xdr
,
5622 struct rpc_rqst
*req
,
5623 struct nfs4_layoutcommit_res
*res
)
5629 status
= decode_op_hdr(xdr
, OP_LAYOUTCOMMIT
);
5630 res
->status
= status
;
5634 p
= xdr_inline_decode(xdr
, 4);
5637 sizechanged
= be32_to_cpup(p
);
5640 /* throw away new size */
5641 p
= xdr_inline_decode(xdr
, 8);
5647 print_overflow_msg(__func__
, xdr
);
5651 static int decode_test_stateid(struct xdr_stream
*xdr
,
5652 struct nfs41_test_stateid_res
*res
)
5658 status
= decode_op_hdr(xdr
, OP_TEST_STATEID
);
5662 p
= xdr_inline_decode(xdr
, 4);
5665 num_res
= be32_to_cpup(p
++);
5669 p
= xdr_inline_decode(xdr
, 4);
5672 res
->status
= be32_to_cpup(p
++);
5675 print_overflow_msg(__func__
, xdr
);
5680 static int decode_free_stateid(struct xdr_stream
*xdr
,
5681 struct nfs41_free_stateid_res
*res
)
5686 status
= decode_op_hdr(xdr
, OP_FREE_STATEID
);
5690 p
= xdr_inline_decode(xdr
, 4);
5693 res
->status
= be32_to_cpup(p
++);
5696 print_overflow_msg(__func__
, xdr
);
5699 #endif /* CONFIG_NFS_V4_1 */
5702 * END OF "GENERIC" DECODE ROUTINES.
5706 * Decode OPEN_DOWNGRADE response
5708 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
,
5709 struct xdr_stream
*xdr
,
5710 struct nfs_closeres
*res
)
5712 struct compound_hdr hdr
;
5715 status
= decode_compound_hdr(xdr
, &hdr
);
5718 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5721 status
= decode_putfh(xdr
);
5724 status
= decode_open_downgrade(xdr
, res
);
5727 decode_getfattr(xdr
, res
->fattr
, res
->server
);
5733 * Decode ACCESS response
5735 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5736 struct nfs4_accessres
*res
)
5738 struct compound_hdr hdr
;
5741 status
= decode_compound_hdr(xdr
, &hdr
);
5744 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5747 status
= decode_putfh(xdr
);
5750 status
= decode_access(xdr
, res
);
5753 decode_getfattr(xdr
, res
->fattr
, res
->server
);
5759 * Decode LOOKUP response
5761 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5762 struct nfs4_lookup_res
*res
)
5764 struct compound_hdr hdr
;
5767 status
= decode_compound_hdr(xdr
, &hdr
);
5770 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5773 status
= decode_putfh(xdr
);
5776 status
= decode_lookup(xdr
);
5779 status
= decode_getfh(xdr
, res
->fh
);
5782 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
);
5788 * Decode LOOKUP_ROOT response
5790 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
,
5791 struct xdr_stream
*xdr
,
5792 struct nfs4_lookup_res
*res
)
5794 struct compound_hdr hdr
;
5797 status
= decode_compound_hdr(xdr
, &hdr
);
5800 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5803 status
= decode_putrootfh(xdr
);
5806 status
= decode_getfh(xdr
, res
->fh
);
5808 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
);
5814 * Decode REMOVE response
5816 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5817 struct nfs_removeres
*res
)
5819 struct compound_hdr hdr
;
5822 status
= decode_compound_hdr(xdr
, &hdr
);
5825 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5828 status
= decode_putfh(xdr
);
5831 status
= decode_remove(xdr
, &res
->cinfo
);
5834 decode_getfattr(xdr
, res
->dir_attr
, res
->server
);
5840 * Decode RENAME response
5842 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5843 struct nfs_renameres
*res
)
5845 struct compound_hdr hdr
;
5848 status
= decode_compound_hdr(xdr
, &hdr
);
5851 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5854 status
= decode_putfh(xdr
);
5857 status
= decode_savefh(xdr
);
5860 status
= decode_putfh(xdr
);
5863 status
= decode_rename(xdr
, &res
->old_cinfo
, &res
->new_cinfo
);
5866 /* Current FH is target directory */
5867 if (decode_getfattr(xdr
, res
->new_fattr
, res
->server
))
5869 status
= decode_restorefh(xdr
);
5872 decode_getfattr(xdr
, res
->old_fattr
, res
->server
);
5878 * Decode LINK response
5880 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5881 struct nfs4_link_res
*res
)
5883 struct compound_hdr hdr
;
5886 status
= decode_compound_hdr(xdr
, &hdr
);
5889 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5892 status
= decode_putfh(xdr
);
5895 status
= decode_savefh(xdr
);
5898 status
= decode_putfh(xdr
);
5901 status
= decode_link(xdr
, &res
->cinfo
);
5905 * Note order: OP_LINK leaves the directory as the current
5908 if (decode_getfattr(xdr
, res
->dir_attr
, res
->server
))
5910 status
= decode_restorefh(xdr
);
5913 decode_getfattr(xdr
, res
->fattr
, res
->server
);
5919 * Decode CREATE response
5921 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5922 struct nfs4_create_res
*res
)
5924 struct compound_hdr hdr
;
5927 status
= decode_compound_hdr(xdr
, &hdr
);
5930 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5933 status
= decode_putfh(xdr
);
5936 status
= decode_savefh(xdr
);
5939 status
= decode_create(xdr
, &res
->dir_cinfo
);
5942 status
= decode_getfh(xdr
, res
->fh
);
5945 if (decode_getfattr(xdr
, res
->fattr
, res
->server
))
5947 status
= decode_restorefh(xdr
);
5950 decode_getfattr(xdr
, res
->dir_fattr
, res
->server
);
5956 * Decode SYMLINK response
5958 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5959 struct nfs4_create_res
*res
)
5961 return nfs4_xdr_dec_create(rqstp
, xdr
, res
);
5965 * Decode GETATTR response
5967 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5968 struct nfs4_getattr_res
*res
)
5970 struct compound_hdr hdr
;
5973 status
= decode_compound_hdr(xdr
, &hdr
);
5976 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5979 status
= decode_putfh(xdr
);
5982 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
);
5988 * Encode an SETACL request
5990 static void nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
5991 struct nfs_setaclargs
*args
)
5993 struct compound_hdr hdr
= {
5994 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
5997 encode_compound_hdr(xdr
, req
, &hdr
);
5998 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
5999 encode_putfh(xdr
, args
->fh
, &hdr
);
6000 encode_setacl(xdr
, args
, &hdr
);
6005 * Decode SETACL response
6008 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6009 struct nfs_setaclres
*res
)
6011 struct compound_hdr hdr
;
6014 status
= decode_compound_hdr(xdr
, &hdr
);
6017 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6020 status
= decode_putfh(xdr
);
6023 status
= decode_setattr(xdr
);
6029 * Decode GETACL response
6032 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6033 struct nfs_getaclres
*res
)
6035 struct compound_hdr hdr
;
6038 if (res
->acl_scratch
!= NULL
) {
6039 void *p
= page_address(res
->acl_scratch
);
6040 xdr_set_scratch_buffer(xdr
, p
, PAGE_SIZE
);
6042 status
= decode_compound_hdr(xdr
, &hdr
);
6045 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6048 status
= decode_putfh(xdr
);
6051 status
= decode_getacl(xdr
, rqstp
, res
);
6058 * Decode CLOSE response
6060 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6061 struct nfs_closeres
*res
)
6063 struct compound_hdr hdr
;
6066 status
= decode_compound_hdr(xdr
, &hdr
);
6069 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6072 status
= decode_putfh(xdr
);
6075 status
= decode_close(xdr
, res
);
6079 * Note: Server may do delete on close for this file
6080 * in which case the getattr call will fail with
6081 * an ESTALE error. Shouldn't be a problem,
6082 * though, since fattr->valid will remain unset.
6084 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6090 * Decode OPEN response
6092 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6093 struct nfs_openres
*res
)
6095 struct compound_hdr hdr
;
6098 status
= decode_compound_hdr(xdr
, &hdr
);
6101 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6104 status
= decode_putfh(xdr
);
6107 status
= decode_savefh(xdr
);
6110 status
= decode_open(xdr
, res
);
6113 if (decode_getfh(xdr
, &res
->fh
) != 0)
6115 if (decode_getfattr(xdr
, res
->f_attr
, res
->server
) != 0)
6117 if (decode_restorefh(xdr
) != 0)
6119 decode_getfattr(xdr
, res
->dir_attr
, res
->server
);
6125 * Decode OPEN_CONFIRM response
6127 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
,
6128 struct xdr_stream
*xdr
,
6129 struct nfs_open_confirmres
*res
)
6131 struct compound_hdr hdr
;
6134 status
= decode_compound_hdr(xdr
, &hdr
);
6137 status
= decode_putfh(xdr
);
6140 status
= decode_open_confirm(xdr
, res
);
6146 * Decode OPEN response
6148 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
,
6149 struct xdr_stream
*xdr
,
6150 struct nfs_openres
*res
)
6152 struct compound_hdr hdr
;
6155 status
= decode_compound_hdr(xdr
, &hdr
);
6158 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6161 status
= decode_putfh(xdr
);
6164 status
= decode_open(xdr
, res
);
6167 decode_getfattr(xdr
, res
->f_attr
, res
->server
);
6173 * Decode SETATTR response
6175 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
,
6176 struct xdr_stream
*xdr
,
6177 struct nfs_setattrres
*res
)
6179 struct compound_hdr hdr
;
6182 status
= decode_compound_hdr(xdr
, &hdr
);
6185 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6188 status
= decode_putfh(xdr
);
6191 status
= decode_setattr(xdr
);
6194 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6200 * Decode LOCK response
6202 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6203 struct nfs_lock_res
*res
)
6205 struct compound_hdr hdr
;
6208 status
= decode_compound_hdr(xdr
, &hdr
);
6211 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6214 status
= decode_putfh(xdr
);
6217 status
= decode_lock(xdr
, res
);
6223 * Decode LOCKT response
6225 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6226 struct nfs_lockt_res
*res
)
6228 struct compound_hdr hdr
;
6231 status
= decode_compound_hdr(xdr
, &hdr
);
6234 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6237 status
= decode_putfh(xdr
);
6240 status
= decode_lockt(xdr
, res
);
6246 * Decode LOCKU response
6248 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6249 struct nfs_locku_res
*res
)
6251 struct compound_hdr hdr
;
6254 status
= decode_compound_hdr(xdr
, &hdr
);
6257 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6260 status
= decode_putfh(xdr
);
6263 status
= decode_locku(xdr
, res
);
6268 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst
*rqstp
,
6269 struct xdr_stream
*xdr
, void *dummy
)
6271 struct compound_hdr hdr
;
6274 status
= decode_compound_hdr(xdr
, &hdr
);
6276 status
= decode_release_lockowner(xdr
);
6281 * Decode READLINK response
6283 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
,
6284 struct xdr_stream
*xdr
,
6285 struct nfs4_readlink_res
*res
)
6287 struct compound_hdr hdr
;
6290 status
= decode_compound_hdr(xdr
, &hdr
);
6293 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6296 status
= decode_putfh(xdr
);
6299 status
= decode_readlink(xdr
, rqstp
);
6305 * Decode READDIR response
6307 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6308 struct nfs4_readdir_res
*res
)
6310 struct compound_hdr hdr
;
6313 status
= decode_compound_hdr(xdr
, &hdr
);
6316 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6319 status
= decode_putfh(xdr
);
6322 status
= decode_readdir(xdr
, rqstp
, res
);
6328 * Decode Read response
6330 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6331 struct nfs_readres
*res
)
6333 struct compound_hdr hdr
;
6336 status
= decode_compound_hdr(xdr
, &hdr
);
6339 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6342 status
= decode_putfh(xdr
);
6345 status
= decode_read(xdr
, rqstp
, res
);
6347 status
= res
->count
;
6353 * Decode WRITE response
6355 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6356 struct nfs_writeres
*res
)
6358 struct compound_hdr hdr
;
6361 status
= decode_compound_hdr(xdr
, &hdr
);
6364 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6367 status
= decode_putfh(xdr
);
6370 status
= decode_write(xdr
, res
);
6374 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6376 status
= res
->count
;
6382 * Decode COMMIT response
6384 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6385 struct nfs_writeres
*res
)
6387 struct compound_hdr hdr
;
6390 status
= decode_compound_hdr(xdr
, &hdr
);
6393 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6396 status
= decode_putfh(xdr
);
6399 status
= decode_commit(xdr
, res
);
6403 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6409 * Decode FSINFO response
6411 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6412 struct nfs4_fsinfo_res
*res
)
6414 struct compound_hdr hdr
;
6417 status
= decode_compound_hdr(xdr
, &hdr
);
6419 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6421 status
= decode_putfh(xdr
);
6423 status
= decode_fsinfo(xdr
, res
->fsinfo
);
6428 * Decode PATHCONF response
6430 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6431 struct nfs4_pathconf_res
*res
)
6433 struct compound_hdr hdr
;
6436 status
= decode_compound_hdr(xdr
, &hdr
);
6438 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6440 status
= decode_putfh(xdr
);
6442 status
= decode_pathconf(xdr
, res
->pathconf
);
6447 * Decode STATFS response
6449 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6450 struct nfs4_statfs_res
*res
)
6452 struct compound_hdr hdr
;
6455 status
= decode_compound_hdr(xdr
, &hdr
);
6457 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6459 status
= decode_putfh(xdr
);
6461 status
= decode_statfs(xdr
, res
->fsstat
);
6466 * Decode GETATTR_BITMAP response
6468 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
,
6469 struct xdr_stream
*xdr
,
6470 struct nfs4_server_caps_res
*res
)
6472 struct compound_hdr hdr
;
6475 status
= decode_compound_hdr(xdr
, &hdr
);
6478 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6481 status
= decode_putfh(xdr
);
6484 status
= decode_server_caps(xdr
, res
);
6490 * Decode RENEW response
6492 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6495 struct compound_hdr hdr
;
6498 status
= decode_compound_hdr(xdr
, &hdr
);
6500 status
= decode_renew(xdr
);
6505 * Decode SETCLIENTID response
6507 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
,
6508 struct xdr_stream
*xdr
,
6509 struct nfs4_setclientid_res
*res
)
6511 struct compound_hdr hdr
;
6514 status
= decode_compound_hdr(xdr
, &hdr
);
6516 status
= decode_setclientid(xdr
, res
);
6521 * Decode SETCLIENTID_CONFIRM response
6523 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
,
6524 struct xdr_stream
*xdr
,
6525 struct nfs_fsinfo
*fsinfo
)
6527 struct compound_hdr hdr
;
6530 status
= decode_compound_hdr(xdr
, &hdr
);
6532 status
= decode_setclientid_confirm(xdr
);
6534 status
= decode_putrootfh(xdr
);
6536 status
= decode_fsinfo(xdr
, fsinfo
);
6541 * Decode DELEGRETURN response
6543 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
,
6544 struct xdr_stream
*xdr
,
6545 struct nfs4_delegreturnres
*res
)
6547 struct compound_hdr hdr
;
6550 status
= decode_compound_hdr(xdr
, &hdr
);
6553 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6556 status
= decode_putfh(xdr
);
6559 status
= decode_delegreturn(xdr
);
6562 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6568 * Decode FS_LOCATIONS response
6570 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
,
6571 struct xdr_stream
*xdr
,
6572 struct nfs4_fs_locations_res
*res
)
6574 struct compound_hdr hdr
;
6577 status
= decode_compound_hdr(xdr
, &hdr
);
6580 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6583 status
= decode_putfh(xdr
);
6586 status
= decode_lookup(xdr
);
6589 xdr_enter_page(xdr
, PAGE_SIZE
);
6590 status
= decode_getfattr(xdr
, &res
->fs_locations
->fattr
,
6591 res
->fs_locations
->server
);
6597 * Decode SECINFO response
6599 static int nfs4_xdr_dec_secinfo(struct rpc_rqst
*rqstp
,
6600 struct xdr_stream
*xdr
,
6601 struct nfs4_secinfo_res
*res
)
6603 struct compound_hdr hdr
;
6606 status
= decode_compound_hdr(xdr
, &hdr
);
6609 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6612 status
= decode_putfh(xdr
);
6615 status
= decode_secinfo(xdr
, res
);
6620 #if defined(CONFIG_NFS_V4_1)
6622 * Decode EXCHANGE_ID response
6624 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst
*rqstp
,
6625 struct xdr_stream
*xdr
,
6628 struct compound_hdr hdr
;
6631 status
= decode_compound_hdr(xdr
, &hdr
);
6633 status
= decode_exchange_id(xdr
, res
);
6638 * Decode CREATE_SESSION response
6640 static int nfs4_xdr_dec_create_session(struct rpc_rqst
*rqstp
,
6641 struct xdr_stream
*xdr
,
6642 struct nfs41_create_session_res
*res
)
6644 struct compound_hdr hdr
;
6647 status
= decode_compound_hdr(xdr
, &hdr
);
6649 status
= decode_create_session(xdr
, res
);
6654 * Decode DESTROY_SESSION response
6656 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst
*rqstp
,
6657 struct xdr_stream
*xdr
,
6660 struct compound_hdr hdr
;
6663 status
= decode_compound_hdr(xdr
, &hdr
);
6665 status
= decode_destroy_session(xdr
, res
);
6670 * Decode SEQUENCE response
6672 static int nfs4_xdr_dec_sequence(struct rpc_rqst
*rqstp
,
6673 struct xdr_stream
*xdr
,
6674 struct nfs4_sequence_res
*res
)
6676 struct compound_hdr hdr
;
6679 status
= decode_compound_hdr(xdr
, &hdr
);
6681 status
= decode_sequence(xdr
, res
, rqstp
);
6686 * Decode GET_LEASE_TIME response
6688 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst
*rqstp
,
6689 struct xdr_stream
*xdr
,
6690 struct nfs4_get_lease_time_res
*res
)
6692 struct compound_hdr hdr
;
6695 status
= decode_compound_hdr(xdr
, &hdr
);
6697 status
= decode_sequence(xdr
, &res
->lr_seq_res
, rqstp
);
6699 status
= decode_putrootfh(xdr
);
6701 status
= decode_fsinfo(xdr
, res
->lr_fsinfo
);
6706 * Decode RECLAIM_COMPLETE response
6708 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst
*rqstp
,
6709 struct xdr_stream
*xdr
,
6710 struct nfs41_reclaim_complete_res
*res
)
6712 struct compound_hdr hdr
;
6715 status
= decode_compound_hdr(xdr
, &hdr
);
6717 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6719 status
= decode_reclaim_complete(xdr
, (void *)NULL
);
6724 * Decode GETDEVICELIST response
6726 static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst
*rqstp
,
6727 struct xdr_stream
*xdr
,
6728 struct nfs4_getdevicelist_res
*res
)
6730 struct compound_hdr hdr
;
6733 dprintk("encoding getdevicelist!\n");
6735 status
= decode_compound_hdr(xdr
, &hdr
);
6738 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6741 status
= decode_putfh(xdr
);
6744 status
= decode_getdevicelist(xdr
, res
->devlist
);
6750 * Decode GETDEVINFO response
6752 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst
*rqstp
,
6753 struct xdr_stream
*xdr
,
6754 struct nfs4_getdeviceinfo_res
*res
)
6756 struct compound_hdr hdr
;
6759 status
= decode_compound_hdr(xdr
, &hdr
);
6762 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6765 status
= decode_getdeviceinfo(xdr
, res
->pdev
);
6771 * Decode LAYOUTGET response
6773 static int nfs4_xdr_dec_layoutget(struct rpc_rqst
*rqstp
,
6774 struct xdr_stream
*xdr
,
6775 struct nfs4_layoutget_res
*res
)
6777 struct compound_hdr hdr
;
6780 status
= decode_compound_hdr(xdr
, &hdr
);
6783 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6786 status
= decode_putfh(xdr
);
6789 status
= decode_layoutget(xdr
, rqstp
, res
);
6795 * Decode LAYOUTRETURN response
6797 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst
*rqstp
,
6798 struct xdr_stream
*xdr
,
6799 struct nfs4_layoutreturn_res
*res
)
6801 struct compound_hdr hdr
;
6804 status
= decode_compound_hdr(xdr
, &hdr
);
6807 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6810 status
= decode_putfh(xdr
);
6813 status
= decode_layoutreturn(xdr
, res
);
6819 * Decode LAYOUTCOMMIT response
6821 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst
*rqstp
,
6822 struct xdr_stream
*xdr
,
6823 struct nfs4_layoutcommit_res
*res
)
6825 struct compound_hdr hdr
;
6828 status
= decode_compound_hdr(xdr
, &hdr
);
6831 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6834 status
= decode_putfh(xdr
);
6837 status
= decode_layoutcommit(xdr
, rqstp
, res
);
6840 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6846 * Decode SECINFO_NO_NAME response
6848 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst
*rqstp
,
6849 struct xdr_stream
*xdr
,
6850 struct nfs4_secinfo_res
*res
)
6852 struct compound_hdr hdr
;
6855 status
= decode_compound_hdr(xdr
, &hdr
);
6858 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6861 status
= decode_putrootfh(xdr
);
6864 status
= decode_secinfo(xdr
, res
);
6870 * Decode TEST_STATEID response
6872 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst
*rqstp
,
6873 struct xdr_stream
*xdr
,
6874 struct nfs41_test_stateid_res
*res
)
6876 struct compound_hdr hdr
;
6879 status
= decode_compound_hdr(xdr
, &hdr
);
6882 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6885 status
= decode_test_stateid(xdr
, res
);
6891 * Decode FREE_STATEID response
6893 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst
*rqstp
,
6894 struct xdr_stream
*xdr
,
6895 struct nfs41_free_stateid_res
*res
)
6897 struct compound_hdr hdr
;
6900 status
= decode_compound_hdr(xdr
, &hdr
);
6903 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6906 status
= decode_free_stateid(xdr
, res
);
6910 #endif /* CONFIG_NFS_V4_1 */
6913 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6914 * the local page cache.
6915 * @xdr: XDR stream where entry resides
6916 * @entry: buffer to fill in with entry data
6917 * @plus: boolean indicating whether this should be a readdirplus entry
6919 * Returns zero if successful, otherwise a negative errno value is
6922 * This function is not invoked during READDIR reply decoding, but
6923 * rather whenever an application invokes the getdents(2) system call
6924 * on a directory already in our cache.
6926 int nfs4_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
6929 uint32_t bitmap
[3] = {0};
6931 __be32
*p
= xdr_inline_decode(xdr
, 4);
6934 if (*p
== xdr_zero
) {
6935 p
= xdr_inline_decode(xdr
, 4);
6944 p
= xdr_inline_decode(xdr
, 12);
6947 entry
->prev_cookie
= entry
->cookie
;
6948 p
= xdr_decode_hyper(p
, &entry
->cookie
);
6949 entry
->len
= be32_to_cpup(p
);
6951 p
= xdr_inline_decode(xdr
, entry
->len
);
6954 entry
->name
= (const char *) p
;
6957 * In case the server doesn't return an inode number,
6958 * we fake one here. (We don't use inode number 0,
6959 * since glibc seems to choke on it...)
6962 entry
->fattr
->valid
= 0;
6964 if (decode_attr_bitmap(xdr
, bitmap
) < 0)
6967 if (decode_attr_length(xdr
, &len
, &p
) < 0)
6970 if (decode_getfattr_attrs(xdr
, bitmap
, entry
->fattr
, entry
->fh
,
6973 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
)
6974 entry
->ino
= entry
->fattr
->mounted_on_fileid
;
6975 else if (entry
->fattr
->valid
& NFS_ATTR_FATTR_FILEID
)
6976 entry
->ino
= entry
->fattr
->fileid
;
6978 entry
->d_type
= DT_UNKNOWN
;
6979 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_TYPE
)
6980 entry
->d_type
= nfs_umode_to_dtype(entry
->fattr
->mode
);
6985 print_overflow_msg(__func__
, xdr
);
6990 * We need to translate between nfs status return values and
6991 * the local errno values which may not be the same.
6998 { NFS4ERR_PERM
, -EPERM
},
6999 { NFS4ERR_NOENT
, -ENOENT
},
7000 { NFS4ERR_IO
, -errno_NFSERR_IO
},
7001 { NFS4ERR_NXIO
, -ENXIO
},
7002 { NFS4ERR_ACCESS
, -EACCES
},
7003 { NFS4ERR_EXIST
, -EEXIST
},
7004 { NFS4ERR_XDEV
, -EXDEV
},
7005 { NFS4ERR_NOTDIR
, -ENOTDIR
},
7006 { NFS4ERR_ISDIR
, -EISDIR
},
7007 { NFS4ERR_INVAL
, -EINVAL
},
7008 { NFS4ERR_FBIG
, -EFBIG
},
7009 { NFS4ERR_NOSPC
, -ENOSPC
},
7010 { NFS4ERR_ROFS
, -EROFS
},
7011 { NFS4ERR_MLINK
, -EMLINK
},
7012 { NFS4ERR_NAMETOOLONG
, -ENAMETOOLONG
},
7013 { NFS4ERR_NOTEMPTY
, -ENOTEMPTY
},
7014 { NFS4ERR_DQUOT
, -EDQUOT
},
7015 { NFS4ERR_STALE
, -ESTALE
},
7016 { NFS4ERR_BADHANDLE
, -EBADHANDLE
},
7017 { NFS4ERR_BAD_COOKIE
, -EBADCOOKIE
},
7018 { NFS4ERR_NOTSUPP
, -ENOTSUPP
},
7019 { NFS4ERR_TOOSMALL
, -ETOOSMALL
},
7020 { NFS4ERR_SERVERFAULT
, -EREMOTEIO
},
7021 { NFS4ERR_BADTYPE
, -EBADTYPE
},
7022 { NFS4ERR_LOCKED
, -EAGAIN
},
7023 { NFS4ERR_SYMLINK
, -ELOOP
},
7024 { NFS4ERR_OP_ILLEGAL
, -EOPNOTSUPP
},
7025 { NFS4ERR_DEADLOCK
, -EDEADLK
},
7030 * Convert an NFS error code to a local one.
7031 * This one is used jointly by NFSv2 and NFSv3.
7034 nfs4_stat_to_errno(int stat
)
7037 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
7038 if (nfs_errtbl
[i
].stat
== stat
)
7039 return nfs_errtbl
[i
].errno
;
7041 if (stat
<= 10000 || stat
> 10100) {
7042 /* The server is looney tunes. */
7045 /* If we cannot translate the error, the recovery routines should
7047 * Note: remaining NFSv4 error codes have values > 10000, so should
7048 * not conflict with native Linux error codes.
7053 #define PROC(proc, argtype, restype) \
7054 [NFSPROC4_CLNT_##proc] = { \
7055 .p_proc = NFSPROC4_COMPOUND, \
7056 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7057 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7058 .p_arglen = NFS4_##argtype##_sz, \
7059 .p_replen = NFS4_##restype##_sz, \
7060 .p_statidx = NFSPROC4_CLNT_##proc, \
7064 struct rpc_procinfo nfs4_procedures
[] = {
7065 PROC(READ
, enc_read
, dec_read
),
7066 PROC(WRITE
, enc_write
, dec_write
),
7067 PROC(COMMIT
, enc_commit
, dec_commit
),
7068 PROC(OPEN
, enc_open
, dec_open
),
7069 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
7070 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
7071 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
7072 PROC(CLOSE
, enc_close
, dec_close
),
7073 PROC(SETATTR
, enc_setattr
, dec_setattr
),
7074 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
7075 PROC(RENEW
, enc_renew
, dec_renew
),
7076 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
7077 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
7078 PROC(LOCK
, enc_lock
, dec_lock
),
7079 PROC(LOCKT
, enc_lockt
, dec_lockt
),
7080 PROC(LOCKU
, enc_locku
, dec_locku
),
7081 PROC(ACCESS
, enc_access
, dec_access
),
7082 PROC(GETATTR
, enc_getattr
, dec_getattr
),
7083 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
7084 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
7085 PROC(REMOVE
, enc_remove
, dec_remove
),
7086 PROC(RENAME
, enc_rename
, dec_rename
),
7087 PROC(LINK
, enc_link
, dec_link
),
7088 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
7089 PROC(CREATE
, enc_create
, dec_create
),
7090 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
7091 PROC(STATFS
, enc_statfs
, dec_statfs
),
7092 PROC(READLINK
, enc_readlink
, dec_readlink
),
7093 PROC(READDIR
, enc_readdir
, dec_readdir
),
7094 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
7095 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
7096 PROC(GETACL
, enc_getacl
, dec_getacl
),
7097 PROC(SETACL
, enc_setacl
, dec_setacl
),
7098 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
7099 PROC(RELEASE_LOCKOWNER
, enc_release_lockowner
, dec_release_lockowner
),
7100 PROC(SECINFO
, enc_secinfo
, dec_secinfo
),
7101 #if defined(CONFIG_NFS_V4_1)
7102 PROC(EXCHANGE_ID
, enc_exchange_id
, dec_exchange_id
),
7103 PROC(CREATE_SESSION
, enc_create_session
, dec_create_session
),
7104 PROC(DESTROY_SESSION
, enc_destroy_session
, dec_destroy_session
),
7105 PROC(SEQUENCE
, enc_sequence
, dec_sequence
),
7106 PROC(GET_LEASE_TIME
, enc_get_lease_time
, dec_get_lease_time
),
7107 PROC(RECLAIM_COMPLETE
, enc_reclaim_complete
, dec_reclaim_complete
),
7108 PROC(GETDEVICEINFO
, enc_getdeviceinfo
, dec_getdeviceinfo
),
7109 PROC(LAYOUTGET
, enc_layoutget
, dec_layoutget
),
7110 PROC(LAYOUTCOMMIT
, enc_layoutcommit
, dec_layoutcommit
),
7111 PROC(LAYOUTRETURN
, enc_layoutreturn
, dec_layoutreturn
),
7112 PROC(SECINFO_NO_NAME
, enc_secinfo_no_name
, dec_secinfo_no_name
),
7113 PROC(TEST_STATEID
, enc_test_stateid
, dec_test_stateid
),
7114 PROC(FREE_STATEID
, enc_free_stateid
, dec_free_stateid
),
7115 PROC(GETDEVICELIST
, enc_getdevicelist
, dec_getdevicelist
),
7116 #endif /* CONFIG_NFS_V4_1 */
7119 struct rpc_version nfs_version4
= {
7121 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
7122 .procs
= nfs4_procedures