Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * fs/nfs/nfs4xdr.c | |
3 | * | |
4 | * Client-side XDR for NFSv4. | |
5 | * | |
6 | * Copyright (c) 2002 The Regents of the University of Michigan. | |
7 | * All rights reserved. | |
8 | * | |
9 | * Kendrick Smith <kmsmith@umich.edu> | |
10 | * Andy Adamson <andros@umich.edu> | |
11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | |
15 | * | |
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. | |
24 | * | |
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. | |
36 | */ | |
37 | ||
38 | #include <linux/param.h> | |
39 | #include <linux/time.h> | |
40 | #include <linux/mm.h> | |
41 | #include <linux/slab.h> | |
42 | #include <linux/utsname.h> | |
43 | #include <linux/errno.h> | |
44 | #include <linux/string.h> | |
45 | #include <linux/in.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> | |
4ce79717 | 54 | #include "nfs4_fs.h" |
1da177e4 LT |
55 | |
56 | #define NFSDBG_FACILITY NFSDBG_XDR | |
57 | ||
58 | /* Mapping from NFS error code to "errno" error code. */ | |
59 | #define errno_NFSERR_IO EIO | |
60 | ||
61 | static int nfs_stat_to_errno(int); | |
62 | ||
63 | /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ | |
64 | #ifdef DEBUG | |
65 | #define NFS4_MAXTAGLEN 20 | |
66 | #else | |
67 | #define NFS4_MAXTAGLEN 0 | |
68 | #endif | |
69 | ||
70 | /* lock,open owner id: | |
71 | * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2) | |
72 | */ | |
73 | #define owner_id_maxsz (1 + 1) | |
74 | #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) | |
75 | #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) | |
76 | #define op_encode_hdr_maxsz (1) | |
77 | #define op_decode_hdr_maxsz (2) | |
78 | #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ | |
79 | (NFS4_FHSIZE >> 2)) | |
80 | #define decode_putfh_maxsz (op_decode_hdr_maxsz) | |
81 | #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) | |
82 | #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) | |
83 | #define encode_getfh_maxsz (op_encode_hdr_maxsz) | |
84 | #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ | |
85 | ((3+NFS4_FHSIZE) >> 2)) | |
96928206 BF |
86 | #define nfs4_fattr_bitmap_maxsz 3 |
87 | #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) | |
1da177e4 LT |
88 | #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) |
89 | #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) | |
96928206 BF |
90 | /* This is based on getfattr, which uses the most attributes: */ |
91 | #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ | |
92 | 3 + 3 + 3 + 2 * nfs4_name_maxsz)) | |
93 | #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ | |
94 | nfs4_fattr_value_maxsz) | |
95 | #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) | |
1da177e4 LT |
96 | #define encode_savefh_maxsz (op_encode_hdr_maxsz) |
97 | #define decode_savefh_maxsz (op_decode_hdr_maxsz) | |
56ae19f3 TM |
98 | #define encode_restorefh_maxsz (op_encode_hdr_maxsz) |
99 | #define decode_restorefh_maxsz (op_decode_hdr_maxsz) | |
1da177e4 LT |
100 | #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2) |
101 | #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11) | |
102 | #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) | |
103 | #define decode_renew_maxsz (op_decode_hdr_maxsz) | |
104 | #define encode_setclientid_maxsz \ | |
105 | (op_encode_hdr_maxsz + \ | |
106 | 4 /*server->ip_addr*/ + \ | |
107 | 1 /*Netid*/ + \ | |
108 | 6 /*uaddr*/ + \ | |
109 | 6 + (NFS4_VERIFIER_SIZE >> 2)) | |
110 | #define decode_setclientid_maxsz \ | |
111 | (op_decode_hdr_maxsz + \ | |
112 | 2 + \ | |
113 | 1024) /* large value for CLID_INUSE */ | |
114 | #define encode_setclientid_confirm_maxsz \ | |
115 | (op_encode_hdr_maxsz + \ | |
116 | 3 + (NFS4_VERIFIER_SIZE >> 2)) | |
117 | #define decode_setclientid_confirm_maxsz \ | |
118 | (op_decode_hdr_maxsz) | |
119 | #define encode_lookup_maxsz (op_encode_hdr_maxsz + \ | |
120 | 1 + ((3 + NFS4_FHSIZE) >> 2)) | |
121 | #define encode_remove_maxsz (op_encode_hdr_maxsz + \ | |
122 | nfs4_name_maxsz) | |
123 | #define encode_rename_maxsz (op_encode_hdr_maxsz + \ | |
124 | 2 * nfs4_name_maxsz) | |
125 | #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5) | |
126 | #define encode_link_maxsz (op_encode_hdr_maxsz + \ | |
127 | nfs4_name_maxsz) | |
128 | #define decode_link_maxsz (op_decode_hdr_maxsz + 5) | |
129 | #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ | |
130 | 1 + nfs4_name_maxsz + \ | |
131 | nfs4_path_maxsz + \ | |
96928206 | 132 | nfs4_fattr_maxsz) |
1da177e4 LT |
133 | #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) |
134 | #define encode_create_maxsz (op_encode_hdr_maxsz + \ | |
135 | 2 + nfs4_name_maxsz + \ | |
96928206 | 136 | nfs4_fattr_maxsz) |
1da177e4 LT |
137 | #define decode_create_maxsz (op_decode_hdr_maxsz + 8) |
138 | #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) | |
139 | #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) | |
140 | #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ | |
141 | #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ | |
142 | #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ | |
143 | encode_putfh_maxsz + \ | |
144 | op_encode_hdr_maxsz + 7) | |
145 | #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ | |
146 | decode_putfh_maxsz + \ | |
147 | op_decode_hdr_maxsz + 2) | |
148 | #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ | |
149 | encode_putfh_maxsz + \ | |
150 | op_encode_hdr_maxsz) | |
151 | #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ | |
152 | decode_putfh_maxsz + \ | |
153 | op_decode_hdr_maxsz) | |
154 | #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ | |
155 | encode_putfh_maxsz + \ | |
156 | op_encode_hdr_maxsz + 9) | |
157 | #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ | |
158 | decode_putfh_maxsz + \ | |
159 | op_decode_hdr_maxsz + 2) | |
160 | #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ | |
161 | encode_putfh_maxsz + \ | |
4f9838c7 TM |
162 | op_encode_hdr_maxsz + 8 + \ |
163 | encode_getattr_maxsz) | |
1da177e4 LT |
164 | #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ |
165 | decode_putfh_maxsz + \ | |
4f9838c7 TM |
166 | op_decode_hdr_maxsz + 4 + \ |
167 | decode_getattr_maxsz) | |
1da177e4 LT |
168 | #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ |
169 | encode_putfh_maxsz + \ | |
4f9838c7 TM |
170 | op_encode_hdr_maxsz + 3 + \ |
171 | encode_getattr_maxsz) | |
1da177e4 LT |
172 | #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ |
173 | decode_putfh_maxsz + \ | |
4f9838c7 TM |
174 | op_decode_hdr_maxsz + 2 + \ |
175 | decode_getattr_maxsz) | |
1da177e4 LT |
176 | #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ |
177 | encode_putfh_maxsz + \ | |
178 | op_encode_hdr_maxsz + \ | |
179 | 13 + 3 + 2 + 64 + \ | |
180 | encode_getattr_maxsz + \ | |
181 | encode_getfh_maxsz) | |
182 | #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ | |
183 | decode_putfh_maxsz + \ | |
184 | op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \ | |
185 | decode_getattr_maxsz + \ | |
186 | decode_getfh_maxsz) | |
187 | #define NFS4_enc_open_confirm_sz \ | |
188 | (compound_encode_hdr_maxsz + \ | |
189 | encode_putfh_maxsz + \ | |
190 | op_encode_hdr_maxsz + 5) | |
191 | #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \ | |
192 | decode_putfh_maxsz + \ | |
193 | op_decode_hdr_maxsz + 4) | |
194 | #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ | |
195 | encode_putfh_maxsz + \ | |
196 | op_encode_hdr_maxsz + \ | |
197 | 11) | |
198 | #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ | |
199 | decode_putfh_maxsz + \ | |
200 | op_decode_hdr_maxsz + \ | |
201 | 4 + 5 + 2 + 3) | |
202 | #define NFS4_enc_open_downgrade_sz \ | |
203 | (compound_encode_hdr_maxsz + \ | |
204 | encode_putfh_maxsz + \ | |
516a6af6 TM |
205 | op_encode_hdr_maxsz + 7 + \ |
206 | encode_getattr_maxsz) | |
1da177e4 LT |
207 | #define NFS4_dec_open_downgrade_sz \ |
208 | (compound_decode_hdr_maxsz + \ | |
209 | decode_putfh_maxsz + \ | |
516a6af6 TM |
210 | op_decode_hdr_maxsz + 4 + \ |
211 | decode_getattr_maxsz) | |
1da177e4 LT |
212 | #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ |
213 | encode_putfh_maxsz + \ | |
516a6af6 TM |
214 | op_encode_hdr_maxsz + 5 + \ |
215 | encode_getattr_maxsz) | |
1da177e4 LT |
216 | #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ |
217 | decode_putfh_maxsz + \ | |
516a6af6 TM |
218 | op_decode_hdr_maxsz + 4 + \ |
219 | decode_getattr_maxsz) | |
1da177e4 LT |
220 | #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ |
221 | encode_putfh_maxsz + \ | |
222 | op_encode_hdr_maxsz + 4 + \ | |
96928206 | 223 | nfs4_fattr_maxsz + \ |
1da177e4 LT |
224 | encode_getattr_maxsz) |
225 | #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ | |
226 | decode_putfh_maxsz + \ | |
227 | op_decode_hdr_maxsz + 3) | |
228 | #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ | |
229 | encode_putfh_maxsz + \ | |
230 | encode_fsinfo_maxsz) | |
231 | #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ | |
232 | decode_putfh_maxsz + \ | |
233 | decode_fsinfo_maxsz) | |
234 | #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ | |
235 | encode_renew_maxsz) | |
236 | #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ | |
237 | decode_renew_maxsz) | |
238 | #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ | |
239 | encode_setclientid_maxsz) | |
240 | #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ | |
241 | decode_setclientid_maxsz) | |
242 | #define NFS4_enc_setclientid_confirm_sz \ | |
243 | (compound_encode_hdr_maxsz + \ | |
244 | encode_setclientid_confirm_maxsz + \ | |
245 | encode_putrootfh_maxsz + \ | |
246 | encode_fsinfo_maxsz) | |
247 | #define NFS4_dec_setclientid_confirm_sz \ | |
248 | (compound_decode_hdr_maxsz + \ | |
249 | decode_setclientid_confirm_maxsz + \ | |
250 | decode_putrootfh_maxsz + \ | |
251 | decode_fsinfo_maxsz) | |
252 | #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ | |
253 | encode_putfh_maxsz + \ | |
254 | encode_getattr_maxsz + \ | |
255 | op_encode_hdr_maxsz + \ | |
256 | 1 + 1 + 2 + 2 + \ | |
257 | 1 + 4 + 1 + 2 + \ | |
258 | owner_id_maxsz) | |
259 | #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ | |
260 | decode_putfh_maxsz + \ | |
261 | decode_getattr_maxsz + \ | |
262 | op_decode_hdr_maxsz + \ | |
263 | 2 + 2 + 1 + 2 + \ | |
264 | owner_id_maxsz) | |
265 | #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ | |
266 | encode_putfh_maxsz + \ | |
267 | encode_getattr_maxsz + \ | |
268 | op_encode_hdr_maxsz + \ | |
269 | 1 + 2 + 2 + 2 + \ | |
270 | owner_id_maxsz) | |
271 | #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz) | |
272 | #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ | |
273 | encode_putfh_maxsz + \ | |
274 | encode_getattr_maxsz + \ | |
275 | op_encode_hdr_maxsz + \ | |
276 | 1 + 1 + 4 + 2 + 2) | |
277 | #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ | |
278 | decode_putfh_maxsz + \ | |
279 | decode_getattr_maxsz + \ | |
280 | op_decode_hdr_maxsz + 4) | |
281 | #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ | |
282 | encode_putfh_maxsz + \ | |
283 | op_encode_hdr_maxsz + 1) | |
284 | #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ | |
285 | decode_putfh_maxsz + \ | |
286 | op_decode_hdr_maxsz + 2) | |
287 | #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ | |
288 | encode_putfh_maxsz + \ | |
289 | encode_getattr_maxsz) | |
290 | #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ | |
291 | decode_putfh_maxsz + \ | |
292 | decode_getattr_maxsz) | |
293 | #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ | |
294 | encode_putfh_maxsz + \ | |
295 | encode_lookup_maxsz + \ | |
296 | encode_getattr_maxsz + \ | |
297 | encode_getfh_maxsz) | |
298 | #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ | |
299 | decode_putfh_maxsz + \ | |
300 | op_decode_hdr_maxsz + \ | |
301 | decode_getattr_maxsz + \ | |
302 | decode_getfh_maxsz) | |
303 | #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ | |
304 | encode_putrootfh_maxsz + \ | |
305 | encode_getattr_maxsz + \ | |
306 | encode_getfh_maxsz) | |
307 | #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ | |
308 | decode_putrootfh_maxsz + \ | |
309 | decode_getattr_maxsz + \ | |
310 | decode_getfh_maxsz) | |
311 | #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ | |
312 | encode_putfh_maxsz + \ | |
16e42959 TM |
313 | encode_remove_maxsz + \ |
314 | encode_getattr_maxsz) | |
1da177e4 LT |
315 | #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ |
316 | decode_putfh_maxsz + \ | |
16e42959 TM |
317 | op_decode_hdr_maxsz + 5 + \ |
318 | decode_getattr_maxsz) | |
1da177e4 LT |
319 | #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ |
320 | encode_putfh_maxsz + \ | |
321 | encode_savefh_maxsz + \ | |
322 | encode_putfh_maxsz + \ | |
6caf2c82 TM |
323 | encode_rename_maxsz + \ |
324 | encode_getattr_maxsz + \ | |
325 | encode_restorefh_maxsz + \ | |
326 | encode_getattr_maxsz) | |
1da177e4 LT |
327 | #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ |
328 | decode_putfh_maxsz + \ | |
329 | decode_savefh_maxsz + \ | |
330 | decode_putfh_maxsz + \ | |
6caf2c82 TM |
331 | decode_rename_maxsz + \ |
332 | decode_getattr_maxsz + \ | |
333 | decode_restorefh_maxsz + \ | |
334 | decode_getattr_maxsz) | |
1da177e4 LT |
335 | #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ |
336 | encode_putfh_maxsz + \ | |
337 | encode_savefh_maxsz + \ | |
338 | encode_putfh_maxsz + \ | |
91ba2eee TM |
339 | encode_link_maxsz + \ |
340 | decode_getattr_maxsz + \ | |
341 | encode_restorefh_maxsz + \ | |
342 | decode_getattr_maxsz) | |
1da177e4 LT |
343 | #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ |
344 | decode_putfh_maxsz + \ | |
345 | decode_savefh_maxsz + \ | |
346 | decode_putfh_maxsz + \ | |
91ba2eee TM |
347 | decode_link_maxsz + \ |
348 | decode_getattr_maxsz + \ | |
349 | decode_restorefh_maxsz + \ | |
350 | decode_getattr_maxsz) | |
1da177e4 LT |
351 | #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ |
352 | encode_putfh_maxsz + \ | |
353 | encode_symlink_maxsz + \ | |
354 | encode_getattr_maxsz + \ | |
355 | encode_getfh_maxsz) | |
356 | #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ | |
357 | decode_putfh_maxsz + \ | |
358 | decode_symlink_maxsz + \ | |
359 | decode_getattr_maxsz + \ | |
360 | decode_getfh_maxsz) | |
361 | #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ | |
362 | encode_putfh_maxsz + \ | |
56ae19f3 | 363 | encode_savefh_maxsz + \ |
1da177e4 | 364 | encode_create_maxsz + \ |
56ae19f3 | 365 | encode_getfh_maxsz + \ |
1da177e4 | 366 | encode_getattr_maxsz + \ |
56ae19f3 TM |
367 | encode_restorefh_maxsz + \ |
368 | encode_getattr_maxsz) | |
1da177e4 LT |
369 | #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ |
370 | decode_putfh_maxsz + \ | |
56ae19f3 | 371 | decode_savefh_maxsz + \ |
1da177e4 | 372 | decode_create_maxsz + \ |
56ae19f3 | 373 | decode_getfh_maxsz + \ |
1da177e4 | 374 | decode_getattr_maxsz + \ |
56ae19f3 TM |
375 | decode_restorefh_maxsz + \ |
376 | decode_getattr_maxsz) | |
1da177e4 LT |
377 | #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ |
378 | encode_putfh_maxsz + \ | |
379 | encode_getattr_maxsz) | |
380 | #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ | |
381 | decode_putfh_maxsz + \ | |
382 | decode_getattr_maxsz) | |
383 | #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ | |
384 | encode_putfh_maxsz + \ | |
385 | encode_getattr_maxsz) | |
386 | #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ | |
387 | decode_putfh_maxsz + \ | |
388 | op_decode_hdr_maxsz + 12) | |
389 | #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ | |
390 | encode_getattr_maxsz) | |
391 | #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ | |
392 | decode_getattr_maxsz) | |
393 | #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ | |
394 | encode_putfh_maxsz + \ | |
fa178f29 TM |
395 | encode_delegreturn_maxsz + \ |
396 | encode_getattr_maxsz) | |
1da177e4 | 397 | #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ |
fa178f29 TM |
398 | decode_delegreturn_maxsz + \ |
399 | decode_getattr_maxsz) | |
029d105e BF |
400 | #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ |
401 | encode_putfh_maxsz + \ | |
402 | encode_getattr_maxsz) | |
403 | #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ | |
404 | decode_putfh_maxsz + \ | |
405 | op_decode_hdr_maxsz + \ | |
406 | nfs4_fattr_bitmap_maxsz + 1) | |
23ec6965 BF |
407 | #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ |
408 | encode_putfh_maxsz + \ | |
409 | op_encode_hdr_maxsz + 4 + \ | |
410 | nfs4_fattr_bitmap_maxsz + 1) | |
411 | #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ | |
412 | decode_putfh_maxsz + \ | |
413 | op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) | |
683b57b4 TM |
414 | #define NFS4_enc_fs_locations_sz \ |
415 | (compound_encode_hdr_maxsz + \ | |
416 | encode_putfh_maxsz + \ | |
417 | encode_getattr_maxsz) | |
418 | #define NFS4_dec_fs_locations_sz \ | |
419 | (compound_decode_hdr_maxsz + \ | |
420 | decode_putfh_maxsz + \ | |
421 | op_decode_hdr_maxsz + \ | |
422 | nfs4_fattr_bitmap_maxsz) | |
1da177e4 LT |
423 | |
424 | static struct { | |
425 | unsigned int mode; | |
426 | unsigned int nfs2type; | |
427 | } nfs_type2fmt[] = { | |
428 | { 0, NFNON }, | |
429 | { S_IFREG, NFREG }, | |
430 | { S_IFDIR, NFDIR }, | |
431 | { S_IFBLK, NFBLK }, | |
432 | { S_IFCHR, NFCHR }, | |
433 | { S_IFLNK, NFLNK }, | |
434 | { S_IFSOCK, NFSOCK }, | |
435 | { S_IFIFO, NFFIFO }, | |
436 | { 0, NFNON }, | |
437 | { 0, NFNON }, | |
438 | }; | |
439 | ||
440 | struct compound_hdr { | |
441 | int32_t status; | |
442 | uint32_t nops; | |
443 | uint32_t taglen; | |
444 | char * tag; | |
445 | }; | |
446 | ||
447 | /* | |
448 | * START OF "GENERIC" ENCODE ROUTINES. | |
449 | * These may look a little ugly since they are imported from a "generic" | |
450 | * set of XDR encode/decode routines which are intended to be shared by | |
451 | * all of our NFSv4 implementations (OpenBSD, MacOS X...). | |
452 | * | |
453 | * If the pain of reading these is too great, it should be a straightforward | |
454 | * task to translate them into Linux-specific versions which are more | |
455 | * consistent with the style used in NFSv2/v3... | |
456 | */ | |
457 | #define WRITE32(n) *p++ = htonl(n) | |
458 | #define WRITE64(n) do { \ | |
459 | *p++ = htonl((uint32_t)((n) >> 32)); \ | |
460 | *p++ = htonl((uint32_t)(n)); \ | |
461 | } while (0) | |
462 | #define WRITEMEM(ptr,nbytes) do { \ | |
463 | p = xdr_encode_opaque_fixed(p, ptr, nbytes); \ | |
464 | } while (0) | |
465 | ||
466 | #define RESERVE_SPACE(nbytes) do { \ | |
467 | p = xdr_reserve_space(xdr, nbytes); \ | |
468 | if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \ | |
469 | BUG_ON(!p); \ | |
470 | } while (0) | |
471 | ||
472 | static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) | |
473 | { | |
474 | uint32_t *p; | |
475 | ||
476 | p = xdr_reserve_space(xdr, 4 + len); | |
477 | BUG_ON(p == NULL); | |
478 | xdr_encode_opaque(p, str, len); | |
479 | } | |
480 | ||
481 | static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) | |
482 | { | |
483 | uint32_t *p; | |
484 | ||
485 | dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag); | |
486 | BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); | |
487 | RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2)); | |
488 | WRITE32(hdr->taglen); | |
489 | WRITEMEM(hdr->tag, hdr->taglen); | |
490 | WRITE32(NFS4_MINOR_VERSION); | |
491 | WRITE32(hdr->nops); | |
492 | return 0; | |
493 | } | |
494 | ||
495 | static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) | |
496 | { | |
497 | uint32_t *p; | |
498 | ||
499 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); | |
500 | BUG_ON(p == NULL); | |
501 | xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE); | |
502 | } | |
503 | ||
504 | static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) | |
505 | { | |
506 | char owner_name[IDMAP_NAMESZ]; | |
507 | char owner_group[IDMAP_NAMESZ]; | |
508 | int owner_namelen = 0; | |
509 | int owner_grouplen = 0; | |
510 | uint32_t *p; | |
511 | uint32_t *q; | |
512 | int len; | |
513 | uint32_t bmval0 = 0; | |
514 | uint32_t bmval1 = 0; | |
515 | int status; | |
516 | ||
517 | /* | |
518 | * We reserve enough space to write the entire attribute buffer at once. | |
519 | * In the worst-case, this would be | |
520 | * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) | |
521 | * = 36 bytes, plus any contribution from variable-length fields | |
23ec6965 | 522 | * such as owner/group. |
1da177e4 LT |
523 | */ |
524 | len = 16; | |
525 | ||
526 | /* Sigh */ | |
527 | if (iap->ia_valid & ATTR_SIZE) | |
528 | len += 8; | |
529 | if (iap->ia_valid & ATTR_MODE) | |
530 | len += 4; | |
531 | if (iap->ia_valid & ATTR_UID) { | |
532 | owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name); | |
533 | if (owner_namelen < 0) { | |
534 | printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n", | |
535 | iap->ia_uid); | |
536 | /* XXX */ | |
537 | strcpy(owner_name, "nobody"); | |
538 | owner_namelen = sizeof("nobody") - 1; | |
539 | /* goto out; */ | |
540 | } | |
541 | len += 4 + (XDR_QUADLEN(owner_namelen) << 2); | |
542 | } | |
543 | if (iap->ia_valid & ATTR_GID) { | |
544 | owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group); | |
545 | if (owner_grouplen < 0) { | |
546 | printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n", | |
547 | iap->ia_gid); | |
548 | strcpy(owner_group, "nobody"); | |
549 | owner_grouplen = sizeof("nobody") - 1; | |
550 | /* goto out; */ | |
551 | } | |
552 | len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); | |
553 | } | |
554 | if (iap->ia_valid & ATTR_ATIME_SET) | |
555 | len += 16; | |
556 | else if (iap->ia_valid & ATTR_ATIME) | |
557 | len += 4; | |
558 | if (iap->ia_valid & ATTR_MTIME_SET) | |
559 | len += 16; | |
560 | else if (iap->ia_valid & ATTR_MTIME) | |
561 | len += 4; | |
562 | RESERVE_SPACE(len); | |
563 | ||
564 | /* | |
565 | * We write the bitmap length now, but leave the bitmap and the attribute | |
566 | * buffer length to be backfilled at the end of this routine. | |
567 | */ | |
568 | WRITE32(2); | |
569 | q = p; | |
570 | p += 3; | |
571 | ||
572 | if (iap->ia_valid & ATTR_SIZE) { | |
573 | bmval0 |= FATTR4_WORD0_SIZE; | |
574 | WRITE64(iap->ia_size); | |
575 | } | |
576 | if (iap->ia_valid & ATTR_MODE) { | |
577 | bmval1 |= FATTR4_WORD1_MODE; | |
cf3fff54 | 578 | WRITE32(iap->ia_mode & S_IALLUGO); |
1da177e4 LT |
579 | } |
580 | if (iap->ia_valid & ATTR_UID) { | |
581 | bmval1 |= FATTR4_WORD1_OWNER; | |
582 | WRITE32(owner_namelen); | |
583 | WRITEMEM(owner_name, owner_namelen); | |
584 | } | |
585 | if (iap->ia_valid & ATTR_GID) { | |
586 | bmval1 |= FATTR4_WORD1_OWNER_GROUP; | |
587 | WRITE32(owner_grouplen); | |
588 | WRITEMEM(owner_group, owner_grouplen); | |
589 | } | |
590 | if (iap->ia_valid & ATTR_ATIME_SET) { | |
591 | bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; | |
592 | WRITE32(NFS4_SET_TO_CLIENT_TIME); | |
593 | WRITE32(0); | |
594 | WRITE32(iap->ia_mtime.tv_sec); | |
595 | WRITE32(iap->ia_mtime.tv_nsec); | |
596 | } | |
597 | else if (iap->ia_valid & ATTR_ATIME) { | |
598 | bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; | |
599 | WRITE32(NFS4_SET_TO_SERVER_TIME); | |
600 | } | |
601 | if (iap->ia_valid & ATTR_MTIME_SET) { | |
602 | bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; | |
603 | WRITE32(NFS4_SET_TO_CLIENT_TIME); | |
604 | WRITE32(0); | |
605 | WRITE32(iap->ia_mtime.tv_sec); | |
606 | WRITE32(iap->ia_mtime.tv_nsec); | |
607 | } | |
608 | else if (iap->ia_valid & ATTR_MTIME) { | |
609 | bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; | |
610 | WRITE32(NFS4_SET_TO_SERVER_TIME); | |
611 | } | |
612 | ||
613 | /* | |
614 | * Now we backfill the bitmap and the attribute buffer length. | |
615 | */ | |
616 | if (len != ((char *)p - (char *)q) + 4) { | |
617 | printk ("encode_attr: Attr length calculation error! %u != %Zu\n", | |
618 | len, ((char *)p - (char *)q) + 4); | |
619 | BUG(); | |
620 | } | |
621 | len = (char *)p - (char *)q - 12; | |
622 | *q++ = htonl(bmval0); | |
623 | *q++ = htonl(bmval1); | |
624 | *q++ = htonl(len); | |
625 | ||
626 | status = 0; | |
627 | /* out: */ | |
628 | return status; | |
629 | } | |
630 | ||
631 | static int encode_access(struct xdr_stream *xdr, u32 access) | |
632 | { | |
633 | uint32_t *p; | |
634 | ||
635 | RESERVE_SPACE(8); | |
636 | WRITE32(OP_ACCESS); | |
637 | WRITE32(access); | |
638 | ||
639 | return 0; | |
640 | } | |
641 | ||
642 | static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg) | |
643 | { | |
644 | uint32_t *p; | |
645 | ||
9512135d | 646 | RESERVE_SPACE(8+sizeof(arg->stateid->data)); |
1da177e4 | 647 | WRITE32(OP_CLOSE); |
cee54fc9 | 648 | WRITE32(arg->seqid->sequence->counter); |
9512135d | 649 | WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); |
1da177e4 LT |
650 | |
651 | return 0; | |
652 | } | |
653 | ||
654 | static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args) | |
655 | { | |
656 | uint32_t *p; | |
657 | ||
658 | RESERVE_SPACE(16); | |
659 | WRITE32(OP_COMMIT); | |
660 | WRITE64(args->offset); | |
661 | WRITE32(args->count); | |
662 | ||
663 | return 0; | |
664 | } | |
665 | ||
666 | static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create) | |
667 | { | |
668 | uint32_t *p; | |
669 | ||
670 | RESERVE_SPACE(8); | |
671 | WRITE32(OP_CREATE); | |
672 | WRITE32(create->ftype); | |
673 | ||
674 | switch (create->ftype) { | |
675 | case NF4LNK: | |
676 | RESERVE_SPACE(4 + create->u.symlink->len); | |
677 | WRITE32(create->u.symlink->len); | |
678 | WRITEMEM(create->u.symlink->name, create->u.symlink->len); | |
679 | break; | |
680 | ||
681 | case NF4BLK: case NF4CHR: | |
682 | RESERVE_SPACE(8); | |
683 | WRITE32(create->u.device.specdata1); | |
684 | WRITE32(create->u.device.specdata2); | |
685 | break; | |
686 | ||
687 | default: | |
688 | break; | |
689 | } | |
690 | ||
691 | RESERVE_SPACE(4 + create->name->len); | |
692 | WRITE32(create->name->len); | |
693 | WRITEMEM(create->name->name, create->name->len); | |
694 | ||
695 | return encode_attrs(xdr, create->attrs, create->server); | |
696 | } | |
697 | ||
698 | static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap) | |
699 | { | |
700 | uint32_t *p; | |
701 | ||
702 | RESERVE_SPACE(12); | |
703 | WRITE32(OP_GETATTR); | |
704 | WRITE32(1); | |
705 | WRITE32(bitmap); | |
706 | return 0; | |
707 | } | |
708 | ||
709 | static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1) | |
710 | { | |
711 | uint32_t *p; | |
712 | ||
713 | RESERVE_SPACE(16); | |
714 | WRITE32(OP_GETATTR); | |
715 | WRITE32(2); | |
716 | WRITE32(bm0); | |
717 | WRITE32(bm1); | |
718 | return 0; | |
719 | } | |
720 | ||
721 | static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask) | |
722 | { | |
1da177e4 LT |
723 | return encode_getattr_two(xdr, |
724 | bitmask[0] & nfs4_fattr_bitmap[0], | |
725 | bitmask[1] & nfs4_fattr_bitmap[1]); | |
726 | } | |
727 | ||
728 | static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask) | |
729 | { | |
1da177e4 LT |
730 | return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0], |
731 | bitmask[1] & nfs4_fsinfo_bitmap[1]); | |
732 | } | |
733 | ||
734 | static int encode_getfh(struct xdr_stream *xdr) | |
735 | { | |
736 | uint32_t *p; | |
737 | ||
738 | RESERVE_SPACE(4); | |
739 | WRITE32(OP_GETFH); | |
740 | ||
741 | return 0; | |
742 | } | |
743 | ||
744 | static int encode_link(struct xdr_stream *xdr, const struct qstr *name) | |
745 | { | |
746 | uint32_t *p; | |
747 | ||
748 | RESERVE_SPACE(8 + name->len); | |
749 | WRITE32(OP_LINK); | |
750 | WRITE32(name->len); | |
751 | WRITEMEM(name->name, name->len); | |
752 | ||
753 | return 0; | |
754 | } | |
755 | ||
911d1aaf TM |
756 | static inline int nfs4_lock_type(struct file_lock *fl, int block) |
757 | { | |
758 | if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK) | |
759 | return block ? NFS4_READW_LT : NFS4_READ_LT; | |
760 | return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; | |
761 | } | |
762 | ||
763 | static inline uint64_t nfs4_lock_length(struct file_lock *fl) | |
764 | { | |
765 | if (fl->fl_end == OFFSET_MAX) | |
766 | return ~(uint64_t)0; | |
767 | return fl->fl_end - fl->fl_start + 1; | |
768 | } | |
769 | ||
1da177e4 LT |
770 | /* |
771 | * opcode,type,reclaim,offset,length,new_lock_owner = 32 | |
772 | * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 | |
773 | */ | |
911d1aaf | 774 | static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args) |
1da177e4 LT |
775 | { |
776 | uint32_t *p; | |
1da177e4 LT |
777 | |
778 | RESERVE_SPACE(32); | |
779 | WRITE32(OP_LOCK); | |
911d1aaf TM |
780 | WRITE32(nfs4_lock_type(args->fl, args->block)); |
781 | WRITE32(args->reclaim); | |
782 | WRITE64(args->fl->fl_start); | |
783 | WRITE64(nfs4_lock_length(args->fl)); | |
784 | WRITE32(args->new_lock_owner); | |
785 | if (args->new_lock_owner){ | |
1da177e4 | 786 | RESERVE_SPACE(40); |
911d1aaf TM |
787 | WRITE32(args->open_seqid->sequence->counter); |
788 | WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data)); | |
789 | WRITE32(args->lock_seqid->sequence->counter); | |
790 | WRITE64(args->lock_owner.clientid); | |
1da177e4 | 791 | WRITE32(4); |
911d1aaf | 792 | WRITE32(args->lock_owner.id); |
1da177e4 LT |
793 | } |
794 | else { | |
1da177e4 | 795 | RESERVE_SPACE(20); |
911d1aaf TM |
796 | WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data)); |
797 | WRITE32(args->lock_seqid->sequence->counter); | |
1da177e4 LT |
798 | } |
799 | ||
800 | return 0; | |
801 | } | |
802 | ||
911d1aaf | 803 | static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args) |
1da177e4 LT |
804 | { |
805 | uint32_t *p; | |
1da177e4 LT |
806 | |
807 | RESERVE_SPACE(40); | |
808 | WRITE32(OP_LOCKT); | |
911d1aaf TM |
809 | WRITE32(nfs4_lock_type(args->fl, 0)); |
810 | WRITE64(args->fl->fl_start); | |
811 | WRITE64(nfs4_lock_length(args->fl)); | |
812 | WRITE64(args->lock_owner.clientid); | |
1da177e4 | 813 | WRITE32(4); |
911d1aaf | 814 | WRITE32(args->lock_owner.id); |
1da177e4 LT |
815 | |
816 | return 0; | |
817 | } | |
818 | ||
911d1aaf | 819 | static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args) |
1da177e4 LT |
820 | { |
821 | uint32_t *p; | |
1da177e4 LT |
822 | |
823 | RESERVE_SPACE(44); | |
824 | WRITE32(OP_LOCKU); | |
911d1aaf TM |
825 | WRITE32(nfs4_lock_type(args->fl, 0)); |
826 | WRITE32(args->seqid->sequence->counter); | |
827 | WRITEMEM(args->stateid->data, sizeof(args->stateid->data)); | |
828 | WRITE64(args->fl->fl_start); | |
829 | WRITE64(nfs4_lock_length(args->fl)); | |
1da177e4 LT |
830 | |
831 | return 0; | |
832 | } | |
833 | ||
834 | static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name) | |
835 | { | |
836 | int len = name->len; | |
837 | uint32_t *p; | |
838 | ||
839 | RESERVE_SPACE(8 + len); | |
840 | WRITE32(OP_LOOKUP); | |
841 | WRITE32(len); | |
842 | WRITEMEM(name->name, len); | |
843 | ||
844 | return 0; | |
845 | } | |
846 | ||
847 | static void encode_share_access(struct xdr_stream *xdr, int open_flags) | |
848 | { | |
849 | uint32_t *p; | |
850 | ||
851 | RESERVE_SPACE(8); | |
852 | switch (open_flags & (FMODE_READ|FMODE_WRITE)) { | |
853 | case FMODE_READ: | |
854 | WRITE32(NFS4_SHARE_ACCESS_READ); | |
855 | break; | |
856 | case FMODE_WRITE: | |
857 | WRITE32(NFS4_SHARE_ACCESS_WRITE); | |
858 | break; | |
859 | case FMODE_READ|FMODE_WRITE: | |
860 | WRITE32(NFS4_SHARE_ACCESS_BOTH); | |
861 | break; | |
862 | default: | |
863 | BUG(); | |
864 | } | |
865 | WRITE32(0); /* for linux, share_deny = 0 always */ | |
866 | } | |
867 | ||
868 | static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) | |
869 | { | |
870 | uint32_t *p; | |
871 | /* | |
872 | * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, | |
873 | * owner 4 = 32 | |
874 | */ | |
875 | RESERVE_SPACE(8); | |
876 | WRITE32(OP_OPEN); | |
cee54fc9 | 877 | WRITE32(arg->seqid->sequence->counter); |
1da177e4 LT |
878 | encode_share_access(xdr, arg->open_flags); |
879 | RESERVE_SPACE(16); | |
880 | WRITE64(arg->clientid); | |
881 | WRITE32(4); | |
882 | WRITE32(arg->id); | |
883 | } | |
884 | ||
885 | static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) | |
886 | { | |
887 | uint32_t *p; | |
888 | ||
889 | RESERVE_SPACE(4); | |
890 | switch(arg->open_flags & O_EXCL) { | |
891 | case 0: | |
892 | WRITE32(NFS4_CREATE_UNCHECKED); | |
893 | encode_attrs(xdr, arg->u.attrs, arg->server); | |
894 | break; | |
895 | default: | |
896 | WRITE32(NFS4_CREATE_EXCLUSIVE); | |
897 | encode_nfs4_verifier(xdr, &arg->u.verifier); | |
898 | } | |
899 | } | |
900 | ||
901 | static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) | |
902 | { | |
903 | uint32_t *p; | |
904 | ||
905 | RESERVE_SPACE(4); | |
906 | switch (arg->open_flags & O_CREAT) { | |
907 | case 0: | |
908 | WRITE32(NFS4_OPEN_NOCREATE); | |
909 | break; | |
910 | default: | |
911 | BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); | |
912 | WRITE32(NFS4_OPEN_CREATE); | |
913 | encode_createmode(xdr, arg); | |
914 | } | |
915 | } | |
916 | ||
917 | static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type) | |
918 | { | |
919 | uint32_t *p; | |
920 | ||
921 | RESERVE_SPACE(4); | |
922 | switch (delegation_type) { | |
923 | case 0: | |
924 | WRITE32(NFS4_OPEN_DELEGATE_NONE); | |
925 | break; | |
926 | case FMODE_READ: | |
927 | WRITE32(NFS4_OPEN_DELEGATE_READ); | |
928 | break; | |
929 | case FMODE_WRITE|FMODE_READ: | |
930 | WRITE32(NFS4_OPEN_DELEGATE_WRITE); | |
931 | break; | |
932 | default: | |
933 | BUG(); | |
934 | } | |
935 | } | |
936 | ||
937 | static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) | |
938 | { | |
939 | uint32_t *p; | |
940 | ||
941 | RESERVE_SPACE(4); | |
942 | WRITE32(NFS4_OPEN_CLAIM_NULL); | |
943 | encode_string(xdr, name->len, name->name); | |
944 | } | |
945 | ||
946 | static inline void encode_claim_previous(struct xdr_stream *xdr, int type) | |
947 | { | |
948 | uint32_t *p; | |
949 | ||
950 | RESERVE_SPACE(4); | |
951 | WRITE32(NFS4_OPEN_CLAIM_PREVIOUS); | |
952 | encode_delegation_type(xdr, type); | |
953 | } | |
954 | ||
955 | static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) | |
956 | { | |
957 | uint32_t *p; | |
958 | ||
959 | RESERVE_SPACE(4+sizeof(stateid->data)); | |
960 | WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR); | |
961 | WRITEMEM(stateid->data, sizeof(stateid->data)); | |
962 | encode_string(xdr, name->len, name->name); | |
963 | } | |
964 | ||
965 | static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg) | |
966 | { | |
967 | encode_openhdr(xdr, arg); | |
968 | encode_opentype(xdr, arg); | |
969 | switch (arg->claim) { | |
970 | case NFS4_OPEN_CLAIM_NULL: | |
971 | encode_claim_null(xdr, arg->name); | |
972 | break; | |
973 | case NFS4_OPEN_CLAIM_PREVIOUS: | |
974 | encode_claim_previous(xdr, arg->u.delegation_type); | |
975 | break; | |
976 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: | |
977 | encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); | |
978 | break; | |
979 | default: | |
980 | BUG(); | |
981 | } | |
982 | return 0; | |
983 | } | |
984 | ||
985 | static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg) | |
986 | { | |
987 | uint32_t *p; | |
988 | ||
cdd4e68b | 989 | RESERVE_SPACE(8+sizeof(arg->stateid->data)); |
1da177e4 | 990 | WRITE32(OP_OPEN_CONFIRM); |
cdd4e68b | 991 | WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); |
cee54fc9 | 992 | WRITE32(arg->seqid->sequence->counter); |
1da177e4 LT |
993 | |
994 | return 0; | |
995 | } | |
996 | ||
997 | static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg) | |
998 | { | |
999 | uint32_t *p; | |
1000 | ||
9512135d | 1001 | RESERVE_SPACE(8+sizeof(arg->stateid->data)); |
1da177e4 | 1002 | WRITE32(OP_OPEN_DOWNGRADE); |
9512135d | 1003 | WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); |
cee54fc9 | 1004 | WRITE32(arg->seqid->sequence->counter); |
1da177e4 LT |
1005 | encode_share_access(xdr, arg->open_flags); |
1006 | return 0; | |
1007 | } | |
1008 | ||
1009 | static int | |
1010 | encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh) | |
1011 | { | |
1012 | int len = fh->size; | |
1013 | uint32_t *p; | |
1014 | ||
1015 | RESERVE_SPACE(8 + len); | |
1016 | WRITE32(OP_PUTFH); | |
1017 | WRITE32(len); | |
1018 | WRITEMEM(fh->data, len); | |
1019 | ||
1020 | return 0; | |
1021 | } | |
1022 | ||
1023 | static int encode_putrootfh(struct xdr_stream *xdr) | |
1024 | { | |
1025 | uint32_t *p; | |
1026 | ||
1027 | RESERVE_SPACE(4); | |
1028 | WRITE32(OP_PUTROOTFH); | |
1029 | ||
1030 | return 0; | |
1031 | } | |
1032 | ||
1033 | static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx) | |
1034 | { | |
1da177e4 LT |
1035 | nfs4_stateid stateid; |
1036 | uint32_t *p; | |
1037 | ||
1038 | RESERVE_SPACE(16); | |
1039 | if (ctx->state != NULL) { | |
1040 | nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner); | |
1041 | WRITEMEM(stateid.data, sizeof(stateid.data)); | |
1042 | } else | |
1043 | WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data)); | |
1044 | } | |
1045 | ||
1046 | static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args) | |
1047 | { | |
1048 | uint32_t *p; | |
1049 | ||
1050 | RESERVE_SPACE(4); | |
1051 | WRITE32(OP_READ); | |
1052 | ||
1053 | encode_stateid(xdr, args->context); | |
1054 | ||
1055 | RESERVE_SPACE(12); | |
1056 | WRITE64(args->offset); | |
1057 | WRITE32(args->count); | |
1058 | ||
1059 | return 0; | |
1060 | } | |
1061 | ||
1062 | static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req) | |
1063 | { | |
1064 | struct rpc_auth *auth = req->rq_task->tk_auth; | |
97d312d0 MN |
1065 | uint32_t attrs[2] = { |
1066 | FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID, | |
1067 | FATTR4_WORD1_MOUNTED_ON_FILEID, | |
1068 | }; | |
1da177e4 LT |
1069 | int replen; |
1070 | uint32_t *p; | |
1071 | ||
1072 | RESERVE_SPACE(32+sizeof(nfs4_verifier)); | |
1073 | WRITE32(OP_READDIR); | |
1074 | WRITE64(readdir->cookie); | |
1075 | WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data)); | |
1076 | WRITE32(readdir->count >> 1); /* We're not doing readdirplus */ | |
1077 | WRITE32(readdir->count); | |
1078 | WRITE32(2); | |
97d312d0 MN |
1079 | /* Switch to mounted_on_fileid if the server supports it */ |
1080 | if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) | |
1081 | attrs[0] &= ~FATTR4_WORD0_FILEID; | |
1082 | else | |
1083 | attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; | |
1084 | WRITE32(attrs[0] & readdir->bitmask[0]); | |
1085 | WRITE32(attrs[1] & readdir->bitmask[1]); | |
eadf4598 TM |
1086 | dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n", |
1087 | __FUNCTION__, | |
1088 | (unsigned long long)readdir->cookie, | |
1089 | ((u32 *)readdir->verifier.data)[0], | |
1090 | ((u32 *)readdir->verifier.data)[1], | |
1091 | attrs[0] & readdir->bitmask[0], | |
1092 | attrs[1] & readdir->bitmask[1]); | |
1da177e4 LT |
1093 | |
1094 | /* set up reply kvec | |
1095 | * toplevel_status + taglen + rescount + OP_PUTFH + status | |
1096 | * + OP_READDIR + status + verifer(2) = 9 | |
1097 | */ | |
1098 | replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2; | |
1099 | xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages, | |
1100 | readdir->pgbase, readdir->count); | |
eadf4598 TM |
1101 | dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", |
1102 | __FUNCTION__, replen, readdir->pages, | |
1103 | readdir->pgbase, readdir->count); | |
1da177e4 LT |
1104 | |
1105 | return 0; | |
1106 | } | |
1107 | ||
1108 | static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req) | |
1109 | { | |
1110 | struct rpc_auth *auth = req->rq_task->tk_auth; | |
1111 | unsigned int replen; | |
1112 | uint32_t *p; | |
1113 | ||
1114 | RESERVE_SPACE(4); | |
1115 | WRITE32(OP_READLINK); | |
1116 | ||
1117 | /* set up reply kvec | |
1118 | * toplevel_status + taglen + rescount + OP_PUTFH + status | |
1119 | * + OP_READLINK + status + string length = 8 | |
1120 | */ | |
1121 | replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2; | |
1122 | xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages, | |
1123 | readlink->pgbase, readlink->pglen); | |
1124 | ||
1125 | return 0; | |
1126 | } | |
1127 | ||
1128 | static int encode_remove(struct xdr_stream *xdr, const struct qstr *name) | |
1129 | { | |
1130 | uint32_t *p; | |
1131 | ||
1132 | RESERVE_SPACE(8 + name->len); | |
1133 | WRITE32(OP_REMOVE); | |
1134 | WRITE32(name->len); | |
1135 | WRITEMEM(name->name, name->len); | |
1136 | ||
1137 | return 0; | |
1138 | } | |
1139 | ||
1140 | static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname) | |
1141 | { | |
1142 | uint32_t *p; | |
1143 | ||
1144 | RESERVE_SPACE(8 + oldname->len); | |
1145 | WRITE32(OP_RENAME); | |
1146 | WRITE32(oldname->len); | |
1147 | WRITEMEM(oldname->name, oldname->len); | |
1148 | ||
1149 | RESERVE_SPACE(4 + newname->len); | |
1150 | WRITE32(newname->len); | |
1151 | WRITEMEM(newname->name, newname->len); | |
1152 | ||
1153 | return 0; | |
1154 | } | |
1155 | ||
1156 | static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid) | |
1157 | { | |
1158 | uint32_t *p; | |
1159 | ||
1160 | RESERVE_SPACE(12); | |
1161 | WRITE32(OP_RENEW); | |
1162 | WRITE64(client_stateid->cl_clientid); | |
1163 | ||
1164 | return 0; | |
1165 | } | |
1166 | ||
56ae19f3 TM |
1167 | static int |
1168 | encode_restorefh(struct xdr_stream *xdr) | |
1169 | { | |
1170 | uint32_t *p; | |
1171 | ||
1172 | RESERVE_SPACE(4); | |
1173 | WRITE32(OP_RESTOREFH); | |
1174 | ||
1175 | return 0; | |
1176 | } | |
1177 | ||
23ec6965 BF |
1178 | static int |
1179 | encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg) | |
1180 | { | |
1181 | uint32_t *p; | |
1182 | ||
1183 | RESERVE_SPACE(4+sizeof(zero_stateid.data)); | |
1184 | WRITE32(OP_SETATTR); | |
1185 | WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data)); | |
1186 | RESERVE_SPACE(2*4); | |
1187 | WRITE32(1); | |
1188 | WRITE32(FATTR4_WORD0_ACL); | |
1189 | if (arg->acl_len % 4) | |
1190 | return -EINVAL; | |
1191 | RESERVE_SPACE(4); | |
1192 | WRITE32(arg->acl_len); | |
1193 | xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); | |
1194 | return 0; | |
1195 | } | |
1196 | ||
1da177e4 LT |
1197 | static int |
1198 | encode_savefh(struct xdr_stream *xdr) | |
1199 | { | |
1200 | uint32_t *p; | |
1201 | ||
1202 | RESERVE_SPACE(4); | |
1203 | WRITE32(OP_SAVEFH); | |
1204 | ||
1205 | return 0; | |
1206 | } | |
1207 | ||
1208 | static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server) | |
1209 | { | |
1210 | int status; | |
1211 | uint32_t *p; | |
1212 | ||
1213 | RESERVE_SPACE(4+sizeof(arg->stateid.data)); | |
1214 | WRITE32(OP_SETATTR); | |
1215 | WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data)); | |
1216 | ||
1217 | if ((status = encode_attrs(xdr, arg->iap, server))) | |
1218 | return status; | |
1219 | ||
1220 | return 0; | |
1221 | } | |
1222 | ||
1223 | static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid) | |
1224 | { | |
1225 | uint32_t *p; | |
1226 | ||
1227 | RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data)); | |
1228 | WRITE32(OP_SETCLIENTID); | |
1229 | WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data)); | |
1230 | ||
1231 | encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); | |
1232 | RESERVE_SPACE(4); | |
1233 | WRITE32(setclientid->sc_prog); | |
1234 | encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); | |
1235 | encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); | |
1236 | RESERVE_SPACE(4); | |
1237 | WRITE32(setclientid->sc_cb_ident); | |
1238 | ||
1239 | return 0; | |
1240 | } | |
1241 | ||
1242 | static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state) | |
1243 | { | |
1244 | uint32_t *p; | |
1245 | ||
1246 | RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data)); | |
1247 | WRITE32(OP_SETCLIENTID_CONFIRM); | |
1248 | WRITE64(client_state->cl_clientid); | |
1249 | WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data)); | |
1250 | ||
1251 | return 0; | |
1252 | } | |
1253 | ||
1254 | static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args) | |
1255 | { | |
1256 | uint32_t *p; | |
1257 | ||
1258 | RESERVE_SPACE(4); | |
1259 | WRITE32(OP_WRITE); | |
1260 | ||
1261 | encode_stateid(xdr, args->context); | |
1262 | ||
1263 | RESERVE_SPACE(16); | |
1264 | WRITE64(args->offset); | |
1265 | WRITE32(args->stable); | |
1266 | WRITE32(args->count); | |
1267 | ||
1268 | xdr_write_pages(xdr, args->pages, args->pgbase, args->count); | |
1269 | ||
1270 | return 0; | |
1271 | } | |
1272 | ||
1273 | static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid) | |
1274 | { | |
1275 | uint32_t *p; | |
1276 | ||
1277 | RESERVE_SPACE(20); | |
1278 | ||
1279 | WRITE32(OP_DELEGRETURN); | |
1280 | WRITEMEM(stateid->data, sizeof(stateid->data)); | |
1281 | return 0; | |
1282 | ||
1283 | } | |
1284 | /* | |
1285 | * END OF "GENERIC" ENCODE ROUTINES. | |
1286 | */ | |
1287 | ||
1288 | /* | |
1289 | * Encode an ACCESS request | |
1290 | */ | |
1291 | static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args) | |
1292 | { | |
1293 | struct xdr_stream xdr; | |
1294 | struct compound_hdr hdr = { | |
1295 | .nops = 2, | |
1296 | }; | |
1297 | int status; | |
1298 | ||
1299 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1300 | encode_compound_hdr(&xdr, &hdr); | |
1301 | if ((status = encode_putfh(&xdr, args->fh)) == 0) | |
1302 | status = encode_access(&xdr, args->access); | |
1303 | return status; | |
1304 | } | |
1305 | ||
1306 | /* | |
1307 | * Encode LOOKUP request | |
1308 | */ | |
1309 | static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args) | |
1310 | { | |
1311 | struct xdr_stream xdr; | |
1312 | struct compound_hdr hdr = { | |
1313 | .nops = 4, | |
1314 | }; | |
1315 | int status; | |
1316 | ||
1317 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1318 | encode_compound_hdr(&xdr, &hdr); | |
1319 | if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) | |
1320 | goto out; | |
1321 | if ((status = encode_lookup(&xdr, args->name)) != 0) | |
1322 | goto out; | |
1323 | if ((status = encode_getfh(&xdr)) != 0) | |
1324 | goto out; | |
1325 | status = encode_getfattr(&xdr, args->bitmask); | |
1326 | out: | |
1327 | return status; | |
1328 | } | |
1329 | ||
1330 | /* | |
1331 | * Encode LOOKUP_ROOT request | |
1332 | */ | |
1333 | static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args) | |
1334 | { | |
1335 | struct xdr_stream xdr; | |
1336 | struct compound_hdr hdr = { | |
1337 | .nops = 3, | |
1338 | }; | |
1339 | int status; | |
1340 | ||
1341 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1342 | encode_compound_hdr(&xdr, &hdr); | |
1343 | if ((status = encode_putrootfh(&xdr)) != 0) | |
1344 | goto out; | |
1345 | if ((status = encode_getfh(&xdr)) == 0) | |
1346 | status = encode_getfattr(&xdr, args->bitmask); | |
1347 | out: | |
1348 | return status; | |
1349 | } | |
1350 | ||
1351 | /* | |
1352 | * Encode REMOVE request | |
1353 | */ | |
1354 | static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args) | |
1355 | { | |
1356 | struct xdr_stream xdr; | |
1357 | struct compound_hdr hdr = { | |
16e42959 | 1358 | .nops = 3, |
1da177e4 LT |
1359 | }; |
1360 | int status; | |
1361 | ||
1362 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1363 | encode_compound_hdr(&xdr, &hdr); | |
16e42959 TM |
1364 | if ((status = encode_putfh(&xdr, args->fh)) != 0) |
1365 | goto out; | |
1366 | if ((status = encode_remove(&xdr, args->name)) != 0) | |
1367 | goto out; | |
1368 | status = encode_getfattr(&xdr, args->bitmask); | |
1369 | out: | |
1da177e4 LT |
1370 | return status; |
1371 | } | |
1372 | ||
1373 | /* | |
1374 | * Encode RENAME request | |
1375 | */ | |
1376 | static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args) | |
1377 | { | |
1378 | struct xdr_stream xdr; | |
1379 | struct compound_hdr hdr = { | |
6caf2c82 | 1380 | .nops = 7, |
1da177e4 LT |
1381 | }; |
1382 | int status; | |
1383 | ||
1384 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1385 | encode_compound_hdr(&xdr, &hdr); | |
1386 | if ((status = encode_putfh(&xdr, args->old_dir)) != 0) | |
1387 | goto out; | |
1388 | if ((status = encode_savefh(&xdr)) != 0) | |
1389 | goto out; | |
1390 | if ((status = encode_putfh(&xdr, args->new_dir)) != 0) | |
1391 | goto out; | |
6caf2c82 TM |
1392 | if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0) |
1393 | goto out; | |
1394 | if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) | |
1395 | goto out; | |
1396 | if ((status = encode_restorefh(&xdr)) != 0) | |
1397 | goto out; | |
1398 | status = encode_getfattr(&xdr, args->bitmask); | |
1da177e4 LT |
1399 | out: |
1400 | return status; | |
1401 | } | |
1402 | ||
1403 | /* | |
1404 | * Encode LINK request | |
1405 | */ | |
1406 | static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args) | |
1407 | { | |
1408 | struct xdr_stream xdr; | |
1409 | struct compound_hdr hdr = { | |
91ba2eee | 1410 | .nops = 7, |
1da177e4 LT |
1411 | }; |
1412 | int status; | |
1413 | ||
1414 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1415 | encode_compound_hdr(&xdr, &hdr); | |
1416 | if ((status = encode_putfh(&xdr, args->fh)) != 0) | |
1417 | goto out; | |
1418 | if ((status = encode_savefh(&xdr)) != 0) | |
1419 | goto out; | |
1420 | if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) | |
1421 | goto out; | |
91ba2eee TM |
1422 | if ((status = encode_link(&xdr, args->name)) != 0) |
1423 | goto out; | |
1424 | if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) | |
1425 | goto out; | |
1426 | if ((status = encode_restorefh(&xdr)) != 0) | |
1427 | goto out; | |
1428 | status = encode_getfattr(&xdr, args->bitmask); | |
1da177e4 LT |
1429 | out: |
1430 | return status; | |
1431 | } | |
1432 | ||
1433 | /* | |
1434 | * Encode CREATE request | |
1435 | */ | |
1436 | static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args) | |
1437 | { | |
1438 | struct xdr_stream xdr; | |
1439 | struct compound_hdr hdr = { | |
56ae19f3 | 1440 | .nops = 7, |
1da177e4 LT |
1441 | }; |
1442 | int status; | |
1443 | ||
1444 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1445 | encode_compound_hdr(&xdr, &hdr); | |
1446 | if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) | |
1447 | goto out; | |
56ae19f3 TM |
1448 | if ((status = encode_savefh(&xdr)) != 0) |
1449 | goto out; | |
1da177e4 LT |
1450 | if ((status = encode_create(&xdr, args)) != 0) |
1451 | goto out; | |
1452 | if ((status = encode_getfh(&xdr)) != 0) | |
1453 | goto out; | |
56ae19f3 TM |
1454 | if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) |
1455 | goto out; | |
1456 | if ((status = encode_restorefh(&xdr)) != 0) | |
1457 | goto out; | |
1da177e4 LT |
1458 | status = encode_getfattr(&xdr, args->bitmask); |
1459 | out: | |
1460 | return status; | |
1461 | } | |
1462 | ||
1463 | /* | |
1464 | * Encode SYMLINK request | |
1465 | */ | |
1466 | static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args) | |
1467 | { | |
1468 | return nfs4_xdr_enc_create(req, p, args); | |
1469 | } | |
1470 | ||
1471 | /* | |
1472 | * Encode GETATTR request | |
1473 | */ | |
1474 | static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args) | |
1475 | { | |
1476 | struct xdr_stream xdr; | |
1477 | struct compound_hdr hdr = { | |
1478 | .nops = 2, | |
1479 | }; | |
1480 | int status; | |
1481 | ||
1482 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1483 | encode_compound_hdr(&xdr, &hdr); | |
1484 | if ((status = encode_putfh(&xdr, args->fh)) == 0) | |
1485 | status = encode_getfattr(&xdr, args->bitmask); | |
1486 | return status; | |
1487 | } | |
1488 | ||
1489 | /* | |
1490 | * Encode a CLOSE request | |
1491 | */ | |
1492 | static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args) | |
1493 | { | |
1494 | struct xdr_stream xdr; | |
1495 | struct compound_hdr hdr = { | |
516a6af6 | 1496 | .nops = 3, |
1da177e4 LT |
1497 | }; |
1498 | int status; | |
1499 | ||
1500 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1501 | encode_compound_hdr(&xdr, &hdr); | |
1502 | status = encode_putfh(&xdr, args->fh); | |
1503 | if(status) | |
1504 | goto out; | |
1505 | status = encode_close(&xdr, args); | |
516a6af6 TM |
1506 | if (status != 0) |
1507 | goto out; | |
1508 | status = encode_getfattr(&xdr, args->bitmask); | |
1da177e4 LT |
1509 | out: |
1510 | return status; | |
1511 | } | |
1512 | ||
1513 | /* | |
1514 | * Encode an OPEN request | |
1515 | */ | |
1516 | static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args) | |
1517 | { | |
1518 | struct xdr_stream xdr; | |
1519 | struct compound_hdr hdr = { | |
56ae19f3 | 1520 | .nops = 7, |
1da177e4 LT |
1521 | }; |
1522 | int status; | |
1523 | ||
1524 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1525 | encode_compound_hdr(&xdr, &hdr); | |
1526 | status = encode_putfh(&xdr, args->fh); | |
56ae19f3 TM |
1527 | if (status) |
1528 | goto out; | |
1529 | status = encode_savefh(&xdr); | |
1da177e4 LT |
1530 | if (status) |
1531 | goto out; | |
1532 | status = encode_open(&xdr, args); | |
1533 | if (status) | |
1534 | goto out; | |
1535 | status = encode_getfh(&xdr); | |
1536 | if (status) | |
1537 | goto out; | |
1538 | status = encode_getfattr(&xdr, args->bitmask); | |
56ae19f3 TM |
1539 | if (status) |
1540 | goto out; | |
1541 | status = encode_restorefh(&xdr); | |
1542 | if (status) | |
1543 | goto out; | |
1544 | status = encode_getfattr(&xdr, args->bitmask); | |
1da177e4 LT |
1545 | out: |
1546 | return status; | |
1547 | } | |
1548 | ||
1549 | /* | |
1550 | * Encode an OPEN_CONFIRM request | |
1551 | */ | |
1552 | static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args) | |
1553 | { | |
1554 | struct xdr_stream xdr; | |
1555 | struct compound_hdr hdr = { | |
1556 | .nops = 2, | |
1557 | }; | |
1558 | int status; | |
1559 | ||
1560 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1561 | encode_compound_hdr(&xdr, &hdr); | |
1562 | status = encode_putfh(&xdr, args->fh); | |
1563 | if(status) | |
1564 | goto out; | |
1565 | status = encode_open_confirm(&xdr, args); | |
1566 | out: | |
1567 | return status; | |
1568 | } | |
1569 | ||
1570 | /* | |
1571 | * Encode an OPEN request with no attributes. | |
1572 | */ | |
1573 | static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args) | |
1574 | { | |
1575 | struct xdr_stream xdr; | |
1576 | struct compound_hdr hdr = { | |
864472e9 | 1577 | .nops = 3, |
1da177e4 LT |
1578 | }; |
1579 | int status; | |
1580 | ||
1581 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1582 | encode_compound_hdr(&xdr, &hdr); | |
1583 | status = encode_putfh(&xdr, args->fh); | |
1584 | if (status) | |
1585 | goto out; | |
1586 | status = encode_open(&xdr, args); | |
864472e9 TM |
1587 | if (status) |
1588 | goto out; | |
1589 | status = encode_getfattr(&xdr, args->bitmask); | |
1da177e4 LT |
1590 | out: |
1591 | return status; | |
1592 | } | |
1593 | ||
1594 | /* | |
1595 | * Encode an OPEN_DOWNGRADE request | |
1596 | */ | |
1597 | static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args) | |
1598 | { | |
1599 | struct xdr_stream xdr; | |
1600 | struct compound_hdr hdr = { | |
516a6af6 | 1601 | .nops = 3, |
1da177e4 LT |
1602 | }; |
1603 | int status; | |
1604 | ||
1605 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1606 | encode_compound_hdr(&xdr, &hdr); | |
1607 | status = encode_putfh(&xdr, args->fh); | |
1608 | if (status) | |
1609 | goto out; | |
1610 | status = encode_open_downgrade(&xdr, args); | |
516a6af6 TM |
1611 | if (status != 0) |
1612 | goto out; | |
1613 | status = encode_getfattr(&xdr, args->bitmask); | |
1da177e4 LT |
1614 | out: |
1615 | return status; | |
1616 | } | |
1617 | ||
1618 | /* | |
1619 | * Encode a LOCK request | |
1620 | */ | |
911d1aaf | 1621 | static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lock_args *args) |
1da177e4 LT |
1622 | { |
1623 | struct xdr_stream xdr; | |
1624 | struct compound_hdr hdr = { | |
1625 | .nops = 2, | |
1626 | }; | |
1627 | int status; | |
1628 | ||
1629 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1630 | encode_compound_hdr(&xdr, &hdr); | |
1631 | status = encode_putfh(&xdr, args->fh); | |
1632 | if(status) | |
1633 | goto out; | |
1634 | status = encode_lock(&xdr, args); | |
1635 | out: | |
1636 | return status; | |
1637 | } | |
1638 | ||
1639 | /* | |
1640 | * Encode a LOCKT request | |
1641 | */ | |
911d1aaf | 1642 | static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockt_args *args) |
1da177e4 LT |
1643 | { |
1644 | struct xdr_stream xdr; | |
1645 | struct compound_hdr hdr = { | |
1646 | .nops = 2, | |
1647 | }; | |
1648 | int status; | |
1649 | ||
1650 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1651 | encode_compound_hdr(&xdr, &hdr); | |
1652 | status = encode_putfh(&xdr, args->fh); | |
1653 | if(status) | |
1654 | goto out; | |
1655 | status = encode_lockt(&xdr, args); | |
1656 | out: | |
1657 | return status; | |
1658 | } | |
1659 | ||
1660 | /* | |
1661 | * Encode a LOCKU request | |
1662 | */ | |
911d1aaf | 1663 | static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_locku_args *args) |
1da177e4 LT |
1664 | { |
1665 | struct xdr_stream xdr; | |
1666 | struct compound_hdr hdr = { | |
1667 | .nops = 2, | |
1668 | }; | |
1669 | int status; | |
1670 | ||
1671 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1672 | encode_compound_hdr(&xdr, &hdr); | |
1673 | status = encode_putfh(&xdr, args->fh); | |
1674 | if(status) | |
1675 | goto out; | |
1676 | status = encode_locku(&xdr, args); | |
1677 | out: | |
1678 | return status; | |
1679 | } | |
1680 | ||
1681 | /* | |
1682 | * Encode a READLINK request | |
1683 | */ | |
1684 | static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args) | |
1685 | { | |
1686 | struct xdr_stream xdr; | |
1687 | struct compound_hdr hdr = { | |
1688 | .nops = 2, | |
1689 | }; | |
1690 | int status; | |
1691 | ||
1692 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1693 | encode_compound_hdr(&xdr, &hdr); | |
1694 | status = encode_putfh(&xdr, args->fh); | |
1695 | if(status) | |
1696 | goto out; | |
1697 | status = encode_readlink(&xdr, args, req); | |
1698 | out: | |
1699 | return status; | |
1700 | } | |
1701 | ||
1702 | /* | |
1703 | * Encode a READDIR request | |
1704 | */ | |
1705 | static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args) | |
1706 | { | |
1707 | struct xdr_stream xdr; | |
1708 | struct compound_hdr hdr = { | |
1709 | .nops = 2, | |
1710 | }; | |
1711 | int status; | |
1712 | ||
1713 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1714 | encode_compound_hdr(&xdr, &hdr); | |
1715 | status = encode_putfh(&xdr, args->fh); | |
1716 | if(status) | |
1717 | goto out; | |
1718 | status = encode_readdir(&xdr, args, req); | |
1719 | out: | |
1720 | return status; | |
1721 | } | |
1722 | ||
1723 | /* | |
1724 | * Encode a READ request | |
1725 | */ | |
1726 | static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args) | |
1727 | { | |
1728 | struct rpc_auth *auth = req->rq_task->tk_auth; | |
1729 | struct xdr_stream xdr; | |
1730 | struct compound_hdr hdr = { | |
1731 | .nops = 2, | |
1732 | }; | |
1733 | int replen, status; | |
1734 | ||
1735 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1736 | encode_compound_hdr(&xdr, &hdr); | |
1737 | status = encode_putfh(&xdr, args->fh); | |
1738 | if (status) | |
1739 | goto out; | |
1740 | status = encode_read(&xdr, args); | |
1741 | if (status) | |
1742 | goto out; | |
1743 | ||
1744 | /* set up reply kvec | |
1745 | * toplevel status + taglen=0 + rescount + OP_PUTFH + status | |
1746 | * + OP_READ + status + eof + datalen = 9 | |
1747 | */ | |
1748 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2; | |
1749 | xdr_inline_pages(&req->rq_rcv_buf, replen, | |
1750 | args->pages, args->pgbase, args->count); | |
1751 | out: | |
1752 | return status; | |
1753 | } | |
1754 | ||
1755 | /* | |
1756 | * Encode an SETATTR request | |
1757 | */ | |
1758 | static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args) | |
1759 | ||
1760 | { | |
1761 | struct xdr_stream xdr; | |
1762 | struct compound_hdr hdr = { | |
1763 | .nops = 3, | |
1764 | }; | |
1765 | int status; | |
1766 | ||
1767 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1768 | encode_compound_hdr(&xdr, &hdr); | |
1769 | status = encode_putfh(&xdr, args->fh); | |
1770 | if(status) | |
1771 | goto out; | |
1772 | status = encode_setattr(&xdr, args, args->server); | |
1773 | if(status) | |
1774 | goto out; | |
1775 | status = encode_getfattr(&xdr, args->bitmask); | |
1776 | out: | |
1777 | return status; | |
1778 | } | |
1779 | ||
029d105e BF |
1780 | /* |
1781 | * Encode a GETACL request | |
1782 | */ | |
1783 | static int | |
1784 | nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p, | |
1785 | struct nfs_getaclargs *args) | |
1786 | { | |
1787 | struct xdr_stream xdr; | |
1788 | struct rpc_auth *auth = req->rq_task->tk_auth; | |
1789 | struct compound_hdr hdr = { | |
1790 | .nops = 2, | |
1791 | }; | |
1792 | int replen, status; | |
1793 | ||
1794 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1795 | encode_compound_hdr(&xdr, &hdr); | |
1796 | status = encode_putfh(&xdr, args->fh); | |
1797 | if (status) | |
1798 | goto out; | |
1799 | status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0); | |
1800 | /* set up reply buffer: */ | |
1801 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2; | |
1802 | xdr_inline_pages(&req->rq_rcv_buf, replen, | |
1803 | args->acl_pages, args->acl_pgbase, args->acl_len); | |
1804 | out: | |
1805 | return status; | |
1806 | } | |
1807 | ||
1da177e4 LT |
1808 | /* |
1809 | * Encode a WRITE request | |
1810 | */ | |
1811 | static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args) | |
1812 | { | |
1813 | struct xdr_stream xdr; | |
1814 | struct compound_hdr hdr = { | |
4f9838c7 | 1815 | .nops = 3, |
1da177e4 LT |
1816 | }; |
1817 | int status; | |
1818 | ||
1819 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1820 | encode_compound_hdr(&xdr, &hdr); | |
1821 | status = encode_putfh(&xdr, args->fh); | |
1822 | if (status) | |
1823 | goto out; | |
1824 | status = encode_write(&xdr, args); | |
4f9838c7 TM |
1825 | if (status) |
1826 | goto out; | |
1827 | status = encode_getfattr(&xdr, args->bitmask); | |
1da177e4 LT |
1828 | out: |
1829 | return status; | |
1830 | } | |
1831 | ||
1832 | /* | |
1833 | * a COMMIT request | |
1834 | */ | |
1835 | static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args) | |
1836 | { | |
1837 | struct xdr_stream xdr; | |
1838 | struct compound_hdr hdr = { | |
4f9838c7 | 1839 | .nops = 3, |
1da177e4 LT |
1840 | }; |
1841 | int status; | |
1842 | ||
1843 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1844 | encode_compound_hdr(&xdr, &hdr); | |
1845 | status = encode_putfh(&xdr, args->fh); | |
1846 | if (status) | |
1847 | goto out; | |
1848 | status = encode_commit(&xdr, args); | |
4f9838c7 TM |
1849 | if (status) |
1850 | goto out; | |
1851 | status = encode_getfattr(&xdr, args->bitmask); | |
1da177e4 LT |
1852 | out: |
1853 | return status; | |
1854 | } | |
1855 | ||
1856 | /* | |
1857 | * FSINFO request | |
1858 | */ | |
1859 | static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args) | |
1860 | { | |
1861 | struct xdr_stream xdr; | |
1862 | struct compound_hdr hdr = { | |
1863 | .nops = 2, | |
1864 | }; | |
1865 | int status; | |
1866 | ||
1867 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1868 | encode_compound_hdr(&xdr, &hdr); | |
1869 | status = encode_putfh(&xdr, args->fh); | |
1870 | if (!status) | |
1871 | status = encode_fsinfo(&xdr, args->bitmask); | |
1872 | return status; | |
1873 | } | |
1874 | ||
1875 | /* | |
1876 | * a PATHCONF request | |
1877 | */ | |
1878 | static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args) | |
1879 | { | |
1da177e4 LT |
1880 | struct xdr_stream xdr; |
1881 | struct compound_hdr hdr = { | |
1882 | .nops = 2, | |
1883 | }; | |
1884 | int status; | |
1885 | ||
1886 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1887 | encode_compound_hdr(&xdr, &hdr); | |
1888 | status = encode_putfh(&xdr, args->fh); | |
1889 | if (!status) | |
1890 | status = encode_getattr_one(&xdr, | |
1891 | args->bitmask[0] & nfs4_pathconf_bitmap[0]); | |
1892 | return status; | |
1893 | } | |
1894 | ||
1895 | /* | |
1896 | * a STATFS request | |
1897 | */ | |
1898 | static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args) | |
1899 | { | |
1da177e4 LT |
1900 | struct xdr_stream xdr; |
1901 | struct compound_hdr hdr = { | |
1902 | .nops = 2, | |
1903 | }; | |
1904 | int status; | |
1905 | ||
1906 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1907 | encode_compound_hdr(&xdr, &hdr); | |
1908 | status = encode_putfh(&xdr, args->fh); | |
1909 | if (status == 0) | |
1910 | status = encode_getattr_two(&xdr, | |
1911 | args->bitmask[0] & nfs4_statfs_bitmap[0], | |
1912 | args->bitmask[1] & nfs4_statfs_bitmap[1]); | |
1913 | return status; | |
1914 | } | |
1915 | ||
1916 | /* | |
1917 | * GETATTR_BITMAP request | |
1918 | */ | |
1919 | static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle) | |
1920 | { | |
1921 | struct xdr_stream xdr; | |
1922 | struct compound_hdr hdr = { | |
1923 | .nops = 2, | |
1924 | }; | |
1925 | int status; | |
1926 | ||
1927 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1928 | encode_compound_hdr(&xdr, &hdr); | |
1929 | status = encode_putfh(&xdr, fhandle); | |
1930 | if (status == 0) | |
1931 | status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS| | |
1932 | FATTR4_WORD0_LINK_SUPPORT| | |
1933 | FATTR4_WORD0_SYMLINK_SUPPORT| | |
1934 | FATTR4_WORD0_ACLSUPPORT); | |
1935 | return status; | |
1936 | } | |
1937 | ||
1938 | /* | |
1939 | * a RENEW request | |
1940 | */ | |
1941 | static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp) | |
1942 | { | |
1943 | struct xdr_stream xdr; | |
1944 | struct compound_hdr hdr = { | |
1945 | .nops = 1, | |
1946 | }; | |
1947 | ||
1948 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1949 | encode_compound_hdr(&xdr, &hdr); | |
1950 | return encode_renew(&xdr, clp); | |
1951 | } | |
1952 | ||
1953 | /* | |
1954 | * a SETCLIENTID request | |
1955 | */ | |
1956 | static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc) | |
1957 | { | |
1958 | struct xdr_stream xdr; | |
1959 | struct compound_hdr hdr = { | |
1960 | .nops = 1, | |
1961 | }; | |
1962 | ||
1963 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1964 | encode_compound_hdr(&xdr, &hdr); | |
1965 | return encode_setclientid(&xdr, sc); | |
1966 | } | |
1967 | ||
1968 | /* | |
1969 | * a SETCLIENTID_CONFIRM request | |
1970 | */ | |
1971 | static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp) | |
1972 | { | |
1973 | struct xdr_stream xdr; | |
1974 | struct compound_hdr hdr = { | |
1975 | .nops = 3, | |
1976 | }; | |
1977 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; | |
1978 | int status; | |
1979 | ||
1980 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
1981 | encode_compound_hdr(&xdr, &hdr); | |
1982 | status = encode_setclientid_confirm(&xdr, clp); | |
1983 | if (!status) | |
1984 | status = encode_putrootfh(&xdr); | |
1985 | if (!status) | |
1986 | status = encode_fsinfo(&xdr, lease_bitmap); | |
1987 | return status; | |
1988 | } | |
1989 | ||
1990 | /* | |
1991 | * DELEGRETURN request | |
1992 | */ | |
1993 | static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args) | |
1994 | { | |
1995 | struct xdr_stream xdr; | |
1996 | struct compound_hdr hdr = { | |
fa178f29 | 1997 | .nops = 3, |
1da177e4 LT |
1998 | }; |
1999 | int status; | |
2000 | ||
2001 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
2002 | encode_compound_hdr(&xdr, &hdr); | |
fa178f29 TM |
2003 | status = encode_putfh(&xdr, args->fhandle); |
2004 | if (status != 0) | |
2005 | goto out; | |
2006 | status = encode_delegreturn(&xdr, args->stateid); | |
2007 | if (status != 0) | |
2008 | goto out; | |
2009 | status = encode_getfattr(&xdr, args->bitmask); | |
2010 | out: | |
1da177e4 LT |
2011 | return status; |
2012 | } | |
2013 | ||
683b57b4 TM |
2014 | /* |
2015 | * Encode FS_LOCATIONS request | |
2016 | */ | |
2017 | static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, uint32_t *p, struct nfs4_fs_locations_arg *args) | |
2018 | { | |
2019 | struct xdr_stream xdr; | |
2020 | struct compound_hdr hdr = { | |
2021 | .nops = 3, | |
2022 | }; | |
2023 | struct rpc_auth *auth = req->rq_task->tk_auth; | |
2024 | int replen; | |
2025 | int status; | |
2026 | ||
2027 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
2028 | encode_compound_hdr(&xdr, &hdr); | |
2029 | if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) | |
2030 | goto out; | |
2031 | if ((status = encode_lookup(&xdr, args->name)) != 0) | |
2032 | goto out; | |
2033 | if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) | |
2034 | goto out; | |
2035 | /* set up reply | |
2036 | * toplevel_status + taglen + rescount + OP_PUTFH + status | |
2037 | * + OP_LOOKUP + status + OP_GETATTR + status = 7 | |
2038 | */ | |
2039 | replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2; | |
2040 | xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page, | |
2041 | 0, PAGE_SIZE); | |
2042 | out: | |
2043 | return status; | |
2044 | } | |
2045 | ||
1da177e4 LT |
2046 | /* |
2047 | * START OF "GENERIC" DECODE ROUTINES. | |
2048 | * These may look a little ugly since they are imported from a "generic" | |
2049 | * set of XDR encode/decode routines which are intended to be shared by | |
2050 | * all of our NFSv4 implementations (OpenBSD, MacOS X...). | |
2051 | * | |
2052 | * If the pain of reading these is too great, it should be a straightforward | |
2053 | * task to translate them into Linux-specific versions which are more | |
2054 | * consistent with the style used in NFSv2/v3... | |
2055 | */ | |
2056 | #define READ32(x) (x) = ntohl(*p++) | |
2057 | #define READ64(x) do { \ | |
2058 | (x) = (u64)ntohl(*p++) << 32; \ | |
2059 | (x) |= ntohl(*p++); \ | |
2060 | } while (0) | |
2061 | #define READTIME(x) do { \ | |
2062 | p++; \ | |
2063 | (x.tv_sec) = ntohl(*p++); \ | |
2064 | (x.tv_nsec) = ntohl(*p++); \ | |
2065 | } while (0) | |
2066 | #define COPYMEM(x,nbytes) do { \ | |
2067 | memcpy((x), p, nbytes); \ | |
2068 | p += XDR_QUADLEN(nbytes); \ | |
2069 | } while (0) | |
2070 | ||
2071 | #define READ_BUF(nbytes) do { \ | |
2072 | p = xdr_inline_decode(xdr, nbytes); \ | |
2073 | if (!p) { \ | |
2074 | printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \ | |
2075 | __FUNCTION__, __LINE__); \ | |
2076 | return -EIO; \ | |
2077 | } \ | |
2078 | } while (0) | |
2079 | ||
683b57b4 | 2080 | static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) |
1da177e4 LT |
2081 | { |
2082 | uint32_t *p; | |
2083 | ||
2084 | READ_BUF(4); | |
2085 | READ32(*len); | |
2086 | READ_BUF(*len); | |
2087 | *string = (char *)p; | |
2088 | return 0; | |
2089 | } | |
2090 | ||
2091 | static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) | |
2092 | { | |
2093 | uint32_t *p; | |
2094 | ||
2095 | READ_BUF(8); | |
2096 | READ32(hdr->status); | |
2097 | READ32(hdr->taglen); | |
2098 | ||
2099 | READ_BUF(hdr->taglen + 4); | |
2100 | hdr->tag = (char *)p; | |
2101 | p += XDR_QUADLEN(hdr->taglen); | |
2102 | READ32(hdr->nops); | |
2103 | return 0; | |
2104 | } | |
2105 | ||
2106 | static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) | |
2107 | { | |
2108 | uint32_t *p; | |
2109 | uint32_t opnum; | |
2110 | int32_t nfserr; | |
2111 | ||
2112 | READ_BUF(8); | |
2113 | READ32(opnum); | |
2114 | if (opnum != expected) { | |
2115 | printk(KERN_NOTICE | |
2116 | "nfs4_decode_op_hdr: Server returned operation" | |
2117 | " %d but we issued a request for %d\n", | |
2118 | opnum, expected); | |
2119 | return -EIO; | |
2120 | } | |
2121 | READ32(nfserr); | |
2122 | if (nfserr != NFS_OK) | |
2123 | return -nfs_stat_to_errno(nfserr); | |
2124 | return 0; | |
2125 | } | |
2126 | ||
2127 | /* Dummy routine */ | |
2128 | static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp) | |
2129 | { | |
2130 | uint32_t *p; | |
683b57b4 | 2131 | unsigned int strlen; |
1da177e4 LT |
2132 | char *str; |
2133 | ||
2134 | READ_BUF(12); | |
2135 | return decode_opaque_inline(xdr, &strlen, &str); | |
2136 | } | |
2137 | ||
2138 | static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) | |
2139 | { | |
2140 | uint32_t bmlen, *p; | |
2141 | ||
2142 | READ_BUF(4); | |
2143 | READ32(bmlen); | |
2144 | ||
2145 | bitmap[0] = bitmap[1] = 0; | |
2146 | READ_BUF((bmlen << 2)); | |
2147 | if (bmlen > 0) { | |
2148 | READ32(bitmap[0]); | |
2149 | if (bmlen > 1) | |
2150 | READ32(bitmap[1]); | |
2151 | } | |
2152 | return 0; | |
2153 | } | |
2154 | ||
2155 | static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep) | |
2156 | { | |
2157 | uint32_t *p; | |
2158 | ||
2159 | READ_BUF(4); | |
2160 | READ32(*attrlen); | |
2161 | *savep = xdr->p; | |
2162 | return 0; | |
2163 | } | |
2164 | ||
2165 | static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) | |
2166 | { | |
2167 | if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { | |
2168 | decode_attr_bitmap(xdr, bitmask); | |
2169 | bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; | |
2170 | } else | |
2171 | bitmask[0] = bitmask[1] = 0; | |
2172 | dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]); | |
2173 | return 0; | |
2174 | } | |
2175 | ||
2176 | static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) | |
2177 | { | |
2178 | uint32_t *p; | |
2179 | ||
2180 | *type = 0; | |
2181 | if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) | |
2182 | return -EIO; | |
2183 | if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { | |
2184 | READ_BUF(4); | |
2185 | READ32(*type); | |
2186 | if (*type < NF4REG || *type > NF4NAMEDATTR) { | |
2187 | dprintk("%s: bad type %d\n", __FUNCTION__, *type); | |
2188 | return -EIO; | |
2189 | } | |
2190 | bitmap[0] &= ~FATTR4_WORD0_TYPE; | |
2191 | } | |
2192 | dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type); | |
2193 | return 0; | |
2194 | } | |
2195 | ||
2196 | static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) | |
2197 | { | |
2198 | uint32_t *p; | |
2199 | ||
2200 | *change = 0; | |
2201 | if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) | |
2202 | return -EIO; | |
2203 | if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { | |
2204 | READ_BUF(8); | |
2205 | READ64(*change); | |
2206 | bitmap[0] &= ~FATTR4_WORD0_CHANGE; | |
2207 | } | |
2208 | dprintk("%s: change attribute=%Lu\n", __FUNCTION__, | |
2209 | (unsigned long long)*change); | |
2210 | return 0; | |
2211 | } | |
2212 | ||
2213 | static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) | |
2214 | { | |
2215 | uint32_t *p; | |
2216 | ||
2217 | *size = 0; | |
2218 | if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) | |
2219 | return -EIO; | |
2220 | if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { | |
2221 | READ_BUF(8); | |
2222 | READ64(*size); | |
2223 | bitmap[0] &= ~FATTR4_WORD0_SIZE; | |
2224 | } | |
2225 | dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size); | |
2226 | return 0; | |
2227 | } | |
2228 | ||
2229 | static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
2230 | { | |
2231 | uint32_t *p; | |
2232 | ||
2233 | *res = 0; | |
2234 | if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) | |
2235 | return -EIO; | |
2236 | if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { | |
2237 | READ_BUF(4); | |
2238 | READ32(*res); | |
2239 | bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; | |
2240 | } | |
2241 | dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true"); | |
2242 | return 0; | |
2243 | } | |
2244 | ||
2245 | static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
2246 | { | |
2247 | uint32_t *p; | |
2248 | ||
2249 | *res = 0; | |
2250 | if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) | |
2251 | return -EIO; | |
2252 | if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { | |
2253 | READ_BUF(4); | |
2254 | READ32(*res); | |
2255 | bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; | |
2256 | } | |
2257 | dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true"); | |
2258 | return 0; | |
2259 | } | |
2260 | ||
8b4bdcf8 | 2261 | static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) |
1da177e4 LT |
2262 | { |
2263 | uint32_t *p; | |
2264 | ||
2265 | fsid->major = 0; | |
2266 | fsid->minor = 0; | |
2267 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) | |
2268 | return -EIO; | |
2269 | if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { | |
2270 | READ_BUF(16); | |
2271 | READ64(fsid->major); | |
2272 | READ64(fsid->minor); | |
2273 | bitmap[0] &= ~FATTR4_WORD0_FSID; | |
2274 | } | |
2275 | dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__, | |
2276 | (unsigned long long)fsid->major, | |
2277 | (unsigned long long)fsid->minor); | |
2278 | return 0; | |
2279 | } | |
2280 | ||
2281 | static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
2282 | { | |
2283 | uint32_t *p; | |
2284 | ||
2285 | *res = 60; | |
2286 | if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) | |
2287 | return -EIO; | |
2288 | if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { | |
2289 | READ_BUF(4); | |
2290 | READ32(*res); | |
2291 | bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; | |
2292 | } | |
2293 | dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res); | |
2294 | return 0; | |
2295 | } | |
2296 | ||
2297 | static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
2298 | { | |
2299 | uint32_t *p; | |
2300 | ||
2301 | *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; | |
2302 | if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) | |
2303 | return -EIO; | |
2304 | if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { | |
2305 | READ_BUF(4); | |
2306 | READ32(*res); | |
2307 | bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; | |
2308 | } | |
2309 | dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res); | |
2310 | return 0; | |
2311 | } | |
2312 | ||
2313 | static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) | |
2314 | { | |
2315 | uint32_t *p; | |
2316 | ||
2317 | *fileid = 0; | |
2318 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) | |
2319 | return -EIO; | |
2320 | if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { | |
2321 | READ_BUF(8); | |
2322 | READ64(*fileid); | |
2323 | bitmap[0] &= ~FATTR4_WORD0_FILEID; | |
2324 | } | |
2325 | dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid); | |
2326 | return 0; | |
2327 | } | |
2328 | ||
2329 | static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
2330 | { | |
2331 | uint32_t *p; | |
2332 | int status = 0; | |
2333 | ||
2334 | *res = 0; | |
2335 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) | |
2336 | return -EIO; | |
2337 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { | |
2338 | READ_BUF(8); | |
2339 | READ64(*res); | |
2340 | bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; | |
2341 | } | |
2342 | dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res); | |
2343 | return status; | |
2344 | } | |
2345 | ||
2346 | static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
2347 | { | |
2348 | uint32_t *p; | |
2349 | int status = 0; | |
2350 | ||
2351 | *res = 0; | |
2352 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) | |
2353 | return -EIO; | |
2354 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { | |
2355 | READ_BUF(8); | |
2356 | READ64(*res); | |
2357 | bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; | |
2358 | } | |
2359 | dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res); | |
2360 | return status; | |
2361 | } | |
2362 | ||
2363 | static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
2364 | { | |
2365 | uint32_t *p; | |
2366 | int status = 0; | |
2367 | ||
2368 | *res = 0; | |
2369 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) | |
2370 | return -EIO; | |
2371 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { | |
2372 | READ_BUF(8); | |
2373 | READ64(*res); | |
2374 | bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; | |
2375 | } | |
2376 | dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res); | |
2377 | return status; | |
2378 | } | |
2379 | ||
683b57b4 TM |
2380 | static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fs_locations *res) |
2381 | { | |
2382 | int n; | |
2383 | uint32_t *p; | |
2384 | int status = -EIO; | |
2385 | ||
2386 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) | |
2387 | goto out; | |
2388 | status = 0; | |
2389 | if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) | |
2390 | goto out; | |
2391 | status = decode_opaque_inline(xdr, &res->fs_pathlen, &res->fs_path); | |
2392 | if (unlikely(status != 0)) | |
2393 | goto out; | |
2394 | READ_BUF(4); | |
2395 | READ32(n); | |
2396 | if (n <= 0) | |
2397 | goto out_eio; | |
2398 | res->nlocations = 0; | |
2399 | while (res->nlocations < n) { | |
2400 | struct nfs_fs_location *loc = &res->locations[res->nlocations]; | |
2401 | ||
2402 | status = decode_opaque_inline(xdr, &loc->serverlen, &loc->server); | |
2403 | if (unlikely(status != 0)) | |
2404 | goto out_eio; | |
2405 | status = decode_opaque_inline(xdr, &loc->rootpathlen, &loc->rootpath); | |
2406 | if (unlikely(status != 0)) | |
2407 | goto out_eio; | |
2408 | if (res->nlocations < NFS_FS_LOCATIONS_MAXENTRIES) | |
2409 | res->nlocations++; | |
2410 | } | |
2411 | out: | |
2412 | dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status); | |
2413 | return status; | |
2414 | out_eio: | |
2415 | status = -EIO; | |
2416 | goto out; | |
2417 | } | |
2418 | ||
1da177e4 LT |
2419 | static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
2420 | { | |
2421 | uint32_t *p; | |
2422 | int status = 0; | |
2423 | ||
2424 | *res = 0; | |
2425 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) | |
2426 | return -EIO; | |
2427 | if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { | |
2428 | READ_BUF(8); | |
2429 | READ64(*res); | |
2430 | bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; | |
2431 | } | |
2432 | dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res); | |
2433 | return status; | |
2434 | } | |
2435 | ||
2436 | static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) | |
2437 | { | |
2438 | uint32_t *p; | |
2439 | int status = 0; | |
2440 | ||
2441 | *maxlink = 1; | |
2442 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) | |
2443 | return -EIO; | |
2444 | if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { | |
2445 | READ_BUF(4); | |
2446 | READ32(*maxlink); | |
2447 | bitmap[0] &= ~FATTR4_WORD0_MAXLINK; | |
2448 | } | |
2449 | dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink); | |
2450 | return status; | |
2451 | } | |
2452 | ||
2453 | static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) | |
2454 | { | |
2455 | uint32_t *p; | |
2456 | int status = 0; | |
2457 | ||
2458 | *maxname = 1024; | |
2459 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) | |
2460 | return -EIO; | |
2461 | if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { | |
2462 | READ_BUF(4); | |
2463 | READ32(*maxname); | |
2464 | bitmap[0] &= ~FATTR4_WORD0_MAXNAME; | |
2465 | } | |
2466 | dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname); | |
2467 | return status; | |
2468 | } | |
2469 | ||
2470 | static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
2471 | { | |
2472 | uint32_t *p; | |
2473 | int status = 0; | |
2474 | ||
2475 | *res = 1024; | |
2476 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) | |
2477 | return -EIO; | |
2478 | if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { | |
2479 | uint64_t maxread; | |
2480 | READ_BUF(8); | |
2481 | READ64(maxread); | |
2482 | if (maxread > 0x7FFFFFFF) | |
2483 | maxread = 0x7FFFFFFF; | |
2484 | *res = (uint32_t)maxread; | |
2485 | bitmap[0] &= ~FATTR4_WORD0_MAXREAD; | |
2486 | } | |
2487 | dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res); | |
2488 | return status; | |
2489 | } | |
2490 | ||
2491 | static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
2492 | { | |
2493 | uint32_t *p; | |
2494 | int status = 0; | |
2495 | ||
2496 | *res = 1024; | |
2497 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) | |
2498 | return -EIO; | |
2499 | if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { | |
2500 | uint64_t maxwrite; | |
2501 | READ_BUF(8); | |
2502 | READ64(maxwrite); | |
2503 | if (maxwrite > 0x7FFFFFFF) | |
2504 | maxwrite = 0x7FFFFFFF; | |
2505 | *res = (uint32_t)maxwrite; | |
2506 | bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; | |
2507 | } | |
2508 | dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res); | |
2509 | return status; | |
2510 | } | |
2511 | ||
2512 | static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode) | |
2513 | { | |
2514 | uint32_t *p; | |
2515 | ||
2516 | *mode = 0; | |
2517 | if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) | |
2518 | return -EIO; | |
2519 | if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { | |
2520 | READ_BUF(4); | |
2521 | READ32(*mode); | |
2522 | *mode &= ~S_IFMT; | |
2523 | bitmap[1] &= ~FATTR4_WORD1_MODE; | |
2524 | } | |
2525 | dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode); | |
2526 | return 0; | |
2527 | } | |
2528 | ||
2529 | static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) | |
2530 | { | |
2531 | uint32_t *p; | |
2532 | ||
2533 | *nlink = 1; | |
2534 | if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) | |
2535 | return -EIO; | |
2536 | if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { | |
2537 | READ_BUF(4); | |
2538 | READ32(*nlink); | |
2539 | bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; | |
2540 | } | |
2541 | dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink); | |
2542 | return 0; | |
2543 | } | |
2544 | ||
2545 | static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid) | |
2546 | { | |
2547 | uint32_t len, *p; | |
2548 | ||
2549 | *uid = -2; | |
2550 | if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) | |
2551 | return -EIO; | |
2552 | if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { | |
2553 | READ_BUF(4); | |
2554 | READ32(len); | |
2555 | READ_BUF(len); | |
2556 | if (len < XDR_MAX_NETOBJ) { | |
2557 | if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0) | |
2558 | dprintk("%s: nfs_map_name_to_uid failed!\n", | |
2559 | __FUNCTION__); | |
2560 | } else | |
2561 | printk(KERN_WARNING "%s: name too long (%u)!\n", | |
2562 | __FUNCTION__, len); | |
2563 | bitmap[1] &= ~FATTR4_WORD1_OWNER; | |
2564 | } | |
2565 | dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid); | |
2566 | return 0; | |
2567 | } | |
2568 | ||
2569 | static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid) | |
2570 | { | |
2571 | uint32_t len, *p; | |
2572 | ||
2573 | *gid = -2; | |
2574 | if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) | |
2575 | return -EIO; | |
2576 | if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { | |
2577 | READ_BUF(4); | |
2578 | READ32(len); | |
2579 | READ_BUF(len); | |
2580 | if (len < XDR_MAX_NETOBJ) { | |
2581 | if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0) | |
2582 | dprintk("%s: nfs_map_group_to_gid failed!\n", | |
2583 | __FUNCTION__); | |
2584 | } else | |
2585 | printk(KERN_WARNING "%s: name too long (%u)!\n", | |
2586 | __FUNCTION__, len); | |
2587 | bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; | |
2588 | } | |
2589 | dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid); | |
2590 | return 0; | |
2591 | } | |
2592 | ||
2593 | static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) | |
2594 | { | |
2595 | uint32_t major = 0, minor = 0, *p; | |
2596 | ||
2597 | *rdev = MKDEV(0,0); | |
2598 | if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) | |
2599 | return -EIO; | |
2600 | if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { | |
2601 | dev_t tmp; | |
2602 | ||
2603 | READ_BUF(8); | |
2604 | READ32(major); | |
2605 | READ32(minor); | |
2606 | tmp = MKDEV(major, minor); | |
2607 | if (MAJOR(tmp) == major && MINOR(tmp) == minor) | |
2608 | *rdev = tmp; | |
2609 | bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; | |
2610 | } | |
2611 | dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor); | |
2612 | return 0; | |
2613 | } | |
2614 | ||
2615 | static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
2616 | { | |
2617 | uint32_t *p; | |
2618 | int status = 0; | |
2619 | ||
2620 | *res = 0; | |
2621 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) | |
2622 | return -EIO; | |
2623 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { | |
2624 | READ_BUF(8); | |
2625 | READ64(*res); | |
2626 | bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; | |
2627 | } | |
2628 | dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res); | |
2629 | return status; | |
2630 | } | |
2631 | ||
2632 | static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
2633 | { | |
2634 | uint32_t *p; | |
2635 | int status = 0; | |
2636 | ||
2637 | *res = 0; | |
2638 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) | |
2639 | return -EIO; | |
2640 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { | |
2641 | READ_BUF(8); | |
2642 | READ64(*res); | |
2643 | bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; | |
2644 | } | |
2645 | dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res); | |
2646 | return status; | |
2647 | } | |
2648 | ||
2649 | static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
2650 | { | |
2651 | uint32_t *p; | |
2652 | int status = 0; | |
2653 | ||
2654 | *res = 0; | |
2655 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) | |
2656 | return -EIO; | |
2657 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { | |
2658 | READ_BUF(8); | |
2659 | READ64(*res); | |
2660 | bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; | |
2661 | } | |
2662 | dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res); | |
2663 | return status; | |
2664 | } | |
2665 | ||
2666 | static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) | |
2667 | { | |
2668 | uint32_t *p; | |
2669 | ||
2670 | *used = 0; | |
2671 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) | |
2672 | return -EIO; | |
2673 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { | |
2674 | READ_BUF(8); | |
2675 | READ64(*used); | |
2676 | bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; | |
2677 | } | |
2678 | dprintk("%s: space used=%Lu\n", __FUNCTION__, | |
2679 | (unsigned long long)*used); | |
2680 | return 0; | |
2681 | } | |
2682 | ||
2683 | static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) | |
2684 | { | |
2685 | uint32_t *p; | |
2686 | uint64_t sec; | |
2687 | uint32_t nsec; | |
2688 | ||
2689 | READ_BUF(12); | |
2690 | READ64(sec); | |
2691 | READ32(nsec); | |
2692 | time->tv_sec = (time_t)sec; | |
2693 | time->tv_nsec = (long)nsec; | |
2694 | return 0; | |
2695 | } | |
2696 | ||
2697 | static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) | |
2698 | { | |
2699 | int status = 0; | |
2700 | ||
2701 | time->tv_sec = 0; | |
2702 | time->tv_nsec = 0; | |
2703 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) | |
2704 | return -EIO; | |
2705 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { | |
2706 | status = decode_attr_time(xdr, time); | |
2707 | bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; | |
2708 | } | |
2709 | dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec); | |
2710 | return status; | |
2711 | } | |
2712 | ||
2713 | static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) | |
2714 | { | |
2715 | int status = 0; | |
2716 | ||
2717 | time->tv_sec = 0; | |
2718 | time->tv_nsec = 0; | |
2719 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) | |
2720 | return -EIO; | |
2721 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { | |
2722 | status = decode_attr_time(xdr, time); | |
2723 | bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; | |
2724 | } | |
2725 | dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec); | |
2726 | return status; | |
2727 | } | |
2728 | ||
2729 | static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) | |
2730 | { | |
2731 | int status = 0; | |
2732 | ||
2733 | time->tv_sec = 0; | |
2734 | time->tv_nsec = 0; | |
2735 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) | |
2736 | return -EIO; | |
2737 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { | |
2738 | status = decode_attr_time(xdr, time); | |
2739 | bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; | |
2740 | } | |
2741 | dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec); | |
2742 | return status; | |
2743 | } | |
2744 | ||
2745 | static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen) | |
2746 | { | |
2747 | unsigned int attrwords = XDR_QUADLEN(attrlen); | |
2748 | unsigned int nwords = xdr->p - savep; | |
2749 | ||
2750 | if (unlikely(attrwords != nwords)) { | |
2751 | printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n", | |
2752 | __FUNCTION__, | |
2753 | attrwords << 2, | |
2754 | (attrwords < nwords) ? '<' : '>', | |
2755 | nwords << 2); | |
2756 | return -EIO; | |
2757 | } | |
2758 | return 0; | |
2759 | } | |
2760 | ||
2761 | static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
2762 | { | |
2763 | uint32_t *p; | |
2764 | ||
2765 | READ_BUF(20); | |
2766 | READ32(cinfo->atomic); | |
2767 | READ64(cinfo->before); | |
2768 | READ64(cinfo->after); | |
2769 | return 0; | |
2770 | } | |
2771 | ||
2772 | static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) | |
2773 | { | |
2774 | uint32_t *p; | |
2775 | uint32_t supp, acc; | |
2776 | int status; | |
2777 | ||
2778 | status = decode_op_hdr(xdr, OP_ACCESS); | |
2779 | if (status) | |
2780 | return status; | |
2781 | READ_BUF(8); | |
2782 | READ32(supp); | |
2783 | READ32(acc); | |
2784 | access->supported = supp; | |
2785 | access->access = acc; | |
2786 | return 0; | |
2787 | } | |
2788 | ||
2789 | static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) | |
2790 | { | |
2791 | uint32_t *p; | |
2792 | int status; | |
2793 | ||
2794 | status = decode_op_hdr(xdr, OP_CLOSE); | |
2795 | if (status) | |
2796 | return status; | |
2797 | READ_BUF(sizeof(res->stateid.data)); | |
2798 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); | |
2799 | return 0; | |
2800 | } | |
2801 | ||
2802 | static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) | |
2803 | { | |
2804 | uint32_t *p; | |
2805 | int status; | |
2806 | ||
2807 | status = decode_op_hdr(xdr, OP_COMMIT); | |
2808 | if (status) | |
2809 | return status; | |
2810 | READ_BUF(8); | |
2811 | COPYMEM(res->verf->verifier, 8); | |
2812 | return 0; | |
2813 | } | |
2814 | ||
2815 | static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
2816 | { | |
2817 | uint32_t *p; | |
2818 | uint32_t bmlen; | |
2819 | int status; | |
2820 | ||
2821 | status = decode_op_hdr(xdr, OP_CREATE); | |
2822 | if (status) | |
2823 | return status; | |
2824 | if ((status = decode_change_info(xdr, cinfo))) | |
2825 | return status; | |
2826 | READ_BUF(4); | |
2827 | READ32(bmlen); | |
2828 | READ_BUF(bmlen << 2); | |
2829 | return 0; | |
2830 | } | |
2831 | ||
2832 | static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) | |
2833 | { | |
2834 | uint32_t *savep; | |
2835 | uint32_t attrlen, | |
2836 | bitmap[2] = {0}; | |
2837 | int status; | |
2838 | ||
2839 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
2840 | goto xdr_error; | |
2841 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
2842 | goto xdr_error; | |
2843 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
2844 | goto xdr_error; | |
2845 | if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) | |
2846 | goto xdr_error; | |
2847 | if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) | |
2848 | goto xdr_error; | |
2849 | if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) | |
2850 | goto xdr_error; | |
2851 | if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) | |
2852 | goto xdr_error; | |
2853 | status = verify_attr_len(xdr, savep, attrlen); | |
2854 | xdr_error: | |
16c32b71 | 2855 | dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); |
1da177e4 LT |
2856 | return status; |
2857 | } | |
2858 | ||
2859 | static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) | |
2860 | { | |
2861 | uint32_t *savep; | |
2862 | uint32_t attrlen, | |
2863 | bitmap[2] = {0}; | |
2864 | int status; | |
2865 | ||
2866 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
2867 | goto xdr_error; | |
2868 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
2869 | goto xdr_error; | |
2870 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
2871 | goto xdr_error; | |
2872 | ||
2873 | if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) | |
2874 | goto xdr_error; | |
2875 | if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) | |
2876 | goto xdr_error; | |
2877 | if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) | |
2878 | goto xdr_error; | |
2879 | if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) | |
2880 | goto xdr_error; | |
2881 | if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) | |
2882 | goto xdr_error; | |
2883 | if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) | |
2884 | goto xdr_error; | |
2885 | ||
2886 | status = verify_attr_len(xdr, savep, attrlen); | |
2887 | xdr_error: | |
16c32b71 | 2888 | dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); |
1da177e4 LT |
2889 | return status; |
2890 | } | |
2891 | ||
2892 | static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) | |
2893 | { | |
2894 | uint32_t *savep; | |
2895 | uint32_t attrlen, | |
2896 | bitmap[2] = {0}; | |
2897 | int status; | |
2898 | ||
2899 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
2900 | goto xdr_error; | |
2901 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
2902 | goto xdr_error; | |
2903 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
2904 | goto xdr_error; | |
2905 | ||
2906 | if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) | |
2907 | goto xdr_error; | |
2908 | if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) | |
2909 | goto xdr_error; | |
2910 | ||
2911 | status = verify_attr_len(xdr, savep, attrlen); | |
2912 | xdr_error: | |
16c32b71 | 2913 | dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); |
1da177e4 LT |
2914 | return status; |
2915 | } | |
2916 | ||
2917 | static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server) | |
2918 | { | |
2919 | uint32_t *savep; | |
2920 | uint32_t attrlen, | |
2921 | bitmap[2] = {0}, | |
2922 | type; | |
2923 | int status, fmode = 0; | |
2924 | ||
2925 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
2926 | goto xdr_error; | |
2927 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
2928 | goto xdr_error; | |
2929 | ||
2930 | fattr->bitmap[0] = bitmap[0]; | |
2931 | fattr->bitmap[1] = bitmap[1]; | |
2932 | ||
2933 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
2934 | goto xdr_error; | |
2935 | ||
2936 | ||
2937 | if ((status = decode_attr_type(xdr, bitmap, &type)) != 0) | |
2938 | goto xdr_error; | |
2939 | fattr->type = nfs_type2fmt[type].nfs2type; | |
2940 | fmode = nfs_type2fmt[type].mode; | |
2941 | ||
2942 | if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0) | |
2943 | goto xdr_error; | |
2944 | if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0) | |
2945 | goto xdr_error; | |
8b4bdcf8 | 2946 | if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0) |
1da177e4 LT |
2947 | goto xdr_error; |
2948 | if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0) | |
2949 | goto xdr_error; | |
683b57b4 TM |
2950 | if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr, |
2951 | struct nfs_fs_locations, | |
2952 | fattr))) != 0) | |
2953 | goto xdr_error; | |
1da177e4 LT |
2954 | if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0) |
2955 | goto xdr_error; | |
2956 | fattr->mode |= fmode; | |
2957 | if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0) | |
2958 | goto xdr_error; | |
2959 | if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0) | |
2960 | goto xdr_error; | |
2961 | if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0) | |
2962 | goto xdr_error; | |
2963 | if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0) | |
2964 | goto xdr_error; | |
2965 | if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0) | |
2966 | goto xdr_error; | |
2967 | if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0) | |
2968 | goto xdr_error; | |
2969 | if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0) | |
2970 | goto xdr_error; | |
2971 | if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0) | |
2972 | goto xdr_error; | |
33801147 | 2973 | if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) |
1da177e4 | 2974 | fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4; |
1da177e4 | 2975 | xdr_error: |
16c32b71 | 2976 | dprintk("%s: xdr returned %d\n", __FUNCTION__, -status); |
1da177e4 LT |
2977 | return status; |
2978 | } | |
2979 | ||
2980 | ||
2981 | static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) | |
2982 | { | |
2983 | uint32_t *savep; | |
2984 | uint32_t attrlen, bitmap[2]; | |
2985 | int status; | |
2986 | ||
2987 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
2988 | goto xdr_error; | |
2989 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
2990 | goto xdr_error; | |
2991 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
2992 | goto xdr_error; | |
2993 | ||
2994 | fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ | |
2995 | ||
2996 | if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) | |
2997 | goto xdr_error; | |
2998 | if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) | |
2999 | goto xdr_error; | |
3000 | if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) | |
3001 | goto xdr_error; | |
3002 | fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; | |
3003 | if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) | |
3004 | goto xdr_error; | |
3005 | fsinfo->wtpref = fsinfo->wtmax; | |
3006 | ||
3007 | status = verify_attr_len(xdr, savep, attrlen); | |
3008 | xdr_error: | |
16c32b71 | 3009 | dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); |
1da177e4 LT |
3010 | return status; |
3011 | } | |
3012 | ||
3013 | static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) | |
3014 | { | |
3015 | uint32_t *p; | |
3016 | uint32_t len; | |
3017 | int status; | |
3018 | ||
3019 | status = decode_op_hdr(xdr, OP_GETFH); | |
3020 | if (status) | |
3021 | return status; | |
3022 | /* Zero handle first to allow comparisons */ | |
3023 | memset(fh, 0, sizeof(*fh)); | |
3024 | ||
3025 | READ_BUF(4); | |
3026 | READ32(len); | |
3027 | if (len > NFS4_FHSIZE) | |
3028 | return -EIO; | |
3029 | fh->size = len; | |
3030 | READ_BUF(len); | |
3031 | COPYMEM(fh->data, len); | |
3032 | return 0; | |
3033 | } | |
3034 | ||
3035 | static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
3036 | { | |
3037 | int status; | |
3038 | ||
3039 | status = decode_op_hdr(xdr, OP_LINK); | |
3040 | if (status) | |
3041 | return status; | |
3042 | return decode_change_info(xdr, cinfo); | |
3043 | } | |
3044 | ||
3045 | /* | |
3046 | * We create the owner, so we know a proper owner.id length is 4. | |
3047 | */ | |
911d1aaf | 3048 | static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) |
1da177e4 | 3049 | { |
911d1aaf | 3050 | uint64_t offset, length, clientid; |
1da177e4 | 3051 | uint32_t *p; |
911d1aaf | 3052 | uint32_t namelen, type; |
1da177e4 LT |
3053 | |
3054 | READ_BUF(32); | |
911d1aaf TM |
3055 | READ64(offset); |
3056 | READ64(length); | |
3057 | READ32(type); | |
3058 | if (fl != NULL) { | |
3059 | fl->fl_start = (loff_t)offset; | |
3060 | fl->fl_end = fl->fl_start + (loff_t)length - 1; | |
3061 | if (length == ~(uint64_t)0) | |
3062 | fl->fl_end = OFFSET_MAX; | |
3063 | fl->fl_type = F_WRLCK; | |
3064 | if (type & 1) | |
3065 | fl->fl_type = F_RDLCK; | |
3066 | fl->fl_pid = 0; | |
3067 | } | |
3068 | READ64(clientid); | |
1da177e4 LT |
3069 | READ32(namelen); |
3070 | READ_BUF(namelen); | |
1da177e4 LT |
3071 | return -NFS4ERR_DENIED; |
3072 | } | |
3073 | ||
911d1aaf | 3074 | static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) |
1da177e4 LT |
3075 | { |
3076 | uint32_t *p; | |
3077 | int status; | |
3078 | ||
3079 | status = decode_op_hdr(xdr, OP_LOCK); | |
3080 | if (status == 0) { | |
911d1aaf TM |
3081 | READ_BUF(sizeof(res->stateid.data)); |
3082 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); | |
1da177e4 | 3083 | } else if (status == -NFS4ERR_DENIED) |
911d1aaf | 3084 | return decode_lock_denied(xdr, NULL); |
1da177e4 LT |
3085 | return status; |
3086 | } | |
3087 | ||
911d1aaf | 3088 | static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) |
1da177e4 LT |
3089 | { |
3090 | int status; | |
3091 | status = decode_op_hdr(xdr, OP_LOCKT); | |
3092 | if (status == -NFS4ERR_DENIED) | |
911d1aaf | 3093 | return decode_lock_denied(xdr, res->denied); |
1da177e4 LT |
3094 | return status; |
3095 | } | |
3096 | ||
911d1aaf | 3097 | static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) |
1da177e4 LT |
3098 | { |
3099 | uint32_t *p; | |
3100 | int status; | |
3101 | ||
3102 | status = decode_op_hdr(xdr, OP_LOCKU); | |
3103 | if (status == 0) { | |
911d1aaf TM |
3104 | READ_BUF(sizeof(res->stateid.data)); |
3105 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); | |
1da177e4 LT |
3106 | } |
3107 | return status; | |
3108 | } | |
3109 | ||
3110 | static int decode_lookup(struct xdr_stream *xdr) | |
3111 | { | |
3112 | return decode_op_hdr(xdr, OP_LOOKUP); | |
3113 | } | |
3114 | ||
3115 | /* This is too sick! */ | |
3116 | static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) | |
3117 | { | |
3118 | uint32_t *p; | |
3119 | uint32_t limit_type, nblocks, blocksize; | |
3120 | ||
3121 | READ_BUF(12); | |
3122 | READ32(limit_type); | |
3123 | switch (limit_type) { | |
3124 | case 1: | |
3125 | READ64(*maxsize); | |
3126 | break; | |
3127 | case 2: | |
3128 | READ32(nblocks); | |
3129 | READ32(blocksize); | |
3130 | *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; | |
3131 | } | |
3132 | return 0; | |
3133 | } | |
3134 | ||
3135 | static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) | |
3136 | { | |
3137 | uint32_t *p; | |
3138 | uint32_t delegation_type; | |
3139 | ||
3140 | READ_BUF(4); | |
3141 | READ32(delegation_type); | |
3142 | if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { | |
3143 | res->delegation_type = 0; | |
3144 | return 0; | |
3145 | } | |
3146 | READ_BUF(20); | |
3147 | COPYMEM(res->delegation.data, sizeof(res->delegation.data)); | |
3148 | READ32(res->do_recall); | |
3149 | switch (delegation_type) { | |
3150 | case NFS4_OPEN_DELEGATE_READ: | |
3151 | res->delegation_type = FMODE_READ; | |
3152 | break; | |
3153 | case NFS4_OPEN_DELEGATE_WRITE: | |
3154 | res->delegation_type = FMODE_WRITE|FMODE_READ; | |
3155 | if (decode_space_limit(xdr, &res->maxsize) < 0) | |
3156 | return -EIO; | |
3157 | } | |
3158 | return decode_ace(xdr, NULL, res->server->nfs4_state); | |
3159 | } | |
3160 | ||
3161 | static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) | |
3162 | { | |
3163 | uint32_t *p; | |
3164 | uint32_t bmlen; | |
3165 | int status; | |
3166 | ||
3167 | status = decode_op_hdr(xdr, OP_OPEN); | |
3168 | if (status) | |
3169 | return status; | |
3170 | READ_BUF(sizeof(res->stateid.data)); | |
3171 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); | |
3172 | ||
3173 | decode_change_info(xdr, &res->cinfo); | |
3174 | ||
3175 | READ_BUF(8); | |
3176 | READ32(res->rflags); | |
3177 | READ32(bmlen); | |
3178 | if (bmlen > 10) | |
3179 | goto xdr_error; | |
3180 | ||
3181 | READ_BUF(bmlen << 2); | |
3182 | p += bmlen; | |
3183 | return decode_delegation(xdr, res); | |
3184 | xdr_error: | |
16c32b71 | 3185 | dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen); |
1da177e4 LT |
3186 | return -EIO; |
3187 | } | |
3188 | ||
3189 | static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) | |
3190 | { | |
3191 | uint32_t *p; | |
3192 | int status; | |
3193 | ||
3194 | status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); | |
3195 | if (status) | |
3196 | return status; | |
3197 | READ_BUF(sizeof(res->stateid.data)); | |
3198 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); | |
3199 | return 0; | |
3200 | } | |
3201 | ||
3202 | static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) | |
3203 | { | |
3204 | uint32_t *p; | |
3205 | int status; | |
3206 | ||
3207 | status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); | |
3208 | if (status) | |
3209 | return status; | |
3210 | READ_BUF(sizeof(res->stateid.data)); | |
3211 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); | |
3212 | return 0; | |
3213 | } | |
3214 | ||
3215 | static int decode_putfh(struct xdr_stream *xdr) | |
3216 | { | |
3217 | return decode_op_hdr(xdr, OP_PUTFH); | |
3218 | } | |
3219 | ||
3220 | static int decode_putrootfh(struct xdr_stream *xdr) | |
3221 | { | |
3222 | return decode_op_hdr(xdr, OP_PUTROOTFH); | |
3223 | } | |
3224 | ||
3225 | static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) | |
3226 | { | |
3227 | struct kvec *iov = req->rq_rcv_buf.head; | |
3228 | uint32_t *p; | |
3229 | uint32_t count, eof, recvd, hdrlen; | |
3230 | int status; | |
3231 | ||
3232 | status = decode_op_hdr(xdr, OP_READ); | |
3233 | if (status) | |
3234 | return status; | |
3235 | READ_BUF(8); | |
3236 | READ32(eof); | |
3237 | READ32(count); | |
3238 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; | |
3239 | recvd = req->rq_rcv_buf.len - hdrlen; | |
3240 | if (count > recvd) { | |
3241 | printk(KERN_WARNING "NFS: server cheating in read reply: " | |
3242 | "count %u > recvd %u\n", count, recvd); | |
3243 | count = recvd; | |
3244 | eof = 0; | |
3245 | } | |
3246 | xdr_read_pages(xdr, count); | |
3247 | res->eof = eof; | |
3248 | res->count = count; | |
3249 | return 0; | |
3250 | } | |
3251 | ||
3252 | static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) | |
3253 | { | |
3254 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; | |
3255 | struct page *page = *rcvbuf->pages; | |
3256 | struct kvec *iov = rcvbuf->head; | |
3257 | unsigned int nr, pglen = rcvbuf->page_len; | |
3258 | uint32_t *end, *entry, *p, *kaddr; | |
3259 | uint32_t len, attrlen; | |
3260 | int hdrlen, recvd, status; | |
3261 | ||
3262 | status = decode_op_hdr(xdr, OP_READDIR); | |
3263 | if (status) | |
3264 | return status; | |
3265 | READ_BUF(8); | |
3266 | COPYMEM(readdir->verifier.data, 8); | |
eadf4598 TM |
3267 | dprintk("%s: verifier = 0x%x%x\n", |
3268 | __FUNCTION__, | |
3269 | ((u32 *)readdir->verifier.data)[0], | |
3270 | ((u32 *)readdir->verifier.data)[1]); | |
3271 | ||
1da177e4 LT |
3272 | |
3273 | hdrlen = (char *) p - (char *) iov->iov_base; | |
3274 | recvd = rcvbuf->len - hdrlen; | |
3275 | if (pglen > recvd) | |
3276 | pglen = recvd; | |
3277 | xdr_read_pages(xdr, pglen); | |
3278 | ||
3279 | BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE); | |
3280 | kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0); | |
3281 | end = (uint32_t *) ((char *)p + pglen + readdir->pgbase); | |
3282 | entry = p; | |
3283 | for (nr = 0; *p++; nr++) { | |
3284 | if (p + 3 > end) | |
3285 | goto short_pkt; | |
eadf4598 | 3286 | dprintk("cookie = %Lu, ", *((unsigned long long *)p)); |
1da177e4 LT |
3287 | p += 2; /* cookie */ |
3288 | len = ntohl(*p++); /* filename length */ | |
3289 | if (len > NFS4_MAXNAMLEN) { | |
3290 | printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len); | |
3291 | goto err_unmap; | |
3292 | } | |
eadf4598 | 3293 | dprintk("filename = %*s\n", len, (char *)p); |
1da177e4 LT |
3294 | p += XDR_QUADLEN(len); |
3295 | if (p + 1 > end) | |
3296 | goto short_pkt; | |
3297 | len = ntohl(*p++); /* bitmap length */ | |
3298 | p += len; | |
3299 | if (p + 1 > end) | |
3300 | goto short_pkt; | |
3301 | attrlen = XDR_QUADLEN(ntohl(*p++)); | |
3302 | p += attrlen; /* attributes */ | |
3303 | if (p + 2 > end) | |
3304 | goto short_pkt; | |
3305 | entry = p; | |
3306 | } | |
3307 | if (!nr && (entry[0] != 0 || entry[1] == 0)) | |
3308 | goto short_pkt; | |
3309 | out: | |
3310 | kunmap_atomic(kaddr, KM_USER0); | |
3311 | return 0; | |
3312 | short_pkt: | |
eadf4598 | 3313 | dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr); |
1da177e4 LT |
3314 | entry[0] = entry[1] = 0; |
3315 | /* truncate listing ? */ | |
3316 | if (!nr) { | |
3317 | printk(KERN_NOTICE "NFS: readdir reply truncated!\n"); | |
3318 | entry[1] = 1; | |
3319 | } | |
3320 | goto out; | |
3321 | err_unmap: | |
3322 | kunmap_atomic(kaddr, KM_USER0); | |
3323 | return -errno_NFSERR_IO; | |
3324 | } | |
3325 | ||
3326 | static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) | |
3327 | { | |
3328 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; | |
3329 | struct kvec *iov = rcvbuf->head; | |
3330 | int hdrlen, len, recvd; | |
3331 | uint32_t *p; | |
3332 | char *kaddr; | |
3333 | int status; | |
3334 | ||
3335 | status = decode_op_hdr(xdr, OP_READLINK); | |
3336 | if (status) | |
3337 | return status; | |
3338 | ||
3339 | /* Convert length of symlink */ | |
3340 | READ_BUF(4); | |
3341 | READ32(len); | |
3342 | if (len >= rcvbuf->page_len || len <= 0) { | |
3343 | dprintk(KERN_WARNING "nfs: server returned giant symlink!\n"); | |
3344 | return -ENAMETOOLONG; | |
3345 | } | |
3346 | hdrlen = (char *) xdr->p - (char *) iov->iov_base; | |
3347 | recvd = req->rq_rcv_buf.len - hdrlen; | |
3348 | if (recvd < len) { | |
3349 | printk(KERN_WARNING "NFS: server cheating in readlink reply: " | |
3350 | "count %u > recvd %u\n", len, recvd); | |
3351 | return -EIO; | |
3352 | } | |
3353 | xdr_read_pages(xdr, len); | |
3354 | /* | |
3355 | * The XDR encode routine has set things up so that | |
3356 | * the link text will be copied directly into the | |
3357 | * buffer. We just have to do overflow-checking, | |
3358 | * and and null-terminate the text (the VFS expects | |
3359 | * null-termination). | |
3360 | */ | |
3361 | kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0); | |
3362 | kaddr[len+rcvbuf->page_base] = '\0'; | |
3363 | kunmap_atomic(kaddr, KM_USER0); | |
3364 | return 0; | |
3365 | } | |
3366 | ||
3367 | static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
3368 | { | |
3369 | int status; | |
3370 | ||
3371 | status = decode_op_hdr(xdr, OP_REMOVE); | |
3372 | if (status) | |
3373 | goto out; | |
3374 | status = decode_change_info(xdr, cinfo); | |
3375 | out: | |
3376 | return status; | |
3377 | } | |
3378 | ||
3379 | static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, | |
3380 | struct nfs4_change_info *new_cinfo) | |
3381 | { | |
3382 | int status; | |
3383 | ||
3384 | status = decode_op_hdr(xdr, OP_RENAME); | |
3385 | if (status) | |
3386 | goto out; | |
3387 | if ((status = decode_change_info(xdr, old_cinfo))) | |
3388 | goto out; | |
3389 | status = decode_change_info(xdr, new_cinfo); | |
3390 | out: | |
3391 | return status; | |
3392 | } | |
3393 | ||
3394 | static int decode_renew(struct xdr_stream *xdr) | |
3395 | { | |
3396 | return decode_op_hdr(xdr, OP_RENEW); | |
3397 | } | |
3398 | ||
56ae19f3 TM |
3399 | static int |
3400 | decode_restorefh(struct xdr_stream *xdr) | |
3401 | { | |
3402 | return decode_op_hdr(xdr, OP_RESTOREFH); | |
3403 | } | |
3404 | ||
029d105e BF |
3405 | static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, |
3406 | size_t *acl_len) | |
3407 | { | |
3408 | uint32_t *savep; | |
3409 | uint32_t attrlen, | |
3410 | bitmap[2] = {0}; | |
3411 | struct kvec *iov = req->rq_rcv_buf.head; | |
3412 | int status; | |
3413 | ||
3414 | *acl_len = 0; | |
3415 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
3416 | goto out; | |
3417 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
3418 | goto out; | |
3419 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
3420 | goto out; | |
3421 | ||
3422 | if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) | |
3423 | return -EIO; | |
3424 | if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { | |
3425 | int hdrlen, recvd; | |
3426 | ||
3427 | /* We ignore &savep and don't do consistency checks on | |
3428 | * the attr length. Let userspace figure it out.... */ | |
3429 | hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; | |
3430 | recvd = req->rq_rcv_buf.len - hdrlen; | |
3431 | if (attrlen > recvd) { | |
3432 | printk(KERN_WARNING "NFS: server cheating in getattr" | |
3433 | " acl reply: attrlen %u > recvd %u\n", | |
3434 | attrlen, recvd); | |
3435 | return -EINVAL; | |
3436 | } | |
c04871e6 | 3437 | xdr_read_pages(xdr, attrlen); |
029d105e | 3438 | *acl_len = attrlen; |
8c233cf9 BF |
3439 | } else |
3440 | status = -EOPNOTSUPP; | |
029d105e BF |
3441 | |
3442 | out: | |
3443 | return status; | |
3444 | } | |
3445 | ||
1da177e4 LT |
3446 | static int |
3447 | decode_savefh(struct xdr_stream *xdr) | |
3448 | { | |
3449 | return decode_op_hdr(xdr, OP_SAVEFH); | |
3450 | } | |
3451 | ||
3452 | static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res) | |
3453 | { | |
3454 | uint32_t *p; | |
3455 | uint32_t bmlen; | |
3456 | int status; | |
3457 | ||
3458 | ||
3459 | status = decode_op_hdr(xdr, OP_SETATTR); | |
3460 | if (status) | |
3461 | return status; | |
3462 | READ_BUF(4); | |
3463 | READ32(bmlen); | |
3464 | READ_BUF(bmlen << 2); | |
3465 | return 0; | |
3466 | } | |
3467 | ||
3468 | static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp) | |
3469 | { | |
3470 | uint32_t *p; | |
3471 | uint32_t opnum; | |
3472 | int32_t nfserr; | |
3473 | ||
3474 | READ_BUF(8); | |
3475 | READ32(opnum); | |
3476 | if (opnum != OP_SETCLIENTID) { | |
3477 | printk(KERN_NOTICE | |
3478 | "nfs4_decode_setclientid: Server returned operation" | |
3479 | " %d\n", opnum); | |
3480 | return -EIO; | |
3481 | } | |
3482 | READ32(nfserr); | |
3483 | if (nfserr == NFS_OK) { | |
3484 | READ_BUF(8 + sizeof(clp->cl_confirm.data)); | |
3485 | READ64(clp->cl_clientid); | |
3486 | COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data)); | |
3487 | } else if (nfserr == NFSERR_CLID_INUSE) { | |
3488 | uint32_t len; | |
3489 | ||
3490 | /* skip netid string */ | |
3491 | READ_BUF(4); | |
3492 | READ32(len); | |
3493 | READ_BUF(len); | |
3494 | ||
3495 | /* skip uaddr string */ | |
3496 | READ_BUF(4); | |
3497 | READ32(len); | |
3498 | READ_BUF(len); | |
3499 | return -NFSERR_CLID_INUSE; | |
3500 | } else | |
3501 | return -nfs_stat_to_errno(nfserr); | |
3502 | ||
3503 | return 0; | |
3504 | } | |
3505 | ||
3506 | static int decode_setclientid_confirm(struct xdr_stream *xdr) | |
3507 | { | |
3508 | return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); | |
3509 | } | |
3510 | ||
3511 | static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) | |
3512 | { | |
3513 | uint32_t *p; | |
3514 | int status; | |
3515 | ||
3516 | status = decode_op_hdr(xdr, OP_WRITE); | |
3517 | if (status) | |
3518 | return status; | |
3519 | ||
3520 | READ_BUF(16); | |
3521 | READ32(res->count); | |
3522 | READ32(res->verf->committed); | |
3523 | COPYMEM(res->verf->verifier, 8); | |
3524 | return 0; | |
3525 | } | |
3526 | ||
3527 | static int decode_delegreturn(struct xdr_stream *xdr) | |
3528 | { | |
3529 | return decode_op_hdr(xdr, OP_DELEGRETURN); | |
3530 | } | |
3531 | ||
3532 | /* | |
3533 | * Decode OPEN_DOWNGRADE response | |
3534 | */ | |
3535 | static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res) | |
3536 | { | |
3537 | struct xdr_stream xdr; | |
3538 | struct compound_hdr hdr; | |
3539 | int status; | |
3540 | ||
3541 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3542 | status = decode_compound_hdr(&xdr, &hdr); | |
3543 | if (status) | |
3544 | goto out; | |
3545 | status = decode_putfh(&xdr); | |
3546 | if (status) | |
3547 | goto out; | |
3548 | status = decode_open_downgrade(&xdr, res); | |
516a6af6 TM |
3549 | if (status != 0) |
3550 | goto out; | |
3551 | decode_getfattr(&xdr, res->fattr, res->server); | |
1da177e4 LT |
3552 | out: |
3553 | return status; | |
3554 | } | |
3555 | ||
3556 | /* | |
3557 | * END OF "GENERIC" DECODE ROUTINES. | |
3558 | */ | |
3559 | ||
3560 | /* | |
3561 | * Decode ACCESS response | |
3562 | */ | |
3563 | static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res) | |
3564 | { | |
3565 | struct xdr_stream xdr; | |
3566 | struct compound_hdr hdr; | |
3567 | int status; | |
3568 | ||
3569 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3570 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) | |
3571 | goto out; | |
3572 | if ((status = decode_putfh(&xdr)) == 0) | |
3573 | status = decode_access(&xdr, res); | |
3574 | out: | |
3575 | return status; | |
3576 | } | |
3577 | ||
3578 | /* | |
3579 | * Decode LOOKUP response | |
3580 | */ | |
3581 | static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res) | |
3582 | { | |
3583 | struct xdr_stream xdr; | |
3584 | struct compound_hdr hdr; | |
3585 | int status; | |
3586 | ||
3587 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3588 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) | |
3589 | goto out; | |
3590 | if ((status = decode_putfh(&xdr)) != 0) | |
3591 | goto out; | |
3592 | if ((status = decode_lookup(&xdr)) != 0) | |
3593 | goto out; | |
3594 | if ((status = decode_getfh(&xdr, res->fh)) != 0) | |
3595 | goto out; | |
3596 | status = decode_getfattr(&xdr, res->fattr, res->server); | |
3597 | out: | |
3598 | return status; | |
3599 | } | |
3600 | ||
3601 | /* | |
3602 | * Decode LOOKUP_ROOT response | |
3603 | */ | |
3604 | static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res) | |
3605 | { | |
3606 | struct xdr_stream xdr; | |
3607 | struct compound_hdr hdr; | |
3608 | int status; | |
3609 | ||
3610 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3611 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) | |
3612 | goto out; | |
3613 | if ((status = decode_putrootfh(&xdr)) != 0) | |
3614 | goto out; | |
3615 | if ((status = decode_getfh(&xdr, res->fh)) == 0) | |
3616 | status = decode_getfattr(&xdr, res->fattr, res->server); | |
3617 | out: | |
3618 | return status; | |
3619 | } | |
3620 | ||
3621 | /* | |
3622 | * Decode REMOVE response | |
3623 | */ | |
16e42959 | 3624 | static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_remove_res *res) |
1da177e4 LT |
3625 | { |
3626 | struct xdr_stream xdr; | |
3627 | struct compound_hdr hdr; | |
3628 | int status; | |
3629 | ||
3630 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3631 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) | |
3632 | goto out; | |
16e42959 TM |
3633 | if ((status = decode_putfh(&xdr)) != 0) |
3634 | goto out; | |
3635 | if ((status = decode_remove(&xdr, &res->cinfo)) != 0) | |
3636 | goto out; | |
3637 | decode_getfattr(&xdr, res->dir_attr, res->server); | |
1da177e4 LT |
3638 | out: |
3639 | return status; | |
3640 | } | |
3641 | ||
3642 | /* | |
3643 | * Decode RENAME response | |
3644 | */ | |
3645 | static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res) | |
3646 | { | |
3647 | struct xdr_stream xdr; | |
3648 | struct compound_hdr hdr; | |
3649 | int status; | |
3650 | ||
3651 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3652 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) | |
3653 | goto out; | |
3654 | if ((status = decode_putfh(&xdr)) != 0) | |
3655 | goto out; | |
3656 | if ((status = decode_savefh(&xdr)) != 0) | |
3657 | goto out; | |
3658 | if ((status = decode_putfh(&xdr)) != 0) | |
3659 | goto out; | |
6caf2c82 TM |
3660 | if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0) |
3661 | goto out; | |
3662 | /* Current FH is target directory */ | |
3663 | if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0) | |
3664 | goto out; | |
3665 | if ((status = decode_restorefh(&xdr)) != 0) | |
3666 | goto out; | |
3667 | decode_getfattr(&xdr, res->old_fattr, res->server); | |
1da177e4 LT |
3668 | out: |
3669 | return status; | |
3670 | } | |
3671 | ||
3672 | /* | |
3673 | * Decode LINK response | |
3674 | */ | |
91ba2eee | 3675 | static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_link_res *res) |
1da177e4 LT |
3676 | { |
3677 | struct xdr_stream xdr; | |
3678 | struct compound_hdr hdr; | |
3679 | int status; | |
3680 | ||
3681 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3682 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) | |
3683 | goto out; | |
3684 | if ((status = decode_putfh(&xdr)) != 0) | |
3685 | goto out; | |
3686 | if ((status = decode_savefh(&xdr)) != 0) | |
3687 | goto out; | |
3688 | if ((status = decode_putfh(&xdr)) != 0) | |
3689 | goto out; | |
91ba2eee TM |
3690 | if ((status = decode_link(&xdr, &res->cinfo)) != 0) |
3691 | goto out; | |
3692 | /* | |
3693 | * Note order: OP_LINK leaves the directory as the current | |
3694 | * filehandle. | |
3695 | */ | |
3696 | if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0) | |
3697 | goto out; | |
3698 | if ((status = decode_restorefh(&xdr)) != 0) | |
3699 | goto out; | |
3700 | decode_getfattr(&xdr, res->fattr, res->server); | |
1da177e4 LT |
3701 | out: |
3702 | return status; | |
3703 | } | |
3704 | ||
3705 | /* | |
3706 | * Decode CREATE response | |
3707 | */ | |
3708 | static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res) | |
3709 | { | |
3710 | struct xdr_stream xdr; | |
3711 | struct compound_hdr hdr; | |
3712 | int status; | |
3713 | ||
3714 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3715 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) | |
3716 | goto out; | |
3717 | if ((status = decode_putfh(&xdr)) != 0) | |
3718 | goto out; | |
56ae19f3 TM |
3719 | if ((status = decode_savefh(&xdr)) != 0) |
3720 | goto out; | |
1da177e4 LT |
3721 | if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0) |
3722 | goto out; | |
3723 | if ((status = decode_getfh(&xdr, res->fh)) != 0) | |
3724 | goto out; | |
56ae19f3 TM |
3725 | if (decode_getfattr(&xdr, res->fattr, res->server) != 0) |
3726 | goto out; | |
3727 | if ((status = decode_restorefh(&xdr)) != 0) | |
3728 | goto out; | |
3729 | decode_getfattr(&xdr, res->dir_fattr, res->server); | |
1da177e4 LT |
3730 | out: |
3731 | return status; | |
3732 | } | |
3733 | ||
3734 | /* | |
3735 | * Decode SYMLINK response | |
3736 | */ | |
3737 | static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res) | |
3738 | { | |
3739 | return nfs4_xdr_dec_create(rqstp, p, res); | |
3740 | } | |
3741 | ||
3742 | /* | |
3743 | * Decode GETATTR response | |
3744 | */ | |
3745 | static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res) | |
3746 | { | |
3747 | struct xdr_stream xdr; | |
3748 | struct compound_hdr hdr; | |
3749 | int status; | |
3750 | ||
3751 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3752 | status = decode_compound_hdr(&xdr, &hdr); | |
3753 | if (status) | |
3754 | goto out; | |
3755 | status = decode_putfh(&xdr); | |
3756 | if (status) | |
3757 | goto out; | |
3758 | status = decode_getfattr(&xdr, res->fattr, res->server); | |
3759 | out: | |
3760 | return status; | |
3761 | ||
3762 | } | |
3763 | ||
23ec6965 BF |
3764 | /* |
3765 | * Encode an SETACL request | |
3766 | */ | |
3767 | static int | |
3768 | nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args) | |
3769 | { | |
3770 | struct xdr_stream xdr; | |
3771 | struct compound_hdr hdr = { | |
3772 | .nops = 2, | |
3773 | }; | |
3774 | int status; | |
3775 | ||
3776 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
3777 | encode_compound_hdr(&xdr, &hdr); | |
3778 | status = encode_putfh(&xdr, args->fh); | |
3779 | if (status) | |
3780 | goto out; | |
3781 | status = encode_setacl(&xdr, args); | |
3782 | out: | |
3783 | return status; | |
3784 | } | |
3785 | /* | |
3786 | * Decode SETACL response | |
3787 | */ | |
3788 | static int | |
3789 | nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res) | |
3790 | { | |
3791 | struct xdr_stream xdr; | |
3792 | struct compound_hdr hdr; | |
3793 | int status; | |
3794 | ||
3795 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3796 | status = decode_compound_hdr(&xdr, &hdr); | |
3797 | if (status) | |
3798 | goto out; | |
3799 | status = decode_putfh(&xdr); | |
3800 | if (status) | |
3801 | goto out; | |
3802 | status = decode_setattr(&xdr, res); | |
3803 | out: | |
3804 | return status; | |
3805 | } | |
1da177e4 | 3806 | |
029d105e BF |
3807 | /* |
3808 | * Decode GETACL response | |
3809 | */ | |
3810 | static int | |
3811 | nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len) | |
3812 | { | |
3813 | struct xdr_stream xdr; | |
3814 | struct compound_hdr hdr; | |
3815 | int status; | |
3816 | ||
3817 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3818 | status = decode_compound_hdr(&xdr, &hdr); | |
3819 | if (status) | |
3820 | goto out; | |
3821 | status = decode_putfh(&xdr); | |
3822 | if (status) | |
3823 | goto out; | |
3824 | status = decode_getacl(&xdr, rqstp, acl_len); | |
3825 | ||
3826 | out: | |
3827 | return status; | |
3828 | } | |
3829 | ||
1da177e4 LT |
3830 | /* |
3831 | * Decode CLOSE response | |
3832 | */ | |
3833 | static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res) | |
3834 | { | |
3835 | struct xdr_stream xdr; | |
3836 | struct compound_hdr hdr; | |
3837 | int status; | |
3838 | ||
3839 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3840 | status = decode_compound_hdr(&xdr, &hdr); | |
3841 | if (status) | |
3842 | goto out; | |
3843 | status = decode_putfh(&xdr); | |
3844 | if (status) | |
3845 | goto out; | |
3846 | status = decode_close(&xdr, res); | |
516a6af6 TM |
3847 | if (status != 0) |
3848 | goto out; | |
3849 | /* | |
3850 | * Note: Server may do delete on close for this file | |
3851 | * in which case the getattr call will fail with | |
3852 | * an ESTALE error. Shouldn't be a problem, | |
3853 | * though, since fattr->valid will remain unset. | |
3854 | */ | |
3855 | decode_getfattr(&xdr, res->fattr, res->server); | |
1da177e4 LT |
3856 | out: |
3857 | return status; | |
3858 | } | |
3859 | ||
3860 | /* | |
3861 | * Decode OPEN response | |
3862 | */ | |
3863 | static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res) | |
3864 | { | |
3865 | struct xdr_stream xdr; | |
3866 | struct compound_hdr hdr; | |
3867 | int status; | |
3868 | ||
3869 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3870 | status = decode_compound_hdr(&xdr, &hdr); | |
3871 | if (status) | |
3872 | goto out; | |
3873 | status = decode_putfh(&xdr); | |
3874 | if (status) | |
3875 | goto out; | |
56ae19f3 TM |
3876 | status = decode_savefh(&xdr); |
3877 | if (status) | |
3878 | goto out; | |
1da177e4 LT |
3879 | status = decode_open(&xdr, res); |
3880 | if (status) | |
3881 | goto out; | |
3882 | status = decode_getfh(&xdr, &res->fh); | |
3883 | if (status) | |
3884 | goto out; | |
56ae19f3 TM |
3885 | if (decode_getfattr(&xdr, res->f_attr, res->server) != 0) |
3886 | goto out; | |
3887 | if ((status = decode_restorefh(&xdr)) != 0) | |
3888 | goto out; | |
3889 | decode_getfattr(&xdr, res->dir_attr, res->server); | |
1da177e4 LT |
3890 | out: |
3891 | return status; | |
3892 | } | |
3893 | ||
3894 | /* | |
3895 | * Decode OPEN_CONFIRM response | |
3896 | */ | |
3897 | static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res) | |
3898 | { | |
3899 | struct xdr_stream xdr; | |
3900 | struct compound_hdr hdr; | |
3901 | int status; | |
3902 | ||
3903 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3904 | status = decode_compound_hdr(&xdr, &hdr); | |
3905 | if (status) | |
3906 | goto out; | |
3907 | status = decode_putfh(&xdr); | |
3908 | if (status) | |
3909 | goto out; | |
3910 | status = decode_open_confirm(&xdr, res); | |
3911 | out: | |
3912 | return status; | |
3913 | } | |
3914 | ||
3915 | /* | |
3916 | * Decode OPEN response | |
3917 | */ | |
3918 | static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res) | |
3919 | { | |
3920 | struct xdr_stream xdr; | |
3921 | struct compound_hdr hdr; | |
3922 | int status; | |
3923 | ||
3924 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3925 | status = decode_compound_hdr(&xdr, &hdr); | |
3926 | if (status) | |
3927 | goto out; | |
3928 | status = decode_putfh(&xdr); | |
3929 | if (status) | |
3930 | goto out; | |
3931 | status = decode_open(&xdr, res); | |
864472e9 TM |
3932 | if (status) |
3933 | goto out; | |
3934 | decode_getfattr(&xdr, res->f_attr, res->server); | |
1da177e4 LT |
3935 | out: |
3936 | return status; | |
3937 | } | |
3938 | ||
3939 | /* | |
3940 | * Decode SETATTR response | |
3941 | */ | |
3942 | static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res) | |
3943 | { | |
3944 | struct xdr_stream xdr; | |
3945 | struct compound_hdr hdr; | |
3946 | int status; | |
3947 | ||
3948 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3949 | status = decode_compound_hdr(&xdr, &hdr); | |
3950 | if (status) | |
3951 | goto out; | |
3952 | status = decode_putfh(&xdr); | |
3953 | if (status) | |
3954 | goto out; | |
3955 | status = decode_setattr(&xdr, res); | |
3956 | if (status) | |
3957 | goto out; | |
3958 | status = decode_getfattr(&xdr, res->fattr, res->server); | |
3959 | if (status == NFS4ERR_DELAY) | |
3960 | status = 0; | |
3961 | out: | |
3962 | return status; | |
3963 | } | |
3964 | ||
3965 | /* | |
3966 | * Decode LOCK response | |
3967 | */ | |
911d1aaf | 3968 | static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lock_res *res) |
1da177e4 LT |
3969 | { |
3970 | struct xdr_stream xdr; | |
3971 | struct compound_hdr hdr; | |
3972 | int status; | |
3973 | ||
3974 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3975 | status = decode_compound_hdr(&xdr, &hdr); | |
3976 | if (status) | |
3977 | goto out; | |
3978 | status = decode_putfh(&xdr); | |
3979 | if (status) | |
3980 | goto out; | |
3981 | status = decode_lock(&xdr, res); | |
3982 | out: | |
3983 | return status; | |
3984 | } | |
3985 | ||
3986 | /* | |
3987 | * Decode LOCKT response | |
3988 | */ | |
911d1aaf | 3989 | static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockt_res *res) |
1da177e4 LT |
3990 | { |
3991 | struct xdr_stream xdr; | |
3992 | struct compound_hdr hdr; | |
3993 | int status; | |
3994 | ||
3995 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
3996 | status = decode_compound_hdr(&xdr, &hdr); | |
3997 | if (status) | |
3998 | goto out; | |
3999 | status = decode_putfh(&xdr); | |
4000 | if (status) | |
4001 | goto out; | |
4002 | status = decode_lockt(&xdr, res); | |
4003 | out: | |
4004 | return status; | |
4005 | } | |
4006 | ||
4007 | /* | |
4008 | * Decode LOCKU response | |
4009 | */ | |
911d1aaf | 4010 | static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_locku_res *res) |
1da177e4 LT |
4011 | { |
4012 | struct xdr_stream xdr; | |
4013 | struct compound_hdr hdr; | |
4014 | int status; | |
4015 | ||
4016 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4017 | status = decode_compound_hdr(&xdr, &hdr); | |
4018 | if (status) | |
4019 | goto out; | |
4020 | status = decode_putfh(&xdr); | |
4021 | if (status) | |
4022 | goto out; | |
4023 | status = decode_locku(&xdr, res); | |
4024 | out: | |
4025 | return status; | |
4026 | } | |
4027 | ||
4028 | /* | |
4029 | * Decode READLINK response | |
4030 | */ | |
4031 | static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res) | |
4032 | { | |
4033 | struct xdr_stream xdr; | |
4034 | struct compound_hdr hdr; | |
4035 | int status; | |
4036 | ||
4037 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4038 | status = decode_compound_hdr(&xdr, &hdr); | |
4039 | if (status) | |
4040 | goto out; | |
4041 | status = decode_putfh(&xdr); | |
4042 | if (status) | |
4043 | goto out; | |
4044 | status = decode_readlink(&xdr, rqstp); | |
4045 | out: | |
4046 | return status; | |
4047 | } | |
4048 | ||
4049 | /* | |
4050 | * Decode READDIR response | |
4051 | */ | |
4052 | static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res) | |
4053 | { | |
4054 | struct xdr_stream xdr; | |
4055 | struct compound_hdr hdr; | |
4056 | int status; | |
4057 | ||
4058 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4059 | status = decode_compound_hdr(&xdr, &hdr); | |
4060 | if (status) | |
4061 | goto out; | |
4062 | status = decode_putfh(&xdr); | |
4063 | if (status) | |
4064 | goto out; | |
4065 | status = decode_readdir(&xdr, rqstp, res); | |
4066 | out: | |
4067 | return status; | |
4068 | } | |
4069 | ||
4070 | /* | |
4071 | * Decode Read response | |
4072 | */ | |
4073 | static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res) | |
4074 | { | |
4075 | struct xdr_stream xdr; | |
4076 | struct compound_hdr hdr; | |
4077 | int status; | |
4078 | ||
4079 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4080 | status = decode_compound_hdr(&xdr, &hdr); | |
4081 | if (status) | |
4082 | goto out; | |
4083 | status = decode_putfh(&xdr); | |
4084 | if (status) | |
4085 | goto out; | |
4086 | status = decode_read(&xdr, rqstp, res); | |
4087 | if (!status) | |
4088 | status = res->count; | |
4089 | out: | |
4090 | return status; | |
4091 | } | |
4092 | ||
4093 | /* | |
4094 | * Decode WRITE response | |
4095 | */ | |
4096 | static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res) | |
4097 | { | |
4098 | struct xdr_stream xdr; | |
4099 | struct compound_hdr hdr; | |
4100 | int status; | |
4101 | ||
4102 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4103 | status = decode_compound_hdr(&xdr, &hdr); | |
4104 | if (status) | |
4105 | goto out; | |
4106 | status = decode_putfh(&xdr); | |
4107 | if (status) | |
4108 | goto out; | |
4109 | status = decode_write(&xdr, res); | |
4f9838c7 TM |
4110 | if (status) |
4111 | goto out; | |
4112 | decode_getfattr(&xdr, res->fattr, res->server); | |
1da177e4 LT |
4113 | if (!status) |
4114 | status = res->count; | |
4115 | out: | |
4116 | return status; | |
4117 | } | |
4118 | ||
4119 | /* | |
4120 | * Decode COMMIT response | |
4121 | */ | |
4122 | static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res) | |
4123 | { | |
4124 | struct xdr_stream xdr; | |
4125 | struct compound_hdr hdr; | |
4126 | int status; | |
4127 | ||
4128 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4129 | status = decode_compound_hdr(&xdr, &hdr); | |
4130 | if (status) | |
4131 | goto out; | |
4132 | status = decode_putfh(&xdr); | |
4133 | if (status) | |
4134 | goto out; | |
4135 | status = decode_commit(&xdr, res); | |
4f9838c7 TM |
4136 | if (status) |
4137 | goto out; | |
4138 | decode_getfattr(&xdr, res->fattr, res->server); | |
1da177e4 LT |
4139 | out: |
4140 | return status; | |
4141 | } | |
4142 | ||
4143 | /* | |
4144 | * FSINFO request | |
4145 | */ | |
4146 | static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo) | |
4147 | { | |
4148 | struct xdr_stream xdr; | |
4149 | struct compound_hdr hdr; | |
4150 | int status; | |
4151 | ||
4152 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
4153 | status = decode_compound_hdr(&xdr, &hdr); | |
4154 | if (!status) | |
4155 | status = decode_putfh(&xdr); | |
4156 | if (!status) | |
4157 | status = decode_fsinfo(&xdr, fsinfo); | |
4158 | if (!status) | |
4159 | status = -nfs_stat_to_errno(hdr.status); | |
4160 | return status; | |
4161 | } | |
4162 | ||
4163 | /* | |
4164 | * PATHCONF request | |
4165 | */ | |
4166 | static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf) | |
4167 | { | |
4168 | struct xdr_stream xdr; | |
4169 | struct compound_hdr hdr; | |
4170 | int status; | |
4171 | ||
4172 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
4173 | status = decode_compound_hdr(&xdr, &hdr); | |
4174 | if (!status) | |
4175 | status = decode_putfh(&xdr); | |
4176 | if (!status) | |
4177 | status = decode_pathconf(&xdr, pathconf); | |
4178 | return status; | |
4179 | } | |
4180 | ||
4181 | /* | |
4182 | * STATFS request | |
4183 | */ | |
4184 | static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat) | |
4185 | { | |
4186 | struct xdr_stream xdr; | |
4187 | struct compound_hdr hdr; | |
4188 | int status; | |
4189 | ||
4190 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
4191 | status = decode_compound_hdr(&xdr, &hdr); | |
4192 | if (!status) | |
4193 | status = decode_putfh(&xdr); | |
4194 | if (!status) | |
4195 | status = decode_statfs(&xdr, fsstat); | |
4196 | return status; | |
4197 | } | |
4198 | ||
4199 | /* | |
4200 | * GETATTR_BITMAP request | |
4201 | */ | |
4202 | static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res) | |
4203 | { | |
4204 | struct xdr_stream xdr; | |
4205 | struct compound_hdr hdr; | |
4206 | int status; | |
4207 | ||
4208 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
4209 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) | |
4210 | goto out; | |
4211 | if ((status = decode_putfh(&xdr)) != 0) | |
4212 | goto out; | |
4213 | status = decode_server_caps(&xdr, res); | |
4214 | out: | |
4215 | return status; | |
4216 | } | |
4217 | ||
4218 | /* | |
4219 | * Decode RENEW response | |
4220 | */ | |
4221 | static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy) | |
4222 | { | |
4223 | struct xdr_stream xdr; | |
4224 | struct compound_hdr hdr; | |
4225 | int status; | |
4226 | ||
4227 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4228 | status = decode_compound_hdr(&xdr, &hdr); | |
4229 | if (!status) | |
4230 | status = decode_renew(&xdr); | |
4231 | return status; | |
4232 | } | |
4233 | ||
4234 | /* | |
4235 | * a SETCLIENTID request | |
4236 | */ | |
4237 | static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p, | |
4238 | struct nfs4_client *clp) | |
4239 | { | |
4240 | struct xdr_stream xdr; | |
4241 | struct compound_hdr hdr; | |
4242 | int status; | |
4243 | ||
4244 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
4245 | status = decode_compound_hdr(&xdr, &hdr); | |
4246 | if (!status) | |
4247 | status = decode_setclientid(&xdr, clp); | |
4248 | if (!status) | |
4249 | status = -nfs_stat_to_errno(hdr.status); | |
4250 | return status; | |
4251 | } | |
4252 | ||
4253 | /* | |
4254 | * a SETCLIENTID_CONFIRM request | |
4255 | */ | |
4256 | static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo) | |
4257 | { | |
4258 | struct xdr_stream xdr; | |
4259 | struct compound_hdr hdr; | |
4260 | int status; | |
4261 | ||
4262 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
4263 | status = decode_compound_hdr(&xdr, &hdr); | |
4264 | if (!status) | |
4265 | status = decode_setclientid_confirm(&xdr); | |
4266 | if (!status) | |
4267 | status = decode_putrootfh(&xdr); | |
4268 | if (!status) | |
4269 | status = decode_fsinfo(&xdr, fsinfo); | |
4270 | if (!status) | |
4271 | status = -nfs_stat_to_errno(hdr.status); | |
4272 | return status; | |
4273 | } | |
4274 | ||
4275 | /* | |
4276 | * DELEGRETURN request | |
4277 | */ | |
fa178f29 | 4278 | static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_delegreturnres *res) |
1da177e4 LT |
4279 | { |
4280 | struct xdr_stream xdr; | |
4281 | struct compound_hdr hdr; | |
4282 | int status; | |
4283 | ||
4284 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4285 | status = decode_compound_hdr(&xdr, &hdr); | |
fa178f29 TM |
4286 | if (status != 0) |
4287 | goto out; | |
4288 | status = decode_putfh(&xdr); | |
4289 | if (status != 0) | |
4290 | goto out; | |
4291 | status = decode_delegreturn(&xdr); | |
4292 | decode_getfattr(&xdr, res->fattr, res->server); | |
4293 | out: | |
1da177e4 LT |
4294 | return status; |
4295 | } | |
4296 | ||
683b57b4 TM |
4297 | /* |
4298 | * FS_LOCATIONS request | |
4299 | */ | |
4300 | static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, uint32_t *p, struct nfs_fs_locations *res) | |
4301 | { | |
4302 | struct xdr_stream xdr; | |
4303 | struct compound_hdr hdr; | |
4304 | int status; | |
4305 | ||
4306 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
4307 | status = decode_compound_hdr(&xdr, &hdr); | |
4308 | if (status != 0) | |
4309 | goto out; | |
4310 | if ((status = decode_putfh(&xdr)) != 0) | |
4311 | goto out; | |
4312 | if ((status = decode_lookup(&xdr)) != 0) | |
4313 | goto out; | |
4314 | xdr_enter_page(&xdr, PAGE_SIZE); | |
4315 | status = decode_getfattr(&xdr, &res->fattr, res->server); | |
4316 | out: | |
4317 | return status; | |
4318 | } | |
4319 | ||
1da177e4 LT |
4320 | uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus) |
4321 | { | |
4322 | uint32_t bitmap[2] = {0}; | |
4323 | uint32_t len; | |
4324 | ||
4325 | if (!*p++) { | |
4326 | if (!*p) | |
4327 | return ERR_PTR(-EAGAIN); | |
4328 | entry->eof = 1; | |
4329 | return ERR_PTR(-EBADCOOKIE); | |
4330 | } | |
4331 | ||
4332 | entry->prev_cookie = entry->cookie; | |
4333 | p = xdr_decode_hyper(p, &entry->cookie); | |
4334 | entry->len = ntohl(*p++); | |
4335 | entry->name = (const char *) p; | |
4336 | p += XDR_QUADLEN(entry->len); | |
4337 | ||
4338 | /* | |
4339 | * In case the server doesn't return an inode number, | |
4340 | * we fake one here. (We don't use inode number 0, | |
4341 | * since glibc seems to choke on it...) | |
4342 | */ | |
4343 | entry->ino = 1; | |
4344 | ||
4345 | len = ntohl(*p++); /* bitmap length */ | |
4346 | if (len-- > 0) { | |
4347 | bitmap[0] = ntohl(*p++); | |
4348 | if (len-- > 0) { | |
4349 | bitmap[1] = ntohl(*p++); | |
4350 | p += len; | |
4351 | } | |
4352 | } | |
4353 | len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */ | |
4354 | if (len > 0) { | |
97d312d0 MN |
4355 | if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) { |
4356 | bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; | |
4357 | /* Ignore the return value of rdattr_error for now */ | |
4358 | p++; | |
4359 | len--; | |
4360 | } | |
1da177e4 LT |
4361 | if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID) |
4362 | xdr_decode_hyper(p, &entry->ino); | |
4363 | else if (bitmap[0] == FATTR4_WORD0_FILEID) | |
4364 | xdr_decode_hyper(p, &entry->ino); | |
4365 | p += len; | |
4366 | } | |
4367 | ||
4368 | entry->eof = !p[0] && p[1]; | |
4369 | return p; | |
4370 | } | |
4371 | ||
4372 | /* | |
4373 | * We need to translate between nfs status return values and | |
4374 | * the local errno values which may not be the same. | |
4375 | */ | |
4376 | static struct { | |
4377 | int stat; | |
4378 | int errno; | |
4379 | } nfs_errtbl[] = { | |
4380 | { NFS4_OK, 0 }, | |
4381 | { NFS4ERR_PERM, EPERM }, | |
4382 | { NFS4ERR_NOENT, ENOENT }, | |
4383 | { NFS4ERR_IO, errno_NFSERR_IO }, | |
4384 | { NFS4ERR_NXIO, ENXIO }, | |
4385 | { NFS4ERR_ACCESS, EACCES }, | |
4386 | { NFS4ERR_EXIST, EEXIST }, | |
4387 | { NFS4ERR_XDEV, EXDEV }, | |
4388 | { NFS4ERR_NOTDIR, ENOTDIR }, | |
4389 | { NFS4ERR_ISDIR, EISDIR }, | |
4390 | { NFS4ERR_INVAL, EINVAL }, | |
4391 | { NFS4ERR_FBIG, EFBIG }, | |
4392 | { NFS4ERR_NOSPC, ENOSPC }, | |
4393 | { NFS4ERR_ROFS, EROFS }, | |
4394 | { NFS4ERR_MLINK, EMLINK }, | |
4395 | { NFS4ERR_NAMETOOLONG, ENAMETOOLONG }, | |
4396 | { NFS4ERR_NOTEMPTY, ENOTEMPTY }, | |
4397 | { NFS4ERR_DQUOT, EDQUOT }, | |
4398 | { NFS4ERR_STALE, ESTALE }, | |
4399 | { NFS4ERR_BADHANDLE, EBADHANDLE }, | |
6ebf3656 MN |
4400 | { NFS4ERR_BADOWNER, EINVAL }, |
4401 | { NFS4ERR_BADNAME, EINVAL }, | |
1da177e4 LT |
4402 | { NFS4ERR_BAD_COOKIE, EBADCOOKIE }, |
4403 | { NFS4ERR_NOTSUPP, ENOTSUPP }, | |
4404 | { NFS4ERR_TOOSMALL, ETOOSMALL }, | |
4405 | { NFS4ERR_SERVERFAULT, ESERVERFAULT }, | |
4406 | { NFS4ERR_BADTYPE, EBADTYPE }, | |
4407 | { NFS4ERR_LOCKED, EAGAIN }, | |
4408 | { NFS4ERR_RESOURCE, EREMOTEIO }, | |
4409 | { NFS4ERR_SYMLINK, ELOOP }, | |
4410 | { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP }, | |
4411 | { NFS4ERR_DEADLOCK, EDEADLK }, | |
4412 | { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs | |
4413 | * to be handled by a | |
4414 | * middle-layer. | |
4415 | */ | |
4416 | { -1, EIO } | |
4417 | }; | |
4418 | ||
4419 | /* | |
4420 | * Convert an NFS error code to a local one. | |
4421 | * This one is used jointly by NFSv2 and NFSv3. | |
4422 | */ | |
4423 | static int | |
4424 | nfs_stat_to_errno(int stat) | |
4425 | { | |
4426 | int i; | |
4427 | for (i = 0; nfs_errtbl[i].stat != -1; i++) { | |
4428 | if (nfs_errtbl[i].stat == stat) | |
4429 | return nfs_errtbl[i].errno; | |
4430 | } | |
4431 | if (stat <= 10000 || stat > 10100) { | |
4432 | /* The server is looney tunes. */ | |
4433 | return ESERVERFAULT; | |
4434 | } | |
4435 | /* If we cannot translate the error, the recovery routines should | |
4436 | * handle it. | |
4437 | * Note: remaining NFSv4 error codes have values > 10000, so should | |
4438 | * not conflict with native Linux error codes. | |
4439 | */ | |
4440 | return stat; | |
4441 | } | |
4442 | ||
4443 | #ifndef MAX | |
4444 | # define MAX(a, b) (((a) > (b))? (a) : (b)) | |
4445 | #endif | |
4446 | ||
4447 | #define PROC(proc, argtype, restype) \ | |
4448 | [NFSPROC4_CLNT_##proc] = { \ | |
4449 | .p_proc = NFSPROC4_COMPOUND, \ | |
4450 | .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \ | |
4451 | .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \ | |
4452 | .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \ | |
cc0175c1 CL |
4453 | .p_statidx = NFSPROC4_CLNT_##proc, \ |
4454 | .p_name = #proc, \ | |
1da177e4 LT |
4455 | } |
4456 | ||
4457 | struct rpc_procinfo nfs4_procedures[] = { | |
4458 | PROC(READ, enc_read, dec_read), | |
4459 | PROC(WRITE, enc_write, dec_write), | |
4460 | PROC(COMMIT, enc_commit, dec_commit), | |
4461 | PROC(OPEN, enc_open, dec_open), | |
4462 | PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), | |
4463 | PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), | |
4464 | PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), | |
4465 | PROC(CLOSE, enc_close, dec_close), | |
4466 | PROC(SETATTR, enc_setattr, dec_setattr), | |
4467 | PROC(FSINFO, enc_fsinfo, dec_fsinfo), | |
4468 | PROC(RENEW, enc_renew, dec_renew), | |
4469 | PROC(SETCLIENTID, enc_setclientid, dec_setclientid), | |
4470 | PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), | |
4471 | PROC(LOCK, enc_lock, dec_lock), | |
4472 | PROC(LOCKT, enc_lockt, dec_lockt), | |
4473 | PROC(LOCKU, enc_locku, dec_locku), | |
4474 | PROC(ACCESS, enc_access, dec_access), | |
4475 | PROC(GETATTR, enc_getattr, dec_getattr), | |
4476 | PROC(LOOKUP, enc_lookup, dec_lookup), | |
4477 | PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), | |
4478 | PROC(REMOVE, enc_remove, dec_remove), | |
4479 | PROC(RENAME, enc_rename, dec_rename), | |
4480 | PROC(LINK, enc_link, dec_link), | |
4481 | PROC(SYMLINK, enc_symlink, dec_symlink), | |
4482 | PROC(CREATE, enc_create, dec_create), | |
4483 | PROC(PATHCONF, enc_pathconf, dec_pathconf), | |
4484 | PROC(STATFS, enc_statfs, dec_statfs), | |
4485 | PROC(READLINK, enc_readlink, dec_readlink), | |
4486 | PROC(READDIR, enc_readdir, dec_readdir), | |
4487 | PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), | |
4488 | PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), | |
029d105e | 4489 | PROC(GETACL, enc_getacl, dec_getacl), |
23ec6965 | 4490 | PROC(SETACL, enc_setacl, dec_setacl), |
683b57b4 | 4491 | PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), |
1da177e4 LT |
4492 | }; |
4493 | ||
4494 | struct rpc_version nfs_version4 = { | |
4495 | .number = 4, | |
e8c96f8c | 4496 | .nrprocs = ARRAY_SIZE(nfs4_procedures), |
1da177e4 LT |
4497 | .procs = nfs4_procedures |
4498 | }; | |
4499 | ||
4500 | /* | |
4501 | * Local variables: | |
4502 | * c-basic-offset: 8 | |
4503 | * End: | |
4504 | */ |