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