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/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 4)
74 #define lock_owner_id_maxsz (1 + 4)
75 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78 #define op_encode_hdr_maxsz (1)
79 #define op_decode_hdr_maxsz (2)
80 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
87 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
92 #define nfs4_fattr_bitmap_maxsz 3
93 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
94 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 /* This is based on getfattr, which uses the most attributes: */
99 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
101 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
104 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
114 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 #define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
128 1024) /* large value for CLID_INUSE */
129 #define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132 #define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
134 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
136 #define encode_share_access_maxsz \
138 #define encode_createmode_maxsz (1 + encode_attrs_maxsz)
139 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141 #define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
147 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
149 #define decode_change_info_maxsz (5)
150 #define decode_open_maxsz (op_decode_hdr_maxsz + \
151 decode_stateid_maxsz + \
152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
155 #define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158 #define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161 #define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165 #define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168 #define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170 #define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
175 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177 #define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
185 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186 #define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188 #define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
193 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
197 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
198 #define encode_link_maxsz (op_encode_hdr_maxsz + \
200 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
201 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
203 1 + encode_stateid_maxsz + 8)
204 #define decode_lock_denied_maxsz \
205 (8 + decode_lockowner_maxsz)
206 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
207 decode_lock_denied_maxsz)
208 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
209 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
210 decode_lock_denied_maxsz)
211 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
212 encode_stateid_maxsz + \
214 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
215 decode_stateid_maxsz)
216 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
217 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
218 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
219 1 + nfs4_name_maxsz + \
222 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
223 #define encode_create_maxsz (op_encode_hdr_maxsz + \
224 1 + 2 + nfs4_name_maxsz + \
226 #define decode_create_maxsz (op_decode_hdr_maxsz + \
227 decode_change_info_maxsz + \
228 nfs4_fattr_bitmap_maxsz)
229 #define encode_statfs_maxsz (encode_getattr_maxsz)
230 #define decode_statfs_maxsz (decode_getattr_maxsz)
231 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
232 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
233 #define encode_getacl_maxsz (encode_getattr_maxsz)
234 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
235 nfs4_fattr_bitmap_maxsz + 1)
236 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
237 encode_stateid_maxsz + 3)
238 #define decode_setacl_maxsz (decode_setattr_maxsz)
239 #define encode_fs_locations_maxsz \
240 (encode_getattr_maxsz)
241 #define decode_fs_locations_maxsz \
243 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
244 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
245 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
246 encode_putfh_maxsz + \
248 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
249 decode_putfh_maxsz + \
251 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
252 encode_putfh_maxsz + \
253 encode_readlink_maxsz)
254 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
255 decode_putfh_maxsz + \
256 decode_readlink_maxsz)
257 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
258 encode_putfh_maxsz + \
259 encode_readdir_maxsz)
260 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
261 decode_putfh_maxsz + \
262 decode_readdir_maxsz)
263 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
264 encode_putfh_maxsz + \
265 encode_write_maxsz + \
266 encode_getattr_maxsz)
267 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
268 decode_putfh_maxsz + \
269 decode_write_maxsz + \
270 decode_getattr_maxsz)
271 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
272 encode_putfh_maxsz + \
273 encode_commit_maxsz + \
274 encode_getattr_maxsz)
275 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
276 decode_putfh_maxsz + \
277 decode_commit_maxsz + \
278 decode_getattr_maxsz)
279 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
280 encode_putfh_maxsz + \
281 encode_savefh_maxsz + \
282 encode_open_maxsz + \
283 encode_getfh_maxsz + \
284 encode_getattr_maxsz + \
285 encode_restorefh_maxsz + \
286 encode_getattr_maxsz)
287 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
288 decode_putfh_maxsz + \
289 decode_savefh_maxsz + \
290 decode_open_maxsz + \
291 decode_getfh_maxsz + \
292 decode_getattr_maxsz + \
293 decode_restorefh_maxsz + \
294 decode_getattr_maxsz)
295 #define NFS4_enc_open_confirm_sz \
296 (compound_encode_hdr_maxsz + \
297 encode_putfh_maxsz + \
298 encode_open_confirm_maxsz)
299 #define NFS4_dec_open_confirm_sz \
300 (compound_decode_hdr_maxsz + \
301 decode_putfh_maxsz + \
302 decode_open_confirm_maxsz)
303 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
304 encode_putfh_maxsz + \
305 encode_open_maxsz + \
306 encode_getattr_maxsz)
307 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
308 decode_putfh_maxsz + \
309 decode_open_maxsz + \
310 decode_getattr_maxsz)
311 #define NFS4_enc_open_downgrade_sz \
312 (compound_encode_hdr_maxsz + \
313 encode_putfh_maxsz + \
314 encode_open_downgrade_maxsz + \
315 encode_getattr_maxsz)
316 #define NFS4_dec_open_downgrade_sz \
317 (compound_decode_hdr_maxsz + \
318 decode_putfh_maxsz + \
319 decode_open_downgrade_maxsz + \
320 decode_getattr_maxsz)
321 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
322 encode_putfh_maxsz + \
323 encode_close_maxsz + \
324 encode_getattr_maxsz)
325 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
326 decode_putfh_maxsz + \
327 decode_close_maxsz + \
328 decode_getattr_maxsz)
329 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
330 encode_putfh_maxsz + \
331 encode_setattr_maxsz + \
332 encode_getattr_maxsz)
333 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
334 decode_putfh_maxsz + \
335 decode_setattr_maxsz + \
336 decode_getattr_maxsz)
337 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
338 encode_putfh_maxsz + \
340 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
341 decode_putfh_maxsz + \
343 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
345 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
347 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
348 encode_setclientid_maxsz)
349 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
350 decode_setclientid_maxsz)
351 #define NFS4_enc_setclientid_confirm_sz \
352 (compound_encode_hdr_maxsz + \
353 encode_setclientid_confirm_maxsz + \
354 encode_putrootfh_maxsz + \
356 #define NFS4_dec_setclientid_confirm_sz \
357 (compound_decode_hdr_maxsz + \
358 decode_setclientid_confirm_maxsz + \
359 decode_putrootfh_maxsz + \
361 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
362 encode_putfh_maxsz + \
364 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
365 decode_putfh_maxsz + \
367 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
368 encode_putfh_maxsz + \
370 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
371 decode_putfh_maxsz + \
373 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
374 encode_putfh_maxsz + \
376 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
377 decode_putfh_maxsz + \
379 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
380 encode_putfh_maxsz + \
381 encode_access_maxsz + \
382 encode_getattr_maxsz)
383 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
384 decode_putfh_maxsz + \
385 decode_access_maxsz + \
386 decode_getattr_maxsz)
387 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
388 encode_putfh_maxsz + \
389 encode_getattr_maxsz)
390 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
391 decode_putfh_maxsz + \
392 decode_getattr_maxsz)
393 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
395 encode_lookup_maxsz + \
396 encode_getattr_maxsz + \
398 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
399 decode_putfh_maxsz + \
400 decode_lookup_maxsz + \
401 decode_getattr_maxsz + \
403 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
404 encode_putrootfh_maxsz + \
405 encode_getattr_maxsz + \
407 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
408 decode_putrootfh_maxsz + \
409 decode_getattr_maxsz + \
411 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
412 encode_putfh_maxsz + \
413 encode_remove_maxsz + \
414 encode_getattr_maxsz)
415 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
416 decode_putfh_maxsz + \
417 op_decode_hdr_maxsz + 5 + \
418 decode_getattr_maxsz)
419 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
420 encode_putfh_maxsz + \
421 encode_savefh_maxsz + \
422 encode_putfh_maxsz + \
423 encode_rename_maxsz + \
424 encode_getattr_maxsz + \
425 encode_restorefh_maxsz + \
426 encode_getattr_maxsz)
427 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
428 decode_putfh_maxsz + \
429 decode_savefh_maxsz + \
430 decode_putfh_maxsz + \
431 decode_rename_maxsz + \
432 decode_getattr_maxsz + \
433 decode_restorefh_maxsz + \
434 decode_getattr_maxsz)
435 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
436 encode_putfh_maxsz + \
437 encode_savefh_maxsz + \
438 encode_putfh_maxsz + \
439 encode_link_maxsz + \
440 decode_getattr_maxsz + \
441 encode_restorefh_maxsz + \
442 decode_getattr_maxsz)
443 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
444 decode_putfh_maxsz + \
445 decode_savefh_maxsz + \
446 decode_putfh_maxsz + \
447 decode_link_maxsz + \
448 decode_getattr_maxsz + \
449 decode_restorefh_maxsz + \
450 decode_getattr_maxsz)
451 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
452 encode_putfh_maxsz + \
453 encode_symlink_maxsz + \
454 encode_getattr_maxsz + \
456 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
457 decode_putfh_maxsz + \
458 decode_symlink_maxsz + \
459 decode_getattr_maxsz + \
461 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
462 encode_putfh_maxsz + \
463 encode_savefh_maxsz + \
464 encode_create_maxsz + \
465 encode_getfh_maxsz + \
466 encode_getattr_maxsz + \
467 encode_restorefh_maxsz + \
468 encode_getattr_maxsz)
469 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
470 decode_putfh_maxsz + \
471 decode_savefh_maxsz + \
472 decode_create_maxsz + \
473 decode_getfh_maxsz + \
474 decode_getattr_maxsz + \
475 decode_restorefh_maxsz + \
476 decode_getattr_maxsz)
477 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
478 encode_putfh_maxsz + \
479 encode_getattr_maxsz)
480 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
481 decode_putfh_maxsz + \
482 decode_getattr_maxsz)
483 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
484 encode_putfh_maxsz + \
486 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
487 decode_putfh_maxsz + \
489 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
490 encode_putfh_maxsz + \
491 encode_getattr_maxsz)
492 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
493 decode_putfh_maxsz + \
494 decode_getattr_maxsz)
495 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
496 encode_putfh_maxsz + \
497 encode_delegreturn_maxsz + \
498 encode_getattr_maxsz)
499 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
500 decode_delegreturn_maxsz + \
501 decode_getattr_maxsz)
502 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
503 encode_putfh_maxsz + \
505 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
506 decode_putfh_maxsz + \
508 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
509 encode_putfh_maxsz + \
511 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
512 decode_putfh_maxsz + \
514 #define NFS4_enc_fs_locations_sz \
515 (compound_encode_hdr_maxsz + \
516 encode_putfh_maxsz + \
517 encode_lookup_maxsz + \
518 encode_fs_locations_maxsz)
519 #define NFS4_dec_fs_locations_sz \
520 (compound_decode_hdr_maxsz + \
521 decode_putfh_maxsz + \
522 decode_lookup_maxsz + \
523 decode_fs_locations_maxsz)
525 static const umode_t nfs_type2fmt
[] = {
532 [NF4SOCK
] = S_IFSOCK
,
538 struct compound_hdr
{
547 * START OF "GENERIC" ENCODE ROUTINES.
548 * These may look a little ugly since they are imported from a "generic"
549 * set of XDR encode/decode routines which are intended to be shared by
550 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
552 * If the pain of reading these is too great, it should be a straightforward
553 * task to translate them into Linux-specific versions which are more
554 * consistent with the style used in NFSv2/v3...
556 #define WRITE32(n) *p++ = htonl(n)
557 #define WRITE64(n) do { \
558 *p++ = htonl((uint32_t)((n) >> 32)); \
559 *p++ = htonl((uint32_t)(n)); \
561 #define WRITEMEM(ptr,nbytes) do { \
562 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
565 #define RESERVE_SPACE(nbytes) do { \
566 p = xdr_reserve_space(xdr, nbytes); \
570 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
574 p
= xdr_reserve_space(xdr
, 4 + len
);
576 xdr_encode_opaque(p
, str
, len
);
579 static void encode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
583 dprintk("encode_compound: tag=%.*s\n", (int)hdr
->taglen
, hdr
->tag
);
584 BUG_ON(hdr
->taglen
> NFS4_MAXTAGLEN
);
585 RESERVE_SPACE(12+(XDR_QUADLEN(hdr
->taglen
)<<2));
586 WRITE32(hdr
->taglen
);
587 WRITEMEM(hdr
->tag
, hdr
->taglen
);
588 WRITE32(NFS4_MINOR_VERSION
);
593 static void encode_nops(struct compound_hdr
*hdr
)
595 *hdr
->nops_p
= htonl(hdr
->nops
);
598 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
602 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
604 xdr_encode_opaque_fixed(p
, verf
->data
, NFS4_VERIFIER_SIZE
);
607 static void encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
, const struct nfs_server
*server
)
609 char owner_name
[IDMAP_NAMESZ
];
610 char owner_group
[IDMAP_NAMESZ
];
611 int owner_namelen
= 0;
612 int owner_grouplen
= 0;
620 * We reserve enough space to write the entire attribute buffer at once.
621 * In the worst-case, this would be
622 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
623 * = 36 bytes, plus any contribution from variable-length fields
624 * such as owner/group.
629 if (iap
->ia_valid
& ATTR_SIZE
)
631 if (iap
->ia_valid
& ATTR_MODE
)
633 if (iap
->ia_valid
& ATTR_UID
) {
634 owner_namelen
= nfs_map_uid_to_name(server
->nfs_client
, iap
->ia_uid
, owner_name
);
635 if (owner_namelen
< 0) {
636 dprintk("nfs: couldn't resolve uid %d to string\n",
639 strcpy(owner_name
, "nobody");
640 owner_namelen
= sizeof("nobody") - 1;
643 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
645 if (iap
->ia_valid
& ATTR_GID
) {
646 owner_grouplen
= nfs_map_gid_to_group(server
->nfs_client
, iap
->ia_gid
, owner_group
);
647 if (owner_grouplen
< 0) {
648 dprintk("nfs: couldn't resolve gid %d to string\n",
650 strcpy(owner_group
, "nobody");
651 owner_grouplen
= sizeof("nobody") - 1;
654 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
656 if (iap
->ia_valid
& ATTR_ATIME_SET
)
658 else if (iap
->ia_valid
& ATTR_ATIME
)
660 if (iap
->ia_valid
& ATTR_MTIME_SET
)
662 else if (iap
->ia_valid
& ATTR_MTIME
)
667 * We write the bitmap length now, but leave the bitmap and the attribute
668 * buffer length to be backfilled at the end of this routine.
674 if (iap
->ia_valid
& ATTR_SIZE
) {
675 bmval0
|= FATTR4_WORD0_SIZE
;
676 WRITE64(iap
->ia_size
);
678 if (iap
->ia_valid
& ATTR_MODE
) {
679 bmval1
|= FATTR4_WORD1_MODE
;
680 WRITE32(iap
->ia_mode
& S_IALLUGO
);
682 if (iap
->ia_valid
& ATTR_UID
) {
683 bmval1
|= FATTR4_WORD1_OWNER
;
684 WRITE32(owner_namelen
);
685 WRITEMEM(owner_name
, owner_namelen
);
687 if (iap
->ia_valid
& ATTR_GID
) {
688 bmval1
|= FATTR4_WORD1_OWNER_GROUP
;
689 WRITE32(owner_grouplen
);
690 WRITEMEM(owner_group
, owner_grouplen
);
692 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
693 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
694 WRITE32(NFS4_SET_TO_CLIENT_TIME
);
696 WRITE32(iap
->ia_mtime
.tv_sec
);
697 WRITE32(iap
->ia_mtime
.tv_nsec
);
699 else if (iap
->ia_valid
& ATTR_ATIME
) {
700 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
701 WRITE32(NFS4_SET_TO_SERVER_TIME
);
703 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
704 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
705 WRITE32(NFS4_SET_TO_CLIENT_TIME
);
707 WRITE32(iap
->ia_mtime
.tv_sec
);
708 WRITE32(iap
->ia_mtime
.tv_nsec
);
710 else if (iap
->ia_valid
& ATTR_MTIME
) {
711 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
712 WRITE32(NFS4_SET_TO_SERVER_TIME
);
716 * Now we backfill the bitmap and the attribute buffer length.
718 if (len
!= ((char *)p
- (char *)q
) + 4) {
719 printk(KERN_ERR
"nfs: Attr length error, %u != %Zu\n",
720 len
, ((char *)p
- (char *)q
) + 4);
723 len
= (char *)p
- (char *)q
- 12;
724 *q
++ = htonl(bmval0
);
725 *q
++ = htonl(bmval1
);
731 static void encode_access(struct xdr_stream
*xdr
, u32 access
, struct compound_hdr
*hdr
)
741 static void encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
745 RESERVE_SPACE(8+NFS4_STATEID_SIZE
);
747 WRITE32(arg
->seqid
->sequence
->counter
);
748 WRITEMEM(arg
->stateid
->data
, NFS4_STATEID_SIZE
);
752 static void encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
758 WRITE64(args
->offset
);
759 WRITE32(args
->count
);
763 static void encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
, struct compound_hdr
*hdr
)
769 WRITE32(create
->ftype
);
771 switch (create
->ftype
) {
774 WRITE32(create
->u
.symlink
.len
);
775 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0, create
->u
.symlink
.len
);
778 case NF4BLK
: case NF4CHR
:
780 WRITE32(create
->u
.device
.specdata1
);
781 WRITE32(create
->u
.device
.specdata2
);
788 RESERVE_SPACE(4 + create
->name
->len
);
789 WRITE32(create
->name
->len
);
790 WRITEMEM(create
->name
->name
, create
->name
->len
);
793 encode_attrs(xdr
, create
->attrs
, create
->server
);
796 static void encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
, struct compound_hdr
*hdr
)
807 static void encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
, struct compound_hdr
*hdr
)
819 static void encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
821 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fattr_bitmap
[0],
822 bitmask
[1] & nfs4_fattr_bitmap
[1], hdr
);
825 static void encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
827 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fsinfo_bitmap
[0],
828 bitmask
[1] & nfs4_fsinfo_bitmap
[1], hdr
);
831 static void encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
833 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fs_locations_bitmap
[0],
834 bitmask
[1] & nfs4_fs_locations_bitmap
[1], hdr
);
837 static void encode_getfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
846 static void encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
850 RESERVE_SPACE(8 + name
->len
);
853 WRITEMEM(name
->name
, name
->len
);
857 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
859 if ((fl
->fl_type
& (F_RDLCK
|F_WRLCK
|F_UNLCK
)) == F_RDLCK
)
860 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
861 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
864 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
866 if (fl
->fl_end
== OFFSET_MAX
)
868 return fl
->fl_end
- fl
->fl_start
+ 1;
872 * opcode,type,reclaim,offset,length,new_lock_owner = 32
873 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
875 static void encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
, struct compound_hdr
*hdr
)
881 WRITE32(nfs4_lock_type(args
->fl
, args
->block
));
882 WRITE32(args
->reclaim
);
883 WRITE64(args
->fl
->fl_start
);
884 WRITE64(nfs4_lock_length(args
->fl
));
885 WRITE32(args
->new_lock_owner
);
886 if (args
->new_lock_owner
){
887 RESERVE_SPACE(4+NFS4_STATEID_SIZE
+32);
888 WRITE32(args
->open_seqid
->sequence
->counter
);
889 WRITEMEM(args
->open_stateid
->data
, NFS4_STATEID_SIZE
);
890 WRITE32(args
->lock_seqid
->sequence
->counter
);
891 WRITE64(args
->lock_owner
.clientid
);
893 WRITEMEM("lock id:", 8);
894 WRITE64(args
->lock_owner
.id
);
897 RESERVE_SPACE(NFS4_STATEID_SIZE
+4);
898 WRITEMEM(args
->lock_stateid
->data
, NFS4_STATEID_SIZE
);
899 WRITE32(args
->lock_seqid
->sequence
->counter
);
904 static void encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
, struct compound_hdr
*hdr
)
910 WRITE32(nfs4_lock_type(args
->fl
, 0));
911 WRITE64(args
->fl
->fl_start
);
912 WRITE64(nfs4_lock_length(args
->fl
));
913 WRITE64(args
->lock_owner
.clientid
);
915 WRITEMEM("lock id:", 8);
916 WRITE64(args
->lock_owner
.id
);
920 static void encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
, struct compound_hdr
*hdr
)
924 RESERVE_SPACE(12+NFS4_STATEID_SIZE
+16);
926 WRITE32(nfs4_lock_type(args
->fl
, 0));
927 WRITE32(args
->seqid
->sequence
->counter
);
928 WRITEMEM(args
->stateid
->data
, NFS4_STATEID_SIZE
);
929 WRITE64(args
->fl
->fl_start
);
930 WRITE64(nfs4_lock_length(args
->fl
));
934 static void encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
939 RESERVE_SPACE(8 + len
);
942 WRITEMEM(name
->name
, len
);
946 static void encode_share_access(struct xdr_stream
*xdr
, fmode_t fmode
)
951 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
953 WRITE32(NFS4_SHARE_ACCESS_READ
);
956 WRITE32(NFS4_SHARE_ACCESS_WRITE
);
958 case FMODE_READ
|FMODE_WRITE
:
959 WRITE32(NFS4_SHARE_ACCESS_BOTH
);
964 WRITE32(0); /* for linux, share_deny = 0 always */
967 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
971 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
976 WRITE32(arg
->seqid
->sequence
->counter
);
977 encode_share_access(xdr
, arg
->fmode
);
979 WRITE64(arg
->clientid
);
981 WRITEMEM("open id:", 8);
985 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
990 switch(arg
->open_flags
& O_EXCL
) {
992 WRITE32(NFS4_CREATE_UNCHECKED
);
993 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
996 WRITE32(NFS4_CREATE_EXCLUSIVE
);
997 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1001 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1006 switch (arg
->open_flags
& O_CREAT
) {
1008 WRITE32(NFS4_OPEN_NOCREATE
);
1011 BUG_ON(arg
->claim
!= NFS4_OPEN_CLAIM_NULL
);
1012 WRITE32(NFS4_OPEN_CREATE
);
1013 encode_createmode(xdr
, arg
);
1017 static inline void encode_delegation_type(struct xdr_stream
*xdr
, fmode_t delegation_type
)
1022 switch (delegation_type
) {
1024 WRITE32(NFS4_OPEN_DELEGATE_NONE
);
1027 WRITE32(NFS4_OPEN_DELEGATE_READ
);
1029 case FMODE_WRITE
|FMODE_READ
:
1030 WRITE32(NFS4_OPEN_DELEGATE_WRITE
);
1037 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
1042 WRITE32(NFS4_OPEN_CLAIM_NULL
);
1043 encode_string(xdr
, name
->len
, name
->name
);
1046 static inline void encode_claim_previous(struct xdr_stream
*xdr
, fmode_t type
)
1051 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS
);
1052 encode_delegation_type(xdr
, type
);
1055 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
1059 RESERVE_SPACE(4+NFS4_STATEID_SIZE
);
1060 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
1061 WRITEMEM(stateid
->data
, NFS4_STATEID_SIZE
);
1062 encode_string(xdr
, name
->len
, name
->name
);
1065 static void encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
, struct compound_hdr
*hdr
)
1067 encode_openhdr(xdr
, arg
);
1068 encode_opentype(xdr
, arg
);
1069 switch (arg
->claim
) {
1070 case NFS4_OPEN_CLAIM_NULL
:
1071 encode_claim_null(xdr
, arg
->name
);
1073 case NFS4_OPEN_CLAIM_PREVIOUS
:
1074 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
1076 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1077 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
1085 static void encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
, struct compound_hdr
*hdr
)
1089 RESERVE_SPACE(4+NFS4_STATEID_SIZE
+4);
1090 WRITE32(OP_OPEN_CONFIRM
);
1091 WRITEMEM(arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1092 WRITE32(arg
->seqid
->sequence
->counter
);
1096 static void encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1100 RESERVE_SPACE(4+NFS4_STATEID_SIZE
+4);
1101 WRITE32(OP_OPEN_DOWNGRADE
);
1102 WRITEMEM(arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1103 WRITE32(arg
->seqid
->sequence
->counter
);
1104 encode_share_access(xdr
, arg
->fmode
);
1109 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
, struct compound_hdr
*hdr
)
1114 RESERVE_SPACE(8 + len
);
1117 WRITEMEM(fh
->data
, len
);
1121 static void encode_putrootfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1126 WRITE32(OP_PUTROOTFH
);
1130 static void encode_stateid(struct xdr_stream
*xdr
, const struct nfs_open_context
*ctx
)
1132 nfs4_stateid stateid
;
1135 RESERVE_SPACE(NFS4_STATEID_SIZE
);
1136 if (ctx
->state
!= NULL
) {
1137 nfs4_copy_stateid(&stateid
, ctx
->state
, ctx
->lockowner
);
1138 WRITEMEM(stateid
.data
, NFS4_STATEID_SIZE
);
1140 WRITEMEM(zero_stateid
.data
, NFS4_STATEID_SIZE
);
1143 static void encode_read(struct xdr_stream
*xdr
, const struct nfs_readargs
*args
, struct compound_hdr
*hdr
)
1150 encode_stateid(xdr
, args
->context
);
1153 WRITE64(args
->offset
);
1154 WRITE32(args
->count
);
1158 static void encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1160 uint32_t attrs
[2] = {
1161 FATTR4_WORD0_RDATTR_ERROR
|FATTR4_WORD0_FILEID
,
1162 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1166 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE
+20);
1167 WRITE32(OP_READDIR
);
1168 WRITE64(readdir
->cookie
);
1169 WRITEMEM(readdir
->verifier
.data
, NFS4_VERIFIER_SIZE
);
1170 WRITE32(readdir
->count
>> 1); /* We're not doing readdirplus */
1171 WRITE32(readdir
->count
);
1173 /* Switch to mounted_on_fileid if the server supports it */
1174 if (readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
1175 attrs
[0] &= ~FATTR4_WORD0_FILEID
;
1177 attrs
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
1178 WRITE32(attrs
[0] & readdir
->bitmask
[0]);
1179 WRITE32(attrs
[1] & readdir
->bitmask
[1]);
1181 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1183 (unsigned long long)readdir
->cookie
,
1184 ((u32
*)readdir
->verifier
.data
)[0],
1185 ((u32
*)readdir
->verifier
.data
)[1],
1186 attrs
[0] & readdir
->bitmask
[0],
1187 attrs
[1] & readdir
->bitmask
[1]);
1190 static void encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1195 WRITE32(OP_READLINK
);
1199 static void encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1203 RESERVE_SPACE(8 + name
->len
);
1206 WRITEMEM(name
->name
, name
->len
);
1210 static void encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
, struct compound_hdr
*hdr
)
1214 RESERVE_SPACE(8 + oldname
->len
);
1216 WRITE32(oldname
->len
);
1217 WRITEMEM(oldname
->name
, oldname
->len
);
1219 RESERVE_SPACE(4 + newname
->len
);
1220 WRITE32(newname
->len
);
1221 WRITEMEM(newname
->name
, newname
->len
);
1225 static void encode_renew(struct xdr_stream
*xdr
, const struct nfs_client
*client_stateid
, struct compound_hdr
*hdr
)
1231 WRITE64(client_stateid
->cl_clientid
);
1236 encode_restorefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1241 WRITE32(OP_RESTOREFH
);
1246 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
, struct compound_hdr
*hdr
)
1250 RESERVE_SPACE(4+NFS4_STATEID_SIZE
);
1251 WRITE32(OP_SETATTR
);
1252 WRITEMEM(zero_stateid
.data
, NFS4_STATEID_SIZE
);
1255 WRITE32(FATTR4_WORD0_ACL
);
1256 if (arg
->acl_len
% 4)
1259 WRITE32(arg
->acl_len
);
1260 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1266 encode_savefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1275 static void encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
, struct compound_hdr
*hdr
)
1279 RESERVE_SPACE(4+NFS4_STATEID_SIZE
);
1280 WRITE32(OP_SETATTR
);
1281 WRITEMEM(arg
->stateid
.data
, NFS4_STATEID_SIZE
);
1283 encode_attrs(xdr
, arg
->iap
, server
);
1286 static void encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
, struct compound_hdr
*hdr
)
1290 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE
);
1291 WRITE32(OP_SETCLIENTID
);
1292 WRITEMEM(setclientid
->sc_verifier
->data
, NFS4_VERIFIER_SIZE
);
1294 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1296 WRITE32(setclientid
->sc_prog
);
1297 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1298 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1300 WRITE32(setclientid
->sc_cb_ident
);
1304 static void encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs_client
*client_state
, struct compound_hdr
*hdr
)
1308 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE
);
1309 WRITE32(OP_SETCLIENTID_CONFIRM
);
1310 WRITE64(client_state
->cl_clientid
);
1311 WRITEMEM(client_state
->cl_confirm
.data
, NFS4_VERIFIER_SIZE
);
1315 static void encode_write(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
1322 encode_stateid(xdr
, args
->context
);
1325 WRITE64(args
->offset
);
1326 WRITE32(args
->stable
);
1327 WRITE32(args
->count
);
1329 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1333 static void encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
, struct compound_hdr
*hdr
)
1337 RESERVE_SPACE(4+NFS4_STATEID_SIZE
);
1339 WRITE32(OP_DELEGRETURN
);
1340 WRITEMEM(stateid
->data
, NFS4_STATEID_SIZE
);
1344 * END OF "GENERIC" ENCODE ROUTINES.
1348 * Encode an ACCESS request
1350 static int nfs4_xdr_enc_access(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_accessargs
*args
)
1352 struct xdr_stream xdr
;
1353 struct compound_hdr hdr
= {
1357 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1358 encode_compound_hdr(&xdr
, &hdr
);
1359 encode_putfh(&xdr
, args
->fh
, &hdr
);
1360 encode_access(&xdr
, args
->access
, &hdr
);
1361 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1367 * Encode LOOKUP request
1369 static int nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_arg
*args
)
1371 struct xdr_stream xdr
;
1372 struct compound_hdr hdr
= {
1376 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1377 encode_compound_hdr(&xdr
, &hdr
);
1378 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1379 encode_lookup(&xdr
, args
->name
, &hdr
);
1380 encode_getfh(&xdr
, &hdr
);
1381 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1387 * Encode LOOKUP_ROOT request
1389 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_root_arg
*args
)
1391 struct xdr_stream xdr
;
1392 struct compound_hdr hdr
= {
1396 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1397 encode_compound_hdr(&xdr
, &hdr
);
1398 encode_putrootfh(&xdr
, &hdr
);
1399 encode_getfh(&xdr
, &hdr
);
1400 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1406 * Encode REMOVE request
1408 static int nfs4_xdr_enc_remove(struct rpc_rqst
*req
, __be32
*p
, const struct nfs_removeargs
*args
)
1410 struct xdr_stream xdr
;
1411 struct compound_hdr hdr
= {
1415 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1416 encode_compound_hdr(&xdr
, &hdr
);
1417 encode_putfh(&xdr
, args
->fh
, &hdr
);
1418 encode_remove(&xdr
, &args
->name
, &hdr
);
1419 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1425 * Encode RENAME request
1427 static int nfs4_xdr_enc_rename(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_rename_arg
*args
)
1429 struct xdr_stream xdr
;
1430 struct compound_hdr hdr
= {
1434 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1435 encode_compound_hdr(&xdr
, &hdr
);
1436 encode_putfh(&xdr
, args
->old_dir
, &hdr
);
1437 encode_savefh(&xdr
, &hdr
);
1438 encode_putfh(&xdr
, args
->new_dir
, &hdr
);
1439 encode_rename(&xdr
, args
->old_name
, args
->new_name
, &hdr
);
1440 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1441 encode_restorefh(&xdr
, &hdr
);
1442 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1448 * Encode LINK request
1450 static int nfs4_xdr_enc_link(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_link_arg
*args
)
1452 struct xdr_stream xdr
;
1453 struct compound_hdr hdr
= {
1457 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1458 encode_compound_hdr(&xdr
, &hdr
);
1459 encode_putfh(&xdr
, args
->fh
, &hdr
);
1460 encode_savefh(&xdr
, &hdr
);
1461 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1462 encode_link(&xdr
, args
->name
, &hdr
);
1463 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1464 encode_restorefh(&xdr
, &hdr
);
1465 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1471 * Encode CREATE request
1473 static int nfs4_xdr_enc_create(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1475 struct xdr_stream xdr
;
1476 struct compound_hdr hdr
= {
1480 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1481 encode_compound_hdr(&xdr
, &hdr
);
1482 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1483 encode_savefh(&xdr
, &hdr
);
1484 encode_create(&xdr
, args
, &hdr
);
1485 encode_getfh(&xdr
, &hdr
);
1486 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1487 encode_restorefh(&xdr
, &hdr
);
1488 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1494 * Encode SYMLINK request
1496 static int nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1498 return nfs4_xdr_enc_create(req
, p
, args
);
1502 * Encode GETATTR request
1504 static int nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_getattr_arg
*args
)
1506 struct xdr_stream xdr
;
1507 struct compound_hdr hdr
= {
1511 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1512 encode_compound_hdr(&xdr
, &hdr
);
1513 encode_putfh(&xdr
, args
->fh
, &hdr
);
1514 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1520 * Encode a CLOSE request
1522 static int nfs4_xdr_enc_close(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1524 struct xdr_stream xdr
;
1525 struct compound_hdr hdr
= {
1529 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1530 encode_compound_hdr(&xdr
, &hdr
);
1531 encode_putfh(&xdr
, args
->fh
, &hdr
);
1532 encode_close(&xdr
, args
, &hdr
);
1533 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1539 * Encode an OPEN request
1541 static int nfs4_xdr_enc_open(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*args
)
1543 struct xdr_stream xdr
;
1544 struct compound_hdr hdr
= {
1548 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1549 encode_compound_hdr(&xdr
, &hdr
);
1550 encode_putfh(&xdr
, args
->fh
, &hdr
);
1551 encode_savefh(&xdr
, &hdr
);
1552 encode_open(&xdr
, args
, &hdr
);
1553 encode_getfh(&xdr
, &hdr
);
1554 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1555 encode_restorefh(&xdr
, &hdr
);
1556 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1562 * Encode an OPEN_CONFIRM request
1564 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_open_confirmargs
*args
)
1566 struct xdr_stream xdr
;
1567 struct compound_hdr hdr
= {
1571 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1572 encode_compound_hdr(&xdr
, &hdr
);
1573 encode_putfh(&xdr
, args
->fh
, &hdr
);
1574 encode_open_confirm(&xdr
, args
, &hdr
);
1580 * Encode an OPEN request with no attributes.
1582 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*args
)
1584 struct xdr_stream xdr
;
1585 struct compound_hdr hdr
= {
1589 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1590 encode_compound_hdr(&xdr
, &hdr
);
1591 encode_putfh(&xdr
, args
->fh
, &hdr
);
1592 encode_open(&xdr
, args
, &hdr
);
1593 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1599 * Encode an OPEN_DOWNGRADE request
1601 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1603 struct xdr_stream xdr
;
1604 struct compound_hdr hdr
= {
1608 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1609 encode_compound_hdr(&xdr
, &hdr
);
1610 encode_putfh(&xdr
, args
->fh
, &hdr
);
1611 encode_open_downgrade(&xdr
, args
, &hdr
);
1612 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1618 * Encode a LOCK request
1620 static int nfs4_xdr_enc_lock(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lock_args
*args
)
1622 struct xdr_stream xdr
;
1623 struct compound_hdr hdr
= {
1627 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1628 encode_compound_hdr(&xdr
, &hdr
);
1629 encode_putfh(&xdr
, args
->fh
, &hdr
);
1630 encode_lock(&xdr
, args
, &hdr
);
1636 * Encode a LOCKT request
1638 static int nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lockt_args
*args
)
1640 struct xdr_stream xdr
;
1641 struct compound_hdr hdr
= {
1645 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1646 encode_compound_hdr(&xdr
, &hdr
);
1647 encode_putfh(&xdr
, args
->fh
, &hdr
);
1648 encode_lockt(&xdr
, args
, &hdr
);
1654 * Encode a LOCKU request
1656 static int nfs4_xdr_enc_locku(struct rpc_rqst
*req
, __be32
*p
, struct nfs_locku_args
*args
)
1658 struct xdr_stream xdr
;
1659 struct compound_hdr hdr
= {
1663 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1664 encode_compound_hdr(&xdr
, &hdr
);
1665 encode_putfh(&xdr
, args
->fh
, &hdr
);
1666 encode_locku(&xdr
, args
, &hdr
);
1672 * Encode a READLINK request
1674 static int nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readlink
*args
)
1676 struct xdr_stream xdr
;
1677 struct compound_hdr hdr
= {
1680 struct rpc_auth
*auth
= req
->rq_task
->tk_msg
.rpc_cred
->cr_auth
;
1681 unsigned int replen
;
1683 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1684 encode_compound_hdr(&xdr
, &hdr
);
1685 encode_putfh(&xdr
, args
->fh
, &hdr
);
1686 encode_readlink(&xdr
, args
, req
, &hdr
);
1688 /* set up reply kvec
1689 * toplevel_status + taglen + rescount + OP_PUTFH + status
1690 * + OP_READLINK + status + string length = 8
1692 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_readlink_sz
) << 2;
1693 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, args
->pages
,
1694 args
->pgbase
, args
->pglen
);
1700 * Encode a READDIR request
1702 static int nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readdir_arg
*args
)
1704 struct xdr_stream xdr
;
1705 struct compound_hdr hdr
= {
1708 struct rpc_auth
*auth
= req
->rq_task
->tk_msg
.rpc_cred
->cr_auth
;
1711 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1712 encode_compound_hdr(&xdr
, &hdr
);
1713 encode_putfh(&xdr
, args
->fh
, &hdr
);
1714 encode_readdir(&xdr
, args
, req
, &hdr
);
1716 /* set up reply kvec
1717 * toplevel_status + taglen + rescount + OP_PUTFH + status
1718 * + OP_READDIR + status + verifer(2) = 9
1720 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_readdir_sz
) << 2;
1721 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, args
->pages
,
1722 args
->pgbase
, args
->count
);
1723 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1724 __func__
, replen
, args
->pages
,
1725 args
->pgbase
, args
->count
);
1731 * Encode a READ request
1733 static int nfs4_xdr_enc_read(struct rpc_rqst
*req
, __be32
*p
, struct nfs_readargs
*args
)
1735 struct rpc_auth
*auth
= req
->rq_task
->tk_msg
.rpc_cred
->cr_auth
;
1736 struct xdr_stream xdr
;
1737 struct compound_hdr hdr
= {
1742 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1743 encode_compound_hdr(&xdr
, &hdr
);
1744 encode_putfh(&xdr
, args
->fh
, &hdr
);
1745 encode_read(&xdr
, args
, &hdr
);
1747 /* set up reply kvec
1748 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1749 * + OP_READ + status + eof + datalen = 9
1751 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_read_sz
) << 2;
1752 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
1753 args
->pages
, args
->pgbase
, args
->count
);
1754 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
1760 * Encode an SETATTR request
1762 static int nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setattrargs
*args
)
1764 struct xdr_stream xdr
;
1765 struct compound_hdr hdr
= {
1769 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1770 encode_compound_hdr(&xdr
, &hdr
);
1771 encode_putfh(&xdr
, args
->fh
, &hdr
);
1772 encode_setattr(&xdr
, args
, args
->server
, &hdr
);
1773 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1779 * Encode a GETACL request
1782 nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, __be32
*p
,
1783 struct nfs_getaclargs
*args
)
1785 struct xdr_stream xdr
;
1786 struct rpc_auth
*auth
= req
->rq_task
->tk_msg
.rpc_cred
->cr_auth
;
1787 struct compound_hdr hdr
= {
1792 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1793 encode_compound_hdr(&xdr
, &hdr
);
1794 encode_putfh(&xdr
, args
->fh
, &hdr
);
1795 encode_getattr_two(&xdr
, FATTR4_WORD0_ACL
, 0, &hdr
);
1797 /* set up reply buffer: */
1798 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_getacl_sz
) << 2;
1799 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
1800 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
1806 * Encode a WRITE request
1808 static int nfs4_xdr_enc_write(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
1810 struct xdr_stream xdr
;
1811 struct compound_hdr hdr
= {
1815 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1816 encode_compound_hdr(&xdr
, &hdr
);
1817 encode_putfh(&xdr
, args
->fh
, &hdr
);
1818 encode_write(&xdr
, args
, &hdr
);
1819 req
->rq_snd_buf
.flags
|= XDRBUF_WRITE
;
1820 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1828 static int nfs4_xdr_enc_commit(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
1830 struct xdr_stream xdr
;
1831 struct compound_hdr hdr
= {
1835 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1836 encode_compound_hdr(&xdr
, &hdr
);
1837 encode_putfh(&xdr
, args
->fh
, &hdr
);
1838 encode_commit(&xdr
, args
, &hdr
);
1839 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1847 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fsinfo_arg
*args
)
1849 struct xdr_stream xdr
;
1850 struct compound_hdr hdr
= {
1854 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1855 encode_compound_hdr(&xdr
, &hdr
);
1856 encode_putfh(&xdr
, args
->fh
, &hdr
);
1857 encode_fsinfo(&xdr
, args
->bitmask
, &hdr
);
1863 * a PATHCONF request
1865 static int nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_pathconf_arg
*args
)
1867 struct xdr_stream xdr
;
1868 struct compound_hdr hdr
= {
1872 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1873 encode_compound_hdr(&xdr
, &hdr
);
1874 encode_putfh(&xdr
, args
->fh
, &hdr
);
1875 encode_getattr_one(&xdr
, args
->bitmask
[0] & nfs4_pathconf_bitmap
[0],
1884 static int nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_statfs_arg
*args
)
1886 struct xdr_stream xdr
;
1887 struct compound_hdr hdr
= {
1891 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1892 encode_compound_hdr(&xdr
, &hdr
);
1893 encode_putfh(&xdr
, args
->fh
, &hdr
);
1894 encode_getattr_two(&xdr
, args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
1895 args
->bitmask
[1] & nfs4_statfs_bitmap
[1], &hdr
);
1901 * GETATTR_BITMAP request
1903 static int nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
, __be32
*p
, const struct nfs_fh
*fhandle
)
1905 struct xdr_stream xdr
;
1906 struct compound_hdr hdr
= {
1910 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1911 encode_compound_hdr(&xdr
, &hdr
);
1912 encode_putfh(&xdr
, fhandle
, &hdr
);
1913 encode_getattr_one(&xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
1914 FATTR4_WORD0_LINK_SUPPORT
|
1915 FATTR4_WORD0_SYMLINK_SUPPORT
|
1916 FATTR4_WORD0_ACLSUPPORT
, &hdr
);
1924 static int nfs4_xdr_enc_renew(struct rpc_rqst
*req
, __be32
*p
, struct nfs_client
*clp
)
1926 struct xdr_stream xdr
;
1927 struct compound_hdr hdr
= {
1931 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1932 encode_compound_hdr(&xdr
, &hdr
);
1933 encode_renew(&xdr
, clp
, &hdr
);
1939 * a SETCLIENTID request
1941 static int nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_setclientid
*sc
)
1943 struct xdr_stream xdr
;
1944 struct compound_hdr hdr
= {
1948 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1949 encode_compound_hdr(&xdr
, &hdr
);
1950 encode_setclientid(&xdr
, sc
, &hdr
);
1956 * a SETCLIENTID_CONFIRM request
1958 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_client
*clp
)
1960 struct xdr_stream xdr
;
1961 struct compound_hdr hdr
= {
1964 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
1966 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1967 encode_compound_hdr(&xdr
, &hdr
);
1968 encode_setclientid_confirm(&xdr
, clp
, &hdr
);
1969 encode_putrootfh(&xdr
, &hdr
);
1970 encode_fsinfo(&xdr
, lease_bitmap
, &hdr
);
1976 * DELEGRETURN request
1978 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_delegreturnargs
*args
)
1980 struct xdr_stream xdr
;
1981 struct compound_hdr hdr
= {
1985 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1986 encode_compound_hdr(&xdr
, &hdr
);
1987 encode_putfh(&xdr
, args
->fhandle
, &hdr
);
1988 encode_delegreturn(&xdr
, args
->stateid
, &hdr
);
1989 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1995 * Encode FS_LOCATIONS request
1997 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fs_locations_arg
*args
)
1999 struct xdr_stream xdr
;
2000 struct compound_hdr hdr
= {
2003 struct rpc_auth
*auth
= req
->rq_task
->tk_msg
.rpc_cred
->cr_auth
;
2006 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2007 encode_compound_hdr(&xdr
, &hdr
);
2008 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
2009 encode_lookup(&xdr
, args
->name
, &hdr
);
2010 encode_fs_locations(&xdr
, args
->bitmask
, &hdr
);
2013 * toplevel_status + OP_PUTFH + status
2014 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2016 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 7) << 2;
2017 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, &args
->page
,
2024 * START OF "GENERIC" DECODE ROUTINES.
2025 * These may look a little ugly since they are imported from a "generic"
2026 * set of XDR encode/decode routines which are intended to be shared by
2027 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2029 * If the pain of reading these is too great, it should be a straightforward
2030 * task to translate them into Linux-specific versions which are more
2031 * consistent with the style used in NFSv2/v3...
2033 #define READ32(x) (x) = ntohl(*p++)
2034 #define READ64(x) do { \
2035 (x) = (u64)ntohl(*p++) << 32; \
2036 (x) |= ntohl(*p++); \
2038 #define READTIME(x) do { \
2040 (x.tv_sec) = ntohl(*p++); \
2041 (x.tv_nsec) = ntohl(*p++); \
2043 #define COPYMEM(x,nbytes) do { \
2044 memcpy((x), p, nbytes); \
2045 p += XDR_QUADLEN(nbytes); \
2048 #define READ_BUF(nbytes) do { \
2049 p = xdr_inline_decode(xdr, nbytes); \
2050 if (unlikely(!p)) { \
2051 dprintk("nfs: %s: prematurely hit end of receive" \
2052 " buffer\n", __func__); \
2053 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2054 __func__, xdr->p, nbytes, xdr->end); \
2059 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
2066 *string
= (char *)p
;
2070 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
2075 READ32(hdr
->status
);
2076 READ32(hdr
->taglen
);
2078 READ_BUF(hdr
->taglen
+ 4);
2079 hdr
->tag
= (char *)p
;
2080 p
+= XDR_QUADLEN(hdr
->taglen
);
2082 if (unlikely(hdr
->nops
< 1))
2083 return nfs4_stat_to_errno(hdr
->status
);
2087 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
2095 if (opnum
!= expected
) {
2096 dprintk("nfs: Server returned operation"
2097 " %d but we issued a request for %d\n",
2102 if (nfserr
!= NFS_OK
)
2103 return nfs4_stat_to_errno(nfserr
);
2108 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
2111 unsigned int strlen
;
2115 return decode_opaque_inline(xdr
, &strlen
, &str
);
2118 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
2126 bitmap
[0] = bitmap
[1] = 0;
2127 READ_BUF((bmlen
<< 2));
2136 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, __be32
**savep
)
2146 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
2148 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
2149 decode_attr_bitmap(xdr
, bitmask
);
2150 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
2152 bitmask
[0] = bitmask
[1] = 0;
2153 dprintk("%s: bitmask=%08x:%08x\n", __func__
, bitmask
[0], bitmask
[1]);
2157 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
2163 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
2165 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
2168 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
2169 dprintk("%s: bad type %d\n", __func__
, *type
);
2172 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
2173 ret
= NFS_ATTR_FATTR_TYPE
;
2175 dprintk("%s: type=0%o\n", __func__
, nfs_type2fmt
[*type
]);
2179 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
2185 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
2187 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
2190 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
2191 ret
= NFS_ATTR_FATTR_CHANGE
;
2193 dprintk("%s: change attribute=%Lu\n", __func__
,
2194 (unsigned long long)*change
);
2198 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
2204 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
2206 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
2209 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
2210 ret
= NFS_ATTR_FATTR_SIZE
;
2212 dprintk("%s: file size=%Lu\n", __func__
, (unsigned long long)*size
);
2216 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2221 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
2223 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
2226 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
2228 dprintk("%s: link support=%s\n", __func__
, *res
== 0 ? "false" : "true");
2232 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2237 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
2239 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
2242 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
2244 dprintk("%s: symlink support=%s\n", __func__
, *res
== 0 ? "false" : "true");
2248 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
2255 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
2257 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
2259 READ64(fsid
->major
);
2260 READ64(fsid
->minor
);
2261 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
2262 ret
= NFS_ATTR_FATTR_FSID
;
2264 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__
,
2265 (unsigned long long)fsid
->major
,
2266 (unsigned long long)fsid
->minor
);
2270 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2275 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
2277 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
2280 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
2282 dprintk("%s: file size=%u\n", __func__
, (unsigned int)*res
);
2286 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2290 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
2291 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
2293 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
2296 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
2298 dprintk("%s: ACLs supported=%u\n", __func__
, (unsigned int)*res
);
2302 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2308 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
2310 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
2313 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
2314 ret
= NFS_ATTR_FATTR_FILEID
;
2316 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
2320 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2326 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
2328 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
2331 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
2332 ret
= NFS_ATTR_FATTR_FILEID
;
2334 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
2338 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2344 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
2346 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
2349 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
2351 dprintk("%s: files avail=%Lu\n", __func__
, (unsigned long long)*res
);
2355 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2361 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
2363 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
2366 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
2368 dprintk("%s: files free=%Lu\n", __func__
, (unsigned long long)*res
);
2372 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2378 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
2380 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
2383 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
2385 dprintk("%s: files total=%Lu\n", __func__
, (unsigned long long)*res
);
2389 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
2400 path
->ncomponents
= 0;
2401 while (path
->ncomponents
< n
) {
2402 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
2403 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
2404 if (unlikely(status
!= 0))
2406 if (path
->ncomponents
!= n
)
2408 dprintk("%s", component
->data
);
2409 if (path
->ncomponents
< NFS4_PATHNAME_MAXCOMPONENTS
)
2410 path
->ncomponents
++;
2412 dprintk("cannot parse %d components in path\n", n
);
2420 /* a root pathname is sent as a zero component4 */
2421 path
->ncomponents
= 1;
2422 path
->components
[0].len
=0;
2423 path
->components
[0].data
=NULL
;
2424 dprintk("path /\n");
2427 dprintk(" status %d", status
);
2432 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
2438 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
2441 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
2443 dprintk("%s: fsroot ", __func__
);
2444 status
= decode_pathname(xdr
, &res
->fs_path
);
2445 if (unlikely(status
!= 0))
2451 res
->nlocations
= 0;
2452 while (res
->nlocations
< n
) {
2454 struct nfs4_fs_location
*loc
= &res
->locations
[res
->nlocations
];
2460 dprintk("%s: servers ", __func__
);
2461 while (loc
->nservers
< m
) {
2462 struct nfs4_string
*server
= &loc
->servers
[loc
->nservers
];
2463 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
2464 if (unlikely(status
!= 0))
2466 dprintk("%s ", server
->data
);
2467 if (loc
->nservers
< NFS4_FS_LOCATION_MAXSERVERS
)
2471 dprintk("%s: using first %u of %u servers "
2472 "returned for location %u\n",
2474 NFS4_FS_LOCATION_MAXSERVERS
,
2475 m
, res
->nlocations
);
2476 for (i
= loc
->nservers
; i
< m
; i
++) {
2479 status
= decode_opaque_inline(xdr
, &len
, &data
);
2480 if (unlikely(status
!= 0))
2485 status
= decode_pathname(xdr
, &loc
->rootpath
);
2486 if (unlikely(status
!= 0))
2488 if (res
->nlocations
< NFS4_FS_LOCATIONS_MAXENTRIES
)
2491 if (res
->nlocations
!= 0)
2492 status
= NFS_ATTR_FATTR_V4_REFERRAL
;
2494 dprintk("%s: fs_locations done, error = %d\n", __func__
, status
);
2501 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2507 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
2509 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
2512 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
2514 dprintk("%s: maxfilesize=%Lu\n", __func__
, (unsigned long long)*res
);
2518 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
2524 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
2526 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
2529 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
2531 dprintk("%s: maxlink=%u\n", __func__
, *maxlink
);
2535 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
2541 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
2543 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
2546 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
2548 dprintk("%s: maxname=%u\n", __func__
, *maxname
);
2552 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2558 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
2560 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
2564 if (maxread
> 0x7FFFFFFF)
2565 maxread
= 0x7FFFFFFF;
2566 *res
= (uint32_t)maxread
;
2567 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
2569 dprintk("%s: maxread=%lu\n", __func__
, (unsigned long)*res
);
2573 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2579 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
2581 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
2585 if (maxwrite
> 0x7FFFFFFF)
2586 maxwrite
= 0x7FFFFFFF;
2587 *res
= (uint32_t)maxwrite
;
2588 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
2590 dprintk("%s: maxwrite=%lu\n", __func__
, (unsigned long)*res
);
2594 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, umode_t
*mode
)
2601 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
2603 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
2606 *mode
= tmp
& ~S_IFMT
;
2607 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
2608 ret
= NFS_ATTR_FATTR_MODE
;
2610 dprintk("%s: file mode=0%o\n", __func__
, (unsigned int)*mode
);
2614 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
2620 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
2622 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
2625 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
2626 ret
= NFS_ATTR_FATTR_NLINK
;
2628 dprintk("%s: nlink=%u\n", __func__
, (unsigned int)*nlink
);
2632 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_client
*clp
, uint32_t *uid
)
2639 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
2641 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
2645 if (len
< XDR_MAX_NETOBJ
) {
2646 if (nfs_map_name_to_uid(clp
, (char *)p
, len
, uid
) == 0)
2647 ret
= NFS_ATTR_FATTR_OWNER
;
2649 dprintk("%s: nfs_map_name_to_uid failed!\n",
2652 dprintk("%s: name too long (%u)!\n",
2654 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
2656 dprintk("%s: uid=%d\n", __func__
, (int)*uid
);
2660 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_client
*clp
, uint32_t *gid
)
2667 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
2669 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
2673 if (len
< XDR_MAX_NETOBJ
) {
2674 if (nfs_map_group_to_gid(clp
, (char *)p
, len
, gid
) == 0)
2675 ret
= NFS_ATTR_FATTR_GROUP
;
2677 dprintk("%s: nfs_map_group_to_gid failed!\n",
2680 dprintk("%s: name too long (%u)!\n",
2682 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
2684 dprintk("%s: gid=%d\n", __func__
, (int)*gid
);
2688 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
2690 uint32_t major
= 0, minor
= 0;
2695 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
2697 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
2703 tmp
= MKDEV(major
, minor
);
2704 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
2706 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
2707 ret
= NFS_ATTR_FATTR_RDEV
;
2709 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__
, major
, minor
);
2713 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2719 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
2721 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
2724 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
2726 dprintk("%s: space avail=%Lu\n", __func__
, (unsigned long long)*res
);
2730 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2736 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
2738 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
2741 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
2743 dprintk("%s: space free=%Lu\n", __func__
, (unsigned long long)*res
);
2747 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2753 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
2755 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
2758 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
2760 dprintk("%s: space total=%Lu\n", __func__
, (unsigned long long)*res
);
2764 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
2770 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
2772 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
2775 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
2776 ret
= NFS_ATTR_FATTR_SPACE_USED
;
2778 dprintk("%s: space used=%Lu\n", __func__
,
2779 (unsigned long long)*used
);
2783 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
2792 time
->tv_sec
= (time_t)sec
;
2793 time
->tv_nsec
= (long)nsec
;
2797 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2803 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
2805 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
2806 status
= decode_attr_time(xdr
, time
);
2808 status
= NFS_ATTR_FATTR_ATIME
;
2809 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
2811 dprintk("%s: atime=%ld\n", __func__
, (long)time
->tv_sec
);
2815 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2821 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
2823 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
2824 status
= decode_attr_time(xdr
, time
);
2826 status
= NFS_ATTR_FATTR_CTIME
;
2827 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
2829 dprintk("%s: ctime=%ld\n", __func__
, (long)time
->tv_sec
);
2833 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2839 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
2841 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
2842 status
= decode_attr_time(xdr
, time
);
2844 status
= NFS_ATTR_FATTR_MTIME
;
2845 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
2847 dprintk("%s: mtime=%ld\n", __func__
, (long)time
->tv_sec
);
2851 static int verify_attr_len(struct xdr_stream
*xdr
, __be32
*savep
, uint32_t attrlen
)
2853 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
2854 unsigned int nwords
= xdr
->p
- savep
;
2856 if (unlikely(attrwords
!= nwords
)) {
2857 dprintk("%s: server returned incorrect attribute length: "
2861 (attrwords
< nwords
) ? '<' : '>',
2868 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2873 READ32(cinfo
->atomic
);
2874 READ64(cinfo
->before
);
2875 READ64(cinfo
->after
);
2879 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
2885 status
= decode_op_hdr(xdr
, OP_ACCESS
);
2891 access
->supported
= supp
;
2892 access
->access
= acc
;
2896 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
2901 status
= decode_op_hdr(xdr
, OP_CLOSE
);
2903 nfs_increment_open_seqid(status
, res
->seqid
);
2906 READ_BUF(NFS4_STATEID_SIZE
);
2907 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
2911 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
2916 status
= decode_op_hdr(xdr
, OP_COMMIT
);
2920 COPYMEM(res
->verf
->verifier
, 8);
2924 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2930 status
= decode_op_hdr(xdr
, OP_CREATE
);
2933 if ((status
= decode_change_info(xdr
, cinfo
)))
2937 READ_BUF(bmlen
<< 2);
2941 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
2944 uint32_t attrlen
, bitmap
[2] = {0};
2947 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2949 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2951 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2953 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
2955 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
2957 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
2959 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
2961 status
= verify_attr_len(xdr
, savep
, attrlen
);
2963 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
2967 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
2970 uint32_t attrlen
, bitmap
[2] = {0};
2973 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2975 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2977 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2980 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
2982 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
2984 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
2986 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
2988 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
2990 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
2993 status
= verify_attr_len(xdr
, savep
, attrlen
);
2995 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
2999 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
3002 uint32_t attrlen
, bitmap
[2] = {0};
3005 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3007 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3009 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3012 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
3014 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
3017 status
= verify_attr_len(xdr
, savep
, attrlen
);
3019 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3023 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
, const struct nfs_server
*server
)
3033 status
= decode_op_hdr(xdr
, OP_GETATTR
);
3037 status
= decode_attr_bitmap(xdr
, bitmap
);
3041 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
3046 status
= decode_attr_type(xdr
, bitmap
, &type
);
3051 fattr
->mode
|= nfs_type2fmt
[type
];
3052 fattr
->valid
|= status
;
3055 status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
);
3058 fattr
->valid
|= status
;
3060 status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
);
3063 fattr
->valid
|= status
;
3065 status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
);
3068 fattr
->valid
|= status
;
3070 status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
);
3073 fattr
->valid
|= status
;
3075 status
= decode_attr_fs_locations(xdr
, bitmap
, container_of(fattr
,
3076 struct nfs4_fs_locations
,
3080 fattr
->valid
|= status
;
3082 status
= decode_attr_mode(xdr
, bitmap
, &fmode
);
3086 fattr
->mode
|= fmode
;
3087 fattr
->valid
|= status
;
3090 status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
);
3093 fattr
->valid
|= status
;
3095 status
= decode_attr_owner(xdr
, bitmap
, server
->nfs_client
, &fattr
->uid
);
3098 fattr
->valid
|= status
;
3100 status
= decode_attr_group(xdr
, bitmap
, server
->nfs_client
, &fattr
->gid
);
3103 fattr
->valid
|= status
;
3105 status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
);
3108 fattr
->valid
|= status
;
3110 status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
);
3113 fattr
->valid
|= status
;
3115 status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
);
3118 fattr
->valid
|= status
;
3120 status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
);
3123 fattr
->valid
|= status
;
3125 status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
);
3128 fattr
->valid
|= status
;
3130 status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fileid
);
3133 if (status
!= 0 && !(fattr
->valid
& status
)) {
3134 fattr
->fileid
= fileid
;
3135 fattr
->valid
|= status
;
3138 status
= verify_attr_len(xdr
, savep
, attrlen
);
3140 dprintk("%s: xdr returned %d\n", __func__
, -status
);
3145 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
3148 uint32_t attrlen
, bitmap
[2];
3151 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3153 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3155 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3158 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
3160 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
3162 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
3164 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
3166 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
3167 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
3169 fsinfo
->wtpref
= fsinfo
->wtmax
;
3171 status
= verify_attr_len(xdr
, savep
, attrlen
);
3173 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3177 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
3183 /* Zero handle first to allow comparisons */
3184 memset(fh
, 0, sizeof(*fh
));
3186 status
= decode_op_hdr(xdr
, OP_GETFH
);
3192 if (len
> NFS4_FHSIZE
)
3196 COPYMEM(fh
->data
, len
);
3200 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3204 status
= decode_op_hdr(xdr
, OP_LINK
);
3207 return decode_change_info(xdr
, cinfo
);
3211 * We create the owner, so we know a proper owner.id length is 4.
3213 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
3215 uint64_t offset
, length
, clientid
;
3217 uint32_t namelen
, type
;
3224 fl
->fl_start
= (loff_t
)offset
;
3225 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
3226 if (length
== ~(uint64_t)0)
3227 fl
->fl_end
= OFFSET_MAX
;
3228 fl
->fl_type
= F_WRLCK
;
3230 fl
->fl_type
= F_RDLCK
;
3236 return -NFS4ERR_DENIED
;
3239 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
3244 status
= decode_op_hdr(xdr
, OP_LOCK
);
3248 READ_BUF(NFS4_STATEID_SIZE
);
3249 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
3250 } else if (status
== -NFS4ERR_DENIED
)
3251 status
= decode_lock_denied(xdr
, NULL
);
3252 if (res
->open_seqid
!= NULL
)
3253 nfs_increment_open_seqid(status
, res
->open_seqid
);
3254 nfs_increment_lock_seqid(status
, res
->lock_seqid
);
3259 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
3262 status
= decode_op_hdr(xdr
, OP_LOCKT
);
3263 if (status
== -NFS4ERR_DENIED
)
3264 return decode_lock_denied(xdr
, res
->denied
);
3268 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
3273 status
= decode_op_hdr(xdr
, OP_LOCKU
);
3275 nfs_increment_lock_seqid(status
, res
->seqid
);
3277 READ_BUF(NFS4_STATEID_SIZE
);
3278 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
3283 static int decode_lookup(struct xdr_stream
*xdr
)
3285 return decode_op_hdr(xdr
, OP_LOOKUP
);
3288 /* This is too sick! */
3289 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
3292 uint32_t limit_type
, nblocks
, blocksize
;
3296 switch (limit_type
) {
3303 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
3308 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3311 uint32_t delegation_type
;
3314 READ32(delegation_type
);
3315 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
3316 res
->delegation_type
= 0;
3319 READ_BUF(NFS4_STATEID_SIZE
+4);
3320 COPYMEM(res
->delegation
.data
, NFS4_STATEID_SIZE
);
3321 READ32(res
->do_recall
);
3323 switch (delegation_type
) {
3324 case NFS4_OPEN_DELEGATE_READ
:
3325 res
->delegation_type
= FMODE_READ
;
3327 case NFS4_OPEN_DELEGATE_WRITE
:
3328 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
3329 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
3332 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
3335 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3338 uint32_t savewords
, bmlen
, i
;
3341 status
= decode_op_hdr(xdr
, OP_OPEN
);
3343 nfs_increment_open_seqid(status
, res
->seqid
);
3346 READ_BUF(NFS4_STATEID_SIZE
);
3347 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
3349 decode_change_info(xdr
, &res
->cinfo
);
3352 READ32(res
->rflags
);
3357 READ_BUF(bmlen
<< 2);
3358 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
3359 for (i
= 0; i
< savewords
; ++i
)
3360 READ32(res
->attrset
[i
]);
3361 for (; i
< NFS4_BITMAP_SIZE
; i
++)
3362 res
->attrset
[i
] = 0;
3364 return decode_delegation(xdr
, res
);
3366 dprintk("%s: Bitmap too large! Length = %u\n", __func__
, bmlen
);
3370 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
3375 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
3377 nfs_increment_open_seqid(status
, res
->seqid
);
3380 READ_BUF(NFS4_STATEID_SIZE
);
3381 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
3385 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
3390 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
3392 nfs_increment_open_seqid(status
, res
->seqid
);
3395 READ_BUF(NFS4_STATEID_SIZE
);
3396 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
3400 static int decode_putfh(struct xdr_stream
*xdr
)
3402 return decode_op_hdr(xdr
, OP_PUTFH
);
3405 static int decode_putrootfh(struct xdr_stream
*xdr
)
3407 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
3410 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
3412 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
3414 uint32_t count
, eof
, recvd
, hdrlen
;
3417 status
= decode_op_hdr(xdr
, OP_READ
);
3423 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
3424 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3425 if (count
> recvd
) {
3426 dprintk("NFS: server cheating in read reply: "
3427 "count %u > recvd %u\n", count
, recvd
);
3431 xdr_read_pages(xdr
, count
);
3437 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
3439 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
3440 struct page
*page
= *rcvbuf
->pages
;
3441 struct kvec
*iov
= rcvbuf
->head
;
3443 u32 recvd
, pglen
= rcvbuf
->page_len
;
3444 __be32
*end
, *entry
, *p
, *kaddr
;
3445 unsigned int nr
= 0;
3448 status
= decode_op_hdr(xdr
, OP_READDIR
);
3452 COPYMEM(readdir
->verifier
.data
, 8);
3453 dprintk("%s: verifier = %08x:%08x\n",
3455 ((u32
*)readdir
->verifier
.data
)[0],
3456 ((u32
*)readdir
->verifier
.data
)[1]);
3459 hdrlen
= (char *) p
- (char *) iov
->iov_base
;
3460 recvd
= rcvbuf
->len
- hdrlen
;
3463 xdr_read_pages(xdr
, pglen
);
3465 BUG_ON(pglen
+ readdir
->pgbase
> PAGE_CACHE_SIZE
);
3466 kaddr
= p
= kmap_atomic(page
, KM_USER0
);
3467 end
= p
+ ((pglen
+ readdir
->pgbase
) >> 2);
3470 /* Make sure the packet actually has a value_follows and EOF entry */
3471 if ((entry
+ 1) > end
)
3474 for (; *p
++; nr
++) {
3475 u32 len
, attrlen
, xlen
;
3478 dprintk("cookie = %Lu, ", *((unsigned long long *)p
));
3479 p
+= 2; /* cookie */
3480 len
= ntohl(*p
++); /* filename length */
3481 if (len
> NFS4_MAXNAMLEN
) {
3482 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3486 xlen
= XDR_QUADLEN(len
);
3487 if (end
- p
< xlen
+ 1)
3489 dprintk("filename = %*s\n", len
, (char *)p
);
3491 len
= ntohl(*p
++); /* bitmap length */
3492 if (end
- p
< len
+ 1)
3495 attrlen
= XDR_QUADLEN(ntohl(*p
++));
3496 if (end
- p
< attrlen
+ 2)
3498 p
+= attrlen
; /* attributes */
3502 * Apparently some server sends responses that are a valid size, but
3503 * contain no entries, and have value_follows==0 and EOF==0. For
3504 * those, just set the EOF marker.
3506 if (!nr
&& entry
[1] == 0) {
3507 dprintk("NFS: readdir reply truncated!\n");
3511 kunmap_atomic(kaddr
, KM_USER0
);
3515 * When we get a short packet there are 2 possibilities. We can
3516 * return an error, or fix up the response to look like a valid
3517 * response and return what we have so far. If there are no
3518 * entries and the packet was short, then return -EIO. If there
3519 * are valid entries in the response, return them and pretend that
3520 * the call was successful, but incomplete. The caller can retry the
3521 * readdir starting at the last cookie.
3523 dprintk("%s: short packet at entry %d\n", __func__
, nr
);
3524 entry
[0] = entry
[1] = 0;
3528 kunmap_atomic(kaddr
, KM_USER0
);
3529 return -errno_NFSERR_IO
;
3532 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
3534 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
3535 struct kvec
*iov
= rcvbuf
->head
;
3542 status
= decode_op_hdr(xdr
, OP_READLINK
);
3546 /* Convert length of symlink */
3549 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
3550 dprintk("nfs: server returned giant symlink!\n");
3551 return -ENAMETOOLONG
;
3553 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
3554 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3556 dprintk("NFS: server cheating in readlink reply: "
3557 "count %u > recvd %u\n", len
, recvd
);
3560 xdr_read_pages(xdr
, len
);
3562 * The XDR encode routine has set things up so that
3563 * the link text will be copied directly into the
3564 * buffer. We just have to do overflow-checking,
3565 * and and null-terminate the text (the VFS expects
3566 * null-termination).
3568 kaddr
= (char *)kmap_atomic(rcvbuf
->pages
[0], KM_USER0
);
3569 kaddr
[len
+rcvbuf
->page_base
] = '\0';
3570 kunmap_atomic(kaddr
, KM_USER0
);
3574 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3578 status
= decode_op_hdr(xdr
, OP_REMOVE
);
3581 status
= decode_change_info(xdr
, cinfo
);
3586 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
3587 struct nfs4_change_info
*new_cinfo
)
3591 status
= decode_op_hdr(xdr
, OP_RENAME
);
3594 if ((status
= decode_change_info(xdr
, old_cinfo
)))
3596 status
= decode_change_info(xdr
, new_cinfo
);
3601 static int decode_renew(struct xdr_stream
*xdr
)
3603 return decode_op_hdr(xdr
, OP_RENEW
);
3607 decode_restorefh(struct xdr_stream
*xdr
)
3609 return decode_op_hdr(xdr
, OP_RESTOREFH
);
3612 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
3618 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
3622 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3624 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3626 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3629 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
3631 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
3635 /* We ignore &savep and don't do consistency checks on
3636 * the attr length. Let userspace figure it out.... */
3637 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
3638 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3639 if (attrlen
> recvd
) {
3640 dprintk("NFS: server cheating in getattr"
3641 " acl reply: attrlen %u > recvd %u\n",
3645 xdr_read_pages(xdr
, attrlen
);
3648 status
= -EOPNOTSUPP
;
3655 decode_savefh(struct xdr_stream
*xdr
)
3657 return decode_op_hdr(xdr
, OP_SAVEFH
);
3660 static int decode_setattr(struct xdr_stream
*xdr
, struct nfs_setattrres
*res
)
3666 status
= decode_op_hdr(xdr
, OP_SETATTR
);
3671 READ_BUF(bmlen
<< 2);
3675 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs_client
*clp
)
3683 if (opnum
!= OP_SETCLIENTID
) {
3684 dprintk("nfs: decode_setclientid: Server returned operation"
3689 if (nfserr
== NFS_OK
) {
3690 READ_BUF(8 + NFS4_VERIFIER_SIZE
);
3691 READ64(clp
->cl_clientid
);
3692 COPYMEM(clp
->cl_confirm
.data
, NFS4_VERIFIER_SIZE
);
3693 } else if (nfserr
== NFSERR_CLID_INUSE
) {
3696 /* skip netid string */
3701 /* skip uaddr string */
3705 return -NFSERR_CLID_INUSE
;
3707 return nfs4_stat_to_errno(nfserr
);
3712 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
3714 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
3717 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
3722 status
= decode_op_hdr(xdr
, OP_WRITE
);
3728 READ32(res
->verf
->committed
);
3729 COPYMEM(res
->verf
->verifier
, 8);
3733 static int decode_delegreturn(struct xdr_stream
*xdr
)
3735 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
3739 * END OF "GENERIC" DECODE ROUTINES.
3743 * Decode OPEN_DOWNGRADE response
3745 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
3747 struct xdr_stream xdr
;
3748 struct compound_hdr hdr
;
3751 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3752 status
= decode_compound_hdr(&xdr
, &hdr
);
3755 status
= decode_putfh(&xdr
);
3758 status
= decode_open_downgrade(&xdr
, res
);
3761 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3767 * Decode ACCESS response
3769 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_accessres
*res
)
3771 struct xdr_stream xdr
;
3772 struct compound_hdr hdr
;
3775 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3776 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3778 status
= decode_putfh(&xdr
);
3781 status
= decode_access(&xdr
, res
);
3784 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3790 * Decode LOOKUP response
3792 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
3794 struct xdr_stream xdr
;
3795 struct compound_hdr hdr
;
3798 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3799 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3801 if ((status
= decode_putfh(&xdr
)) != 0)
3803 if ((status
= decode_lookup(&xdr
)) != 0)
3805 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
3807 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3813 * Decode LOOKUP_ROOT response
3815 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
3817 struct xdr_stream xdr
;
3818 struct compound_hdr hdr
;
3821 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3822 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3824 if ((status
= decode_putrootfh(&xdr
)) != 0)
3826 if ((status
= decode_getfh(&xdr
, res
->fh
)) == 0)
3827 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3833 * Decode REMOVE response
3835 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_removeres
*res
)
3837 struct xdr_stream xdr
;
3838 struct compound_hdr hdr
;
3841 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3842 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3844 if ((status
= decode_putfh(&xdr
)) != 0)
3846 if ((status
= decode_remove(&xdr
, &res
->cinfo
)) != 0)
3848 decode_getfattr(&xdr
, &res
->dir_attr
, res
->server
);
3854 * Decode RENAME response
3856 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_rename_res
*res
)
3858 struct xdr_stream xdr
;
3859 struct compound_hdr hdr
;
3862 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3863 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3865 if ((status
= decode_putfh(&xdr
)) != 0)
3867 if ((status
= decode_savefh(&xdr
)) != 0)
3869 if ((status
= decode_putfh(&xdr
)) != 0)
3871 if ((status
= decode_rename(&xdr
, &res
->old_cinfo
, &res
->new_cinfo
)) != 0)
3873 /* Current FH is target directory */
3874 if (decode_getfattr(&xdr
, res
->new_fattr
, res
->server
) != 0)
3876 if ((status
= decode_restorefh(&xdr
)) != 0)
3878 decode_getfattr(&xdr
, res
->old_fattr
, res
->server
);
3884 * Decode LINK response
3886 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_link_res
*res
)
3888 struct xdr_stream xdr
;
3889 struct compound_hdr hdr
;
3892 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3893 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3895 if ((status
= decode_putfh(&xdr
)) != 0)
3897 if ((status
= decode_savefh(&xdr
)) != 0)
3899 if ((status
= decode_putfh(&xdr
)) != 0)
3901 if ((status
= decode_link(&xdr
, &res
->cinfo
)) != 0)
3904 * Note order: OP_LINK leaves the directory as the current
3907 if (decode_getfattr(&xdr
, res
->dir_attr
, res
->server
) != 0)
3909 if ((status
= decode_restorefh(&xdr
)) != 0)
3911 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3917 * Decode CREATE response
3919 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
3921 struct xdr_stream xdr
;
3922 struct compound_hdr hdr
;
3925 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3926 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3928 if ((status
= decode_putfh(&xdr
)) != 0)
3930 if ((status
= decode_savefh(&xdr
)) != 0)
3932 if ((status
= decode_create(&xdr
,&res
->dir_cinfo
)) != 0)
3934 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
3936 if (decode_getfattr(&xdr
, res
->fattr
, res
->server
) != 0)
3938 if ((status
= decode_restorefh(&xdr
)) != 0)
3940 decode_getfattr(&xdr
, res
->dir_fattr
, res
->server
);
3946 * Decode SYMLINK response
3948 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
3950 return nfs4_xdr_dec_create(rqstp
, p
, res
);
3954 * Decode GETATTR response
3956 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_getattr_res
*res
)
3958 struct xdr_stream xdr
;
3959 struct compound_hdr hdr
;
3962 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3963 status
= decode_compound_hdr(&xdr
, &hdr
);
3966 status
= decode_putfh(&xdr
);
3969 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3975 * Encode an SETACL request
3978 nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setaclargs
*args
)
3980 struct xdr_stream xdr
;
3981 struct compound_hdr hdr
= {
3986 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
3987 encode_compound_hdr(&xdr
, &hdr
);
3988 encode_putfh(&xdr
, args
->fh
, &hdr
);
3989 status
= encode_setacl(&xdr
, args
, &hdr
);
3995 * Decode SETACL response
3998 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, __be32
*p
, void *res
)
4000 struct xdr_stream xdr
;
4001 struct compound_hdr hdr
;
4004 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4005 status
= decode_compound_hdr(&xdr
, &hdr
);
4008 status
= decode_putfh(&xdr
);
4011 status
= decode_setattr(&xdr
, res
);
4017 * Decode GETACL response
4020 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, __be32
*p
, size_t *acl_len
)
4022 struct xdr_stream xdr
;
4023 struct compound_hdr hdr
;
4026 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4027 status
= decode_compound_hdr(&xdr
, &hdr
);
4030 status
= decode_putfh(&xdr
);
4033 status
= decode_getacl(&xdr
, rqstp
, acl_len
);
4040 * Decode CLOSE response
4042 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
4044 struct xdr_stream xdr
;
4045 struct compound_hdr hdr
;
4048 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4049 status
= decode_compound_hdr(&xdr
, &hdr
);
4052 status
= decode_putfh(&xdr
);
4055 status
= decode_close(&xdr
, res
);
4059 * Note: Server may do delete on close for this file
4060 * in which case the getattr call will fail with
4061 * an ESTALE error. Shouldn't be a problem,
4062 * though, since fattr->valid will remain unset.
4064 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4070 * Decode OPEN response
4072 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
4074 struct xdr_stream xdr
;
4075 struct compound_hdr hdr
;
4078 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4079 status
= decode_compound_hdr(&xdr
, &hdr
);
4082 status
= decode_putfh(&xdr
);
4085 status
= decode_savefh(&xdr
);
4088 status
= decode_open(&xdr
, res
);
4091 if (decode_getfh(&xdr
, &res
->fh
) != 0)
4093 if (decode_getfattr(&xdr
, res
->f_attr
, res
->server
) != 0)
4095 if (decode_restorefh(&xdr
) != 0)
4097 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
);
4103 * Decode OPEN_CONFIRM response
4105 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_open_confirmres
*res
)
4107 struct xdr_stream xdr
;
4108 struct compound_hdr hdr
;
4111 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4112 status
= decode_compound_hdr(&xdr
, &hdr
);
4115 status
= decode_putfh(&xdr
);
4118 status
= decode_open_confirm(&xdr
, res
);
4124 * Decode OPEN response
4126 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
4128 struct xdr_stream xdr
;
4129 struct compound_hdr hdr
;
4132 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4133 status
= decode_compound_hdr(&xdr
, &hdr
);
4136 status
= decode_putfh(&xdr
);
4139 status
= decode_open(&xdr
, res
);
4142 decode_getfattr(&xdr
, res
->f_attr
, res
->server
);
4148 * Decode SETATTR response
4150 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_setattrres
*res
)
4152 struct xdr_stream xdr
;
4153 struct compound_hdr hdr
;
4156 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4157 status
= decode_compound_hdr(&xdr
, &hdr
);
4160 status
= decode_putfh(&xdr
);
4163 status
= decode_setattr(&xdr
, res
);
4166 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4172 * Decode LOCK response
4174 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lock_res
*res
)
4176 struct xdr_stream xdr
;
4177 struct compound_hdr hdr
;
4180 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4181 status
= decode_compound_hdr(&xdr
, &hdr
);
4184 status
= decode_putfh(&xdr
);
4187 status
= decode_lock(&xdr
, res
);
4193 * Decode LOCKT response
4195 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lockt_res
*res
)
4197 struct xdr_stream xdr
;
4198 struct compound_hdr hdr
;
4201 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4202 status
= decode_compound_hdr(&xdr
, &hdr
);
4205 status
= decode_putfh(&xdr
);
4208 status
= decode_lockt(&xdr
, res
);
4214 * Decode LOCKU response
4216 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_locku_res
*res
)
4218 struct xdr_stream xdr
;
4219 struct compound_hdr hdr
;
4222 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4223 status
= decode_compound_hdr(&xdr
, &hdr
);
4226 status
= decode_putfh(&xdr
);
4229 status
= decode_locku(&xdr
, res
);
4235 * Decode READLINK response
4237 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
, __be32
*p
, void *res
)
4239 struct xdr_stream xdr
;
4240 struct compound_hdr hdr
;
4243 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4244 status
= decode_compound_hdr(&xdr
, &hdr
);
4247 status
= decode_putfh(&xdr
);
4250 status
= decode_readlink(&xdr
, rqstp
);
4256 * Decode READDIR response
4258 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_readdir_res
*res
)
4260 struct xdr_stream xdr
;
4261 struct compound_hdr hdr
;
4264 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4265 status
= decode_compound_hdr(&xdr
, &hdr
);
4268 status
= decode_putfh(&xdr
);
4271 status
= decode_readdir(&xdr
, rqstp
, res
);
4277 * Decode Read response
4279 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_readres
*res
)
4281 struct xdr_stream xdr
;
4282 struct compound_hdr hdr
;
4285 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4286 status
= decode_compound_hdr(&xdr
, &hdr
);
4289 status
= decode_putfh(&xdr
);
4292 status
= decode_read(&xdr
, rqstp
, res
);
4294 status
= res
->count
;
4300 * Decode WRITE response
4302 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
4304 struct xdr_stream xdr
;
4305 struct compound_hdr hdr
;
4308 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4309 status
= decode_compound_hdr(&xdr
, &hdr
);
4312 status
= decode_putfh(&xdr
);
4315 status
= decode_write(&xdr
, res
);
4318 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4320 status
= res
->count
;
4326 * Decode COMMIT response
4328 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
4330 struct xdr_stream xdr
;
4331 struct compound_hdr hdr
;
4334 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4335 status
= decode_compound_hdr(&xdr
, &hdr
);
4338 status
= decode_putfh(&xdr
);
4341 status
= decode_commit(&xdr
, res
);
4344 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4352 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsinfo
*fsinfo
)
4354 struct xdr_stream xdr
;
4355 struct compound_hdr hdr
;
4358 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4359 status
= decode_compound_hdr(&xdr
, &hdr
);
4361 status
= decode_putfh(&xdr
);
4363 status
= decode_fsinfo(&xdr
, fsinfo
);
4370 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, __be32
*p
, struct nfs_pathconf
*pathconf
)
4372 struct xdr_stream xdr
;
4373 struct compound_hdr hdr
;
4376 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4377 status
= decode_compound_hdr(&xdr
, &hdr
);
4379 status
= decode_putfh(&xdr
);
4381 status
= decode_pathconf(&xdr
, pathconf
);
4388 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsstat
*fsstat
)
4390 struct xdr_stream xdr
;
4391 struct compound_hdr hdr
;
4394 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4395 status
= decode_compound_hdr(&xdr
, &hdr
);
4397 status
= decode_putfh(&xdr
);
4399 status
= decode_statfs(&xdr
, fsstat
);
4404 * GETATTR_BITMAP request
4406 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_server_caps_res
*res
)
4408 struct xdr_stream xdr
;
4409 struct compound_hdr hdr
;
4412 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4413 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
4415 if ((status
= decode_putfh(&xdr
)) != 0)
4417 status
= decode_server_caps(&xdr
, res
);
4423 * Decode RENEW response
4425 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, __be32
*p
, void *dummy
)
4427 struct xdr_stream xdr
;
4428 struct compound_hdr hdr
;
4431 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4432 status
= decode_compound_hdr(&xdr
, &hdr
);
4434 status
= decode_renew(&xdr
);
4439 * a SETCLIENTID request
4441 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
, __be32
*p
,
4442 struct nfs_client
*clp
)
4444 struct xdr_stream xdr
;
4445 struct compound_hdr hdr
;
4448 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4449 status
= decode_compound_hdr(&xdr
, &hdr
);
4451 status
= decode_setclientid(&xdr
, clp
);
4456 * a SETCLIENTID_CONFIRM request
4458 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsinfo
*fsinfo
)
4460 struct xdr_stream xdr
;
4461 struct compound_hdr hdr
;
4464 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4465 status
= decode_compound_hdr(&xdr
, &hdr
);
4467 status
= decode_setclientid_confirm(&xdr
);
4469 status
= decode_putrootfh(&xdr
);
4471 status
= decode_fsinfo(&xdr
, fsinfo
);
4476 * DELEGRETURN request
4478 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_delegreturnres
*res
)
4480 struct xdr_stream xdr
;
4481 struct compound_hdr hdr
;
4484 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4485 status
= decode_compound_hdr(&xdr
, &hdr
);
4488 status
= decode_putfh(&xdr
);
4491 status
= decode_delegreturn(&xdr
);
4492 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4498 * FS_LOCATIONS request
4500 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fs_locations
*res
)
4502 struct xdr_stream xdr
;
4503 struct compound_hdr hdr
;
4506 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4507 status
= decode_compound_hdr(&xdr
, &hdr
);
4510 if ((status
= decode_putfh(&xdr
)) != 0)
4512 if ((status
= decode_lookup(&xdr
)) != 0)
4514 xdr_enter_page(&xdr
, PAGE_SIZE
);
4515 status
= decode_getfattr(&xdr
, &res
->fattr
, res
->server
);
4520 __be32
*nfs4_decode_dirent(__be32
*p
, struct nfs_entry
*entry
, int plus
)
4522 uint32_t bitmap
[2] = {0};
4527 return ERR_PTR(-EAGAIN
);
4529 return ERR_PTR(-EBADCOOKIE
);
4532 entry
->prev_cookie
= entry
->cookie
;
4533 p
= xdr_decode_hyper(p
, &entry
->cookie
);
4534 entry
->len
= ntohl(*p
++);
4535 entry
->name
= (const char *) p
;
4536 p
+= XDR_QUADLEN(entry
->len
);
4539 * In case the server doesn't return an inode number,
4540 * we fake one here. (We don't use inode number 0,
4541 * since glibc seems to choke on it...)
4545 len
= ntohl(*p
++); /* bitmap length */
4547 bitmap
[0] = ntohl(*p
++);
4549 bitmap
[1] = ntohl(*p
++);
4553 len
= XDR_QUADLEN(ntohl(*p
++)); /* attribute buffer length */
4555 if (bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
) {
4556 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
4557 /* Ignore the return value of rdattr_error for now */
4561 if (bitmap
[0] == 0 && bitmap
[1] == FATTR4_WORD1_MOUNTED_ON_FILEID
)
4562 xdr_decode_hyper(p
, &entry
->ino
);
4563 else if (bitmap
[0] == FATTR4_WORD0_FILEID
)
4564 xdr_decode_hyper(p
, &entry
->ino
);
4568 entry
->eof
= !p
[0] && p
[1];
4573 * We need to translate between nfs status return values and
4574 * the local errno values which may not be the same.
4581 { NFS4ERR_PERM
, -EPERM
},
4582 { NFS4ERR_NOENT
, -ENOENT
},
4583 { NFS4ERR_IO
, -errno_NFSERR_IO
},
4584 { NFS4ERR_NXIO
, -ENXIO
},
4585 { NFS4ERR_ACCESS
, -EACCES
},
4586 { NFS4ERR_EXIST
, -EEXIST
},
4587 { NFS4ERR_XDEV
, -EXDEV
},
4588 { NFS4ERR_NOTDIR
, -ENOTDIR
},
4589 { NFS4ERR_ISDIR
, -EISDIR
},
4590 { NFS4ERR_INVAL
, -EINVAL
},
4591 { NFS4ERR_FBIG
, -EFBIG
},
4592 { NFS4ERR_NOSPC
, -ENOSPC
},
4593 { NFS4ERR_ROFS
, -EROFS
},
4594 { NFS4ERR_MLINK
, -EMLINK
},
4595 { NFS4ERR_NAMETOOLONG
, -ENAMETOOLONG
},
4596 { NFS4ERR_NOTEMPTY
, -ENOTEMPTY
},
4597 { NFS4ERR_DQUOT
, -EDQUOT
},
4598 { NFS4ERR_STALE
, -ESTALE
},
4599 { NFS4ERR_BADHANDLE
, -EBADHANDLE
},
4600 { NFS4ERR_BADOWNER
, -EINVAL
},
4601 { NFS4ERR_BADNAME
, -EINVAL
},
4602 { NFS4ERR_BAD_COOKIE
, -EBADCOOKIE
},
4603 { NFS4ERR_NOTSUPP
, -ENOTSUPP
},
4604 { NFS4ERR_TOOSMALL
, -ETOOSMALL
},
4605 { NFS4ERR_SERVERFAULT
, -ESERVERFAULT
},
4606 { NFS4ERR_BADTYPE
, -EBADTYPE
},
4607 { NFS4ERR_LOCKED
, -EAGAIN
},
4608 { NFS4ERR_RESOURCE
, -EREMOTEIO
},
4609 { NFS4ERR_SYMLINK
, -ELOOP
},
4610 { NFS4ERR_OP_ILLEGAL
, -EOPNOTSUPP
},
4611 { NFS4ERR_DEADLOCK
, -EDEADLK
},
4612 { NFS4ERR_WRONGSEC
, -EPERM
}, /* FIXME: this needs
4613 * to be handled by a
4620 * Convert an NFS error code to a local one.
4621 * This one is used jointly by NFSv2 and NFSv3.
4624 nfs4_stat_to_errno(int stat
)
4627 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
4628 if (nfs_errtbl
[i
].stat
== stat
)
4629 return nfs_errtbl
[i
].errno
;
4631 if (stat
<= 10000 || stat
> 10100) {
4632 /* The server is looney tunes. */
4633 return -ESERVERFAULT
;
4635 /* If we cannot translate the error, the recovery routines should
4637 * Note: remaining NFSv4 error codes have values > 10000, so should
4638 * not conflict with native Linux error codes.
4643 #define PROC(proc, argtype, restype) \
4644 [NFSPROC4_CLNT_##proc] = { \
4645 .p_proc = NFSPROC4_COMPOUND, \
4646 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4647 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4648 .p_arglen = NFS4_##argtype##_sz, \
4649 .p_replen = NFS4_##restype##_sz, \
4650 .p_statidx = NFSPROC4_CLNT_##proc, \
4654 struct rpc_procinfo nfs4_procedures
[] = {
4655 PROC(READ
, enc_read
, dec_read
),
4656 PROC(WRITE
, enc_write
, dec_write
),
4657 PROC(COMMIT
, enc_commit
, dec_commit
),
4658 PROC(OPEN
, enc_open
, dec_open
),
4659 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
4660 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
4661 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
4662 PROC(CLOSE
, enc_close
, dec_close
),
4663 PROC(SETATTR
, enc_setattr
, dec_setattr
),
4664 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
4665 PROC(RENEW
, enc_renew
, dec_renew
),
4666 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
4667 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
4668 PROC(LOCK
, enc_lock
, dec_lock
),
4669 PROC(LOCKT
, enc_lockt
, dec_lockt
),
4670 PROC(LOCKU
, enc_locku
, dec_locku
),
4671 PROC(ACCESS
, enc_access
, dec_access
),
4672 PROC(GETATTR
, enc_getattr
, dec_getattr
),
4673 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
4674 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
4675 PROC(REMOVE
, enc_remove
, dec_remove
),
4676 PROC(RENAME
, enc_rename
, dec_rename
),
4677 PROC(LINK
, enc_link
, dec_link
),
4678 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
4679 PROC(CREATE
, enc_create
, dec_create
),
4680 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
4681 PROC(STATFS
, enc_statfs
, dec_statfs
),
4682 PROC(READLINK
, enc_readlink
, dec_readlink
),
4683 PROC(READDIR
, enc_readdir
, dec_readdir
),
4684 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
4685 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
4686 PROC(GETACL
, enc_getacl
, dec_getacl
),
4687 PROC(SETACL
, enc_setacl
, dec_setacl
),
4688 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
4691 struct rpc_version nfs_version4
= {
4693 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
4694 .procs
= nfs4_procedures