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