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> | |
1da177e4 LT |
41 | #include <linux/errno.h> |
42 | #include <linux/string.h> | |
43 | #include <linux/in.h> | |
44 | #include <linux/pagemap.h> | |
45 | #include <linux/proc_fs.h> | |
46 | #include <linux/kdev_t.h> | |
47 | #include <linux/sunrpc/clnt.h> | |
2449ea2e | 48 | #include <linux/sunrpc/msg_prot.h> |
5a5ea0d4 | 49 | #include <linux/sunrpc/gss_api.h> |
1da177e4 LT |
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" |
4882ef72 | 55 | #include "internal.h" |
b1f69b75 | 56 | #include "pnfs.h" |
1da177e4 LT |
57 | |
58 | #define NFSDBG_FACILITY NFSDBG_XDR | |
59 | ||
60 | /* Mapping from NFS error code to "errno" error code. */ | |
61 | #define errno_NFSERR_IO EIO | |
62 | ||
0a8ea437 | 63 | static int nfs4_stat_to_errno(int); |
1da177e4 LT |
64 | |
65 | /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ | |
66 | #ifdef DEBUG | |
67 | #define NFS4_MAXTAGLEN 20 | |
68 | #else | |
69 | #define NFS4_MAXTAGLEN 0 | |
70 | #endif | |
71 | ||
6c0195a4 | 72 | /* lock,open owner id: |
9f958ab8 | 73 | * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) |
1da177e4 | 74 | */ |
d035c36c TM |
75 | #define open_owner_id_maxsz (1 + 1 + 4) |
76 | #define lock_owner_id_maxsz (1 + 1 + 4) | |
9104a55d | 77 | #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) |
1da177e4 LT |
78 | #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) |
79 | #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) | |
80 | #define op_encode_hdr_maxsz (1) | |
81 | #define op_decode_hdr_maxsz (2) | |
9104a55d TM |
82 | #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) |
83 | #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) | |
84 | #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) | |
85 | #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) | |
1da177e4 LT |
86 | #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ |
87 | (NFS4_FHSIZE >> 2)) | |
88 | #define decode_putfh_maxsz (op_decode_hdr_maxsz) | |
89 | #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) | |
90 | #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) | |
91 | #define encode_getfh_maxsz (op_encode_hdr_maxsz) | |
92 | #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ | |
93 | ((3+NFS4_FHSIZE) >> 2)) | |
e5012d1f | 94 | #define nfs4_fattr_bitmap_maxsz 4 |
96928206 | 95 | #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) |
1da177e4 LT |
96 | #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) |
97 | #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) | |
bd625ba8 TM |
98 | #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) |
99 | #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) | |
96928206 BF |
100 | /* This is based on getfattr, which uses the most attributes: */ |
101 | #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ | |
bd625ba8 | 102 | 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz)) |
96928206 BF |
103 | #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ |
104 | nfs4_fattr_value_maxsz) | |
105 | #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) | |
9104a55d TM |
106 | #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ |
107 | 1 + 2 + 1 + \ | |
108 | nfs4_owner_maxsz + \ | |
109 | nfs4_group_maxsz + \ | |
110 | 4 + 4) | |
1da177e4 LT |
111 | #define encode_savefh_maxsz (op_encode_hdr_maxsz) |
112 | #define decode_savefh_maxsz (op_decode_hdr_maxsz) | |
56ae19f3 TM |
113 | #define encode_restorefh_maxsz (op_encode_hdr_maxsz) |
114 | #define decode_restorefh_maxsz (op_decode_hdr_maxsz) | |
2f42b5d0 | 115 | #define encode_fsinfo_maxsz (encode_getattr_maxsz) |
7ebb9315 | 116 | #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 15) |
1da177e4 LT |
117 | #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) |
118 | #define decode_renew_maxsz (op_decode_hdr_maxsz) | |
119 | #define encode_setclientid_maxsz \ | |
120 | (op_encode_hdr_maxsz + \ | |
cc38bac3 CL |
121 | XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ |
122 | XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \ | |
123 | 1 /* sc_prog */ + \ | |
124 | XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ | |
125 | XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ | |
126 | 1) /* sc_cb_ident */ | |
1da177e4 LT |
127 | #define decode_setclientid_maxsz \ |
128 | (op_decode_hdr_maxsz + \ | |
129 | 2 + \ | |
130 | 1024) /* large value for CLID_INUSE */ | |
131 | #define encode_setclientid_confirm_maxsz \ | |
132 | (op_encode_hdr_maxsz + \ | |
133 | 3 + (NFS4_VERIFIER_SIZE >> 2)) | |
134 | #define decode_setclientid_confirm_maxsz \ | |
135 | (op_decode_hdr_maxsz) | |
e6889620 TM |
136 | #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) |
137 | #define decode_lookup_maxsz (op_decode_hdr_maxsz) | |
2cebf828 TM |
138 | #define encode_share_access_maxsz \ |
139 | (2) | |
4882ef72 | 140 | #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) |
2cebf828 TM |
141 | #define encode_opentype_maxsz (1 + encode_createmode_maxsz) |
142 | #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) | |
143 | #define encode_open_maxsz (op_encode_hdr_maxsz + \ | |
144 | 2 + encode_share_access_maxsz + 2 + \ | |
145 | open_owner_id_maxsz + \ | |
146 | encode_opentype_maxsz + \ | |
147 | encode_claim_null_maxsz) | |
148 | #define decode_ace_maxsz (3 + nfs4_owner_maxsz) | |
9104a55d | 149 | #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ |
2cebf828 TM |
150 | decode_ace_maxsz) |
151 | #define decode_change_info_maxsz (5) | |
152 | #define decode_open_maxsz (op_decode_hdr_maxsz + \ | |
9104a55d | 153 | decode_stateid_maxsz + \ |
2cebf828 TM |
154 | decode_change_info_maxsz + 1 + \ |
155 | nfs4_fattr_bitmap_maxsz + \ | |
156 | decode_delegation_maxsz) | |
9104a55d TM |
157 | #define encode_open_confirm_maxsz \ |
158 | (op_encode_hdr_maxsz + \ | |
159 | encode_stateid_maxsz + 1) | |
160 | #define decode_open_confirm_maxsz \ | |
161 | (op_decode_hdr_maxsz + \ | |
162 | decode_stateid_maxsz) | |
163 | #define encode_open_downgrade_maxsz \ | |
164 | (op_encode_hdr_maxsz + \ | |
165 | encode_stateid_maxsz + 1 + \ | |
166 | encode_share_access_maxsz) | |
167 | #define decode_open_downgrade_maxsz \ | |
168 | (op_decode_hdr_maxsz + \ | |
169 | decode_stateid_maxsz) | |
170 | #define encode_close_maxsz (op_encode_hdr_maxsz + \ | |
171 | 1 + encode_stateid_maxsz) | |
172 | #define decode_close_maxsz (op_decode_hdr_maxsz + \ | |
173 | decode_stateid_maxsz) | |
174 | #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ | |
175 | encode_stateid_maxsz + \ | |
176 | encode_attrs_maxsz) | |
177 | #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ | |
178 | nfs4_fattr_bitmap_maxsz) | |
179 | #define encode_read_maxsz (op_encode_hdr_maxsz + \ | |
180 | encode_stateid_maxsz + 3) | |
181 | #define decode_read_maxsz (op_decode_hdr_maxsz + 2) | |
182 | #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ | |
183 | 2 + encode_verifier_maxsz + 5) | |
184 | #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ | |
185 | decode_verifier_maxsz) | |
186 | #define encode_readlink_maxsz (op_encode_hdr_maxsz) | |
187 | #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) | |
188 | #define encode_write_maxsz (op_encode_hdr_maxsz + \ | |
189 | encode_stateid_maxsz + 4) | |
190 | #define decode_write_maxsz (op_decode_hdr_maxsz + \ | |
191 | 2 + decode_verifier_maxsz) | |
192 | #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) | |
193 | #define decode_commit_maxsz (op_decode_hdr_maxsz + \ | |
194 | decode_verifier_maxsz) | |
1da177e4 LT |
195 | #define encode_remove_maxsz (op_encode_hdr_maxsz + \ |
196 | nfs4_name_maxsz) | |
6ce18391 BH |
197 | #define decode_remove_maxsz (op_decode_hdr_maxsz + \ |
198 | decode_change_info_maxsz) | |
1da177e4 LT |
199 | #define encode_rename_maxsz (op_encode_hdr_maxsz + \ |
200 | 2 * nfs4_name_maxsz) | |
6ce18391 BH |
201 | #define decode_rename_maxsz (op_decode_hdr_maxsz + \ |
202 | decode_change_info_maxsz + \ | |
203 | decode_change_info_maxsz) | |
1da177e4 LT |
204 | #define encode_link_maxsz (op_encode_hdr_maxsz + \ |
205 | nfs4_name_maxsz) | |
6ce18391 | 206 | #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) |
daccbded | 207 | #define encode_lockowner_maxsz (7) |
9104a55d TM |
208 | #define encode_lock_maxsz (op_encode_hdr_maxsz + \ |
209 | 7 + \ | |
daccbded TM |
210 | 1 + encode_stateid_maxsz + 1 + \ |
211 | encode_lockowner_maxsz) | |
9104a55d TM |
212 | #define decode_lock_denied_maxsz \ |
213 | (8 + decode_lockowner_maxsz) | |
214 | #define decode_lock_maxsz (op_decode_hdr_maxsz + \ | |
215 | decode_lock_denied_maxsz) | |
daccbded TM |
216 | #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ |
217 | encode_lockowner_maxsz) | |
9104a55d TM |
218 | #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ |
219 | decode_lock_denied_maxsz) | |
220 | #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ | |
221 | encode_stateid_maxsz + \ | |
222 | 4) | |
223 | #define decode_locku_maxsz (op_decode_hdr_maxsz + \ | |
224 | decode_stateid_maxsz) | |
d3c7b7cc TM |
225 | #define encode_release_lockowner_maxsz \ |
226 | (op_encode_hdr_maxsz + \ | |
227 | encode_lockowner_maxsz) | |
228 | #define decode_release_lockowner_maxsz \ | |
229 | (op_decode_hdr_maxsz) | |
9104a55d TM |
230 | #define encode_access_maxsz (op_encode_hdr_maxsz + 1) |
231 | #define decode_access_maxsz (op_decode_hdr_maxsz + 2) | |
1da177e4 LT |
232 | #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ |
233 | 1 + nfs4_name_maxsz + \ | |
94a6d753 | 234 | 1 + \ |
96928206 | 235 | nfs4_fattr_maxsz) |
1da177e4 LT |
236 | #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) |
237 | #define encode_create_maxsz (op_encode_hdr_maxsz + \ | |
9104a55d TM |
238 | 1 + 2 + nfs4_name_maxsz + \ |
239 | encode_attrs_maxsz) | |
2cebf828 TM |
240 | #define decode_create_maxsz (op_decode_hdr_maxsz + \ |
241 | decode_change_info_maxsz + \ | |
242 | nfs4_fattr_bitmap_maxsz) | |
9104a55d TM |
243 | #define encode_statfs_maxsz (encode_getattr_maxsz) |
244 | #define decode_statfs_maxsz (decode_getattr_maxsz) | |
1da177e4 LT |
245 | #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) |
246 | #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) | |
9104a55d TM |
247 | #define encode_getacl_maxsz (encode_getattr_maxsz) |
248 | #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ | |
249 | nfs4_fattr_bitmap_maxsz + 1) | |
250 | #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ | |
251 | encode_stateid_maxsz + 3) | |
252 | #define decode_setacl_maxsz (decode_setattr_maxsz) | |
e6889620 TM |
253 | #define encode_fs_locations_maxsz \ |
254 | (encode_getattr_maxsz) | |
255 | #define decode_fs_locations_maxsz \ | |
256 | (0) | |
5a5ea0d4 | 257 | #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) |
1650add2 | 258 | #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) |
9b7b9fcc AA |
259 | |
260 | #if defined(CONFIG_NFS_V4_1) | |
fc931582 AA |
261 | #define NFS4_MAX_MACHINE_NAME_LEN (64) |
262 | ||
99fe60d0 BH |
263 | #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ |
264 | encode_verifier_maxsz + \ | |
265 | 1 /* co_ownerid.len */ + \ | |
266 | XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \ | |
267 | 1 /* flags */ + \ | |
268 | 1 /* spa_how */ + \ | |
269 | 0 /* SP4_NONE (for now) */ + \ | |
270 | 1 /* zero implemetation id array */) | |
271 | #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ | |
272 | 2 /* eir_clientid */ + \ | |
273 | 1 /* eir_sequenceid */ + \ | |
274 | 1 /* eir_flags */ + \ | |
275 | 1 /* spr_how */ + \ | |
276 | 0 /* SP4_NONE (for now) */ + \ | |
277 | 2 /* eir_server_owner.so_minor_id */ + \ | |
278 | /* eir_server_owner.so_major_id<> */ \ | |
279 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ | |
280 | /* eir_server_scope<> */ \ | |
281 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ | |
282 | 1 /* eir_server_impl_id array length */ + \ | |
283 | 0 /* ignored eir_server_impl_id contents */) | |
fc931582 AA |
284 | #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) |
285 | #define decode_channel_attrs_maxsz (6 + \ | |
286 | 1 /* ca_rdma_ird.len */ + \ | |
287 | 1 /* ca_rdma_ird */) | |
288 | #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ | |
289 | 2 /* csa_clientid */ + \ | |
290 | 1 /* csa_sequence */ + \ | |
291 | 1 /* csa_flags */ + \ | |
292 | encode_channel_attrs_maxsz + \ | |
293 | encode_channel_attrs_maxsz + \ | |
294 | 1 /* csa_cb_program */ + \ | |
295 | 1 /* csa_sec_parms.len (1) */ + \ | |
296 | 1 /* cb_secflavor (AUTH_SYS) */ + \ | |
297 | 1 /* stamp */ + \ | |
298 | 1 /* machinename.len */ + \ | |
299 | XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ | |
300 | 1 /* uid */ + \ | |
301 | 1 /* gid */ + \ | |
302 | 1 /* gids.len (0) */) | |
303 | #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ | |
304 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ | |
305 | 1 /* csr_sequence */ + \ | |
306 | 1 /* csr_flags */ + \ | |
307 | decode_channel_attrs_maxsz + \ | |
308 | decode_channel_attrs_maxsz) | |
0f3e66c6 AA |
309 | #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) |
310 | #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) | |
fc01cea9 AA |
311 | #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ |
312 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) | |
313 | #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ | |
314 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) | |
18019753 RL |
315 | #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) |
316 | #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) | |
b1f69b75 AA |
317 | #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \ |
318 | XDR_QUADLEN(NFS4_DEVICEID4_SIZE)) | |
319 | #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ | |
320 | 1 /* layout type */ + \ | |
321 | 1 /* opaque devaddr4 length */ + \ | |
322 | /* devaddr4 payload is read into page */ \ | |
323 | 1 /* notification bitmap length */ + \ | |
324 | 1 /* notification bitmap */) | |
325 | #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ | |
326 | encode_stateid_maxsz) | |
327 | #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ | |
328 | decode_stateid_maxsz + \ | |
329 | XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE)) | |
863a3c6c AA |
330 | #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ |
331 | 2 /* offset */ + \ | |
332 | 2 /* length */ + \ | |
333 | 1 /* reclaim */ + \ | |
334 | encode_stateid_maxsz + \ | |
335 | 1 /* new offset (true) */ + \ | |
336 | 2 /* last byte written */ + \ | |
337 | 1 /* nt_timechanged (false) */ + \ | |
338 | 1 /* layoutupdate4 layout type */ + \ | |
339 | 1 /* NULL filelayout layoutupdate4 payload */) | |
340 | #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) | |
cbe82603 BH |
341 | #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ |
342 | encode_stateid_maxsz + \ | |
343 | 1 /* FIXME: opaque lrf_body always empty at the moment */) | |
344 | #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ | |
345 | 1 + decode_stateid_maxsz) | |
fca78d6d BS |
346 | #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) |
347 | #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz | |
9b7b9fcc AA |
348 | #else /* CONFIG_NFS_V4_1 */ |
349 | #define encode_sequence_maxsz 0 | |
350 | #define decode_sequence_maxsz 0 | |
351 | #endif /* CONFIG_NFS_V4_1 */ | |
352 | ||
1da177e4 LT |
353 | #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ |
354 | #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ | |
355 | #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 356 | encode_sequence_maxsz + \ |
1da177e4 | 357 | encode_putfh_maxsz + \ |
9104a55d | 358 | encode_read_maxsz) |
1da177e4 | 359 | #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 360 | decode_sequence_maxsz + \ |
1da177e4 | 361 | decode_putfh_maxsz + \ |
9104a55d | 362 | decode_read_maxsz) |
1da177e4 | 363 | #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 364 | encode_sequence_maxsz + \ |
1da177e4 | 365 | encode_putfh_maxsz + \ |
9104a55d | 366 | encode_readlink_maxsz) |
1da177e4 | 367 | #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 368 | decode_sequence_maxsz + \ |
1da177e4 | 369 | decode_putfh_maxsz + \ |
9104a55d | 370 | decode_readlink_maxsz) |
1da177e4 | 371 | #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 372 | encode_sequence_maxsz + \ |
1da177e4 | 373 | encode_putfh_maxsz + \ |
9104a55d | 374 | encode_readdir_maxsz) |
1da177e4 | 375 | #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 376 | decode_sequence_maxsz + \ |
1da177e4 | 377 | decode_putfh_maxsz + \ |
9104a55d | 378 | decode_readdir_maxsz) |
1da177e4 | 379 | #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 380 | encode_sequence_maxsz + \ |
1da177e4 | 381 | encode_putfh_maxsz + \ |
9104a55d | 382 | encode_write_maxsz + \ |
4f9838c7 | 383 | encode_getattr_maxsz) |
1da177e4 | 384 | #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 385 | decode_sequence_maxsz + \ |
1da177e4 | 386 | decode_putfh_maxsz + \ |
9104a55d | 387 | decode_write_maxsz + \ |
4f9838c7 | 388 | decode_getattr_maxsz) |
1da177e4 | 389 | #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 390 | encode_sequence_maxsz + \ |
1da177e4 | 391 | encode_putfh_maxsz + \ |
9104a55d | 392 | encode_commit_maxsz + \ |
4f9838c7 | 393 | encode_getattr_maxsz) |
1da177e4 | 394 | #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 395 | decode_sequence_maxsz + \ |
1da177e4 | 396 | decode_putfh_maxsz + \ |
9104a55d | 397 | decode_commit_maxsz + \ |
4f9838c7 | 398 | decode_getattr_maxsz) |
1da177e4 | 399 | #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 400 | encode_sequence_maxsz + \ |
2cebf828 TM |
401 | encode_putfh_maxsz + \ |
402 | encode_savefh_maxsz + \ | |
403 | encode_open_maxsz + \ | |
404 | encode_getfh_maxsz + \ | |
405 | encode_getattr_maxsz + \ | |
406 | encode_restorefh_maxsz + \ | |
407 | encode_getattr_maxsz) | |
1da177e4 | 408 | #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 409 | decode_sequence_maxsz + \ |
2cebf828 TM |
410 | decode_putfh_maxsz + \ |
411 | decode_savefh_maxsz + \ | |
412 | decode_open_maxsz + \ | |
413 | decode_getfh_maxsz + \ | |
414 | decode_getattr_maxsz + \ | |
415 | decode_restorefh_maxsz + \ | |
416 | decode_getattr_maxsz) | |
9104a55d TM |
417 | #define NFS4_enc_open_confirm_sz \ |
418 | (compound_encode_hdr_maxsz + \ | |
419 | encode_putfh_maxsz + \ | |
420 | encode_open_confirm_maxsz) | |
421 | #define NFS4_dec_open_confirm_sz \ | |
422 | (compound_decode_hdr_maxsz + \ | |
423 | decode_putfh_maxsz + \ | |
424 | decode_open_confirm_maxsz) | |
1da177e4 | 425 | #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 426 | encode_sequence_maxsz + \ |
1da177e4 | 427 | encode_putfh_maxsz + \ |
2cebf828 TM |
428 | encode_open_maxsz + \ |
429 | encode_getattr_maxsz) | |
1da177e4 | 430 | #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 431 | decode_sequence_maxsz + \ |
1da177e4 | 432 | decode_putfh_maxsz + \ |
2cebf828 TM |
433 | decode_open_maxsz + \ |
434 | decode_getattr_maxsz) | |
1da177e4 LT |
435 | #define NFS4_enc_open_downgrade_sz \ |
436 | (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 437 | encode_sequence_maxsz + \ |
9104a55d TM |
438 | encode_putfh_maxsz + \ |
439 | encode_open_downgrade_maxsz + \ | |
440 | encode_getattr_maxsz) | |
1da177e4 LT |
441 | #define NFS4_dec_open_downgrade_sz \ |
442 | (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 443 | decode_sequence_maxsz + \ |
9104a55d TM |
444 | decode_putfh_maxsz + \ |
445 | decode_open_downgrade_maxsz + \ | |
446 | decode_getattr_maxsz) | |
447 | #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 448 | encode_sequence_maxsz + \ |
9104a55d TM |
449 | encode_putfh_maxsz + \ |
450 | encode_close_maxsz + \ | |
451 | encode_getattr_maxsz) | |
452 | #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 453 | decode_sequence_maxsz + \ |
9104a55d TM |
454 | decode_putfh_maxsz + \ |
455 | decode_close_maxsz + \ | |
456 | decode_getattr_maxsz) | |
457 | #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 458 | encode_sequence_maxsz + \ |
9104a55d TM |
459 | encode_putfh_maxsz + \ |
460 | encode_setattr_maxsz + \ | |
461 | encode_getattr_maxsz) | |
462 | #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 463 | decode_sequence_maxsz + \ |
9104a55d TM |
464 | decode_putfh_maxsz + \ |
465 | decode_setattr_maxsz + \ | |
466 | decode_getattr_maxsz) | |
1da177e4 | 467 | #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 468 | encode_sequence_maxsz + \ |
1da177e4 LT |
469 | encode_putfh_maxsz + \ |
470 | encode_fsinfo_maxsz) | |
471 | #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 472 | decode_sequence_maxsz + \ |
1da177e4 LT |
473 | decode_putfh_maxsz + \ |
474 | decode_fsinfo_maxsz) | |
475 | #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ | |
476 | encode_renew_maxsz) | |
477 | #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ | |
478 | decode_renew_maxsz) | |
479 | #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ | |
480 | encode_setclientid_maxsz) | |
481 | #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ | |
482 | decode_setclientid_maxsz) | |
483 | #define NFS4_enc_setclientid_confirm_sz \ | |
484 | (compound_encode_hdr_maxsz + \ | |
485 | encode_setclientid_confirm_maxsz + \ | |
486 | encode_putrootfh_maxsz + \ | |
487 | encode_fsinfo_maxsz) | |
488 | #define NFS4_dec_setclientid_confirm_sz \ | |
489 | (compound_decode_hdr_maxsz + \ | |
490 | decode_setclientid_confirm_maxsz + \ | |
491 | decode_putrootfh_maxsz + \ | |
492 | decode_fsinfo_maxsz) | |
493 | #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 494 | encode_sequence_maxsz + \ |
1da177e4 | 495 | encode_putfh_maxsz + \ |
9104a55d | 496 | encode_lock_maxsz) |
1da177e4 | 497 | #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 498 | decode_sequence_maxsz + \ |
1da177e4 | 499 | decode_putfh_maxsz + \ |
9104a55d | 500 | decode_lock_maxsz) |
1da177e4 | 501 | #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 502 | encode_sequence_maxsz + \ |
1da177e4 | 503 | encode_putfh_maxsz + \ |
9104a55d TM |
504 | encode_lockt_maxsz) |
505 | #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 506 | decode_sequence_maxsz + \ |
9104a55d TM |
507 | decode_putfh_maxsz + \ |
508 | decode_lockt_maxsz) | |
1da177e4 | 509 | #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 510 | encode_sequence_maxsz + \ |
1da177e4 | 511 | encode_putfh_maxsz + \ |
9104a55d | 512 | encode_locku_maxsz) |
1da177e4 | 513 | #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 514 | decode_sequence_maxsz + \ |
1da177e4 | 515 | decode_putfh_maxsz + \ |
9104a55d | 516 | decode_locku_maxsz) |
d3c7b7cc TM |
517 | #define NFS4_enc_release_lockowner_sz \ |
518 | (compound_encode_hdr_maxsz + \ | |
519 | encode_lockowner_maxsz) | |
520 | #define NFS4_dec_release_lockowner_sz \ | |
521 | (compound_decode_hdr_maxsz + \ | |
522 | decode_lockowner_maxsz) | |
1da177e4 | 523 | #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 524 | encode_sequence_maxsz + \ |
1da177e4 | 525 | encode_putfh_maxsz + \ |
76b32999 TM |
526 | encode_access_maxsz + \ |
527 | encode_getattr_maxsz) | |
1da177e4 | 528 | #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 529 | decode_sequence_maxsz + \ |
1da177e4 | 530 | decode_putfh_maxsz + \ |
76b32999 TM |
531 | decode_access_maxsz + \ |
532 | decode_getattr_maxsz) | |
1da177e4 | 533 | #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 534 | encode_sequence_maxsz + \ |
1da177e4 LT |
535 | encode_putfh_maxsz + \ |
536 | encode_getattr_maxsz) | |
537 | #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 538 | decode_sequence_maxsz + \ |
1da177e4 LT |
539 | decode_putfh_maxsz + \ |
540 | decode_getattr_maxsz) | |
541 | #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 542 | encode_sequence_maxsz + \ |
1da177e4 LT |
543 | encode_putfh_maxsz + \ |
544 | encode_lookup_maxsz + \ | |
545 | encode_getattr_maxsz + \ | |
546 | encode_getfh_maxsz) | |
547 | #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 548 | decode_sequence_maxsz + \ |
1da177e4 | 549 | decode_putfh_maxsz + \ |
e6889620 | 550 | decode_lookup_maxsz + \ |
1da177e4 LT |
551 | decode_getattr_maxsz + \ |
552 | decode_getfh_maxsz) | |
553 | #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 554 | encode_sequence_maxsz + \ |
1da177e4 LT |
555 | encode_putrootfh_maxsz + \ |
556 | encode_getattr_maxsz + \ | |
557 | encode_getfh_maxsz) | |
558 | #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 559 | decode_sequence_maxsz + \ |
1da177e4 LT |
560 | decode_putrootfh_maxsz + \ |
561 | decode_getattr_maxsz + \ | |
562 | decode_getfh_maxsz) | |
563 | #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 564 | encode_sequence_maxsz + \ |
1da177e4 | 565 | encode_putfh_maxsz + \ |
16e42959 TM |
566 | encode_remove_maxsz + \ |
567 | encode_getattr_maxsz) | |
1da177e4 | 568 | #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 569 | decode_sequence_maxsz + \ |
1da177e4 | 570 | decode_putfh_maxsz + \ |
6ce18391 | 571 | decode_remove_maxsz + \ |
16e42959 | 572 | decode_getattr_maxsz) |
1da177e4 | 573 | #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 574 | encode_sequence_maxsz + \ |
1da177e4 LT |
575 | encode_putfh_maxsz + \ |
576 | encode_savefh_maxsz + \ | |
577 | encode_putfh_maxsz + \ | |
6caf2c82 TM |
578 | encode_rename_maxsz + \ |
579 | encode_getattr_maxsz + \ | |
580 | encode_restorefh_maxsz + \ | |
581 | encode_getattr_maxsz) | |
1da177e4 | 582 | #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 583 | decode_sequence_maxsz + \ |
1da177e4 LT |
584 | decode_putfh_maxsz + \ |
585 | decode_savefh_maxsz + \ | |
586 | decode_putfh_maxsz + \ | |
6caf2c82 TM |
587 | decode_rename_maxsz + \ |
588 | decode_getattr_maxsz + \ | |
589 | decode_restorefh_maxsz + \ | |
590 | decode_getattr_maxsz) | |
1da177e4 | 591 | #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 592 | encode_sequence_maxsz + \ |
1da177e4 LT |
593 | encode_putfh_maxsz + \ |
594 | encode_savefh_maxsz + \ | |
595 | encode_putfh_maxsz + \ | |
91ba2eee TM |
596 | encode_link_maxsz + \ |
597 | decode_getattr_maxsz + \ | |
598 | encode_restorefh_maxsz + \ | |
599 | decode_getattr_maxsz) | |
1da177e4 | 600 | #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 601 | decode_sequence_maxsz + \ |
1da177e4 LT |
602 | decode_putfh_maxsz + \ |
603 | decode_savefh_maxsz + \ | |
604 | decode_putfh_maxsz + \ | |
91ba2eee TM |
605 | decode_link_maxsz + \ |
606 | decode_getattr_maxsz + \ | |
607 | decode_restorefh_maxsz + \ | |
608 | decode_getattr_maxsz) | |
1da177e4 | 609 | #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 610 | encode_sequence_maxsz + \ |
1da177e4 LT |
611 | encode_putfh_maxsz + \ |
612 | encode_symlink_maxsz + \ | |
613 | encode_getattr_maxsz + \ | |
614 | encode_getfh_maxsz) | |
615 | #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 616 | decode_sequence_maxsz + \ |
1da177e4 LT |
617 | decode_putfh_maxsz + \ |
618 | decode_symlink_maxsz + \ | |
619 | decode_getattr_maxsz + \ | |
620 | decode_getfh_maxsz) | |
621 | #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 622 | encode_sequence_maxsz + \ |
1da177e4 | 623 | encode_putfh_maxsz + \ |
56ae19f3 | 624 | encode_savefh_maxsz + \ |
1da177e4 | 625 | encode_create_maxsz + \ |
56ae19f3 | 626 | encode_getfh_maxsz + \ |
1da177e4 | 627 | encode_getattr_maxsz + \ |
56ae19f3 TM |
628 | encode_restorefh_maxsz + \ |
629 | encode_getattr_maxsz) | |
1da177e4 | 630 | #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 631 | decode_sequence_maxsz + \ |
1da177e4 | 632 | decode_putfh_maxsz + \ |
56ae19f3 | 633 | decode_savefh_maxsz + \ |
1da177e4 | 634 | decode_create_maxsz + \ |
56ae19f3 | 635 | decode_getfh_maxsz + \ |
1da177e4 | 636 | decode_getattr_maxsz + \ |
56ae19f3 TM |
637 | decode_restorefh_maxsz + \ |
638 | decode_getattr_maxsz) | |
1da177e4 | 639 | #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 640 | encode_sequence_maxsz + \ |
1da177e4 LT |
641 | encode_putfh_maxsz + \ |
642 | encode_getattr_maxsz) | |
643 | #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 644 | decode_sequence_maxsz + \ |
1da177e4 LT |
645 | decode_putfh_maxsz + \ |
646 | decode_getattr_maxsz) | |
647 | #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 648 | encode_sequence_maxsz + \ |
1da177e4 | 649 | encode_putfh_maxsz + \ |
9104a55d | 650 | encode_statfs_maxsz) |
1da177e4 | 651 | #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 652 | decode_sequence_maxsz + \ |
1da177e4 | 653 | decode_putfh_maxsz + \ |
9104a55d | 654 | decode_statfs_maxsz) |
1da177e4 | 655 | #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 656 | encode_sequence_maxsz + \ |
ab91f264 | 657 | encode_putfh_maxsz + \ |
1da177e4 LT |
658 | encode_getattr_maxsz) |
659 | #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 660 | decode_sequence_maxsz + \ |
ab91f264 | 661 | decode_putfh_maxsz + \ |
1da177e4 LT |
662 | decode_getattr_maxsz) |
663 | #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 664 | encode_sequence_maxsz + \ |
1da177e4 | 665 | encode_putfh_maxsz + \ |
fa178f29 TM |
666 | encode_delegreturn_maxsz + \ |
667 | encode_getattr_maxsz) | |
1da177e4 | 668 | #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 669 | decode_sequence_maxsz + \ |
fa178f29 TM |
670 | decode_delegreturn_maxsz + \ |
671 | decode_getattr_maxsz) | |
029d105e | 672 | #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 673 | encode_sequence_maxsz + \ |
029d105e | 674 | encode_putfh_maxsz + \ |
9104a55d | 675 | encode_getacl_maxsz) |
029d105e | 676 | #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 677 | decode_sequence_maxsz + \ |
029d105e | 678 | decode_putfh_maxsz + \ |
9104a55d | 679 | decode_getacl_maxsz) |
23ec6965 | 680 | #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 681 | encode_sequence_maxsz + \ |
23ec6965 | 682 | encode_putfh_maxsz + \ |
9104a55d | 683 | encode_setacl_maxsz) |
23ec6965 | 684 | #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 685 | decode_sequence_maxsz + \ |
23ec6965 | 686 | decode_putfh_maxsz + \ |
9104a55d | 687 | decode_setacl_maxsz) |
683b57b4 TM |
688 | #define NFS4_enc_fs_locations_sz \ |
689 | (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 690 | encode_sequence_maxsz + \ |
683b57b4 | 691 | encode_putfh_maxsz + \ |
e6889620 TM |
692 | encode_lookup_maxsz + \ |
693 | encode_fs_locations_maxsz) | |
683b57b4 TM |
694 | #define NFS4_dec_fs_locations_sz \ |
695 | (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 696 | decode_sequence_maxsz + \ |
683b57b4 | 697 | decode_putfh_maxsz + \ |
e6889620 TM |
698 | decode_lookup_maxsz + \ |
699 | decode_fs_locations_maxsz) | |
5a5ea0d4 BS |
700 | #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ |
701 | encode_sequence_maxsz + \ | |
702 | encode_putfh_maxsz + \ | |
703 | encode_secinfo_maxsz) | |
704 | #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ | |
705 | decode_sequence_maxsz + \ | |
706 | decode_putfh_maxsz + \ | |
707 | decode_secinfo_maxsz) | |
99fe60d0 BH |
708 | #if defined(CONFIG_NFS_V4_1) |
709 | #define NFS4_enc_exchange_id_sz \ | |
710 | (compound_encode_hdr_maxsz + \ | |
711 | encode_exchange_id_maxsz) | |
712 | #define NFS4_dec_exchange_id_sz \ | |
713 | (compound_decode_hdr_maxsz + \ | |
714 | decode_exchange_id_maxsz) | |
fc931582 AA |
715 | #define NFS4_enc_create_session_sz \ |
716 | (compound_encode_hdr_maxsz + \ | |
717 | encode_create_session_maxsz) | |
718 | #define NFS4_dec_create_session_sz \ | |
719 | (compound_decode_hdr_maxsz + \ | |
720 | decode_create_session_maxsz) | |
0f3e66c6 AA |
721 | #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ |
722 | encode_destroy_session_maxsz) | |
723 | #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ | |
724 | decode_destroy_session_maxsz) | |
fc01cea9 AA |
725 | #define NFS4_enc_sequence_sz \ |
726 | (compound_decode_hdr_maxsz + \ | |
727 | encode_sequence_maxsz) | |
728 | #define NFS4_dec_sequence_sz \ | |
729 | (compound_decode_hdr_maxsz + \ | |
730 | decode_sequence_maxsz) | |
2050f0cc AA |
731 | #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ |
732 | encode_sequence_maxsz + \ | |
733 | encode_putrootfh_maxsz + \ | |
734 | encode_fsinfo_maxsz) | |
735 | #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ | |
736 | decode_sequence_maxsz + \ | |
737 | decode_putrootfh_maxsz + \ | |
738 | decode_fsinfo_maxsz) | |
18019753 RL |
739 | #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ |
740 | encode_sequence_maxsz + \ | |
741 | encode_reclaim_complete_maxsz) | |
742 | #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ | |
743 | decode_sequence_maxsz + \ | |
744 | decode_reclaim_complete_maxsz) | |
b1f69b75 AA |
745 | #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ |
746 | encode_sequence_maxsz +\ | |
747 | encode_getdeviceinfo_maxsz) | |
748 | #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ | |
749 | decode_sequence_maxsz + \ | |
750 | decode_getdeviceinfo_maxsz) | |
751 | #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ | |
752 | encode_sequence_maxsz + \ | |
753 | encode_putfh_maxsz + \ | |
754 | encode_layoutget_maxsz) | |
755 | #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ | |
756 | decode_sequence_maxsz + \ | |
757 | decode_putfh_maxsz + \ | |
758 | decode_layoutget_maxsz) | |
863a3c6c AA |
759 | #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ |
760 | encode_sequence_maxsz +\ | |
761 | encode_putfh_maxsz + \ | |
762 | encode_layoutcommit_maxsz + \ | |
763 | encode_getattr_maxsz) | |
764 | #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ | |
765 | decode_sequence_maxsz + \ | |
766 | decode_putfh_maxsz + \ | |
767 | decode_layoutcommit_maxsz + \ | |
768 | decode_getattr_maxsz) | |
cbe82603 BH |
769 | #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ |
770 | encode_sequence_maxsz + \ | |
771 | encode_putfh_maxsz + \ | |
772 | encode_layoutreturn_maxsz) | |
773 | #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ | |
774 | decode_sequence_maxsz + \ | |
775 | decode_putfh_maxsz + \ | |
776 | decode_layoutreturn_maxsz) | |
fca78d6d BS |
777 | #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ |
778 | encode_sequence_maxsz + \ | |
779 | encode_putrootfh_maxsz +\ | |
780 | encode_secinfo_no_name_maxsz) | |
781 | #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ | |
782 | decode_sequence_maxsz + \ | |
783 | decode_putrootfh_maxsz + \ | |
784 | decode_secinfo_no_name_maxsz) | |
2449ea2e AB |
785 | |
786 | const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + | |
787 | compound_encode_hdr_maxsz + | |
788 | encode_sequence_maxsz + | |
789 | encode_putfh_maxsz + | |
790 | encode_getattr_maxsz) * | |
791 | XDR_UNIT); | |
792 | ||
793 | const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + | |
794 | compound_decode_hdr_maxsz + | |
795 | decode_sequence_maxsz + | |
796 | decode_putfh_maxsz) * | |
797 | XDR_UNIT); | |
99fe60d0 | 798 | #endif /* CONFIG_NFS_V4_1 */ |
1da177e4 | 799 | |
bca79478 TM |
800 | static const umode_t nfs_type2fmt[] = { |
801 | [NF4BAD] = 0, | |
802 | [NF4REG] = S_IFREG, | |
803 | [NF4DIR] = S_IFDIR, | |
804 | [NF4BLK] = S_IFBLK, | |
805 | [NF4CHR] = S_IFCHR, | |
806 | [NF4LNK] = S_IFLNK, | |
807 | [NF4SOCK] = S_IFSOCK, | |
808 | [NF4FIFO] = S_IFIFO, | |
809 | [NF4ATTRDIR] = 0, | |
810 | [NF4NAMEDATTR] = 0, | |
1da177e4 LT |
811 | }; |
812 | ||
813 | struct compound_hdr { | |
814 | int32_t status; | |
815 | uint32_t nops; | |
d017931c | 816 | __be32 * nops_p; |
1da177e4 LT |
817 | uint32_t taglen; |
818 | char * tag; | |
0c4e8c18 | 819 | uint32_t replen; /* expected reply words */ |
66cc0429 | 820 | u32 minorversion; |
1da177e4 LT |
821 | }; |
822 | ||
13c65ce9 BH |
823 | static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) |
824 | { | |
825 | __be32 *p = xdr_reserve_space(xdr, nbytes); | |
826 | BUG_ON(!p); | |
827 | return p; | |
828 | } | |
1da177e4 LT |
829 | |
830 | static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) | |
831 | { | |
8687b63a | 832 | __be32 *p; |
1da177e4 LT |
833 | |
834 | p = xdr_reserve_space(xdr, 4 + len); | |
835 | BUG_ON(p == NULL); | |
836 | xdr_encode_opaque(p, str, len); | |
837 | } | |
838 | ||
0c4e8c18 BH |
839 | static void encode_compound_hdr(struct xdr_stream *xdr, |
840 | struct rpc_rqst *req, | |
841 | struct compound_hdr *hdr) | |
1da177e4 | 842 | { |
8687b63a | 843 | __be32 *p; |
a17c2153 | 844 | struct rpc_auth *auth = req->rq_cred->cr_auth; |
0c4e8c18 BH |
845 | |
846 | /* initialize running count of expected bytes in reply. | |
847 | * NOTE: the replied tag SHOULD be the same is the one sent, | |
848 | * but this is not required as a MUST for the server to do so. */ | |
849 | hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; | |
1da177e4 LT |
850 | |
851 | dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag); | |
852 | BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); | |
811652bd BH |
853 | p = reserve_space(xdr, 4 + hdr->taglen + 8); |
854 | p = xdr_encode_opaque(p, hdr->tag, hdr->taglen); | |
e75bc1c8 | 855 | *p++ = cpu_to_be32(hdr->minorversion); |
d017931c | 856 | hdr->nops_p = p; |
34558513 | 857 | *p = cpu_to_be32(hdr->nops); |
d017931c AA |
858 | } |
859 | ||
860 | static void encode_nops(struct compound_hdr *hdr) | |
861 | { | |
fc931582 | 862 | BUG_ON(hdr->nops > NFS4_MAX_OPS); |
d017931c | 863 | *hdr->nops_p = htonl(hdr->nops); |
1da177e4 LT |
864 | } |
865 | ||
866 | static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) | |
867 | { | |
8687b63a | 868 | __be32 *p; |
1da177e4 LT |
869 | |
870 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); | |
871 | BUG_ON(p == NULL); | |
872 | xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE); | |
873 | } | |
874 | ||
cf8cdbe5 | 875 | static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) |
1da177e4 LT |
876 | { |
877 | char owner_name[IDMAP_NAMESZ]; | |
878 | char owner_group[IDMAP_NAMESZ]; | |
879 | int owner_namelen = 0; | |
880 | int owner_grouplen = 0; | |
8687b63a AV |
881 | __be32 *p; |
882 | __be32 *q; | |
1da177e4 LT |
883 | int len; |
884 | uint32_t bmval0 = 0; | |
885 | uint32_t bmval1 = 0; | |
1da177e4 LT |
886 | |
887 | /* | |
888 | * We reserve enough space to write the entire attribute buffer at once. | |
889 | * In the worst-case, this would be | |
890 | * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) | |
891 | * = 36 bytes, plus any contribution from variable-length fields | |
23ec6965 | 892 | * such as owner/group. |
1da177e4 LT |
893 | */ |
894 | len = 16; | |
895 | ||
896 | /* Sigh */ | |
897 | if (iap->ia_valid & ATTR_SIZE) | |
898 | len += 8; | |
899 | if (iap->ia_valid & ATTR_MODE) | |
900 | len += 4; | |
901 | if (iap->ia_valid & ATTR_UID) { | |
e4fd72a1 | 902 | owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); |
1da177e4 | 903 | if (owner_namelen < 0) { |
fe82a183 CL |
904 | dprintk("nfs: couldn't resolve uid %d to string\n", |
905 | iap->ia_uid); | |
1da177e4 LT |
906 | /* XXX */ |
907 | strcpy(owner_name, "nobody"); | |
908 | owner_namelen = sizeof("nobody") - 1; | |
909 | /* goto out; */ | |
910 | } | |
911 | len += 4 + (XDR_QUADLEN(owner_namelen) << 2); | |
912 | } | |
913 | if (iap->ia_valid & ATTR_GID) { | |
e4fd72a1 | 914 | owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); |
1da177e4 | 915 | if (owner_grouplen < 0) { |
fe82a183 CL |
916 | dprintk("nfs: couldn't resolve gid %d to string\n", |
917 | iap->ia_gid); | |
1da177e4 LT |
918 | strcpy(owner_group, "nobody"); |
919 | owner_grouplen = sizeof("nobody") - 1; | |
920 | /* goto out; */ | |
921 | } | |
922 | len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); | |
923 | } | |
924 | if (iap->ia_valid & ATTR_ATIME_SET) | |
925 | len += 16; | |
926 | else if (iap->ia_valid & ATTR_ATIME) | |
927 | len += 4; | |
928 | if (iap->ia_valid & ATTR_MTIME_SET) | |
929 | len += 16; | |
930 | else if (iap->ia_valid & ATTR_MTIME) | |
931 | len += 4; | |
13c65ce9 | 932 | p = reserve_space(xdr, len); |
1da177e4 LT |
933 | |
934 | /* | |
935 | * We write the bitmap length now, but leave the bitmap and the attribute | |
936 | * buffer length to be backfilled at the end of this routine. | |
937 | */ | |
e75bc1c8 | 938 | *p++ = cpu_to_be32(2); |
1da177e4 LT |
939 | q = p; |
940 | p += 3; | |
941 | ||
942 | if (iap->ia_valid & ATTR_SIZE) { | |
943 | bmval0 |= FATTR4_WORD0_SIZE; | |
b95be5a9 | 944 | p = xdr_encode_hyper(p, iap->ia_size); |
1da177e4 LT |
945 | } |
946 | if (iap->ia_valid & ATTR_MODE) { | |
947 | bmval1 |= FATTR4_WORD1_MODE; | |
e75bc1c8 | 948 | *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); |
1da177e4 LT |
949 | } |
950 | if (iap->ia_valid & ATTR_UID) { | |
951 | bmval1 |= FATTR4_WORD1_OWNER; | |
811652bd | 952 | p = xdr_encode_opaque(p, owner_name, owner_namelen); |
1da177e4 LT |
953 | } |
954 | if (iap->ia_valid & ATTR_GID) { | |
955 | bmval1 |= FATTR4_WORD1_OWNER_GROUP; | |
811652bd | 956 | p = xdr_encode_opaque(p, owner_group, owner_grouplen); |
1da177e4 LT |
957 | } |
958 | if (iap->ia_valid & ATTR_ATIME_SET) { | |
959 | bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; | |
e75bc1c8 BH |
960 | *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); |
961 | *p++ = cpu_to_be32(0); | |
d3f6baaa TM |
962 | *p++ = cpu_to_be32(iap->ia_atime.tv_sec); |
963 | *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); | |
1da177e4 LT |
964 | } |
965 | else if (iap->ia_valid & ATTR_ATIME) { | |
966 | bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; | |
e75bc1c8 | 967 | *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); |
1da177e4 LT |
968 | } |
969 | if (iap->ia_valid & ATTR_MTIME_SET) { | |
970 | bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; | |
e75bc1c8 BH |
971 | *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); |
972 | *p++ = cpu_to_be32(0); | |
973 | *p++ = cpu_to_be32(iap->ia_mtime.tv_sec); | |
974 | *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); | |
1da177e4 LT |
975 | } |
976 | else if (iap->ia_valid & ATTR_MTIME) { | |
977 | bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; | |
e75bc1c8 | 978 | *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); |
1da177e4 | 979 | } |
6c0195a4 | 980 | |
1da177e4 LT |
981 | /* |
982 | * Now we backfill the bitmap and the attribute buffer length. | |
983 | */ | |
984 | if (len != ((char *)p - (char *)q) + 4) { | |
fe82a183 | 985 | printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n", |
1da177e4 LT |
986 | len, ((char *)p - (char *)q) + 4); |
987 | BUG(); | |
988 | } | |
989 | len = (char *)p - (char *)q - 12; | |
990 | *q++ = htonl(bmval0); | |
991 | *q++ = htonl(bmval1); | |
34558513 | 992 | *q = htonl(len); |
1da177e4 | 993 | |
1da177e4 | 994 | /* out: */ |
1da177e4 LT |
995 | } |
996 | ||
cf8cdbe5 | 997 | static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) |
1da177e4 | 998 | { |
8687b63a | 999 | __be32 *p; |
1da177e4 | 1000 | |
13c65ce9 | 1001 | p = reserve_space(xdr, 8); |
e75bc1c8 | 1002 | *p++ = cpu_to_be32(OP_ACCESS); |
34558513 | 1003 | *p = cpu_to_be32(access); |
d017931c | 1004 | hdr->nops++; |
dadf0c27 | 1005 | hdr->replen += decode_access_maxsz; |
1da177e4 LT |
1006 | } |
1007 | ||
cf8cdbe5 | 1008 | static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) |
1da177e4 | 1009 | { |
8687b63a | 1010 | __be32 *p; |
1da177e4 | 1011 | |
13c65ce9 | 1012 | p = reserve_space(xdr, 8+NFS4_STATEID_SIZE); |
e75bc1c8 BH |
1013 | *p++ = cpu_to_be32(OP_CLOSE); |
1014 | *p++ = cpu_to_be32(arg->seqid->sequence->counter); | |
34558513 | 1015 | xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE); |
d017931c | 1016 | hdr->nops++; |
dadf0c27 | 1017 | hdr->replen += decode_close_maxsz; |
1da177e4 LT |
1018 | } |
1019 | ||
cf8cdbe5 | 1020 | static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) |
1da177e4 | 1021 | { |
8687b63a | 1022 | __be32 *p; |
6c0195a4 | 1023 | |
13c65ce9 | 1024 | p = reserve_space(xdr, 16); |
e75bc1c8 | 1025 | *p++ = cpu_to_be32(OP_COMMIT); |
b95be5a9 | 1026 | p = xdr_encode_hyper(p, args->offset); |
34558513 | 1027 | *p = cpu_to_be32(args->count); |
d017931c | 1028 | hdr->nops++; |
dadf0c27 | 1029 | hdr->replen += decode_commit_maxsz; |
1da177e4 LT |
1030 | } |
1031 | ||
cf8cdbe5 | 1032 | static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) |
1da177e4 | 1033 | { |
8687b63a | 1034 | __be32 *p; |
6c0195a4 | 1035 | |
13c65ce9 | 1036 | p = reserve_space(xdr, 8); |
e75bc1c8 | 1037 | *p++ = cpu_to_be32(OP_CREATE); |
34558513 | 1038 | *p = cpu_to_be32(create->ftype); |
1da177e4 LT |
1039 | |
1040 | switch (create->ftype) { | |
1041 | case NF4LNK: | |
13c65ce9 | 1042 | p = reserve_space(xdr, 4); |
34558513 | 1043 | *p = cpu_to_be32(create->u.symlink.len); |
94a6d753 | 1044 | xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); |
1da177e4 LT |
1045 | break; |
1046 | ||
1047 | case NF4BLK: case NF4CHR: | |
13c65ce9 | 1048 | p = reserve_space(xdr, 8); |
e75bc1c8 | 1049 | *p++ = cpu_to_be32(create->u.device.specdata1); |
34558513 | 1050 | *p = cpu_to_be32(create->u.device.specdata2); |
1da177e4 LT |
1051 | break; |
1052 | ||
1053 | default: | |
1054 | break; | |
1055 | } | |
1056 | ||
811652bd | 1057 | encode_string(xdr, create->name->len, create->name->name); |
d017931c | 1058 | hdr->nops++; |
dadf0c27 | 1059 | hdr->replen += decode_create_maxsz; |
1da177e4 | 1060 | |
cf8cdbe5 | 1061 | encode_attrs(xdr, create->attrs, create->server); |
1da177e4 LT |
1062 | } |
1063 | ||
cf8cdbe5 | 1064 | static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) |
1da177e4 | 1065 | { |
05d564fe | 1066 | __be32 *p; |
1da177e4 | 1067 | |
13c65ce9 | 1068 | p = reserve_space(xdr, 12); |
e75bc1c8 BH |
1069 | *p++ = cpu_to_be32(OP_GETATTR); |
1070 | *p++ = cpu_to_be32(1); | |
34558513 | 1071 | *p = cpu_to_be32(bitmap); |
d017931c | 1072 | hdr->nops++; |
dadf0c27 | 1073 | hdr->replen += decode_getattr_maxsz; |
1da177e4 LT |
1074 | } |
1075 | ||
cf8cdbe5 | 1076 | static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) |
1da177e4 | 1077 | { |
05d564fe | 1078 | __be32 *p; |
1da177e4 | 1079 | |
13c65ce9 | 1080 | p = reserve_space(xdr, 16); |
e75bc1c8 BH |
1081 | *p++ = cpu_to_be32(OP_GETATTR); |
1082 | *p++ = cpu_to_be32(2); | |
1083 | *p++ = cpu_to_be32(bm0); | |
34558513 | 1084 | *p = cpu_to_be32(bm1); |
d017931c | 1085 | hdr->nops++; |
dadf0c27 | 1086 | hdr->replen += decode_getattr_maxsz; |
1da177e4 LT |
1087 | } |
1088 | ||
cf8cdbe5 | 1089 | static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) |
1da177e4 | 1090 | { |
cf8cdbe5 AA |
1091 | encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0], |
1092 | bitmask[1] & nfs4_fattr_bitmap[1], hdr); | |
1da177e4 LT |
1093 | } |
1094 | ||
cf8cdbe5 | 1095 | static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) |
1da177e4 | 1096 | { |
cf8cdbe5 AA |
1097 | encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0], |
1098 | bitmask[1] & nfs4_fsinfo_bitmap[1], hdr); | |
1da177e4 LT |
1099 | } |
1100 | ||
cf8cdbe5 | 1101 | static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) |
830b8e33 | 1102 | { |
cf8cdbe5 AA |
1103 | encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], |
1104 | bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); | |
830b8e33 MN |
1105 | } |
1106 | ||
cf8cdbe5 | 1107 | static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
1da177e4 | 1108 | { |
8687b63a | 1109 | __be32 *p; |
1da177e4 | 1110 | |
13c65ce9 | 1111 | p = reserve_space(xdr, 4); |
34558513 | 1112 | *p = cpu_to_be32(OP_GETFH); |
d017931c | 1113 | hdr->nops++; |
dadf0c27 | 1114 | hdr->replen += decode_getfh_maxsz; |
1da177e4 LT |
1115 | } |
1116 | ||
cf8cdbe5 | 1117 | static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) |
1da177e4 | 1118 | { |
8687b63a | 1119 | __be32 *p; |
1da177e4 | 1120 | |
13c65ce9 | 1121 | p = reserve_space(xdr, 8 + name->len); |
e75bc1c8 | 1122 | *p++ = cpu_to_be32(OP_LINK); |
811652bd | 1123 | xdr_encode_opaque(p, name->name, name->len); |
d017931c | 1124 | hdr->nops++; |
dadf0c27 | 1125 | hdr->replen += decode_link_maxsz; |
1da177e4 LT |
1126 | } |
1127 | ||
911d1aaf TM |
1128 | static inline int nfs4_lock_type(struct file_lock *fl, int block) |
1129 | { | |
1130 | if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK) | |
1131 | return block ? NFS4_READW_LT : NFS4_READ_LT; | |
1132 | return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; | |
1133 | } | |
1134 | ||
1135 | static inline uint64_t nfs4_lock_length(struct file_lock *fl) | |
1136 | { | |
1137 | if (fl->fl_end == OFFSET_MAX) | |
1138 | return ~(uint64_t)0; | |
1139 | return fl->fl_end - fl->fl_start + 1; | |
1140 | } | |
1141 | ||
daccbded TM |
1142 | static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) |
1143 | { | |
1144 | __be32 *p; | |
1145 | ||
d035c36c | 1146 | p = reserve_space(xdr, 32); |
daccbded | 1147 | p = xdr_encode_hyper(p, lowner->clientid); |
d035c36c | 1148 | *p++ = cpu_to_be32(20); |
daccbded | 1149 | p = xdr_encode_opaque_fixed(p, "lock id:", 8); |
d035c36c | 1150 | *p++ = cpu_to_be32(lowner->s_dev); |
daccbded TM |
1151 | xdr_encode_hyper(p, lowner->id); |
1152 | } | |
1153 | ||
1da177e4 LT |
1154 | /* |
1155 | * opcode,type,reclaim,offset,length,new_lock_owner = 32 | |
1156 | * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 | |
1157 | */ | |
cf8cdbe5 | 1158 | static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) |
1da177e4 | 1159 | { |
8687b63a | 1160 | __be32 *p; |
1da177e4 | 1161 | |
13c65ce9 | 1162 | p = reserve_space(xdr, 32); |
e75bc1c8 BH |
1163 | *p++ = cpu_to_be32(OP_LOCK); |
1164 | *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); | |
1165 | *p++ = cpu_to_be32(args->reclaim); | |
b95be5a9 BH |
1166 | p = xdr_encode_hyper(p, args->fl->fl_start); |
1167 | p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); | |
34558513 | 1168 | *p = cpu_to_be32(args->new_lock_owner); |
911d1aaf | 1169 | if (args->new_lock_owner){ |
daccbded | 1170 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); |
e75bc1c8 | 1171 | *p++ = cpu_to_be32(args->open_seqid->sequence->counter); |
93f0cf25 | 1172 | p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE); |
e75bc1c8 | 1173 | *p++ = cpu_to_be32(args->lock_seqid->sequence->counter); |
daccbded | 1174 | encode_lockowner(xdr, &args->lock_owner); |
1da177e4 LT |
1175 | } |
1176 | else { | |
13c65ce9 | 1177 | p = reserve_space(xdr, NFS4_STATEID_SIZE+4); |
93f0cf25 | 1178 | p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE); |
34558513 | 1179 | *p = cpu_to_be32(args->lock_seqid->sequence->counter); |
1da177e4 | 1180 | } |
d017931c | 1181 | hdr->nops++; |
dadf0c27 | 1182 | hdr->replen += decode_lock_maxsz; |
1da177e4 LT |
1183 | } |
1184 | ||
cf8cdbe5 | 1185 | static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) |
1da177e4 | 1186 | { |
8687b63a | 1187 | __be32 *p; |
1da177e4 | 1188 | |
daccbded | 1189 | p = reserve_space(xdr, 24); |
e75bc1c8 BH |
1190 | *p++ = cpu_to_be32(OP_LOCKT); |
1191 | *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); | |
b95be5a9 BH |
1192 | p = xdr_encode_hyper(p, args->fl->fl_start); |
1193 | p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); | |
daccbded | 1194 | encode_lockowner(xdr, &args->lock_owner); |
d017931c | 1195 | hdr->nops++; |
dadf0c27 | 1196 | hdr->replen += decode_lockt_maxsz; |
1da177e4 LT |
1197 | } |
1198 | ||
cf8cdbe5 | 1199 | static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) |
1da177e4 | 1200 | { |
8687b63a | 1201 | __be32 *p; |
1da177e4 | 1202 | |
13c65ce9 | 1203 | p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16); |
e75bc1c8 BH |
1204 | *p++ = cpu_to_be32(OP_LOCKU); |
1205 | *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); | |
1206 | *p++ = cpu_to_be32(args->seqid->sequence->counter); | |
93f0cf25 | 1207 | p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE); |
b95be5a9 | 1208 | p = xdr_encode_hyper(p, args->fl->fl_start); |
34558513 | 1209 | xdr_encode_hyper(p, nfs4_lock_length(args->fl)); |
d017931c | 1210 | hdr->nops++; |
dadf0c27 | 1211 | hdr->replen += decode_locku_maxsz; |
1da177e4 LT |
1212 | } |
1213 | ||
d3c7b7cc TM |
1214 | static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) |
1215 | { | |
1216 | __be32 *p; | |
1217 | ||
1218 | p = reserve_space(xdr, 4); | |
1219 | *p = cpu_to_be32(OP_RELEASE_LOCKOWNER); | |
1220 | encode_lockowner(xdr, lowner); | |
1221 | hdr->nops++; | |
1222 | hdr->replen += decode_release_lockowner_maxsz; | |
1223 | } | |
1224 | ||
cf8cdbe5 | 1225 | static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) |
1da177e4 LT |
1226 | { |
1227 | int len = name->len; | |
8687b63a | 1228 | __be32 *p; |
1da177e4 | 1229 | |
13c65ce9 | 1230 | p = reserve_space(xdr, 8 + len); |
e75bc1c8 | 1231 | *p++ = cpu_to_be32(OP_LOOKUP); |
811652bd | 1232 | xdr_encode_opaque(p, name->name, len); |
d017931c | 1233 | hdr->nops++; |
dadf0c27 | 1234 | hdr->replen += decode_lookup_maxsz; |
1da177e4 LT |
1235 | } |
1236 | ||
dc0b027d | 1237 | static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) |
1da177e4 | 1238 | { |
8687b63a | 1239 | __be32 *p; |
1da177e4 | 1240 | |
13c65ce9 | 1241 | p = reserve_space(xdr, 8); |
dc0b027d | 1242 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
05d564fe | 1243 | case FMODE_READ: |
e75bc1c8 | 1244 | *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); |
05d564fe AA |
1245 | break; |
1246 | case FMODE_WRITE: | |
e75bc1c8 | 1247 | *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); |
05d564fe AA |
1248 | break; |
1249 | case FMODE_READ|FMODE_WRITE: | |
e75bc1c8 | 1250 | *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); |
05d564fe AA |
1251 | break; |
1252 | default: | |
e75bc1c8 | 1253 | *p++ = cpu_to_be32(0); |
1da177e4 | 1254 | } |
34558513 | 1255 | *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ |
1da177e4 LT |
1256 | } |
1257 | ||
1258 | static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) | |
1259 | { | |
8687b63a | 1260 | __be32 *p; |
1da177e4 LT |
1261 | /* |
1262 | * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, | |
1263 | * owner 4 = 32 | |
1264 | */ | |
13c65ce9 | 1265 | p = reserve_space(xdr, 8); |
e75bc1c8 | 1266 | *p++ = cpu_to_be32(OP_OPEN); |
34558513 | 1267 | *p = cpu_to_be32(arg->seqid->sequence->counter); |
dc0b027d | 1268 | encode_share_access(xdr, arg->fmode); |
d035c36c | 1269 | p = reserve_space(xdr, 32); |
b95be5a9 | 1270 | p = xdr_encode_hyper(p, arg->clientid); |
d035c36c | 1271 | *p++ = cpu_to_be32(20); |
93f0cf25 | 1272 | p = xdr_encode_opaque_fixed(p, "open id:", 8); |
d035c36c | 1273 | *p++ = cpu_to_be32(arg->server->s_dev); |
34558513 | 1274 | xdr_encode_hyper(p, arg->id); |
1da177e4 LT |
1275 | } |
1276 | ||
1277 | static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) | |
1278 | { | |
8687b63a | 1279 | __be32 *p; |
4882ef72 | 1280 | struct nfs_client *clp; |
1da177e4 | 1281 | |
13c65ce9 | 1282 | p = reserve_space(xdr, 4); |
1da177e4 | 1283 | switch(arg->open_flags & O_EXCL) { |
05d564fe | 1284 | case 0: |
34558513 | 1285 | *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); |
05d564fe AA |
1286 | encode_attrs(xdr, arg->u.attrs, arg->server); |
1287 | break; | |
1288 | default: | |
4882ef72 | 1289 | clp = arg->server->nfs_client; |
a4432345 | 1290 | if (clp->cl_mvops->minor_version > 0) { |
4882ef72 AB |
1291 | if (nfs4_has_persistent_session(clp)) { |
1292 | *p = cpu_to_be32(NFS4_CREATE_GUARDED); | |
1293 | encode_attrs(xdr, arg->u.attrs, arg->server); | |
1294 | } else { | |
1295 | struct iattr dummy; | |
1296 | ||
1297 | *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); | |
1298 | encode_nfs4_verifier(xdr, &arg->u.verifier); | |
1299 | dummy.ia_valid = 0; | |
1300 | encode_attrs(xdr, &dummy, arg->server); | |
1301 | } | |
1302 | } else { | |
1303 | *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); | |
1304 | encode_nfs4_verifier(xdr, &arg->u.verifier); | |
1305 | } | |
1da177e4 LT |
1306 | } |
1307 | } | |
1308 | ||
1309 | static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) | |
1310 | { | |
8687b63a | 1311 | __be32 *p; |
1da177e4 | 1312 | |
13c65ce9 | 1313 | p = reserve_space(xdr, 4); |
1da177e4 | 1314 | switch (arg->open_flags & O_CREAT) { |
05d564fe | 1315 | case 0: |
34558513 | 1316 | *p = cpu_to_be32(NFS4_OPEN_NOCREATE); |
05d564fe AA |
1317 | break; |
1318 | default: | |
1319 | BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); | |
34558513 | 1320 | *p = cpu_to_be32(NFS4_OPEN_CREATE); |
05d564fe | 1321 | encode_createmode(xdr, arg); |
1da177e4 LT |
1322 | } |
1323 | } | |
1324 | ||
bd7bf9d5 | 1325 | static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) |
1da177e4 | 1326 | { |
8687b63a | 1327 | __be32 *p; |
1da177e4 | 1328 | |
13c65ce9 | 1329 | p = reserve_space(xdr, 4); |
1da177e4 | 1330 | switch (delegation_type) { |
05d564fe | 1331 | case 0: |
34558513 | 1332 | *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); |
05d564fe AA |
1333 | break; |
1334 | case FMODE_READ: | |
34558513 | 1335 | *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); |
05d564fe AA |
1336 | break; |
1337 | case FMODE_WRITE|FMODE_READ: | |
34558513 | 1338 | *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); |
05d564fe AA |
1339 | break; |
1340 | default: | |
1341 | BUG(); | |
1da177e4 LT |
1342 | } |
1343 | } | |
1344 | ||
1345 | static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) | |
1346 | { | |
8687b63a | 1347 | __be32 *p; |
1da177e4 | 1348 | |
13c65ce9 | 1349 | p = reserve_space(xdr, 4); |
34558513 | 1350 | *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); |
1da177e4 LT |
1351 | encode_string(xdr, name->len, name->name); |
1352 | } | |
1353 | ||
bd7bf9d5 | 1354 | static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) |
1da177e4 | 1355 | { |
8687b63a | 1356 | __be32 *p; |
1da177e4 | 1357 | |
13c65ce9 | 1358 | p = reserve_space(xdr, 4); |
34558513 | 1359 | *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); |
1da177e4 LT |
1360 | encode_delegation_type(xdr, type); |
1361 | } | |
1362 | ||
1363 | static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) | |
1364 | { | |
8687b63a | 1365 | __be32 *p; |
1da177e4 | 1366 | |
13c65ce9 | 1367 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); |
e75bc1c8 | 1368 | *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); |
34558513 | 1369 | xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE); |
1da177e4 LT |
1370 | encode_string(xdr, name->len, name->name); |
1371 | } | |
1372 | ||
cf8cdbe5 | 1373 | static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) |
1da177e4 LT |
1374 | { |
1375 | encode_openhdr(xdr, arg); | |
1376 | encode_opentype(xdr, arg); | |
1377 | switch (arg->claim) { | |
05d564fe AA |
1378 | case NFS4_OPEN_CLAIM_NULL: |
1379 | encode_claim_null(xdr, arg->name); | |
1380 | break; | |
1381 | case NFS4_OPEN_CLAIM_PREVIOUS: | |
1382 | encode_claim_previous(xdr, arg->u.delegation_type); | |
1383 | break; | |
1384 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: | |
1385 | encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); | |
1386 | break; | |
1387 | default: | |
1388 | BUG(); | |
1da177e4 | 1389 | } |
d017931c | 1390 | hdr->nops++; |
dadf0c27 | 1391 | hdr->replen += decode_open_maxsz; |
1da177e4 LT |
1392 | } |
1393 | ||
cf8cdbe5 | 1394 | static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) |
1da177e4 | 1395 | { |
8687b63a | 1396 | __be32 *p; |
1da177e4 | 1397 | |
13c65ce9 | 1398 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); |
e75bc1c8 | 1399 | *p++ = cpu_to_be32(OP_OPEN_CONFIRM); |
93f0cf25 | 1400 | p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE); |
34558513 | 1401 | *p = cpu_to_be32(arg->seqid->sequence->counter); |
d017931c | 1402 | hdr->nops++; |
dadf0c27 | 1403 | hdr->replen += decode_open_confirm_maxsz; |
1da177e4 LT |
1404 | } |
1405 | ||
cf8cdbe5 | 1406 | static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) |
1da177e4 | 1407 | { |
8687b63a | 1408 | __be32 *p; |
1da177e4 | 1409 | |
13c65ce9 | 1410 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); |
e75bc1c8 | 1411 | *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE); |
93f0cf25 | 1412 | p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE); |
34558513 | 1413 | *p = cpu_to_be32(arg->seqid->sequence->counter); |
dc0b027d | 1414 | encode_share_access(xdr, arg->fmode); |
d017931c | 1415 | hdr->nops++; |
dadf0c27 | 1416 | hdr->replen += decode_open_downgrade_maxsz; |
1da177e4 LT |
1417 | } |
1418 | ||
cf8cdbe5 | 1419 | static void |
d017931c | 1420 | encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) |
1da177e4 LT |
1421 | { |
1422 | int len = fh->size; | |
8687b63a | 1423 | __be32 *p; |
1da177e4 | 1424 | |
13c65ce9 | 1425 | p = reserve_space(xdr, 8 + len); |
e75bc1c8 | 1426 | *p++ = cpu_to_be32(OP_PUTFH); |
811652bd | 1427 | xdr_encode_opaque(p, fh->data, len); |
d017931c | 1428 | hdr->nops++; |
dadf0c27 | 1429 | hdr->replen += decode_putfh_maxsz; |
1da177e4 LT |
1430 | } |
1431 | ||
cf8cdbe5 | 1432 | static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
1da177e4 | 1433 | { |
05d564fe | 1434 | __be32 *p; |
6c0195a4 | 1435 | |
13c65ce9 | 1436 | p = reserve_space(xdr, 4); |
34558513 | 1437 | *p = cpu_to_be32(OP_PUTROOTFH); |
d017931c | 1438 | hdr->nops++; |
dadf0c27 | 1439 | hdr->replen += decode_putrootfh_maxsz; |
1da177e4 LT |
1440 | } |
1441 | ||
89d1ea65 | 1442 | static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid) |
1da177e4 | 1443 | { |
1da177e4 | 1444 | nfs4_stateid stateid; |
8687b63a | 1445 | __be32 *p; |
1da177e4 | 1446 | |
13c65ce9 | 1447 | p = reserve_space(xdr, NFS4_STATEID_SIZE); |
1da177e4 | 1448 | if (ctx->state != NULL) { |
77041ed9 | 1449 | nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid); |
89d1ea65 AA |
1450 | if (zero_seqid) |
1451 | stateid.stateid.seqid = 0; | |
34558513 | 1452 | xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE); |
1da177e4 | 1453 | } else |
34558513 | 1454 | xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE); |
1da177e4 LT |
1455 | } |
1456 | ||
cf8cdbe5 | 1457 | static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) |
1da177e4 | 1458 | { |
8687b63a | 1459 | __be32 *p; |
1da177e4 | 1460 | |
13c65ce9 | 1461 | p = reserve_space(xdr, 4); |
34558513 | 1462 | *p = cpu_to_be32(OP_READ); |
1da177e4 | 1463 | |
89d1ea65 AA |
1464 | encode_stateid(xdr, args->context, args->lock_context, |
1465 | hdr->minorversion); | |
1da177e4 | 1466 | |
13c65ce9 | 1467 | p = reserve_space(xdr, 12); |
b95be5a9 | 1468 | p = xdr_encode_hyper(p, args->offset); |
34558513 | 1469 | *p = cpu_to_be32(args->count); |
d017931c | 1470 | hdr->nops++; |
dadf0c27 | 1471 | hdr->replen += decode_read_maxsz; |
1da177e4 LT |
1472 | } |
1473 | ||
cf8cdbe5 | 1474 | static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) |
1da177e4 | 1475 | { |
28331a46 TM |
1476 | uint32_t attrs[2] = { |
1477 | FATTR4_WORD0_RDATTR_ERROR, | |
1478 | FATTR4_WORD1_MOUNTED_ON_FILEID, | |
1479 | }; | |
6f7a35bd | 1480 | uint32_t dircount = readdir->count >> 1; |
8687b63a | 1481 | __be32 *p; |
1da177e4 | 1482 | |
82f2e547 BS |
1483 | if (readdir->plus) { |
1484 | attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| | |
28331a46 | 1485 | FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; |
82f2e547 BS |
1486 | attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| |
1487 | FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| | |
1488 | FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| | |
1489 | FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; | |
6f7a35bd | 1490 | dircount >>= 1; |
82f2e547 | 1491 | } |
28331a46 TM |
1492 | /* Use mounted_on_fileid only if the server supports it */ |
1493 | if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) | |
1494 | attrs[0] |= FATTR4_WORD0_FILEID; | |
82f2e547 | 1495 | |
13c65ce9 | 1496 | p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20); |
e75bc1c8 | 1497 | *p++ = cpu_to_be32(OP_READDIR); |
b95be5a9 | 1498 | p = xdr_encode_hyper(p, readdir->cookie); |
93f0cf25 | 1499 | p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE); |
6f7a35bd | 1500 | *p++ = cpu_to_be32(dircount); |
e75bc1c8 BH |
1501 | *p++ = cpu_to_be32(readdir->count); |
1502 | *p++ = cpu_to_be32(2); | |
82f2e547 | 1503 | |
e75bc1c8 | 1504 | *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); |
34558513 | 1505 | *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); |
d017931c | 1506 | hdr->nops++; |
dadf0c27 | 1507 | hdr->replen += decode_readdir_maxsz; |
44109241 FI |
1508 | dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", |
1509 | __func__, | |
eadf4598 TM |
1510 | (unsigned long long)readdir->cookie, |
1511 | ((u32 *)readdir->verifier.data)[0], | |
1512 | ((u32 *)readdir->verifier.data)[1], | |
1513 | attrs[0] & readdir->bitmask[0], | |
1514 | attrs[1] & readdir->bitmask[1]); | |
1da177e4 LT |
1515 | } |
1516 | ||
cf8cdbe5 | 1517 | static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) |
1da177e4 | 1518 | { |
8687b63a | 1519 | __be32 *p; |
1da177e4 | 1520 | |
13c65ce9 | 1521 | p = reserve_space(xdr, 4); |
34558513 | 1522 | *p = cpu_to_be32(OP_READLINK); |
d017931c | 1523 | hdr->nops++; |
dadf0c27 | 1524 | hdr->replen += decode_readlink_maxsz; |
1da177e4 LT |
1525 | } |
1526 | ||
cf8cdbe5 | 1527 | static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) |
1da177e4 | 1528 | { |
8687b63a | 1529 | __be32 *p; |
1da177e4 | 1530 | |
13c65ce9 | 1531 | p = reserve_space(xdr, 8 + name->len); |
e75bc1c8 | 1532 | *p++ = cpu_to_be32(OP_REMOVE); |
811652bd | 1533 | xdr_encode_opaque(p, name->name, name->len); |
d017931c | 1534 | hdr->nops++; |
dadf0c27 | 1535 | hdr->replen += decode_remove_maxsz; |
1da177e4 LT |
1536 | } |
1537 | ||
cf8cdbe5 | 1538 | static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) |
1da177e4 | 1539 | { |
8687b63a | 1540 | __be32 *p; |
1da177e4 | 1541 | |
811652bd BH |
1542 | p = reserve_space(xdr, 4); |
1543 | *p = cpu_to_be32(OP_RENAME); | |
1544 | encode_string(xdr, oldname->len, oldname->name); | |
1545 | encode_string(xdr, newname->len, newname->name); | |
d017931c | 1546 | hdr->nops++; |
dadf0c27 | 1547 | hdr->replen += decode_rename_maxsz; |
1da177e4 LT |
1548 | } |
1549 | ||
cf8cdbe5 | 1550 | static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr) |
1da177e4 | 1551 | { |
8687b63a | 1552 | __be32 *p; |
1da177e4 | 1553 | |
13c65ce9 | 1554 | p = reserve_space(xdr, 12); |
e75bc1c8 | 1555 | *p++ = cpu_to_be32(OP_RENEW); |
34558513 | 1556 | xdr_encode_hyper(p, client_stateid->cl_clientid); |
d017931c | 1557 | hdr->nops++; |
dadf0c27 | 1558 | hdr->replen += decode_renew_maxsz; |
1da177e4 LT |
1559 | } |
1560 | ||
cf8cdbe5 | 1561 | static void |
d017931c | 1562 | encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
56ae19f3 | 1563 | { |
8687b63a | 1564 | __be32 *p; |
56ae19f3 | 1565 | |
13c65ce9 | 1566 | p = reserve_space(xdr, 4); |
34558513 | 1567 | *p = cpu_to_be32(OP_RESTOREFH); |
d017931c | 1568 | hdr->nops++; |
dadf0c27 | 1569 | hdr->replen += decode_restorefh_maxsz; |
56ae19f3 TM |
1570 | } |
1571 | ||
9f06c719 | 1572 | static void |
d017931c | 1573 | encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) |
23ec6965 | 1574 | { |
8687b63a | 1575 | __be32 *p; |
23ec6965 | 1576 | |
13c65ce9 | 1577 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); |
e75bc1c8 | 1578 | *p++ = cpu_to_be32(OP_SETATTR); |
34558513 | 1579 | xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE); |
13c65ce9 | 1580 | p = reserve_space(xdr, 2*4); |
e75bc1c8 | 1581 | *p++ = cpu_to_be32(1); |
34558513 | 1582 | *p = cpu_to_be32(FATTR4_WORD0_ACL); |
9f06c719 | 1583 | BUG_ON(arg->acl_len % 4); |
13c65ce9 | 1584 | p = reserve_space(xdr, 4); |
34558513 | 1585 | *p = cpu_to_be32(arg->acl_len); |
23ec6965 | 1586 | xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); |
d017931c | 1587 | hdr->nops++; |
dadf0c27 | 1588 | hdr->replen += decode_setacl_maxsz; |
23ec6965 BF |
1589 | } |
1590 | ||
cf8cdbe5 | 1591 | static void |
d017931c | 1592 | encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
1da177e4 | 1593 | { |
8687b63a | 1594 | __be32 *p; |
1da177e4 | 1595 | |
13c65ce9 | 1596 | p = reserve_space(xdr, 4); |
34558513 | 1597 | *p = cpu_to_be32(OP_SAVEFH); |
d017931c | 1598 | hdr->nops++; |
dadf0c27 | 1599 | hdr->replen += decode_savefh_maxsz; |
1da177e4 LT |
1600 | } |
1601 | ||
cf8cdbe5 | 1602 | static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) |
1da177e4 | 1603 | { |
8687b63a | 1604 | __be32 *p; |
6c0195a4 | 1605 | |
13c65ce9 | 1606 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); |
e75bc1c8 | 1607 | *p++ = cpu_to_be32(OP_SETATTR); |
34558513 | 1608 | xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE); |
d017931c | 1609 | hdr->nops++; |
dadf0c27 | 1610 | hdr->replen += decode_setattr_maxsz; |
cf8cdbe5 | 1611 | encode_attrs(xdr, arg->iap, server); |
1da177e4 LT |
1612 | } |
1613 | ||
cf8cdbe5 | 1614 | static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) |
1da177e4 | 1615 | { |
8687b63a | 1616 | __be32 *p; |
1da177e4 | 1617 | |
13c65ce9 | 1618 | p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE); |
e75bc1c8 | 1619 | *p++ = cpu_to_be32(OP_SETCLIENTID); |
34558513 | 1620 | xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE); |
1da177e4 LT |
1621 | |
1622 | encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); | |
13c65ce9 | 1623 | p = reserve_space(xdr, 4); |
34558513 | 1624 | *p = cpu_to_be32(setclientid->sc_prog); |
1da177e4 LT |
1625 | encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); |
1626 | encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); | |
13c65ce9 | 1627 | p = reserve_space(xdr, 4); |
34558513 | 1628 | *p = cpu_to_be32(setclientid->sc_cb_ident); |
d017931c | 1629 | hdr->nops++; |
dadf0c27 | 1630 | hdr->replen += decode_setclientid_maxsz; |
1da177e4 LT |
1631 | } |
1632 | ||
bb8b27e5 | 1633 | static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) |
1da177e4 | 1634 | { |
05d564fe | 1635 | __be32 *p; |
1da177e4 | 1636 | |
13c65ce9 | 1637 | p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE); |
e75bc1c8 | 1638 | *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM); |
bb8b27e5 TM |
1639 | p = xdr_encode_hyper(p, arg->clientid); |
1640 | xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE); | |
d017931c | 1641 | hdr->nops++; |
dadf0c27 | 1642 | hdr->replen += decode_setclientid_confirm_maxsz; |
1da177e4 LT |
1643 | } |
1644 | ||
cf8cdbe5 | 1645 | static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) |
1da177e4 | 1646 | { |
8687b63a | 1647 | __be32 *p; |
1da177e4 | 1648 | |
13c65ce9 | 1649 | p = reserve_space(xdr, 4); |
34558513 | 1650 | *p = cpu_to_be32(OP_WRITE); |
1da177e4 | 1651 | |
89d1ea65 AA |
1652 | encode_stateid(xdr, args->context, args->lock_context, |
1653 | hdr->minorversion); | |
1da177e4 | 1654 | |
13c65ce9 | 1655 | p = reserve_space(xdr, 16); |
b95be5a9 | 1656 | p = xdr_encode_hyper(p, args->offset); |
e75bc1c8 | 1657 | *p++ = cpu_to_be32(args->stable); |
34558513 | 1658 | *p = cpu_to_be32(args->count); |
1da177e4 LT |
1659 | |
1660 | xdr_write_pages(xdr, args->pages, args->pgbase, args->count); | |
d017931c | 1661 | hdr->nops++; |
dadf0c27 | 1662 | hdr->replen += decode_write_maxsz; |
1da177e4 LT |
1663 | } |
1664 | ||
cf8cdbe5 | 1665 | static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) |
1da177e4 | 1666 | { |
8687b63a | 1667 | __be32 *p; |
1da177e4 | 1668 | |
13c65ce9 | 1669 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); |
1da177e4 | 1670 | |
e75bc1c8 | 1671 | *p++ = cpu_to_be32(OP_DELEGRETURN); |
34558513 | 1672 | xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE); |
d017931c | 1673 | hdr->nops++; |
dadf0c27 | 1674 | hdr->replen += decode_delegreturn_maxsz; |
1da177e4 | 1675 | } |
9b7b9fcc | 1676 | |
5a5ea0d4 BS |
1677 | static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) |
1678 | { | |
1679 | int len = name->len; | |
1680 | __be32 *p; | |
1681 | ||
1682 | p = reserve_space(xdr, 8 + len); | |
1683 | *p++ = cpu_to_be32(OP_SECINFO); | |
1684 | xdr_encode_opaque(p, name->name, len); | |
1685 | hdr->nops++; | |
1686 | hdr->replen += decode_secinfo_maxsz; | |
1687 | } | |
1688 | ||
99fe60d0 | 1689 | #if defined(CONFIG_NFS_V4_1) |
9b7b9fcc | 1690 | /* NFSv4.1 operations */ |
99fe60d0 BH |
1691 | static void encode_exchange_id(struct xdr_stream *xdr, |
1692 | struct nfs41_exchange_id_args *args, | |
1693 | struct compound_hdr *hdr) | |
1694 | { | |
1695 | __be32 *p; | |
1696 | ||
13c65ce9 | 1697 | p = reserve_space(xdr, 4 + sizeof(args->verifier->data)); |
e75bc1c8 | 1698 | *p++ = cpu_to_be32(OP_EXCHANGE_ID); |
34558513 | 1699 | xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data)); |
99fe60d0 BH |
1700 | |
1701 | encode_string(xdr, args->id_len, args->id); | |
1702 | ||
13c65ce9 | 1703 | p = reserve_space(xdr, 12); |
e75bc1c8 BH |
1704 | *p++ = cpu_to_be32(args->flags); |
1705 | *p++ = cpu_to_be32(0); /* zero length state_protect4_a */ | |
34558513 | 1706 | *p = cpu_to_be32(0); /* zero length implementation id array */ |
99fe60d0 BH |
1707 | hdr->nops++; |
1708 | hdr->replen += decode_exchange_id_maxsz; | |
1709 | } | |
fc931582 AA |
1710 | |
1711 | static void encode_create_session(struct xdr_stream *xdr, | |
1712 | struct nfs41_create_session_args *args, | |
1713 | struct compound_hdr *hdr) | |
1714 | { | |
1715 | __be32 *p; | |
1716 | char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; | |
1717 | uint32_t len; | |
1718 | struct nfs_client *clp = args->client; | |
8e0d46e1 MS |
1719 | u32 max_resp_sz_cached; |
1720 | ||
1721 | /* | |
1722 | * Assumes OPEN is the biggest non-idempotent compound. | |
1723 | * 2 is the verifier. | |
1724 | */ | |
1725 | max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + | |
1726 | RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; | |
fc931582 | 1727 | |
42edd698 BH |
1728 | len = scnprintf(machine_name, sizeof(machine_name), "%s", |
1729 | clp->cl_ipaddr); | |
fc931582 | 1730 | |
13c65ce9 | 1731 | p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12); |
42edd698 | 1732 | *p++ = cpu_to_be32(OP_CREATE_SESSION); |
114f64b5 | 1733 | p = xdr_encode_hyper(p, clp->cl_clientid); |
e75bc1c8 BH |
1734 | *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ |
1735 | *p++ = cpu_to_be32(args->flags); /*flags */ | |
fc931582 | 1736 | |
fc931582 | 1737 | /* Fore Channel */ |
c9c30dd5 | 1738 | *p++ = cpu_to_be32(0); /* header padding size */ |
e75bc1c8 BH |
1739 | *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ |
1740 | *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ | |
8e0d46e1 | 1741 | *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ |
e75bc1c8 BH |
1742 | *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ |
1743 | *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ | |
1744 | *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ | |
fc931582 AA |
1745 | |
1746 | /* Back Channel */ | |
c9c30dd5 | 1747 | *p++ = cpu_to_be32(0); /* header padding size */ |
e75bc1c8 BH |
1748 | *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ |
1749 | *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ | |
1750 | *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ | |
1751 | *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ | |
1752 | *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ | |
1753 | *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ | |
fc931582 | 1754 | |
e75bc1c8 | 1755 | *p++ = cpu_to_be32(args->cb_program); /* cb_program */ |
e75bc1c8 | 1756 | *p++ = cpu_to_be32(1); |
e75bc1c8 | 1757 | *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ |
fc931582 AA |
1758 | |
1759 | /* authsys_parms rfc1831 */ | |
e75bc1c8 | 1760 | *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */ |
811652bd | 1761 | p = xdr_encode_opaque(p, machine_name, len); |
e75bc1c8 BH |
1762 | *p++ = cpu_to_be32(0); /* UID */ |
1763 | *p++ = cpu_to_be32(0); /* GID */ | |
34558513 | 1764 | *p = cpu_to_be32(0); /* No more gids */ |
fc931582 AA |
1765 | hdr->nops++; |
1766 | hdr->replen += decode_create_session_maxsz; | |
1767 | } | |
0f3e66c6 AA |
1768 | |
1769 | static void encode_destroy_session(struct xdr_stream *xdr, | |
1770 | struct nfs4_session *session, | |
1771 | struct compound_hdr *hdr) | |
1772 | { | |
1773 | __be32 *p; | |
13c65ce9 | 1774 | p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN); |
e75bc1c8 | 1775 | *p++ = cpu_to_be32(OP_DESTROY_SESSION); |
34558513 | 1776 | xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); |
0f3e66c6 AA |
1777 | hdr->nops++; |
1778 | hdr->replen += decode_destroy_session_maxsz; | |
1779 | } | |
18019753 RL |
1780 | |
1781 | static void encode_reclaim_complete(struct xdr_stream *xdr, | |
1782 | struct nfs41_reclaim_complete_args *args, | |
1783 | struct compound_hdr *hdr) | |
1784 | { | |
1785 | __be32 *p; | |
1786 | ||
1787 | p = reserve_space(xdr, 8); | |
1788 | *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE); | |
1789 | *p++ = cpu_to_be32(args->one_fs); | |
1790 | hdr->nops++; | |
1791 | hdr->replen += decode_reclaim_complete_maxsz; | |
1792 | } | |
99fe60d0 BH |
1793 | #endif /* CONFIG_NFS_V4_1 */ |
1794 | ||
9b7b9fcc AA |
1795 | static void encode_sequence(struct xdr_stream *xdr, |
1796 | const struct nfs4_sequence_args *args, | |
1797 | struct compound_hdr *hdr) | |
1798 | { | |
1799 | #if defined(CONFIG_NFS_V4_1) | |
1800 | struct nfs4_session *session = args->sa_session; | |
fc01cea9 AA |
1801 | struct nfs4_slot_table *tp; |
1802 | struct nfs4_slot *slot; | |
1803 | __be32 *p; | |
9b7b9fcc AA |
1804 | |
1805 | if (!session) | |
1806 | return; | |
1807 | ||
fc01cea9 AA |
1808 | tp = &session->fc_slot_table; |
1809 | ||
1810 | WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); | |
1811 | slot = tp->slots + args->sa_slotid; | |
1812 | ||
13c65ce9 | 1813 | p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16); |
e75bc1c8 | 1814 | *p++ = cpu_to_be32(OP_SEQUENCE); |
fc01cea9 AA |
1815 | |
1816 | /* | |
1817 | * Sessionid + seqid + slotid + max slotid + cache_this | |
1818 | */ | |
1819 | dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " | |
1820 | "max_slotid=%d cache_this=%d\n", | |
1821 | __func__, | |
1822 | ((u32 *)session->sess_id.data)[0], | |
1823 | ((u32 *)session->sess_id.data)[1], | |
1824 | ((u32 *)session->sess_id.data)[2], | |
1825 | ((u32 *)session->sess_id.data)[3], | |
1826 | slot->seq_nr, args->sa_slotid, | |
1827 | tp->highest_used_slotid, args->sa_cache_this); | |
93f0cf25 | 1828 | p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); |
e75bc1c8 BH |
1829 | *p++ = cpu_to_be32(slot->seq_nr); |
1830 | *p++ = cpu_to_be32(args->sa_slotid); | |
1831 | *p++ = cpu_to_be32(tp->highest_used_slotid); | |
34558513 | 1832 | *p = cpu_to_be32(args->sa_cache_this); |
9b7b9fcc AA |
1833 | hdr->nops++; |
1834 | hdr->replen += decode_sequence_maxsz; | |
1835 | #endif /* CONFIG_NFS_V4_1 */ | |
1836 | } | |
1837 | ||
b1f69b75 AA |
1838 | #ifdef CONFIG_NFS_V4_1 |
1839 | static void | |
1840 | encode_getdeviceinfo(struct xdr_stream *xdr, | |
1841 | const struct nfs4_getdeviceinfo_args *args, | |
1842 | struct compound_hdr *hdr) | |
1843 | { | |
1844 | __be32 *p; | |
1845 | ||
1846 | p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE); | |
1847 | *p++ = cpu_to_be32(OP_GETDEVICEINFO); | |
1848 | p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, | |
1849 | NFS4_DEVICEID4_SIZE); | |
1850 | *p++ = cpu_to_be32(args->pdev->layout_type); | |
1851 | *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */ | |
1852 | *p++ = cpu_to_be32(0); /* bitmap length 0 */ | |
1853 | hdr->nops++; | |
1854 | hdr->replen += decode_getdeviceinfo_maxsz; | |
1855 | } | |
1856 | ||
1857 | static void | |
1858 | encode_layoutget(struct xdr_stream *xdr, | |
1859 | const struct nfs4_layoutget_args *args, | |
1860 | struct compound_hdr *hdr) | |
1861 | { | |
b1f69b75 AA |
1862 | __be32 *p; |
1863 | ||
1864 | p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE); | |
1865 | *p++ = cpu_to_be32(OP_LAYOUTGET); | |
1866 | *p++ = cpu_to_be32(0); /* Signal layout available */ | |
1867 | *p++ = cpu_to_be32(args->type); | |
1868 | *p++ = cpu_to_be32(args->range.iomode); | |
1869 | p = xdr_encode_hyper(p, args->range.offset); | |
1870 | p = xdr_encode_hyper(p, args->range.length); | |
1871 | p = xdr_encode_hyper(p, args->minlength); | |
cf7d63f1 | 1872 | p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE); |
b1f69b75 AA |
1873 | *p = cpu_to_be32(args->maxcount); |
1874 | ||
1875 | dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", | |
1876 | __func__, | |
1877 | args->type, | |
1878 | args->range.iomode, | |
1879 | (unsigned long)args->range.offset, | |
1880 | (unsigned long)args->range.length, | |
1881 | args->maxcount); | |
1882 | hdr->nops++; | |
1883 | hdr->replen += decode_layoutget_maxsz; | |
1884 | } | |
863a3c6c AA |
1885 | |
1886 | static int | |
1887 | encode_layoutcommit(struct xdr_stream *xdr, | |
ac7db726 | 1888 | struct inode *inode, |
863a3c6c AA |
1889 | const struct nfs4_layoutcommit_args *args, |
1890 | struct compound_hdr *hdr) | |
1891 | { | |
1892 | __be32 *p; | |
1893 | ||
1894 | dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, | |
1895 | NFS_SERVER(args->inode)->pnfs_curr_ld->id); | |
1896 | ||
ac7db726 | 1897 | p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE); |
863a3c6c AA |
1898 | *p++ = cpu_to_be32(OP_LAYOUTCOMMIT); |
1899 | /* Only whole file layouts */ | |
1900 | p = xdr_encode_hyper(p, 0); /* offset */ | |
1901 | p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */ | |
1902 | *p++ = cpu_to_be32(0); /* reclaim */ | |
1903 | p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE); | |
1904 | *p++ = cpu_to_be32(1); /* newoffset = TRUE */ | |
1905 | p = xdr_encode_hyper(p, args->lastbytewritten); | |
1906 | *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ | |
1907 | *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ | |
ac7db726 BH |
1908 | |
1909 | if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) | |
1910 | NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( | |
1911 | NFS_I(inode)->layout, xdr, args); | |
1912 | else { | |
1913 | p = reserve_space(xdr, 4); | |
1914 | *p = cpu_to_be32(0); /* no layout-type payload */ | |
1915 | } | |
863a3c6c AA |
1916 | |
1917 | hdr->nops++; | |
1918 | hdr->replen += decode_layoutcommit_maxsz; | |
1919 | return 0; | |
1920 | } | |
cbe82603 BH |
1921 | |
1922 | static void | |
1923 | encode_layoutreturn(struct xdr_stream *xdr, | |
1924 | const struct nfs4_layoutreturn_args *args, | |
1925 | struct compound_hdr *hdr) | |
1926 | { | |
1927 | __be32 *p; | |
1928 | ||
1929 | p = reserve_space(xdr, 20); | |
1930 | *p++ = cpu_to_be32(OP_LAYOUTRETURN); | |
1931 | *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ | |
1932 | *p++ = cpu_to_be32(args->layout_type); | |
1933 | *p++ = cpu_to_be32(IOMODE_ANY); | |
1934 | *p = cpu_to_be32(RETURN_FILE); | |
1935 | p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE); | |
1936 | p = xdr_encode_hyper(p, 0); | |
1937 | p = xdr_encode_hyper(p, NFS4_MAX_UINT64); | |
1938 | spin_lock(&args->inode->i_lock); | |
1939 | xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE); | |
1940 | spin_unlock(&args->inode->i_lock); | |
04a55549 AA |
1941 | if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) { |
1942 | NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn( | |
1943 | NFS_I(args->inode)->layout, xdr, args); | |
1944 | } else { | |
1945 | p = reserve_space(xdr, 4); | |
1946 | *p = cpu_to_be32(0); | |
1947 | } | |
cbe82603 BH |
1948 | hdr->nops++; |
1949 | hdr->replen += decode_layoutreturn_maxsz; | |
1950 | } | |
fca78d6d BS |
1951 | |
1952 | static int | |
1953 | encode_secinfo_no_name(struct xdr_stream *xdr, | |
1954 | const struct nfs41_secinfo_no_name_args *args, | |
1955 | struct compound_hdr *hdr) | |
1956 | { | |
1957 | __be32 *p; | |
1958 | p = reserve_space(xdr, 8); | |
1959 | *p++ = cpu_to_be32(OP_SECINFO_NO_NAME); | |
1960 | *p++ = cpu_to_be32(args->style); | |
1961 | hdr->nops++; | |
1962 | hdr->replen += decode_secinfo_no_name_maxsz; | |
1963 | return 0; | |
1964 | } | |
b1f69b75 AA |
1965 | #endif /* CONFIG_NFS_V4_1 */ |
1966 | ||
1da177e4 LT |
1967 | /* |
1968 | * END OF "GENERIC" ENCODE ROUTINES. | |
1969 | */ | |
1970 | ||
66cc0429 BH |
1971 | static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) |
1972 | { | |
1973 | #if defined(CONFIG_NFS_V4_1) | |
1974 | if (args->sa_session) | |
a4432345 | 1975 | return args->sa_session->clp->cl_mvops->minor_version; |
66cc0429 BH |
1976 | #endif /* CONFIG_NFS_V4_1 */ |
1977 | return 0; | |
1978 | } | |
1979 | ||
1da177e4 LT |
1980 | /* |
1981 | * Encode an ACCESS request | |
1982 | */ | |
9f06c719 CL |
1983 | static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, |
1984 | const struct nfs4_accessargs *args) | |
1da177e4 | 1985 | { |
1da177e4 | 1986 | struct compound_hdr hdr = { |
66cc0429 | 1987 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1988 | }; |
1da177e4 | 1989 | |
9f06c719 CL |
1990 | encode_compound_hdr(xdr, req, &hdr); |
1991 | encode_sequence(xdr, &args->seq_args, &hdr); | |
1992 | encode_putfh(xdr, args->fh, &hdr); | |
1993 | encode_access(xdr, args->access, &hdr); | |
1994 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 1995 | encode_nops(&hdr); |
1da177e4 LT |
1996 | } |
1997 | ||
1998 | /* | |
1999 | * Encode LOOKUP request | |
2000 | */ | |
9f06c719 CL |
2001 | static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, |
2002 | const struct nfs4_lookup_arg *args) | |
1da177e4 | 2003 | { |
1da177e4 | 2004 | struct compound_hdr hdr = { |
66cc0429 | 2005 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2006 | }; |
1da177e4 | 2007 | |
9f06c719 CL |
2008 | encode_compound_hdr(xdr, req, &hdr); |
2009 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2010 | encode_putfh(xdr, args->dir_fh, &hdr); | |
2011 | encode_lookup(xdr, args->name, &hdr); | |
2012 | encode_getfh(xdr, &hdr); | |
2013 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2014 | encode_nops(&hdr); |
1da177e4 LT |
2015 | } |
2016 | ||
2017 | /* | |
2018 | * Encode LOOKUP_ROOT request | |
2019 | */ | |
9f06c719 CL |
2020 | static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, |
2021 | struct xdr_stream *xdr, | |
2022 | const struct nfs4_lookup_root_arg *args) | |
1da177e4 | 2023 | { |
1da177e4 | 2024 | struct compound_hdr hdr = { |
66cc0429 | 2025 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2026 | }; |
1da177e4 | 2027 | |
9f06c719 CL |
2028 | encode_compound_hdr(xdr, req, &hdr); |
2029 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2030 | encode_putrootfh(xdr, &hdr); | |
2031 | encode_getfh(xdr, &hdr); | |
2032 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2033 | encode_nops(&hdr); |
1da177e4 LT |
2034 | } |
2035 | ||
2036 | /* | |
2037 | * Encode REMOVE request | |
2038 | */ | |
9f06c719 CL |
2039 | static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, |
2040 | const struct nfs_removeargs *args) | |
1da177e4 | 2041 | { |
1da177e4 | 2042 | struct compound_hdr hdr = { |
66cc0429 | 2043 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2044 | }; |
1da177e4 | 2045 | |
9f06c719 CL |
2046 | encode_compound_hdr(xdr, req, &hdr); |
2047 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2048 | encode_putfh(xdr, args->fh, &hdr); | |
2049 | encode_remove(xdr, &args->name, &hdr); | |
2050 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2051 | encode_nops(&hdr); |
1da177e4 LT |
2052 | } |
2053 | ||
2054 | /* | |
2055 | * Encode RENAME request | |
2056 | */ | |
9f06c719 CL |
2057 | static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, |
2058 | const struct nfs_renameargs *args) | |
1da177e4 | 2059 | { |
1da177e4 | 2060 | struct compound_hdr hdr = { |
66cc0429 | 2061 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2062 | }; |
1da177e4 | 2063 | |
9f06c719 CL |
2064 | encode_compound_hdr(xdr, req, &hdr); |
2065 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2066 | encode_putfh(xdr, args->old_dir, &hdr); | |
2067 | encode_savefh(xdr, &hdr); | |
2068 | encode_putfh(xdr, args->new_dir, &hdr); | |
2069 | encode_rename(xdr, args->old_name, args->new_name, &hdr); | |
2070 | encode_getfattr(xdr, args->bitmask, &hdr); | |
2071 | encode_restorefh(xdr, &hdr); | |
2072 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2073 | encode_nops(&hdr); |
1da177e4 LT |
2074 | } |
2075 | ||
2076 | /* | |
2077 | * Encode LINK request | |
2078 | */ | |
9f06c719 CL |
2079 | static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, |
2080 | const struct nfs4_link_arg *args) | |
1da177e4 | 2081 | { |
1da177e4 | 2082 | struct compound_hdr hdr = { |
66cc0429 | 2083 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2084 | }; |
1da177e4 | 2085 | |
9f06c719 CL |
2086 | encode_compound_hdr(xdr, req, &hdr); |
2087 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2088 | encode_putfh(xdr, args->fh, &hdr); | |
2089 | encode_savefh(xdr, &hdr); | |
2090 | encode_putfh(xdr, args->dir_fh, &hdr); | |
2091 | encode_link(xdr, args->name, &hdr); | |
2092 | encode_getfattr(xdr, args->bitmask, &hdr); | |
2093 | encode_restorefh(xdr, &hdr); | |
2094 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2095 | encode_nops(&hdr); |
1da177e4 LT |
2096 | } |
2097 | ||
2098 | /* | |
2099 | * Encode CREATE request | |
2100 | */ | |
9f06c719 CL |
2101 | static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, |
2102 | const struct nfs4_create_arg *args) | |
1da177e4 | 2103 | { |
1da177e4 | 2104 | struct compound_hdr hdr = { |
66cc0429 | 2105 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2106 | }; |
1da177e4 | 2107 | |
9f06c719 CL |
2108 | encode_compound_hdr(xdr, req, &hdr); |
2109 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2110 | encode_putfh(xdr, args->dir_fh, &hdr); | |
2111 | encode_savefh(xdr, &hdr); | |
2112 | encode_create(xdr, args, &hdr); | |
2113 | encode_getfh(xdr, &hdr); | |
2114 | encode_getfattr(xdr, args->bitmask, &hdr); | |
2115 | encode_restorefh(xdr, &hdr); | |
2116 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2117 | encode_nops(&hdr); |
1da177e4 LT |
2118 | } |
2119 | ||
2120 | /* | |
2121 | * Encode SYMLINK request | |
2122 | */ | |
9f06c719 CL |
2123 | static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, |
2124 | const struct nfs4_create_arg *args) | |
1da177e4 | 2125 | { |
9f06c719 | 2126 | nfs4_xdr_enc_create(req, xdr, args); |
1da177e4 LT |
2127 | } |
2128 | ||
2129 | /* | |
2130 | * Encode GETATTR request | |
2131 | */ | |
9f06c719 CL |
2132 | static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, |
2133 | const struct nfs4_getattr_arg *args) | |
1da177e4 | 2134 | { |
1da177e4 | 2135 | struct compound_hdr hdr = { |
66cc0429 | 2136 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2137 | }; |
1da177e4 | 2138 | |
9f06c719 CL |
2139 | encode_compound_hdr(xdr, req, &hdr); |
2140 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2141 | encode_putfh(xdr, args->fh, &hdr); | |
2142 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2143 | encode_nops(&hdr); |
1da177e4 LT |
2144 | } |
2145 | ||
2146 | /* | |
2147 | * Encode a CLOSE request | |
2148 | */ | |
9f06c719 CL |
2149 | static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, |
2150 | struct nfs_closeargs *args) | |
1da177e4 | 2151 | { |
05d564fe | 2152 | struct compound_hdr hdr = { |
66cc0429 | 2153 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
05d564fe | 2154 | }; |
05d564fe | 2155 | |
9f06c719 CL |
2156 | encode_compound_hdr(xdr, req, &hdr); |
2157 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2158 | encode_putfh(xdr, args->fh, &hdr); | |
2159 | encode_close(xdr, args, &hdr); | |
2160 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2161 | encode_nops(&hdr); |
1da177e4 LT |
2162 | } |
2163 | ||
2164 | /* | |
2165 | * Encode an OPEN request | |
2166 | */ | |
9f06c719 CL |
2167 | static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, |
2168 | struct nfs_openargs *args) | |
1da177e4 | 2169 | { |
1da177e4 | 2170 | struct compound_hdr hdr = { |
66cc0429 | 2171 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2172 | }; |
1da177e4 | 2173 | |
9f06c719 CL |
2174 | encode_compound_hdr(xdr, req, &hdr); |
2175 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2176 | encode_putfh(xdr, args->fh, &hdr); | |
2177 | encode_savefh(xdr, &hdr); | |
2178 | encode_open(xdr, args, &hdr); | |
2179 | encode_getfh(xdr, &hdr); | |
2180 | encode_getfattr(xdr, args->bitmask, &hdr); | |
2181 | encode_restorefh(xdr, &hdr); | |
2182 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2183 | encode_nops(&hdr); |
1da177e4 LT |
2184 | } |
2185 | ||
2186 | /* | |
2187 | * Encode an OPEN_CONFIRM request | |
2188 | */ | |
9f06c719 CL |
2189 | static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, |
2190 | struct xdr_stream *xdr, | |
2191 | struct nfs_open_confirmargs *args) | |
1da177e4 | 2192 | { |
1da177e4 | 2193 | struct compound_hdr hdr = { |
d017931c | 2194 | .nops = 0, |
1da177e4 | 2195 | }; |
1da177e4 | 2196 | |
9f06c719 CL |
2197 | encode_compound_hdr(xdr, req, &hdr); |
2198 | encode_putfh(xdr, args->fh, &hdr); | |
2199 | encode_open_confirm(xdr, args, &hdr); | |
d017931c | 2200 | encode_nops(&hdr); |
1da177e4 LT |
2201 | } |
2202 | ||
2203 | /* | |
2204 | * Encode an OPEN request with no attributes. | |
2205 | */ | |
9f06c719 CL |
2206 | static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, |
2207 | struct xdr_stream *xdr, | |
2208 | struct nfs_openargs *args) | |
1da177e4 | 2209 | { |
1da177e4 | 2210 | struct compound_hdr hdr = { |
66cc0429 | 2211 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2212 | }; |
1da177e4 | 2213 | |
9f06c719 CL |
2214 | encode_compound_hdr(xdr, req, &hdr); |
2215 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2216 | encode_putfh(xdr, args->fh, &hdr); | |
2217 | encode_open(xdr, args, &hdr); | |
2218 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2219 | encode_nops(&hdr); |
1da177e4 LT |
2220 | } |
2221 | ||
2222 | /* | |
2223 | * Encode an OPEN_DOWNGRADE request | |
2224 | */ | |
9f06c719 CL |
2225 | static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, |
2226 | struct xdr_stream *xdr, | |
2227 | struct nfs_closeargs *args) | |
1da177e4 | 2228 | { |
1da177e4 | 2229 | struct compound_hdr hdr = { |
66cc0429 | 2230 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2231 | }; |
1da177e4 | 2232 | |
9f06c719 CL |
2233 | encode_compound_hdr(xdr, req, &hdr); |
2234 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2235 | encode_putfh(xdr, args->fh, &hdr); | |
2236 | encode_open_downgrade(xdr, args, &hdr); | |
2237 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2238 | encode_nops(&hdr); |
1da177e4 LT |
2239 | } |
2240 | ||
2241 | /* | |
2242 | * Encode a LOCK request | |
2243 | */ | |
9f06c719 CL |
2244 | static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, |
2245 | struct nfs_lock_args *args) | |
1da177e4 | 2246 | { |
1da177e4 | 2247 | struct compound_hdr hdr = { |
66cc0429 | 2248 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2249 | }; |
1da177e4 | 2250 | |
9f06c719 CL |
2251 | encode_compound_hdr(xdr, req, &hdr); |
2252 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2253 | encode_putfh(xdr, args->fh, &hdr); | |
2254 | encode_lock(xdr, args, &hdr); | |
d017931c | 2255 | encode_nops(&hdr); |
1da177e4 LT |
2256 | } |
2257 | ||
2258 | /* | |
2259 | * Encode a LOCKT request | |
2260 | */ | |
9f06c719 CL |
2261 | static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, |
2262 | struct nfs_lockt_args *args) | |
1da177e4 | 2263 | { |
1da177e4 | 2264 | struct compound_hdr hdr = { |
66cc0429 | 2265 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2266 | }; |
1da177e4 | 2267 | |
9f06c719 CL |
2268 | encode_compound_hdr(xdr, req, &hdr); |
2269 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2270 | encode_putfh(xdr, args->fh, &hdr); | |
2271 | encode_lockt(xdr, args, &hdr); | |
d017931c | 2272 | encode_nops(&hdr); |
1da177e4 LT |
2273 | } |
2274 | ||
2275 | /* | |
2276 | * Encode a LOCKU request | |
2277 | */ | |
9f06c719 CL |
2278 | static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, |
2279 | struct nfs_locku_args *args) | |
1da177e4 | 2280 | { |
1da177e4 | 2281 | struct compound_hdr hdr = { |
66cc0429 | 2282 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2283 | }; |
1da177e4 | 2284 | |
9f06c719 CL |
2285 | encode_compound_hdr(xdr, req, &hdr); |
2286 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2287 | encode_putfh(xdr, args->fh, &hdr); | |
2288 | encode_locku(xdr, args, &hdr); | |
d017931c | 2289 | encode_nops(&hdr); |
1da177e4 LT |
2290 | } |
2291 | ||
9f06c719 CL |
2292 | static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, |
2293 | struct xdr_stream *xdr, | |
2294 | struct nfs_release_lockowner_args *args) | |
d3c7b7cc | 2295 | { |
d3c7b7cc TM |
2296 | struct compound_hdr hdr = { |
2297 | .minorversion = 0, | |
2298 | }; | |
2299 | ||
9f06c719 CL |
2300 | encode_compound_hdr(xdr, req, &hdr); |
2301 | encode_release_lockowner(xdr, &args->lock_owner, &hdr); | |
d3c7b7cc | 2302 | encode_nops(&hdr); |
d3c7b7cc TM |
2303 | } |
2304 | ||
1da177e4 LT |
2305 | /* |
2306 | * Encode a READLINK request | |
2307 | */ | |
9f06c719 CL |
2308 | static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, |
2309 | const struct nfs4_readlink *args) | |
1da177e4 | 2310 | { |
1da177e4 | 2311 | struct compound_hdr hdr = { |
66cc0429 | 2312 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2313 | }; |
1da177e4 | 2314 | |
9f06c719 CL |
2315 | encode_compound_hdr(xdr, req, &hdr); |
2316 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2317 | encode_putfh(xdr, args->fh, &hdr); | |
2318 | encode_readlink(xdr, args, req, &hdr); | |
e3a535e1 | 2319 | |
28f56694 | 2320 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, |
e3a535e1 | 2321 | args->pgbase, args->pglen); |
d017931c | 2322 | encode_nops(&hdr); |
1da177e4 LT |
2323 | } |
2324 | ||
2325 | /* | |
2326 | * Encode a READDIR request | |
2327 | */ | |
9f06c719 CL |
2328 | static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, |
2329 | const struct nfs4_readdir_arg *args) | |
1da177e4 | 2330 | { |
1da177e4 | 2331 | struct compound_hdr hdr = { |
66cc0429 | 2332 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2333 | }; |
1da177e4 | 2334 | |
9f06c719 CL |
2335 | encode_compound_hdr(xdr, req, &hdr); |
2336 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2337 | encode_putfh(xdr, args->fh, &hdr); | |
2338 | encode_readdir(xdr, args, req, &hdr); | |
d6ac02df | 2339 | |
28f56694 | 2340 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, |
d6ac02df TM |
2341 | args->pgbase, args->count); |
2342 | dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", | |
28f56694 | 2343 | __func__, hdr.replen << 2, args->pages, |
d6ac02df | 2344 | args->pgbase, args->count); |
d017931c | 2345 | encode_nops(&hdr); |
1da177e4 LT |
2346 | } |
2347 | ||
2348 | /* | |
2349 | * Encode a READ request | |
2350 | */ | |
9f06c719 CL |
2351 | static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, |
2352 | struct nfs_readargs *args) | |
1da177e4 | 2353 | { |
1da177e4 | 2354 | struct compound_hdr hdr = { |
66cc0429 | 2355 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2356 | }; |
1da177e4 | 2357 | |
9f06c719 CL |
2358 | encode_compound_hdr(xdr, req, &hdr); |
2359 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2360 | encode_putfh(xdr, args->fh, &hdr); | |
2361 | encode_read(xdr, args, &hdr); | |
1da177e4 | 2362 | |
28f56694 | 2363 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, |
1da177e4 | 2364 | args->pages, args->pgbase, args->count); |
4f22ccc3 | 2365 | req->rq_rcv_buf.flags |= XDRBUF_READ; |
d017931c | 2366 | encode_nops(&hdr); |
1da177e4 LT |
2367 | } |
2368 | ||
2369 | /* | |
2370 | * Encode an SETATTR request | |
2371 | */ | |
9f06c719 CL |
2372 | static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, |
2373 | struct nfs_setattrargs *args) | |
1da177e4 | 2374 | { |
05d564fe | 2375 | struct compound_hdr hdr = { |
66cc0429 | 2376 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
05d564fe | 2377 | }; |
05d564fe | 2378 | |
9f06c719 CL |
2379 | encode_compound_hdr(xdr, req, &hdr); |
2380 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2381 | encode_putfh(xdr, args->fh, &hdr); | |
2382 | encode_setattr(xdr, args, args->server, &hdr); | |
2383 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2384 | encode_nops(&hdr); |
1da177e4 LT |
2385 | } |
2386 | ||
029d105e BF |
2387 | /* |
2388 | * Encode a GETACL request | |
2389 | */ | |
9f06c719 CL |
2390 | static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, |
2391 | struct nfs_getaclargs *args) | |
029d105e | 2392 | { |
029d105e | 2393 | struct compound_hdr hdr = { |
66cc0429 | 2394 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
029d105e | 2395 | }; |
28f56694 | 2396 | uint32_t replen; |
029d105e | 2397 | |
9f06c719 CL |
2398 | encode_compound_hdr(xdr, req, &hdr); |
2399 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2400 | encode_putfh(xdr, args->fh, &hdr); | |
d327cf74 | 2401 | replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1; |
9f06c719 | 2402 | encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); |
cf8cdbe5 | 2403 | |
28f56694 | 2404 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, |
029d105e | 2405 | args->acl_pages, args->acl_pgbase, args->acl_len); |
d017931c | 2406 | encode_nops(&hdr); |
029d105e BF |
2407 | } |
2408 | ||
1da177e4 LT |
2409 | /* |
2410 | * Encode a WRITE request | |
2411 | */ | |
9f06c719 CL |
2412 | static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, |
2413 | struct nfs_writeargs *args) | |
1da177e4 | 2414 | { |
1da177e4 | 2415 | struct compound_hdr hdr = { |
66cc0429 | 2416 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2417 | }; |
1da177e4 | 2418 | |
9f06c719 CL |
2419 | encode_compound_hdr(xdr, req, &hdr); |
2420 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2421 | encode_putfh(xdr, args->fh, &hdr); | |
2422 | encode_write(xdr, args, &hdr); | |
4f22ccc3 | 2423 | req->rq_snd_buf.flags |= XDRBUF_WRITE; |
7ffd1064 FI |
2424 | if (args->bitmask) |
2425 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2426 | encode_nops(&hdr); |
1da177e4 LT |
2427 | } |
2428 | ||
2429 | /* | |
2430 | * a COMMIT request | |
2431 | */ | |
9f06c719 CL |
2432 | static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, |
2433 | struct nfs_writeargs *args) | |
1da177e4 | 2434 | { |
1da177e4 | 2435 | struct compound_hdr hdr = { |
66cc0429 | 2436 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2437 | }; |
1da177e4 | 2438 | |
9f06c719 CL |
2439 | encode_compound_hdr(xdr, req, &hdr); |
2440 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2441 | encode_putfh(xdr, args->fh, &hdr); | |
2442 | encode_commit(xdr, args, &hdr); | |
988b6dce FI |
2443 | if (args->bitmask) |
2444 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2445 | encode_nops(&hdr); |
1da177e4 LT |
2446 | } |
2447 | ||
2448 | /* | |
2449 | * FSINFO request | |
2450 | */ | |
9f06c719 CL |
2451 | static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, |
2452 | struct nfs4_fsinfo_arg *args) | |
1da177e4 | 2453 | { |
1da177e4 | 2454 | struct compound_hdr hdr = { |
66cc0429 | 2455 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2456 | }; |
1da177e4 | 2457 | |
9f06c719 CL |
2458 | encode_compound_hdr(xdr, req, &hdr); |
2459 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2460 | encode_putfh(xdr, args->fh, &hdr); | |
2461 | encode_fsinfo(xdr, args->bitmask, &hdr); | |
d017931c | 2462 | encode_nops(&hdr); |
1da177e4 LT |
2463 | } |
2464 | ||
2465 | /* | |
2466 | * a PATHCONF request | |
2467 | */ | |
9f06c719 CL |
2468 | static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, |
2469 | const struct nfs4_pathconf_arg *args) | |
1da177e4 | 2470 | { |
1da177e4 | 2471 | struct compound_hdr hdr = { |
66cc0429 | 2472 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2473 | }; |
1da177e4 | 2474 | |
9f06c719 CL |
2475 | encode_compound_hdr(xdr, req, &hdr); |
2476 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2477 | encode_putfh(xdr, args->fh, &hdr); | |
2478 | encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], | |
cf8cdbe5 | 2479 | &hdr); |
d017931c | 2480 | encode_nops(&hdr); |
1da177e4 LT |
2481 | } |
2482 | ||
2483 | /* | |
2484 | * a STATFS request | |
2485 | */ | |
9f06c719 CL |
2486 | static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, |
2487 | const struct nfs4_statfs_arg *args) | |
1da177e4 | 2488 | { |
1da177e4 | 2489 | struct compound_hdr hdr = { |
66cc0429 | 2490 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2491 | }; |
1da177e4 | 2492 | |
9f06c719 CL |
2493 | encode_compound_hdr(xdr, req, &hdr); |
2494 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2495 | encode_putfh(xdr, args->fh, &hdr); | |
2496 | encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], | |
cf8cdbe5 | 2497 | args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); |
d017931c | 2498 | encode_nops(&hdr); |
1da177e4 LT |
2499 | } |
2500 | ||
2501 | /* | |
2502 | * GETATTR_BITMAP request | |
2503 | */ | |
9f06c719 CL |
2504 | static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, |
2505 | struct xdr_stream *xdr, | |
2506 | struct nfs4_server_caps_arg *args) | |
1da177e4 | 2507 | { |
1da177e4 | 2508 | struct compound_hdr hdr = { |
66cc0429 | 2509 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2510 | }; |
1da177e4 | 2511 | |
9f06c719 CL |
2512 | encode_compound_hdr(xdr, req, &hdr); |
2513 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2514 | encode_putfh(xdr, args->fhandle, &hdr); | |
2515 | encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| | |
cf8cdbe5 AA |
2516 | FATTR4_WORD0_LINK_SUPPORT| |
2517 | FATTR4_WORD0_SYMLINK_SUPPORT| | |
2518 | FATTR4_WORD0_ACLSUPPORT, &hdr); | |
d017931c | 2519 | encode_nops(&hdr); |
1da177e4 LT |
2520 | } |
2521 | ||
2522 | /* | |
2523 | * a RENEW request | |
2524 | */ | |
9f06c719 CL |
2525 | static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, |
2526 | struct nfs_client *clp) | |
1da177e4 | 2527 | { |
1da177e4 | 2528 | struct compound_hdr hdr = { |
d017931c | 2529 | .nops = 0, |
1da177e4 LT |
2530 | }; |
2531 | ||
9f06c719 CL |
2532 | encode_compound_hdr(xdr, req, &hdr); |
2533 | encode_renew(xdr, clp, &hdr); | |
d017931c | 2534 | encode_nops(&hdr); |
1da177e4 LT |
2535 | } |
2536 | ||
2537 | /* | |
2538 | * a SETCLIENTID request | |
2539 | */ | |
9f06c719 CL |
2540 | static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, |
2541 | struct xdr_stream *xdr, | |
2542 | struct nfs4_setclientid *sc) | |
1da177e4 | 2543 | { |
1da177e4 | 2544 | struct compound_hdr hdr = { |
d017931c | 2545 | .nops = 0, |
1da177e4 LT |
2546 | }; |
2547 | ||
9f06c719 CL |
2548 | encode_compound_hdr(xdr, req, &hdr); |
2549 | encode_setclientid(xdr, sc, &hdr); | |
d017931c | 2550 | encode_nops(&hdr); |
1da177e4 LT |
2551 | } |
2552 | ||
2553 | /* | |
2554 | * a SETCLIENTID_CONFIRM request | |
2555 | */ | |
9f06c719 CL |
2556 | static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, |
2557 | struct xdr_stream *xdr, | |
2558 | struct nfs4_setclientid_res *arg) | |
1da177e4 | 2559 | { |
1da177e4 | 2560 | struct compound_hdr hdr = { |
d017931c | 2561 | .nops = 0, |
1da177e4 LT |
2562 | }; |
2563 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; | |
1da177e4 | 2564 | |
9f06c719 CL |
2565 | encode_compound_hdr(xdr, req, &hdr); |
2566 | encode_setclientid_confirm(xdr, arg, &hdr); | |
2567 | encode_putrootfh(xdr, &hdr); | |
2568 | encode_fsinfo(xdr, lease_bitmap, &hdr); | |
d017931c | 2569 | encode_nops(&hdr); |
1da177e4 LT |
2570 | } |
2571 | ||
2572 | /* | |
2573 | * DELEGRETURN request | |
2574 | */ | |
9f06c719 CL |
2575 | static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, |
2576 | struct xdr_stream *xdr, | |
2577 | const struct nfs4_delegreturnargs *args) | |
1da177e4 | 2578 | { |
1da177e4 | 2579 | struct compound_hdr hdr = { |
66cc0429 | 2580 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2581 | }; |
1da177e4 | 2582 | |
9f06c719 CL |
2583 | encode_compound_hdr(xdr, req, &hdr); |
2584 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2585 | encode_putfh(xdr, args->fhandle, &hdr); | |
2586 | encode_delegreturn(xdr, args->stateid, &hdr); | |
2587 | encode_getfattr(xdr, args->bitmask, &hdr); | |
d017931c | 2588 | encode_nops(&hdr); |
1da177e4 LT |
2589 | } |
2590 | ||
683b57b4 TM |
2591 | /* |
2592 | * Encode FS_LOCATIONS request | |
2593 | */ | |
9f06c719 CL |
2594 | static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, |
2595 | struct xdr_stream *xdr, | |
2596 | struct nfs4_fs_locations_arg *args) | |
683b57b4 | 2597 | { |
683b57b4 | 2598 | struct compound_hdr hdr = { |
66cc0429 | 2599 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
683b57b4 | 2600 | }; |
28f56694 | 2601 | uint32_t replen; |
683b57b4 | 2602 | |
9f06c719 CL |
2603 | encode_compound_hdr(xdr, req, &hdr); |
2604 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2605 | encode_putfh(xdr, args->dir_fh, &hdr); | |
2606 | encode_lookup(xdr, args->name, &hdr); | |
28f56694 | 2607 | replen = hdr.replen; /* get the attribute into args->page */ |
9f06c719 | 2608 | encode_fs_locations(xdr, args->bitmask, &hdr); |
cf8cdbe5 | 2609 | |
28f56694 | 2610 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, |
683b57b4 | 2611 | 0, PAGE_SIZE); |
d017931c | 2612 | encode_nops(&hdr); |
683b57b4 TM |
2613 | } |
2614 | ||
5a5ea0d4 BS |
2615 | /* |
2616 | * Encode SECINFO request | |
2617 | */ | |
2618 | static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, | |
2619 | struct xdr_stream *xdr, | |
2620 | struct nfs4_secinfo_arg *args) | |
2621 | { | |
2622 | struct compound_hdr hdr = { | |
2623 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | |
2624 | }; | |
2625 | ||
2626 | encode_compound_hdr(xdr, req, &hdr); | |
2627 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2628 | encode_putfh(xdr, args->dir_fh, &hdr); | |
2629 | encode_secinfo(xdr, args->name, &hdr); | |
2630 | encode_nops(&hdr); | |
2631 | } | |
2632 | ||
99fe60d0 BH |
2633 | #if defined(CONFIG_NFS_V4_1) |
2634 | /* | |
2635 | * EXCHANGE_ID request | |
2636 | */ | |
9f06c719 CL |
2637 | static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, |
2638 | struct xdr_stream *xdr, | |
2639 | struct nfs41_exchange_id_args *args) | |
99fe60d0 | 2640 | { |
99fe60d0 | 2641 | struct compound_hdr hdr = { |
a4432345 | 2642 | .minorversion = args->client->cl_mvops->minor_version, |
99fe60d0 BH |
2643 | }; |
2644 | ||
9f06c719 CL |
2645 | encode_compound_hdr(xdr, req, &hdr); |
2646 | encode_exchange_id(xdr, args, &hdr); | |
99fe60d0 | 2647 | encode_nops(&hdr); |
99fe60d0 | 2648 | } |
2050f0cc | 2649 | |
fc931582 AA |
2650 | /* |
2651 | * a CREATE_SESSION request | |
2652 | */ | |
9f06c719 CL |
2653 | static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, |
2654 | struct xdr_stream *xdr, | |
2655 | struct nfs41_create_session_args *args) | |
fc931582 | 2656 | { |
fc931582 | 2657 | struct compound_hdr hdr = { |
a4432345 | 2658 | .minorversion = args->client->cl_mvops->minor_version, |
fc931582 AA |
2659 | }; |
2660 | ||
9f06c719 CL |
2661 | encode_compound_hdr(xdr, req, &hdr); |
2662 | encode_create_session(xdr, args, &hdr); | |
fc931582 | 2663 | encode_nops(&hdr); |
fc931582 AA |
2664 | } |
2665 | ||
0f3e66c6 AA |
2666 | /* |
2667 | * a DESTROY_SESSION request | |
2668 | */ | |
9f06c719 CL |
2669 | static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, |
2670 | struct xdr_stream *xdr, | |
2671 | struct nfs4_session *session) | |
0f3e66c6 | 2672 | { |
0f3e66c6 | 2673 | struct compound_hdr hdr = { |
a4432345 | 2674 | .minorversion = session->clp->cl_mvops->minor_version, |
0f3e66c6 AA |
2675 | }; |
2676 | ||
9f06c719 CL |
2677 | encode_compound_hdr(xdr, req, &hdr); |
2678 | encode_destroy_session(xdr, session, &hdr); | |
0f3e66c6 | 2679 | encode_nops(&hdr); |
0f3e66c6 AA |
2680 | } |
2681 | ||
fc01cea9 AA |
2682 | /* |
2683 | * a SEQUENCE request | |
2684 | */ | |
9f06c719 CL |
2685 | static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, |
2686 | struct nfs4_sequence_args *args) | |
fc01cea9 | 2687 | { |
fc01cea9 AA |
2688 | struct compound_hdr hdr = { |
2689 | .minorversion = nfs4_xdr_minorversion(args), | |
2690 | }; | |
2691 | ||
9f06c719 CL |
2692 | encode_compound_hdr(xdr, req, &hdr); |
2693 | encode_sequence(xdr, args, &hdr); | |
fc01cea9 | 2694 | encode_nops(&hdr); |
fc01cea9 AA |
2695 | } |
2696 | ||
2050f0cc AA |
2697 | /* |
2698 | * a GET_LEASE_TIME request | |
2699 | */ | |
9f06c719 CL |
2700 | static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, |
2701 | struct xdr_stream *xdr, | |
2702 | struct nfs4_get_lease_time_args *args) | |
2050f0cc | 2703 | { |
2050f0cc AA |
2704 | struct compound_hdr hdr = { |
2705 | .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), | |
2706 | }; | |
2707 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; | |
2708 | ||
9f06c719 CL |
2709 | encode_compound_hdr(xdr, req, &hdr); |
2710 | encode_sequence(xdr, &args->la_seq_args, &hdr); | |
2711 | encode_putrootfh(xdr, &hdr); | |
2712 | encode_fsinfo(xdr, lease_bitmap, &hdr); | |
2050f0cc | 2713 | encode_nops(&hdr); |
2050f0cc | 2714 | } |
18019753 RL |
2715 | |
2716 | /* | |
2717 | * a RECLAIM_COMPLETE request | |
2718 | */ | |
9f06c719 CL |
2719 | static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, |
2720 | struct xdr_stream *xdr, | |
2721 | struct nfs41_reclaim_complete_args *args) | |
18019753 | 2722 | { |
18019753 RL |
2723 | struct compound_hdr hdr = { |
2724 | .minorversion = nfs4_xdr_minorversion(&args->seq_args) | |
2725 | }; | |
2726 | ||
9f06c719 CL |
2727 | encode_compound_hdr(xdr, req, &hdr); |
2728 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2729 | encode_reclaim_complete(xdr, args, &hdr); | |
18019753 | 2730 | encode_nops(&hdr); |
18019753 RL |
2731 | } |
2732 | ||
b1f69b75 AA |
2733 | /* |
2734 | * Encode GETDEVICEINFO request | |
2735 | */ | |
9f06c719 CL |
2736 | static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, |
2737 | struct xdr_stream *xdr, | |
2738 | struct nfs4_getdeviceinfo_args *args) | |
b1f69b75 | 2739 | { |
b1f69b75 AA |
2740 | struct compound_hdr hdr = { |
2741 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | |
2742 | }; | |
2743 | ||
9f06c719 CL |
2744 | encode_compound_hdr(xdr, req, &hdr); |
2745 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2746 | encode_getdeviceinfo(xdr, args, &hdr); | |
b1f69b75 AA |
2747 | |
2748 | /* set up reply kvec. Subtract notification bitmap max size (2) | |
2749 | * so that notification bitmap is put in xdr_buf tail */ | |
2750 | xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, | |
2751 | args->pdev->pages, args->pdev->pgbase, | |
2752 | args->pdev->pglen); | |
2753 | ||
2754 | encode_nops(&hdr); | |
b1f69b75 AA |
2755 | } |
2756 | ||
2757 | /* | |
2758 | * Encode LAYOUTGET request | |
2759 | */ | |
9f06c719 CL |
2760 | static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, |
2761 | struct xdr_stream *xdr, | |
2762 | struct nfs4_layoutget_args *args) | |
b1f69b75 | 2763 | { |
b1f69b75 AA |
2764 | struct compound_hdr hdr = { |
2765 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | |
2766 | }; | |
2767 | ||
9f06c719 CL |
2768 | encode_compound_hdr(xdr, req, &hdr); |
2769 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2770 | encode_putfh(xdr, NFS_FH(args->inode), &hdr); | |
2771 | encode_layoutget(xdr, args, &hdr); | |
35124a09 WAA |
2772 | |
2773 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, | |
2774 | args->layout.pages, 0, args->layout.pglen); | |
2775 | ||
b1f69b75 | 2776 | encode_nops(&hdr); |
b1f69b75 | 2777 | } |
863a3c6c AA |
2778 | |
2779 | /* | |
2780 | * Encode LAYOUTCOMMIT request | |
2781 | */ | |
cbe82603 BH |
2782 | static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, |
2783 | struct xdr_stream *xdr, | |
2784 | struct nfs4_layoutcommit_args *args) | |
863a3c6c | 2785 | { |
ac7db726 BH |
2786 | struct nfs4_layoutcommit_data *data = |
2787 | container_of(args, struct nfs4_layoutcommit_data, args); | |
863a3c6c AA |
2788 | struct compound_hdr hdr = { |
2789 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | |
2790 | }; | |
2791 | ||
2792 | encode_compound_hdr(xdr, req, &hdr); | |
2793 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2794 | encode_putfh(xdr, NFS_FH(args->inode), &hdr); | |
ac7db726 | 2795 | encode_layoutcommit(xdr, data->args.inode, args, &hdr); |
863a3c6c | 2796 | encode_getfattr(xdr, args->bitmask, &hdr); |
b1f69b75 | 2797 | encode_nops(&hdr); |
cbe82603 BH |
2798 | } |
2799 | ||
2800 | /* | |
2801 | * Encode LAYOUTRETURN request | |
2802 | */ | |
2803 | static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, | |
2804 | struct xdr_stream *xdr, | |
2805 | struct nfs4_layoutreturn_args *args) | |
2806 | { | |
2807 | struct compound_hdr hdr = { | |
2808 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | |
2809 | }; | |
2810 | ||
2811 | encode_compound_hdr(xdr, req, &hdr); | |
2812 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2813 | encode_putfh(xdr, NFS_FH(args->inode), &hdr); | |
2814 | encode_layoutreturn(xdr, args, &hdr); | |
2815 | encode_nops(&hdr); | |
b1f69b75 | 2816 | } |
fca78d6d BS |
2817 | |
2818 | /* | |
2819 | * Encode SECINFO_NO_NAME request | |
2820 | */ | |
2821 | static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, | |
2822 | struct xdr_stream *xdr, | |
2823 | struct nfs41_secinfo_no_name_args *args) | |
2824 | { | |
2825 | struct compound_hdr hdr = { | |
2826 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | |
2827 | }; | |
2828 | ||
2829 | encode_compound_hdr(xdr, req, &hdr); | |
2830 | encode_sequence(xdr, &args->seq_args, &hdr); | |
2831 | encode_putrootfh(xdr, &hdr); | |
2832 | encode_secinfo_no_name(xdr, args, &hdr); | |
2833 | encode_nops(&hdr); | |
2834 | return 0; | |
2835 | } | |
99fe60d0 BH |
2836 | #endif /* CONFIG_NFS_V4_1 */ |
2837 | ||
686841b3 BH |
2838 | static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) |
2839 | { | |
2840 | dprintk("nfs: %s: prematurely hit end of receive buffer. " | |
2841 | "Remaining buffer length is %tu words.\n", | |
2842 | func, xdr->end - xdr->p); | |
2843 | } | |
1da177e4 | 2844 | |
683b57b4 | 2845 | static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) |
1da177e4 | 2846 | { |
8687b63a | 2847 | __be32 *p; |
1da177e4 | 2848 | |
c0eae66e BH |
2849 | p = xdr_inline_decode(xdr, 4); |
2850 | if (unlikely(!p)) | |
2851 | goto out_overflow; | |
cccddf4f | 2852 | *len = be32_to_cpup(p); |
c0eae66e BH |
2853 | p = xdr_inline_decode(xdr, *len); |
2854 | if (unlikely(!p)) | |
2855 | goto out_overflow; | |
1da177e4 LT |
2856 | *string = (char *)p; |
2857 | return 0; | |
c0eae66e BH |
2858 | out_overflow: |
2859 | print_overflow_msg(__func__, xdr); | |
2860 | return -EIO; | |
1da177e4 LT |
2861 | } |
2862 | ||
2863 | static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) | |
2864 | { | |
8687b63a | 2865 | __be32 *p; |
1da177e4 | 2866 | |
c0eae66e BH |
2867 | p = xdr_inline_decode(xdr, 8); |
2868 | if (unlikely(!p)) | |
2869 | goto out_overflow; | |
6f723f77 | 2870 | hdr->status = be32_to_cpup(p++); |
cccddf4f | 2871 | hdr->taglen = be32_to_cpup(p); |
6c0195a4 | 2872 | |
c0eae66e BH |
2873 | p = xdr_inline_decode(xdr, hdr->taglen + 4); |
2874 | if (unlikely(!p)) | |
2875 | goto out_overflow; | |
1da177e4 LT |
2876 | hdr->tag = (char *)p; |
2877 | p += XDR_QUADLEN(hdr->taglen); | |
cccddf4f | 2878 | hdr->nops = be32_to_cpup(p); |
aadf6152 BH |
2879 | if (unlikely(hdr->nops < 1)) |
2880 | return nfs4_stat_to_errno(hdr->status); | |
1da177e4 | 2881 | return 0; |
c0eae66e BH |
2882 | out_overflow: |
2883 | print_overflow_msg(__func__, xdr); | |
2884 | return -EIO; | |
1da177e4 LT |
2885 | } |
2886 | ||
2887 | static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) | |
2888 | { | |
8687b63a | 2889 | __be32 *p; |
1da177e4 LT |
2890 | uint32_t opnum; |
2891 | int32_t nfserr; | |
2892 | ||
c0eae66e BH |
2893 | p = xdr_inline_decode(xdr, 8); |
2894 | if (unlikely(!p)) | |
2895 | goto out_overflow; | |
6f723f77 | 2896 | opnum = be32_to_cpup(p++); |
1da177e4 | 2897 | if (opnum != expected) { |
fe82a183 CL |
2898 | dprintk("nfs: Server returned operation" |
2899 | " %d but we issued a request for %d\n", | |
1da177e4 LT |
2900 | opnum, expected); |
2901 | return -EIO; | |
2902 | } | |
cccddf4f | 2903 | nfserr = be32_to_cpup(p); |
1da177e4 | 2904 | if (nfserr != NFS_OK) |
856dff3d | 2905 | return nfs4_stat_to_errno(nfserr); |
1da177e4 | 2906 | return 0; |
c0eae66e BH |
2907 | out_overflow: |
2908 | print_overflow_msg(__func__, xdr); | |
2909 | return -EIO; | |
1da177e4 LT |
2910 | } |
2911 | ||
2912 | /* Dummy routine */ | |
adfa6f98 | 2913 | static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) |
1da177e4 | 2914 | { |
8687b63a | 2915 | __be32 *p; |
683b57b4 | 2916 | unsigned int strlen; |
1da177e4 LT |
2917 | char *str; |
2918 | ||
c0eae66e BH |
2919 | p = xdr_inline_decode(xdr, 12); |
2920 | if (likely(p)) | |
2921 | return decode_opaque_inline(xdr, &strlen, &str); | |
2922 | print_overflow_msg(__func__, xdr); | |
2923 | return -EIO; | |
1da177e4 LT |
2924 | } |
2925 | ||
2926 | static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) | |
2927 | { | |
8687b63a AV |
2928 | uint32_t bmlen; |
2929 | __be32 *p; | |
1da177e4 | 2930 | |
c0eae66e BH |
2931 | p = xdr_inline_decode(xdr, 4); |
2932 | if (unlikely(!p)) | |
2933 | goto out_overflow; | |
cccddf4f | 2934 | bmlen = be32_to_cpup(p); |
1da177e4 LT |
2935 | |
2936 | bitmap[0] = bitmap[1] = 0; | |
c0eae66e BH |
2937 | p = xdr_inline_decode(xdr, (bmlen << 2)); |
2938 | if (unlikely(!p)) | |
2939 | goto out_overflow; | |
1da177e4 | 2940 | if (bmlen > 0) { |
6f723f77 | 2941 | bitmap[0] = be32_to_cpup(p++); |
1da177e4 | 2942 | if (bmlen > 1) |
cccddf4f | 2943 | bitmap[1] = be32_to_cpup(p); |
1da177e4 LT |
2944 | } |
2945 | return 0; | |
c0eae66e BH |
2946 | out_overflow: |
2947 | print_overflow_msg(__func__, xdr); | |
2948 | return -EIO; | |
1da177e4 LT |
2949 | } |
2950 | ||
8687b63a | 2951 | static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep) |
1da177e4 | 2952 | { |
8687b63a | 2953 | __be32 *p; |
1da177e4 | 2954 | |
c0eae66e BH |
2955 | p = xdr_inline_decode(xdr, 4); |
2956 | if (unlikely(!p)) | |
2957 | goto out_overflow; | |
cccddf4f | 2958 | *attrlen = be32_to_cpup(p); |
1da177e4 LT |
2959 | *savep = xdr->p; |
2960 | return 0; | |
c0eae66e BH |
2961 | out_overflow: |
2962 | print_overflow_msg(__func__, xdr); | |
2963 | return -EIO; | |
1da177e4 LT |
2964 | } |
2965 | ||
2966 | static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) | |
2967 | { | |
2968 | if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { | |
3388bff5 RB |
2969 | int ret; |
2970 | ret = decode_attr_bitmap(xdr, bitmask); | |
2971 | if (unlikely(ret < 0)) | |
2972 | return ret; | |
1da177e4 LT |
2973 | bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; |
2974 | } else | |
2975 | bitmask[0] = bitmask[1] = 0; | |
44109241 | 2976 | dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]); |
1da177e4 LT |
2977 | return 0; |
2978 | } | |
2979 | ||
2980 | static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) | |
2981 | { | |
8687b63a | 2982 | __be32 *p; |
409924e4 | 2983 | int ret = 0; |
1da177e4 LT |
2984 | |
2985 | *type = 0; | |
2986 | if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) | |
2987 | return -EIO; | |
2988 | if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { | |
c0eae66e BH |
2989 | p = xdr_inline_decode(xdr, 4); |
2990 | if (unlikely(!p)) | |
2991 | goto out_overflow; | |
cccddf4f | 2992 | *type = be32_to_cpup(p); |
1da177e4 | 2993 | if (*type < NF4REG || *type > NF4NAMEDATTR) { |
3110ff80 | 2994 | dprintk("%s: bad type %d\n", __func__, *type); |
1da177e4 LT |
2995 | return -EIO; |
2996 | } | |
2997 | bitmap[0] &= ~FATTR4_WORD0_TYPE; | |
409924e4 | 2998 | ret = NFS_ATTR_FATTR_TYPE; |
1da177e4 | 2999 | } |
bca79478 | 3000 | dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); |
409924e4 | 3001 | return ret; |
c0eae66e BH |
3002 | out_overflow: |
3003 | print_overflow_msg(__func__, xdr); | |
3004 | return -EIO; | |
1da177e4 LT |
3005 | } |
3006 | ||
3007 | static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) | |
3008 | { | |
8687b63a | 3009 | __be32 *p; |
409924e4 | 3010 | int ret = 0; |
1da177e4 LT |
3011 | |
3012 | *change = 0; | |
3013 | if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) | |
3014 | return -EIO; | |
3015 | if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { | |
c0eae66e BH |
3016 | p = xdr_inline_decode(xdr, 8); |
3017 | if (unlikely(!p)) | |
3018 | goto out_overflow; | |
cccddf4f | 3019 | xdr_decode_hyper(p, change); |
1da177e4 | 3020 | bitmap[0] &= ~FATTR4_WORD0_CHANGE; |
409924e4 | 3021 | ret = NFS_ATTR_FATTR_CHANGE; |
1da177e4 | 3022 | } |
3110ff80 | 3023 | dprintk("%s: change attribute=%Lu\n", __func__, |
1da177e4 | 3024 | (unsigned long long)*change); |
409924e4 | 3025 | return ret; |
c0eae66e BH |
3026 | out_overflow: |
3027 | print_overflow_msg(__func__, xdr); | |
3028 | return -EIO; | |
1da177e4 LT |
3029 | } |
3030 | ||
3031 | static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) | |
3032 | { | |
8687b63a | 3033 | __be32 *p; |
409924e4 | 3034 | int ret = 0; |
1da177e4 LT |
3035 | |
3036 | *size = 0; | |
3037 | if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) | |
3038 | return -EIO; | |
3039 | if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { | |
c0eae66e BH |
3040 | p = xdr_inline_decode(xdr, 8); |
3041 | if (unlikely(!p)) | |
3042 | goto out_overflow; | |
cccddf4f | 3043 | xdr_decode_hyper(p, size); |
1da177e4 | 3044 | bitmap[0] &= ~FATTR4_WORD0_SIZE; |
409924e4 | 3045 | ret = NFS_ATTR_FATTR_SIZE; |
1da177e4 | 3046 | } |
3110ff80 | 3047 | dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); |
409924e4 | 3048 | return ret; |
c0eae66e BH |
3049 | out_overflow: |
3050 | print_overflow_msg(__func__, xdr); | |
3051 | return -EIO; | |
1da177e4 LT |
3052 | } |
3053 | ||
3054 | static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
3055 | { | |
8687b63a | 3056 | __be32 *p; |
1da177e4 LT |
3057 | |
3058 | *res = 0; | |
3059 | if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) | |
3060 | return -EIO; | |
3061 | if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { | |
c0eae66e BH |
3062 | p = xdr_inline_decode(xdr, 4); |
3063 | if (unlikely(!p)) | |
3064 | goto out_overflow; | |
cccddf4f | 3065 | *res = be32_to_cpup(p); |
1da177e4 LT |
3066 | bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; |
3067 | } | |
3110ff80 | 3068 | dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); |
1da177e4 | 3069 | return 0; |
c0eae66e BH |
3070 | out_overflow: |
3071 | print_overflow_msg(__func__, xdr); | |
3072 | return -EIO; | |
1da177e4 LT |
3073 | } |
3074 | ||
3075 | static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
3076 | { | |
8687b63a | 3077 | __be32 *p; |
1da177e4 LT |
3078 | |
3079 | *res = 0; | |
3080 | if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) | |
3081 | return -EIO; | |
3082 | if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { | |
c0eae66e BH |
3083 | p = xdr_inline_decode(xdr, 4); |
3084 | if (unlikely(!p)) | |
3085 | goto out_overflow; | |
cccddf4f | 3086 | *res = be32_to_cpup(p); |
1da177e4 LT |
3087 | bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; |
3088 | } | |
3110ff80 | 3089 | dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); |
1da177e4 | 3090 | return 0; |
c0eae66e BH |
3091 | out_overflow: |
3092 | print_overflow_msg(__func__, xdr); | |
3093 | return -EIO; | |
1da177e4 LT |
3094 | } |
3095 | ||
8b4bdcf8 | 3096 | static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) |
1da177e4 | 3097 | { |
8687b63a | 3098 | __be32 *p; |
409924e4 | 3099 | int ret = 0; |
1da177e4 LT |
3100 | |
3101 | fsid->major = 0; | |
3102 | fsid->minor = 0; | |
3103 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) | |
3104 | return -EIO; | |
3105 | if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { | |
c0eae66e BH |
3106 | p = xdr_inline_decode(xdr, 16); |
3107 | if (unlikely(!p)) | |
3108 | goto out_overflow; | |
3ceb4dbb | 3109 | p = xdr_decode_hyper(p, &fsid->major); |
cccddf4f | 3110 | xdr_decode_hyper(p, &fsid->minor); |
1da177e4 | 3111 | bitmap[0] &= ~FATTR4_WORD0_FSID; |
409924e4 | 3112 | ret = NFS_ATTR_FATTR_FSID; |
1da177e4 | 3113 | } |
3110ff80 | 3114 | dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, |
1da177e4 LT |
3115 | (unsigned long long)fsid->major, |
3116 | (unsigned long long)fsid->minor); | |
409924e4 | 3117 | return ret; |
c0eae66e BH |
3118 | out_overflow: |
3119 | print_overflow_msg(__func__, xdr); | |
3120 | return -EIO; | |
1da177e4 LT |
3121 | } |
3122 | ||
3123 | static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
3124 | { | |
8687b63a | 3125 | __be32 *p; |
1da177e4 LT |
3126 | |
3127 | *res = 60; | |
3128 | if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) | |
3129 | return -EIO; | |
3130 | if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { | |
c0eae66e BH |
3131 | p = xdr_inline_decode(xdr, 4); |
3132 | if (unlikely(!p)) | |
3133 | goto out_overflow; | |
cccddf4f | 3134 | *res = be32_to_cpup(p); |
1da177e4 LT |
3135 | bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; |
3136 | } | |
3110ff80 | 3137 | dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); |
1da177e4 | 3138 | return 0; |
c0eae66e BH |
3139 | out_overflow: |
3140 | print_overflow_msg(__func__, xdr); | |
3141 | return -EIO; | |
1da177e4 LT |
3142 | } |
3143 | ||
ee7b75fc | 3144 | static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) |
ae42c70a BS |
3145 | { |
3146 | __be32 *p; | |
3147 | ||
3148 | if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) | |
3149 | return -EIO; | |
3150 | if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { | |
3151 | p = xdr_inline_decode(xdr, 4); | |
3152 | if (unlikely(!p)) | |
3153 | goto out_overflow; | |
3154 | bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; | |
ee7b75fc | 3155 | *res = -be32_to_cpup(p); |
ae42c70a BS |
3156 | } |
3157 | return 0; | |
3158 | out_overflow: | |
3159 | print_overflow_msg(__func__, xdr); | |
3160 | return -EIO; | |
3161 | } | |
3162 | ||
3163 | static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) | |
3164 | { | |
3165 | __be32 *p; | |
3166 | int len; | |
3167 | ||
7ad07353 TM |
3168 | if (fh != NULL) |
3169 | memset(fh, 0, sizeof(*fh)); | |
ae42c70a BS |
3170 | |
3171 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) | |
3172 | return -EIO; | |
3173 | if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { | |
3174 | p = xdr_inline_decode(xdr, 4); | |
3175 | if (unlikely(!p)) | |
3176 | goto out_overflow; | |
3177 | len = be32_to_cpup(p); | |
3178 | if (len > NFS4_FHSIZE) | |
3179 | return -EIO; | |
ae42c70a BS |
3180 | p = xdr_inline_decode(xdr, len); |
3181 | if (unlikely(!p)) | |
3182 | goto out_overflow; | |
7ad07353 TM |
3183 | if (fh != NULL) { |
3184 | memcpy(fh->data, p, len); | |
3185 | fh->size = len; | |
3186 | } | |
ae42c70a BS |
3187 | bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; |
3188 | } | |
3189 | return 0; | |
3190 | out_overflow: | |
3191 | print_overflow_msg(__func__, xdr); | |
3192 | return -EIO; | |
3193 | } | |
3194 | ||
1da177e4 LT |
3195 | static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
3196 | { | |
8687b63a | 3197 | __be32 *p; |
1da177e4 LT |
3198 | |
3199 | *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; | |
3200 | if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) | |
3201 | return -EIO; | |
3202 | if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { | |
c0eae66e BH |
3203 | p = xdr_inline_decode(xdr, 4); |
3204 | if (unlikely(!p)) | |
3205 | goto out_overflow; | |
cccddf4f | 3206 | *res = be32_to_cpup(p); |
1da177e4 LT |
3207 | bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; |
3208 | } | |
3110ff80 | 3209 | dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); |
1da177e4 | 3210 | return 0; |
c0eae66e BH |
3211 | out_overflow: |
3212 | print_overflow_msg(__func__, xdr); | |
3213 | return -EIO; | |
1da177e4 LT |
3214 | } |
3215 | ||
3216 | static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) | |
3217 | { | |
8687b63a | 3218 | __be32 *p; |
409924e4 | 3219 | int ret = 0; |
1da177e4 LT |
3220 | |
3221 | *fileid = 0; | |
3222 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) | |
3223 | return -EIO; | |
3224 | if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { | |
c0eae66e BH |
3225 | p = xdr_inline_decode(xdr, 8); |
3226 | if (unlikely(!p)) | |
3227 | goto out_overflow; | |
cccddf4f | 3228 | xdr_decode_hyper(p, fileid); |
1da177e4 | 3229 | bitmap[0] &= ~FATTR4_WORD0_FILEID; |
409924e4 | 3230 | ret = NFS_ATTR_FATTR_FILEID; |
1da177e4 | 3231 | } |
3110ff80 | 3232 | dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); |
409924e4 | 3233 | return ret; |
c0eae66e BH |
3234 | out_overflow: |
3235 | print_overflow_msg(__func__, xdr); | |
3236 | return -EIO; | |
1da177e4 LT |
3237 | } |
3238 | ||
99baf625 MN |
3239 | static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) |
3240 | { | |
8687b63a | 3241 | __be32 *p; |
409924e4 | 3242 | int ret = 0; |
99baf625 MN |
3243 | |
3244 | *fileid = 0; | |
3245 | if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) | |
3246 | return -EIO; | |
3247 | if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { | |
c0eae66e BH |
3248 | p = xdr_inline_decode(xdr, 8); |
3249 | if (unlikely(!p)) | |
3250 | goto out_overflow; | |
cccddf4f | 3251 | xdr_decode_hyper(p, fileid); |
99baf625 | 3252 | bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
28331a46 | 3253 | ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; |
99baf625 | 3254 | } |
3110ff80 | 3255 | dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); |
409924e4 | 3256 | return ret; |
c0eae66e BH |
3257 | out_overflow: |
3258 | print_overflow_msg(__func__, xdr); | |
3259 | return -EIO; | |
99baf625 MN |
3260 | } |
3261 | ||
1da177e4 LT |
3262 | static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
3263 | { | |
8687b63a | 3264 | __be32 *p; |
1da177e4 LT |
3265 | int status = 0; |
3266 | ||
3267 | *res = 0; | |
3268 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) | |
3269 | return -EIO; | |
3270 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { | |
c0eae66e BH |
3271 | p = xdr_inline_decode(xdr, 8); |
3272 | if (unlikely(!p)) | |
3273 | goto out_overflow; | |
cccddf4f | 3274 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3275 | bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; |
3276 | } | |
3110ff80 | 3277 | dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3278 | return status; |
c0eae66e BH |
3279 | out_overflow: |
3280 | print_overflow_msg(__func__, xdr); | |
3281 | return -EIO; | |
1da177e4 LT |
3282 | } |
3283 | ||
3284 | static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
3285 | { | |
8687b63a | 3286 | __be32 *p; |
1da177e4 LT |
3287 | int status = 0; |
3288 | ||
3289 | *res = 0; | |
3290 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) | |
3291 | return -EIO; | |
3292 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { | |
c0eae66e BH |
3293 | p = xdr_inline_decode(xdr, 8); |
3294 | if (unlikely(!p)) | |
3295 | goto out_overflow; | |
cccddf4f | 3296 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3297 | bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; |
3298 | } | |
3110ff80 | 3299 | dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3300 | return status; |
c0eae66e BH |
3301 | out_overflow: |
3302 | print_overflow_msg(__func__, xdr); | |
3303 | return -EIO; | |
1da177e4 LT |
3304 | } |
3305 | ||
3306 | static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
3307 | { | |
8687b63a | 3308 | __be32 *p; |
1da177e4 LT |
3309 | int status = 0; |
3310 | ||
3311 | *res = 0; | |
3312 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) | |
3313 | return -EIO; | |
3314 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { | |
c0eae66e BH |
3315 | p = xdr_inline_decode(xdr, 8); |
3316 | if (unlikely(!p)) | |
3317 | goto out_overflow; | |
cccddf4f | 3318 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3319 | bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; |
3320 | } | |
3110ff80 | 3321 | dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3322 | return status; |
c0eae66e BH |
3323 | out_overflow: |
3324 | print_overflow_msg(__func__, xdr); | |
3325 | return -EIO; | |
1da177e4 LT |
3326 | } |
3327 | ||
7aaa0b3b MN |
3328 | static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) |
3329 | { | |
464ad6b1 | 3330 | u32 n; |
8687b63a | 3331 | __be32 *p; |
7aaa0b3b MN |
3332 | int status = 0; |
3333 | ||
c0eae66e BH |
3334 | p = xdr_inline_decode(xdr, 4); |
3335 | if (unlikely(!p)) | |
3336 | goto out_overflow; | |
cccddf4f | 3337 | n = be32_to_cpup(p); |
33a43f28 AA |
3338 | if (n == 0) |
3339 | goto root_path; | |
7aaa0b3b MN |
3340 | dprintk("path "); |
3341 | path->ncomponents = 0; | |
3342 | while (path->ncomponents < n) { | |
3343 | struct nfs4_string *component = &path->components[path->ncomponents]; | |
3344 | status = decode_opaque_inline(xdr, &component->len, &component->data); | |
3345 | if (unlikely(status != 0)) | |
3346 | goto out_eio; | |
3347 | if (path->ncomponents != n) | |
3348 | dprintk("/"); | |
3349 | dprintk("%s", component->data); | |
3350 | if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) | |
3351 | path->ncomponents++; | |
3352 | else { | |
3353 | dprintk("cannot parse %d components in path\n", n); | |
3354 | goto out_eio; | |
3355 | } | |
3356 | } | |
3357 | out: | |
3358 | dprintk("\n"); | |
3359 | return status; | |
33a43f28 AA |
3360 | root_path: |
3361 | /* a root pathname is sent as a zero component4 */ | |
3362 | path->ncomponents = 1; | |
3363 | path->components[0].len=0; | |
3364 | path->components[0].data=NULL; | |
3365 | dprintk("path /\n"); | |
3366 | goto out; | |
7aaa0b3b MN |
3367 | out_eio: |
3368 | dprintk(" status %d", status); | |
3369 | status = -EIO; | |
3370 | goto out; | |
c0eae66e BH |
3371 | out_overflow: |
3372 | print_overflow_msg(__func__, xdr); | |
3373 | return -EIO; | |
7aaa0b3b MN |
3374 | } |
3375 | ||
3376 | static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) | |
683b57b4 TM |
3377 | { |
3378 | int n; | |
8687b63a | 3379 | __be32 *p; |
683b57b4 TM |
3380 | int status = -EIO; |
3381 | ||
3382 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) | |
3383 | goto out; | |
3384 | status = 0; | |
3385 | if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) | |
3386 | goto out; | |
3110ff80 | 3387 | dprintk("%s: fsroot ", __func__); |
7aaa0b3b | 3388 | status = decode_pathname(xdr, &res->fs_path); |
683b57b4 TM |
3389 | if (unlikely(status != 0)) |
3390 | goto out; | |
c0eae66e BH |
3391 | p = xdr_inline_decode(xdr, 4); |
3392 | if (unlikely(!p)) | |
3393 | goto out_overflow; | |
cccddf4f | 3394 | n = be32_to_cpup(p); |
683b57b4 TM |
3395 | if (n <= 0) |
3396 | goto out_eio; | |
3397 | res->nlocations = 0; | |
3398 | while (res->nlocations < n) { | |
464ad6b1 | 3399 | u32 m; |
7aaa0b3b | 3400 | struct nfs4_fs_location *loc = &res->locations[res->nlocations]; |
683b57b4 | 3401 | |
c0eae66e BH |
3402 | p = xdr_inline_decode(xdr, 4); |
3403 | if (unlikely(!p)) | |
3404 | goto out_overflow; | |
cccddf4f | 3405 | m = be32_to_cpup(p); |
7aaa0b3b MN |
3406 | |
3407 | loc->nservers = 0; | |
3110ff80 | 3408 | dprintk("%s: servers ", __func__); |
7aaa0b3b MN |
3409 | while (loc->nservers < m) { |
3410 | struct nfs4_string *server = &loc->servers[loc->nservers]; | |
3411 | status = decode_opaque_inline(xdr, &server->len, &server->data); | |
3412 | if (unlikely(status != 0)) | |
3413 | goto out_eio; | |
3414 | dprintk("%s ", server->data); | |
3415 | if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) | |
3416 | loc->nservers++; | |
3417 | else { | |
464ad6b1 CL |
3418 | unsigned int i; |
3419 | dprintk("%s: using first %u of %u servers " | |
3420 | "returned for location %u\n", | |
3110ff80 | 3421 | __func__, |
464ad6b1 CL |
3422 | NFS4_FS_LOCATION_MAXSERVERS, |
3423 | m, res->nlocations); | |
7aaa0b3b | 3424 | for (i = loc->nservers; i < m; i++) { |
2e42c3e2 | 3425 | unsigned int len; |
7aaa0b3b MN |
3426 | char *data; |
3427 | status = decode_opaque_inline(xdr, &len, &data); | |
3428 | if (unlikely(status != 0)) | |
3429 | goto out_eio; | |
3430 | } | |
3431 | } | |
3432 | } | |
3433 | status = decode_pathname(xdr, &loc->rootpath); | |
683b57b4 TM |
3434 | if (unlikely(status != 0)) |
3435 | goto out_eio; | |
7aaa0b3b | 3436 | if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) |
683b57b4 TM |
3437 | res->nlocations++; |
3438 | } | |
409924e4 TM |
3439 | if (res->nlocations != 0) |
3440 | status = NFS_ATTR_FATTR_V4_REFERRAL; | |
683b57b4 | 3441 | out: |
3110ff80 | 3442 | dprintk("%s: fs_locations done, error = %d\n", __func__, status); |
683b57b4 | 3443 | return status; |
c0eae66e BH |
3444 | out_overflow: |
3445 | print_overflow_msg(__func__, xdr); | |
683b57b4 TM |
3446 | out_eio: |
3447 | status = -EIO; | |
3448 | goto out; | |
3449 | } | |
3450 | ||
1da177e4 LT |
3451 | static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
3452 | { | |
8687b63a | 3453 | __be32 *p; |
1da177e4 LT |
3454 | int status = 0; |
3455 | ||
3456 | *res = 0; | |
3457 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) | |
3458 | return -EIO; | |
3459 | if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { | |
c0eae66e BH |
3460 | p = xdr_inline_decode(xdr, 8); |
3461 | if (unlikely(!p)) | |
3462 | goto out_overflow; | |
cccddf4f | 3463 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3464 | bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; |
3465 | } | |
3110ff80 | 3466 | dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3467 | return status; |
c0eae66e BH |
3468 | out_overflow: |
3469 | print_overflow_msg(__func__, xdr); | |
3470 | return -EIO; | |
1da177e4 LT |
3471 | } |
3472 | ||
3473 | static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) | |
3474 | { | |
8687b63a | 3475 | __be32 *p; |
1da177e4 LT |
3476 | int status = 0; |
3477 | ||
3478 | *maxlink = 1; | |
3479 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) | |
3480 | return -EIO; | |
3481 | if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { | |
c0eae66e BH |
3482 | p = xdr_inline_decode(xdr, 4); |
3483 | if (unlikely(!p)) | |
3484 | goto out_overflow; | |
cccddf4f | 3485 | *maxlink = be32_to_cpup(p); |
1da177e4 LT |
3486 | bitmap[0] &= ~FATTR4_WORD0_MAXLINK; |
3487 | } | |
3110ff80 | 3488 | dprintk("%s: maxlink=%u\n", __func__, *maxlink); |
1da177e4 | 3489 | return status; |
c0eae66e BH |
3490 | out_overflow: |
3491 | print_overflow_msg(__func__, xdr); | |
3492 | return -EIO; | |
1da177e4 LT |
3493 | } |
3494 | ||
3495 | static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) | |
3496 | { | |
8687b63a | 3497 | __be32 *p; |
1da177e4 LT |
3498 | int status = 0; |
3499 | ||
3500 | *maxname = 1024; | |
3501 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) | |
3502 | return -EIO; | |
3503 | if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { | |
c0eae66e BH |
3504 | p = xdr_inline_decode(xdr, 4); |
3505 | if (unlikely(!p)) | |
3506 | goto out_overflow; | |
cccddf4f | 3507 | *maxname = be32_to_cpup(p); |
1da177e4 LT |
3508 | bitmap[0] &= ~FATTR4_WORD0_MAXNAME; |
3509 | } | |
3110ff80 | 3510 | dprintk("%s: maxname=%u\n", __func__, *maxname); |
1da177e4 | 3511 | return status; |
c0eae66e BH |
3512 | out_overflow: |
3513 | print_overflow_msg(__func__, xdr); | |
3514 | return -EIO; | |
1da177e4 LT |
3515 | } |
3516 | ||
3517 | static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
3518 | { | |
8687b63a | 3519 | __be32 *p; |
1da177e4 LT |
3520 | int status = 0; |
3521 | ||
3522 | *res = 1024; | |
3523 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) | |
3524 | return -EIO; | |
3525 | if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { | |
3526 | uint64_t maxread; | |
c0eae66e BH |
3527 | p = xdr_inline_decode(xdr, 8); |
3528 | if (unlikely(!p)) | |
3529 | goto out_overflow; | |
cccddf4f | 3530 | xdr_decode_hyper(p, &maxread); |
1da177e4 LT |
3531 | if (maxread > 0x7FFFFFFF) |
3532 | maxread = 0x7FFFFFFF; | |
3533 | *res = (uint32_t)maxread; | |
3534 | bitmap[0] &= ~FATTR4_WORD0_MAXREAD; | |
3535 | } | |
3110ff80 | 3536 | dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); |
1da177e4 | 3537 | return status; |
c0eae66e BH |
3538 | out_overflow: |
3539 | print_overflow_msg(__func__, xdr); | |
3540 | return -EIO; | |
1da177e4 LT |
3541 | } |
3542 | ||
3543 | static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
3544 | { | |
8687b63a | 3545 | __be32 *p; |
1da177e4 LT |
3546 | int status = 0; |
3547 | ||
3548 | *res = 1024; | |
3549 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) | |
3550 | return -EIO; | |
3551 | if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { | |
3552 | uint64_t maxwrite; | |
c0eae66e BH |
3553 | p = xdr_inline_decode(xdr, 8); |
3554 | if (unlikely(!p)) | |
3555 | goto out_overflow; | |
cccddf4f | 3556 | xdr_decode_hyper(p, &maxwrite); |
1da177e4 LT |
3557 | if (maxwrite > 0x7FFFFFFF) |
3558 | maxwrite = 0x7FFFFFFF; | |
3559 | *res = (uint32_t)maxwrite; | |
3560 | bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; | |
3561 | } | |
3110ff80 | 3562 | dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); |
1da177e4 | 3563 | return status; |
c0eae66e BH |
3564 | out_overflow: |
3565 | print_overflow_msg(__func__, xdr); | |
3566 | return -EIO; | |
1da177e4 LT |
3567 | } |
3568 | ||
bca79478 | 3569 | static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) |
1da177e4 | 3570 | { |
bca79478 | 3571 | uint32_t tmp; |
8687b63a | 3572 | __be32 *p; |
409924e4 | 3573 | int ret = 0; |
1da177e4 LT |
3574 | |
3575 | *mode = 0; | |
3576 | if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) | |
3577 | return -EIO; | |
3578 | if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { | |
c0eae66e BH |
3579 | p = xdr_inline_decode(xdr, 4); |
3580 | if (unlikely(!p)) | |
3581 | goto out_overflow; | |
cccddf4f | 3582 | tmp = be32_to_cpup(p); |
bca79478 | 3583 | *mode = tmp & ~S_IFMT; |
1da177e4 | 3584 | bitmap[1] &= ~FATTR4_WORD1_MODE; |
409924e4 | 3585 | ret = NFS_ATTR_FATTR_MODE; |
1da177e4 | 3586 | } |
3110ff80 | 3587 | dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); |
409924e4 | 3588 | return ret; |
c0eae66e BH |
3589 | out_overflow: |
3590 | print_overflow_msg(__func__, xdr); | |
3591 | return -EIO; | |
1da177e4 LT |
3592 | } |
3593 | ||
3594 | static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) | |
3595 | { | |
8687b63a | 3596 | __be32 *p; |
409924e4 | 3597 | int ret = 0; |
1da177e4 LT |
3598 | |
3599 | *nlink = 1; | |
3600 | if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) | |
3601 | return -EIO; | |
3602 | if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { | |
c0eae66e BH |
3603 | p = xdr_inline_decode(xdr, 4); |
3604 | if (unlikely(!p)) | |
3605 | goto out_overflow; | |
cccddf4f | 3606 | *nlink = be32_to_cpup(p); |
1da177e4 | 3607 | bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; |
409924e4 | 3608 | ret = NFS_ATTR_FATTR_NLINK; |
1da177e4 | 3609 | } |
3110ff80 | 3610 | dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); |
409924e4 | 3611 | return ret; |
c0eae66e BH |
3612 | out_overflow: |
3613 | print_overflow_msg(__func__, xdr); | |
3614 | return -EIO; | |
1da177e4 LT |
3615 | } |
3616 | ||
80e52ace | 3617 | static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, |
e4fd72a1 | 3618 | const struct nfs_server *server, uint32_t *uid, int may_sleep) |
1da177e4 | 3619 | { |
8687b63a AV |
3620 | uint32_t len; |
3621 | __be32 *p; | |
409924e4 | 3622 | int ret = 0; |
1da177e4 LT |
3623 | |
3624 | *uid = -2; | |
3625 | if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) | |
3626 | return -EIO; | |
3627 | if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { | |
c0eae66e BH |
3628 | p = xdr_inline_decode(xdr, 4); |
3629 | if (unlikely(!p)) | |
3630 | goto out_overflow; | |
cccddf4f | 3631 | len = be32_to_cpup(p); |
c0eae66e BH |
3632 | p = xdr_inline_decode(xdr, len); |
3633 | if (unlikely(!p)) | |
3634 | goto out_overflow; | |
80e52ace TM |
3635 | if (!may_sleep) { |
3636 | /* do nothing */ | |
3637 | } else if (len < XDR_MAX_NETOBJ) { | |
e4fd72a1 | 3638 | if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0) |
409924e4 TM |
3639 | ret = NFS_ATTR_FATTR_OWNER; |
3640 | else | |
1da177e4 | 3641 | dprintk("%s: nfs_map_name_to_uid failed!\n", |
3110ff80 | 3642 | __func__); |
1da177e4 | 3643 | } else |
fe82a183 | 3644 | dprintk("%s: name too long (%u)!\n", |
3110ff80 | 3645 | __func__, len); |
1da177e4 LT |
3646 | bitmap[1] &= ~FATTR4_WORD1_OWNER; |
3647 | } | |
3110ff80 | 3648 | dprintk("%s: uid=%d\n", __func__, (int)*uid); |
409924e4 | 3649 | return ret; |
c0eae66e BH |
3650 | out_overflow: |
3651 | print_overflow_msg(__func__, xdr); | |
3652 | return -EIO; | |
1da177e4 LT |
3653 | } |
3654 | ||
80e52ace | 3655 | static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, |
e4fd72a1 | 3656 | const struct nfs_server *server, uint32_t *gid, int may_sleep) |
1da177e4 | 3657 | { |
8687b63a AV |
3658 | uint32_t len; |
3659 | __be32 *p; | |
409924e4 | 3660 | int ret = 0; |
1da177e4 LT |
3661 | |
3662 | *gid = -2; | |
3663 | if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) | |
3664 | return -EIO; | |
3665 | if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { | |
c0eae66e BH |
3666 | p = xdr_inline_decode(xdr, 4); |
3667 | if (unlikely(!p)) | |
3668 | goto out_overflow; | |
cccddf4f | 3669 | len = be32_to_cpup(p); |
c0eae66e BH |
3670 | p = xdr_inline_decode(xdr, len); |
3671 | if (unlikely(!p)) | |
3672 | goto out_overflow; | |
80e52ace TM |
3673 | if (!may_sleep) { |
3674 | /* do nothing */ | |
3675 | } else if (len < XDR_MAX_NETOBJ) { | |
e4fd72a1 | 3676 | if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0) |
409924e4 TM |
3677 | ret = NFS_ATTR_FATTR_GROUP; |
3678 | else | |
1da177e4 | 3679 | dprintk("%s: nfs_map_group_to_gid failed!\n", |
3110ff80 | 3680 | __func__); |
1da177e4 | 3681 | } else |
fe82a183 | 3682 | dprintk("%s: name too long (%u)!\n", |
3110ff80 | 3683 | __func__, len); |
1da177e4 LT |
3684 | bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; |
3685 | } | |
3110ff80 | 3686 | dprintk("%s: gid=%d\n", __func__, (int)*gid); |
409924e4 | 3687 | return ret; |
c0eae66e BH |
3688 | out_overflow: |
3689 | print_overflow_msg(__func__, xdr); | |
3690 | return -EIO; | |
1da177e4 LT |
3691 | } |
3692 | ||
3693 | static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) | |
3694 | { | |
8687b63a AV |
3695 | uint32_t major = 0, minor = 0; |
3696 | __be32 *p; | |
409924e4 | 3697 | int ret = 0; |
1da177e4 LT |
3698 | |
3699 | *rdev = MKDEV(0,0); | |
3700 | if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) | |
3701 | return -EIO; | |
3702 | if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { | |
3703 | dev_t tmp; | |
3704 | ||
c0eae66e BH |
3705 | p = xdr_inline_decode(xdr, 8); |
3706 | if (unlikely(!p)) | |
3707 | goto out_overflow; | |
6f723f77 | 3708 | major = be32_to_cpup(p++); |
cccddf4f | 3709 | minor = be32_to_cpup(p); |
1da177e4 LT |
3710 | tmp = MKDEV(major, minor); |
3711 | if (MAJOR(tmp) == major && MINOR(tmp) == minor) | |
3712 | *rdev = tmp; | |
3713 | bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; | |
409924e4 | 3714 | ret = NFS_ATTR_FATTR_RDEV; |
1da177e4 | 3715 | } |
3110ff80 | 3716 | dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); |
409924e4 | 3717 | return ret; |
c0eae66e BH |
3718 | out_overflow: |
3719 | print_overflow_msg(__func__, xdr); | |
3720 | return -EIO; | |
1da177e4 LT |
3721 | } |
3722 | ||
3723 | static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
3724 | { | |
8687b63a | 3725 | __be32 *p; |
1da177e4 LT |
3726 | int status = 0; |
3727 | ||
3728 | *res = 0; | |
3729 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) | |
3730 | return -EIO; | |
3731 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { | |
c0eae66e BH |
3732 | p = xdr_inline_decode(xdr, 8); |
3733 | if (unlikely(!p)) | |
3734 | goto out_overflow; | |
cccddf4f | 3735 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3736 | bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; |
3737 | } | |
3110ff80 | 3738 | dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3739 | return status; |
c0eae66e BH |
3740 | out_overflow: |
3741 | print_overflow_msg(__func__, xdr); | |
3742 | return -EIO; | |
1da177e4 LT |
3743 | } |
3744 | ||
3745 | static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
3746 | { | |
8687b63a | 3747 | __be32 *p; |
1da177e4 LT |
3748 | int status = 0; |
3749 | ||
3750 | *res = 0; | |
3751 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) | |
3752 | return -EIO; | |
3753 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { | |
c0eae66e BH |
3754 | p = xdr_inline_decode(xdr, 8); |
3755 | if (unlikely(!p)) | |
3756 | goto out_overflow; | |
cccddf4f | 3757 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3758 | bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; |
3759 | } | |
3110ff80 | 3760 | dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3761 | return status; |
c0eae66e BH |
3762 | out_overflow: |
3763 | print_overflow_msg(__func__, xdr); | |
3764 | return -EIO; | |
1da177e4 LT |
3765 | } |
3766 | ||
3767 | static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
3768 | { | |
8687b63a | 3769 | __be32 *p; |
1da177e4 LT |
3770 | int status = 0; |
3771 | ||
3772 | *res = 0; | |
3773 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) | |
3774 | return -EIO; | |
3775 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { | |
c0eae66e BH |
3776 | p = xdr_inline_decode(xdr, 8); |
3777 | if (unlikely(!p)) | |
3778 | goto out_overflow; | |
cccddf4f | 3779 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3780 | bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; |
3781 | } | |
3110ff80 | 3782 | dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3783 | return status; |
c0eae66e BH |
3784 | out_overflow: |
3785 | print_overflow_msg(__func__, xdr); | |
3786 | return -EIO; | |
1da177e4 LT |
3787 | } |
3788 | ||
3789 | static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) | |
3790 | { | |
8687b63a | 3791 | __be32 *p; |
409924e4 | 3792 | int ret = 0; |
1da177e4 LT |
3793 | |
3794 | *used = 0; | |
3795 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) | |
3796 | return -EIO; | |
3797 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { | |
c0eae66e BH |
3798 | p = xdr_inline_decode(xdr, 8); |
3799 | if (unlikely(!p)) | |
3800 | goto out_overflow; | |
cccddf4f | 3801 | xdr_decode_hyper(p, used); |
1da177e4 | 3802 | bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; |
409924e4 | 3803 | ret = NFS_ATTR_FATTR_SPACE_USED; |
1da177e4 | 3804 | } |
3110ff80 | 3805 | dprintk("%s: space used=%Lu\n", __func__, |
1da177e4 | 3806 | (unsigned long long)*used); |
409924e4 | 3807 | return ret; |
c0eae66e BH |
3808 | out_overflow: |
3809 | print_overflow_msg(__func__, xdr); | |
3810 | return -EIO; | |
1da177e4 LT |
3811 | } |
3812 | ||
3813 | static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) | |
3814 | { | |
8687b63a | 3815 | __be32 *p; |
1da177e4 LT |
3816 | uint64_t sec; |
3817 | uint32_t nsec; | |
3818 | ||
c0eae66e BH |
3819 | p = xdr_inline_decode(xdr, 12); |
3820 | if (unlikely(!p)) | |
3821 | goto out_overflow; | |
3ceb4dbb | 3822 | p = xdr_decode_hyper(p, &sec); |
cccddf4f | 3823 | nsec = be32_to_cpup(p); |
1da177e4 LT |
3824 | time->tv_sec = (time_t)sec; |
3825 | time->tv_nsec = (long)nsec; | |
3826 | return 0; | |
c0eae66e BH |
3827 | out_overflow: |
3828 | print_overflow_msg(__func__, xdr); | |
3829 | return -EIO; | |
1da177e4 LT |
3830 | } |
3831 | ||
3832 | static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) | |
3833 | { | |
3834 | int status = 0; | |
3835 | ||
3836 | time->tv_sec = 0; | |
3837 | time->tv_nsec = 0; | |
3838 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) | |
3839 | return -EIO; | |
3840 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { | |
3841 | status = decode_attr_time(xdr, time); | |
409924e4 TM |
3842 | if (status == 0) |
3843 | status = NFS_ATTR_FATTR_ATIME; | |
1da177e4 LT |
3844 | bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; |
3845 | } | |
3110ff80 | 3846 | dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); |
1da177e4 LT |
3847 | return status; |
3848 | } | |
3849 | ||
3850 | static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) | |
3851 | { | |
3852 | int status = 0; | |
3853 | ||
3854 | time->tv_sec = 0; | |
3855 | time->tv_nsec = 0; | |
3856 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) | |
3857 | return -EIO; | |
3858 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { | |
3859 | status = decode_attr_time(xdr, time); | |
409924e4 TM |
3860 | if (status == 0) |
3861 | status = NFS_ATTR_FATTR_CTIME; | |
1da177e4 LT |
3862 | bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; |
3863 | } | |
3110ff80 | 3864 | dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); |
1da177e4 LT |
3865 | return status; |
3866 | } | |
3867 | ||
55b6e774 RL |
3868 | static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, |
3869 | struct timespec *time) | |
3870 | { | |
3871 | int status = 0; | |
3872 | ||
3873 | time->tv_sec = 0; | |
3874 | time->tv_nsec = 0; | |
3875 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) | |
3876 | return -EIO; | |
3877 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { | |
3878 | status = decode_attr_time(xdr, time); | |
3879 | bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; | |
3880 | } | |
3881 | dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, | |
3882 | (long)time->tv_nsec); | |
3883 | return status; | |
3884 | } | |
3885 | ||
1da177e4 LT |
3886 | static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) |
3887 | { | |
3888 | int status = 0; | |
3889 | ||
3890 | time->tv_sec = 0; | |
3891 | time->tv_nsec = 0; | |
3892 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) | |
3893 | return -EIO; | |
3894 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { | |
3895 | status = decode_attr_time(xdr, time); | |
409924e4 TM |
3896 | if (status == 0) |
3897 | status = NFS_ATTR_FATTR_MTIME; | |
1da177e4 LT |
3898 | bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; |
3899 | } | |
3110ff80 | 3900 | dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); |
1da177e4 LT |
3901 | return status; |
3902 | } | |
3903 | ||
8687b63a | 3904 | static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen) |
1da177e4 LT |
3905 | { |
3906 | unsigned int attrwords = XDR_QUADLEN(attrlen); | |
3907 | unsigned int nwords = xdr->p - savep; | |
3908 | ||
3909 | if (unlikely(attrwords != nwords)) { | |
fe82a183 CL |
3910 | dprintk("%s: server returned incorrect attribute length: " |
3911 | "%u %c %u\n", | |
3110ff80 | 3912 | __func__, |
1da177e4 LT |
3913 | attrwords << 2, |
3914 | (attrwords < nwords) ? '<' : '>', | |
3915 | nwords << 2); | |
3916 | return -EIO; | |
3917 | } | |
3918 | return 0; | |
3919 | } | |
3920 | ||
3921 | static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
3922 | { | |
8687b63a | 3923 | __be32 *p; |
1da177e4 | 3924 | |
c0eae66e BH |
3925 | p = xdr_inline_decode(xdr, 20); |
3926 | if (unlikely(!p)) | |
3927 | goto out_overflow; | |
6f723f77 | 3928 | cinfo->atomic = be32_to_cpup(p++); |
3ceb4dbb | 3929 | p = xdr_decode_hyper(p, &cinfo->before); |
cccddf4f | 3930 | xdr_decode_hyper(p, &cinfo->after); |
1da177e4 | 3931 | return 0; |
c0eae66e BH |
3932 | out_overflow: |
3933 | print_overflow_msg(__func__, xdr); | |
3934 | return -EIO; | |
1da177e4 LT |
3935 | } |
3936 | ||
3937 | static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) | |
3938 | { | |
8687b63a | 3939 | __be32 *p; |
1da177e4 LT |
3940 | uint32_t supp, acc; |
3941 | int status; | |
3942 | ||
3943 | status = decode_op_hdr(xdr, OP_ACCESS); | |
3944 | if (status) | |
3945 | return status; | |
c0eae66e BH |
3946 | p = xdr_inline_decode(xdr, 8); |
3947 | if (unlikely(!p)) | |
3948 | goto out_overflow; | |
6f723f77 | 3949 | supp = be32_to_cpup(p++); |
cccddf4f | 3950 | acc = be32_to_cpup(p); |
1da177e4 LT |
3951 | access->supported = supp; |
3952 | access->access = acc; | |
3953 | return 0; | |
c0eae66e BH |
3954 | out_overflow: |
3955 | print_overflow_msg(__func__, xdr); | |
3956 | return -EIO; | |
1da177e4 LT |
3957 | } |
3958 | ||
07d30434 | 3959 | static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) |
1da177e4 | 3960 | { |
8687b63a | 3961 | __be32 *p; |
07d30434 BH |
3962 | |
3963 | p = xdr_inline_decode(xdr, len); | |
3964 | if (likely(p)) { | |
3965 | memcpy(buf, p, len); | |
3966 | return 0; | |
3967 | } | |
3968 | print_overflow_msg(__func__, xdr); | |
3969 | return -EIO; | |
3970 | } | |
3971 | ||
3972 | static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) | |
3973 | { | |
3974 | return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE); | |
3975 | } | |
3976 | ||
3977 | static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) | |
3978 | { | |
1da177e4 LT |
3979 | int status; |
3980 | ||
3981 | status = decode_op_hdr(xdr, OP_CLOSE); | |
c1d51931 TM |
3982 | if (status != -EIO) |
3983 | nfs_increment_open_seqid(status, res->seqid); | |
07d30434 BH |
3984 | if (!status) |
3985 | status = decode_stateid(xdr, &res->stateid); | |
3986 | return status; | |
1da177e4 LT |
3987 | } |
3988 | ||
db942bbd BH |
3989 | static int decode_verifier(struct xdr_stream *xdr, void *verifier) |
3990 | { | |
3991 | return decode_opaque_fixed(xdr, verifier, 8); | |
1da177e4 LT |
3992 | } |
3993 | ||
3994 | static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) | |
3995 | { | |
1da177e4 LT |
3996 | int status; |
3997 | ||
3998 | status = decode_op_hdr(xdr, OP_COMMIT); | |
db942bbd BH |
3999 | if (!status) |
4000 | status = decode_verifier(xdr, res->verf->verifier); | |
4001 | return status; | |
1da177e4 LT |
4002 | } |
4003 | ||
4004 | static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
4005 | { | |
8687b63a | 4006 | __be32 *p; |
1da177e4 LT |
4007 | uint32_t bmlen; |
4008 | int status; | |
4009 | ||
4010 | status = decode_op_hdr(xdr, OP_CREATE); | |
4011 | if (status) | |
4012 | return status; | |
4013 | if ((status = decode_change_info(xdr, cinfo))) | |
4014 | return status; | |
c0eae66e BH |
4015 | p = xdr_inline_decode(xdr, 4); |
4016 | if (unlikely(!p)) | |
4017 | goto out_overflow; | |
cccddf4f | 4018 | bmlen = be32_to_cpup(p); |
c0eae66e BH |
4019 | p = xdr_inline_decode(xdr, bmlen << 2); |
4020 | if (likely(p)) | |
4021 | return 0; | |
4022 | out_overflow: | |
4023 | print_overflow_msg(__func__, xdr); | |
4024 | return -EIO; | |
1da177e4 LT |
4025 | } |
4026 | ||
4027 | static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) | |
4028 | { | |
8687b63a | 4029 | __be32 *savep; |
6c0195a4 | 4030 | uint32_t attrlen, bitmap[2] = {0}; |
1da177e4 LT |
4031 | int status; |
4032 | ||
4033 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
4034 | goto xdr_error; | |
4035 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
4036 | goto xdr_error; | |
4037 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
4038 | goto xdr_error; | |
4039 | if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) | |
4040 | goto xdr_error; | |
4041 | if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) | |
4042 | goto xdr_error; | |
4043 | if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) | |
4044 | goto xdr_error; | |
4045 | if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) | |
4046 | goto xdr_error; | |
4047 | status = verify_attr_len(xdr, savep, attrlen); | |
4048 | xdr_error: | |
3110ff80 | 4049 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
1da177e4 LT |
4050 | return status; |
4051 | } | |
6c0195a4 | 4052 | |
1da177e4 LT |
4053 | static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) |
4054 | { | |
8687b63a | 4055 | __be32 *savep; |
6c0195a4 | 4056 | uint32_t attrlen, bitmap[2] = {0}; |
1da177e4 | 4057 | int status; |
6c0195a4 | 4058 | |
1da177e4 LT |
4059 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
4060 | goto xdr_error; | |
4061 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
4062 | goto xdr_error; | |
4063 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
4064 | goto xdr_error; | |
4065 | ||
4066 | if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) | |
4067 | goto xdr_error; | |
4068 | if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) | |
4069 | goto xdr_error; | |
4070 | if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) | |
4071 | goto xdr_error; | |
4072 | if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) | |
4073 | goto xdr_error; | |
4074 | if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) | |
4075 | goto xdr_error; | |
4076 | if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) | |
4077 | goto xdr_error; | |
4078 | ||
4079 | status = verify_attr_len(xdr, savep, attrlen); | |
4080 | xdr_error: | |
3110ff80 | 4081 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
1da177e4 LT |
4082 | return status; |
4083 | } | |
4084 | ||
4085 | static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) | |
4086 | { | |
8687b63a | 4087 | __be32 *savep; |
6c0195a4 | 4088 | uint32_t attrlen, bitmap[2] = {0}; |
1da177e4 | 4089 | int status; |
6c0195a4 | 4090 | |
1da177e4 LT |
4091 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
4092 | goto xdr_error; | |
4093 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
4094 | goto xdr_error; | |
4095 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
4096 | goto xdr_error; | |
4097 | ||
4098 | if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) | |
4099 | goto xdr_error; | |
4100 | if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) | |
4101 | goto xdr_error; | |
4102 | ||
4103 | status = verify_attr_len(xdr, savep, attrlen); | |
4104 | xdr_error: | |
3110ff80 | 4105 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
1da177e4 LT |
4106 | return status; |
4107 | } | |
4108 | ||
ae42c70a BS |
4109 | static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, |
4110 | struct nfs_fattr *fattr, struct nfs_fh *fh, | |
80e52ace | 4111 | const struct nfs_server *server, int may_sleep) |
1da177e4 | 4112 | { |
bca79478 TM |
4113 | int status; |
4114 | umode_t fmode = 0; | |
ae42c70a | 4115 | uint32_t type; |
ee7b75fc | 4116 | int32_t err; |
1da177e4 | 4117 | |
f26c7a78 TM |
4118 | status = decode_attr_type(xdr, bitmap, &type); |
4119 | if (status < 0) | |
1da177e4 | 4120 | goto xdr_error; |
409924e4 TM |
4121 | fattr->mode = 0; |
4122 | if (status != 0) { | |
4123 | fattr->mode |= nfs_type2fmt[type]; | |
4124 | fattr->valid |= status; | |
4125 | } | |
1da177e4 | 4126 | |
f26c7a78 TM |
4127 | status = decode_attr_change(xdr, bitmap, &fattr->change_attr); |
4128 | if (status < 0) | |
1da177e4 | 4129 | goto xdr_error; |
409924e4 | 4130 | fattr->valid |= status; |
f26c7a78 TM |
4131 | |
4132 | status = decode_attr_size(xdr, bitmap, &fattr->size); | |
4133 | if (status < 0) | |
1da177e4 | 4134 | goto xdr_error; |
409924e4 | 4135 | fattr->valid |= status; |
f26c7a78 TM |
4136 | |
4137 | status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); | |
4138 | if (status < 0) | |
1da177e4 | 4139 | goto xdr_error; |
409924e4 | 4140 | fattr->valid |= status; |
f26c7a78 | 4141 | |
ee7b75fc TM |
4142 | err = 0; |
4143 | status = decode_attr_error(xdr, bitmap, &err); | |
ae42c70a BS |
4144 | if (status < 0) |
4145 | goto xdr_error; | |
ee7b75fc TM |
4146 | if (err == -NFS4ERR_WRONGSEC) |
4147 | nfs_fixup_secinfo_attributes(fattr, fh); | |
ae42c70a BS |
4148 | |
4149 | status = decode_attr_filehandle(xdr, bitmap, fh); | |
4150 | if (status < 0) | |
4151 | goto xdr_error; | |
4152 | ||
f26c7a78 TM |
4153 | status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); |
4154 | if (status < 0) | |
1da177e4 | 4155 | goto xdr_error; |
409924e4 | 4156 | fattr->valid |= status; |
f26c7a78 TM |
4157 | |
4158 | status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr, | |
7aaa0b3b | 4159 | struct nfs4_fs_locations, |
f26c7a78 TM |
4160 | fattr)); |
4161 | if (status < 0) | |
683b57b4 | 4162 | goto xdr_error; |
409924e4 | 4163 | fattr->valid |= status; |
f26c7a78 TM |
4164 | |
4165 | status = decode_attr_mode(xdr, bitmap, &fmode); | |
4166 | if (status < 0) | |
1da177e4 | 4167 | goto xdr_error; |
409924e4 TM |
4168 | if (status != 0) { |
4169 | fattr->mode |= fmode; | |
4170 | fattr->valid |= status; | |
4171 | } | |
f26c7a78 TM |
4172 | |
4173 | status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); | |
4174 | if (status < 0) | |
1da177e4 | 4175 | goto xdr_error; |
409924e4 | 4176 | fattr->valid |= status; |
f26c7a78 | 4177 | |
e4fd72a1 | 4178 | status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep); |
f26c7a78 | 4179 | if (status < 0) |
1da177e4 | 4180 | goto xdr_error; |
409924e4 | 4181 | fattr->valid |= status; |
f26c7a78 | 4182 | |
e4fd72a1 | 4183 | status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep); |
f26c7a78 | 4184 | if (status < 0) |
1da177e4 | 4185 | goto xdr_error; |
409924e4 | 4186 | fattr->valid |= status; |
f26c7a78 TM |
4187 | |
4188 | status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); | |
4189 | if (status < 0) | |
1da177e4 | 4190 | goto xdr_error; |
409924e4 | 4191 | fattr->valid |= status; |
f26c7a78 TM |
4192 | |
4193 | status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); | |
4194 | if (status < 0) | |
1da177e4 | 4195 | goto xdr_error; |
409924e4 | 4196 | fattr->valid |= status; |
f26c7a78 TM |
4197 | |
4198 | status = decode_attr_time_access(xdr, bitmap, &fattr->atime); | |
4199 | if (status < 0) | |
1da177e4 | 4200 | goto xdr_error; |
409924e4 | 4201 | fattr->valid |= status; |
f26c7a78 TM |
4202 | |
4203 | status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); | |
4204 | if (status < 0) | |
1da177e4 | 4205 | goto xdr_error; |
409924e4 | 4206 | fattr->valid |= status; |
f26c7a78 TM |
4207 | |
4208 | status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); | |
4209 | if (status < 0) | |
1da177e4 | 4210 | goto xdr_error; |
409924e4 | 4211 | fattr->valid |= status; |
f26c7a78 | 4212 | |
28331a46 | 4213 | status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); |
f26c7a78 | 4214 | if (status < 0) |
99baf625 | 4215 | goto xdr_error; |
28331a46 | 4216 | fattr->valid |= status; |
f26c7a78 | 4217 | |
ae42c70a BS |
4218 | xdr_error: |
4219 | dprintk("%s: xdr returned %d\n", __func__, -status); | |
4220 | return status; | |
4221 | } | |
4222 | ||
4223 | static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, | |
4224 | struct nfs_fh *fh, const struct nfs_server *server, int may_sleep) | |
4225 | { | |
4226 | __be32 *savep; | |
4227 | uint32_t attrlen, | |
4228 | bitmap[2] = {0}; | |
4229 | int status; | |
4230 | ||
4231 | status = decode_op_hdr(xdr, OP_GETATTR); | |
4232 | if (status < 0) | |
4233 | goto xdr_error; | |
4234 | ||
4235 | status = decode_attr_bitmap(xdr, bitmap); | |
4236 | if (status < 0) | |
4237 | goto xdr_error; | |
4238 | ||
4239 | status = decode_attr_length(xdr, &attrlen, &savep); | |
4240 | if (status < 0) | |
4241 | goto xdr_error; | |
4242 | ||
4243 | status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep); | |
4244 | if (status < 0) | |
4245 | goto xdr_error; | |
4246 | ||
f26c7a78 | 4247 | status = verify_attr_len(xdr, savep, attrlen); |
1da177e4 | 4248 | xdr_error: |
3110ff80 | 4249 | dprintk("%s: xdr returned %d\n", __func__, -status); |
1da177e4 LT |
4250 | return status; |
4251 | } | |
4252 | ||
ae42c70a BS |
4253 | static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, |
4254 | const struct nfs_server *server, int may_sleep) | |
4255 | { | |
4256 | return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep); | |
4257 | } | |
1da177e4 | 4258 | |
504913fb AA |
4259 | /* |
4260 | * Decode potentially multiple layout types. Currently we only support | |
4261 | * one layout driver per file system. | |
4262 | */ | |
4263 | static int decode_first_pnfs_layout_type(struct xdr_stream *xdr, | |
4264 | uint32_t *layouttype) | |
4265 | { | |
4266 | uint32_t *p; | |
4267 | int num; | |
4268 | ||
4269 | p = xdr_inline_decode(xdr, 4); | |
4270 | if (unlikely(!p)) | |
4271 | goto out_overflow; | |
4272 | num = be32_to_cpup(p); | |
4273 | ||
4274 | /* pNFS is not supported by the underlying file system */ | |
4275 | if (num == 0) { | |
4276 | *layouttype = 0; | |
4277 | return 0; | |
4278 | } | |
4279 | if (num > 1) | |
4280 | printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers " | |
4281 | "per filesystem not supported\n", __func__); | |
4282 | ||
4283 | /* Decode and set first layout type, move xdr->p past unused types */ | |
4284 | p = xdr_inline_decode(xdr, num * 4); | |
4285 | if (unlikely(!p)) | |
4286 | goto out_overflow; | |
4287 | *layouttype = be32_to_cpup(p); | |
4288 | return 0; | |
4289 | out_overflow: | |
4290 | print_overflow_msg(__func__, xdr); | |
4291 | return -EIO; | |
4292 | } | |
4293 | ||
4294 | /* | |
4295 | * The type of file system exported. | |
4296 | * Note we must ensure that layouttype is set in any non-error case. | |
4297 | */ | |
4298 | static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, | |
4299 | uint32_t *layouttype) | |
4300 | { | |
4301 | int status = 0; | |
4302 | ||
4303 | dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); | |
4304 | if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) | |
4305 | return -EIO; | |
4306 | if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { | |
4307 | status = decode_first_pnfs_layout_type(xdr, layouttype); | |
4308 | bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; | |
4309 | } else | |
4310 | *layouttype = 0; | |
4311 | return status; | |
4312 | } | |
4313 | ||
1da177e4 LT |
4314 | static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) |
4315 | { | |
8687b63a | 4316 | __be32 *savep; |
1da177e4 LT |
4317 | uint32_t attrlen, bitmap[2]; |
4318 | int status; | |
4319 | ||
4320 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
4321 | goto xdr_error; | |
4322 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
4323 | goto xdr_error; | |
4324 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
4325 | goto xdr_error; | |
4326 | ||
4327 | fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ | |
4328 | ||
4329 | if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) | |
4330 | goto xdr_error; | |
4331 | if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) | |
4332 | goto xdr_error; | |
4333 | if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) | |
4334 | goto xdr_error; | |
4335 | fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; | |
4336 | if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) | |
4337 | goto xdr_error; | |
4338 | fsinfo->wtpref = fsinfo->wtmax; | |
55b6e774 | 4339 | status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); |
504913fb AA |
4340 | if (status != 0) |
4341 | goto xdr_error; | |
4342 | status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype); | |
55b6e774 RL |
4343 | if (status != 0) |
4344 | goto xdr_error; | |
1da177e4 LT |
4345 | |
4346 | status = verify_attr_len(xdr, savep, attrlen); | |
4347 | xdr_error: | |
3110ff80 | 4348 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
1da177e4 LT |
4349 | return status; |
4350 | } | |
4351 | ||
4352 | static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) | |
4353 | { | |
8687b63a | 4354 | __be32 *p; |
1da177e4 LT |
4355 | uint32_t len; |
4356 | int status; | |
4357 | ||
9936781d TM |
4358 | /* Zero handle first to allow comparisons */ |
4359 | memset(fh, 0, sizeof(*fh)); | |
4360 | ||
1da177e4 LT |
4361 | status = decode_op_hdr(xdr, OP_GETFH); |
4362 | if (status) | |
4363 | return status; | |
1da177e4 | 4364 | |
c0eae66e BH |
4365 | p = xdr_inline_decode(xdr, 4); |
4366 | if (unlikely(!p)) | |
4367 | goto out_overflow; | |
cccddf4f | 4368 | len = be32_to_cpup(p); |
1da177e4 LT |
4369 | if (len > NFS4_FHSIZE) |
4370 | return -EIO; | |
4371 | fh->size = len; | |
c0eae66e BH |
4372 | p = xdr_inline_decode(xdr, len); |
4373 | if (unlikely(!p)) | |
4374 | goto out_overflow; | |
99398d06 | 4375 | memcpy(fh->data, p, len); |
1da177e4 | 4376 | return 0; |
c0eae66e BH |
4377 | out_overflow: |
4378 | print_overflow_msg(__func__, xdr); | |
4379 | return -EIO; | |
1da177e4 LT |
4380 | } |
4381 | ||
4382 | static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
4383 | { | |
4384 | int status; | |
6c0195a4 | 4385 | |
1da177e4 LT |
4386 | status = decode_op_hdr(xdr, OP_LINK); |
4387 | if (status) | |
4388 | return status; | |
4389 | return decode_change_info(xdr, cinfo); | |
4390 | } | |
4391 | ||
4392 | /* | |
4393 | * We create the owner, so we know a proper owner.id length is 4. | |
4394 | */ | |
911d1aaf | 4395 | static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) |
1da177e4 | 4396 | { |
911d1aaf | 4397 | uint64_t offset, length, clientid; |
8687b63a | 4398 | __be32 *p; |
911d1aaf | 4399 | uint32_t namelen, type; |
1da177e4 | 4400 | |
babddc72 | 4401 | p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ |
c0eae66e BH |
4402 | if (unlikely(!p)) |
4403 | goto out_overflow; | |
babddc72 | 4404 | p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ |
3ceb4dbb | 4405 | p = xdr_decode_hyper(p, &length); |
babddc72 BS |
4406 | type = be32_to_cpup(p++); /* 4 byte read */ |
4407 | if (fl != NULL) { /* manipulate file lock */ | |
911d1aaf TM |
4408 | fl->fl_start = (loff_t)offset; |
4409 | fl->fl_end = fl->fl_start + (loff_t)length - 1; | |
4410 | if (length == ~(uint64_t)0) | |
4411 | fl->fl_end = OFFSET_MAX; | |
4412 | fl->fl_type = F_WRLCK; | |
4413 | if (type & 1) | |
4414 | fl->fl_type = F_RDLCK; | |
4415 | fl->fl_pid = 0; | |
4416 | } | |
babddc72 BS |
4417 | p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ |
4418 | namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ | |
4419 | p = xdr_inline_decode(xdr, namelen); /* variable size field */ | |
c0eae66e BH |
4420 | if (likely(p)) |
4421 | return -NFS4ERR_DENIED; | |
4422 | out_overflow: | |
4423 | print_overflow_msg(__func__, xdr); | |
4424 | return -EIO; | |
1da177e4 LT |
4425 | } |
4426 | ||
911d1aaf | 4427 | static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) |
1da177e4 | 4428 | { |
1da177e4 LT |
4429 | int status; |
4430 | ||
4431 | status = decode_op_hdr(xdr, OP_LOCK); | |
c1d51931 TM |
4432 | if (status == -EIO) |
4433 | goto out; | |
1da177e4 | 4434 | if (status == 0) { |
07d30434 BH |
4435 | status = decode_stateid(xdr, &res->stateid); |
4436 | if (unlikely(status)) | |
4437 | goto out; | |
1da177e4 | 4438 | } else if (status == -NFS4ERR_DENIED) |
c1d51931 TM |
4439 | status = decode_lock_denied(xdr, NULL); |
4440 | if (res->open_seqid != NULL) | |
4441 | nfs_increment_open_seqid(status, res->open_seqid); | |
4442 | nfs_increment_lock_seqid(status, res->lock_seqid); | |
4443 | out: | |
1da177e4 LT |
4444 | return status; |
4445 | } | |
4446 | ||
911d1aaf | 4447 | static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) |
1da177e4 LT |
4448 | { |
4449 | int status; | |
4450 | status = decode_op_hdr(xdr, OP_LOCKT); | |
4451 | if (status == -NFS4ERR_DENIED) | |
911d1aaf | 4452 | return decode_lock_denied(xdr, res->denied); |
1da177e4 LT |
4453 | return status; |
4454 | } | |
4455 | ||
911d1aaf | 4456 | static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) |
1da177e4 | 4457 | { |
1da177e4 LT |
4458 | int status; |
4459 | ||
4460 | status = decode_op_hdr(xdr, OP_LOCKU); | |
c1d51931 TM |
4461 | if (status != -EIO) |
4462 | nfs_increment_lock_seqid(status, res->seqid); | |
07d30434 BH |
4463 | if (status == 0) |
4464 | status = decode_stateid(xdr, &res->stateid); | |
1da177e4 LT |
4465 | return status; |
4466 | } | |
4467 | ||
d3c7b7cc TM |
4468 | static int decode_release_lockowner(struct xdr_stream *xdr) |
4469 | { | |
4470 | return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); | |
4471 | } | |
4472 | ||
1da177e4 LT |
4473 | static int decode_lookup(struct xdr_stream *xdr) |
4474 | { | |
4475 | return decode_op_hdr(xdr, OP_LOOKUP); | |
4476 | } | |
4477 | ||
4478 | /* This is too sick! */ | |
4479 | static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) | |
4480 | { | |
05d564fe | 4481 | __be32 *p; |
1da177e4 LT |
4482 | uint32_t limit_type, nblocks, blocksize; |
4483 | ||
c0eae66e BH |
4484 | p = xdr_inline_decode(xdr, 12); |
4485 | if (unlikely(!p)) | |
4486 | goto out_overflow; | |
6f723f77 | 4487 | limit_type = be32_to_cpup(p++); |
1da177e4 | 4488 | switch (limit_type) { |
05d564fe | 4489 | case 1: |
cccddf4f | 4490 | xdr_decode_hyper(p, maxsize); |
05d564fe AA |
4491 | break; |
4492 | case 2: | |
6f723f77 | 4493 | nblocks = be32_to_cpup(p++); |
cccddf4f | 4494 | blocksize = be32_to_cpup(p); |
05d564fe | 4495 | *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; |
1da177e4 LT |
4496 | } |
4497 | return 0; | |
c0eae66e BH |
4498 | out_overflow: |
4499 | print_overflow_msg(__func__, xdr); | |
4500 | return -EIO; | |
1da177e4 LT |
4501 | } |
4502 | ||
4503 | static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) | |
4504 | { | |
05d564fe AA |
4505 | __be32 *p; |
4506 | uint32_t delegation_type; | |
07d30434 | 4507 | int status; |
1da177e4 | 4508 | |
c0eae66e BH |
4509 | p = xdr_inline_decode(xdr, 4); |
4510 | if (unlikely(!p)) | |
4511 | goto out_overflow; | |
cccddf4f | 4512 | delegation_type = be32_to_cpup(p); |
1da177e4 LT |
4513 | if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { |
4514 | res->delegation_type = 0; | |
4515 | return 0; | |
4516 | } | |
07d30434 BH |
4517 | status = decode_stateid(xdr, &res->delegation); |
4518 | if (unlikely(status)) | |
4519 | return status; | |
c0eae66e BH |
4520 | p = xdr_inline_decode(xdr, 4); |
4521 | if (unlikely(!p)) | |
4522 | goto out_overflow; | |
cccddf4f | 4523 | res->do_recall = be32_to_cpup(p); |
05d564fe | 4524 | |
1da177e4 | 4525 | switch (delegation_type) { |
05d564fe AA |
4526 | case NFS4_OPEN_DELEGATE_READ: |
4527 | res->delegation_type = FMODE_READ; | |
4528 | break; | |
4529 | case NFS4_OPEN_DELEGATE_WRITE: | |
4530 | res->delegation_type = FMODE_WRITE|FMODE_READ; | |
4531 | if (decode_space_limit(xdr, &res->maxsize) < 0) | |
1da177e4 LT |
4532 | return -EIO; |
4533 | } | |
7539bbab | 4534 | return decode_ace(xdr, NULL, res->server->nfs_client); |
c0eae66e BH |
4535 | out_overflow: |
4536 | print_overflow_msg(__func__, xdr); | |
4537 | return -EIO; | |
1da177e4 LT |
4538 | } |
4539 | ||
4540 | static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) | |
4541 | { | |
05d564fe | 4542 | __be32 *p; |
aa53ed54 | 4543 | uint32_t savewords, bmlen, i; |
05d564fe | 4544 | int status; |
1da177e4 | 4545 | |
05d564fe | 4546 | status = decode_op_hdr(xdr, OP_OPEN); |
c1d51931 TM |
4547 | if (status != -EIO) |
4548 | nfs_increment_open_seqid(status, res->seqid); | |
07d30434 BH |
4549 | if (!status) |
4550 | status = decode_stateid(xdr, &res->stateid); | |
4551 | if (unlikely(status)) | |
05d564fe | 4552 | return status; |
1da177e4 | 4553 | |
05d564fe | 4554 | decode_change_info(xdr, &res->cinfo); |
1da177e4 | 4555 | |
c0eae66e BH |
4556 | p = xdr_inline_decode(xdr, 8); |
4557 | if (unlikely(!p)) | |
4558 | goto out_overflow; | |
6f723f77 | 4559 | res->rflags = be32_to_cpup(p++); |
cccddf4f | 4560 | bmlen = be32_to_cpup(p); |
05d564fe AA |
4561 | if (bmlen > 10) |
4562 | goto xdr_error; | |
1da177e4 | 4563 | |
c0eae66e BH |
4564 | p = xdr_inline_decode(xdr, bmlen << 2); |
4565 | if (unlikely(!p)) | |
4566 | goto out_overflow; | |
aa53ed54 JL |
4567 | savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); |
4568 | for (i = 0; i < savewords; ++i) | |
6f723f77 | 4569 | res->attrset[i] = be32_to_cpup(p++); |
aa53ed54 JL |
4570 | for (; i < NFS4_BITMAP_SIZE; i++) |
4571 | res->attrset[i] = 0; | |
4572 | ||
1da177e4 LT |
4573 | return decode_delegation(xdr, res); |
4574 | xdr_error: | |
3110ff80 | 4575 | dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); |
1da177e4 | 4576 | return -EIO; |
c0eae66e BH |
4577 | out_overflow: |
4578 | print_overflow_msg(__func__, xdr); | |
4579 | return -EIO; | |
1da177e4 LT |
4580 | } |
4581 | ||
4582 | static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) | |
4583 | { | |
1da177e4 LT |
4584 | int status; |
4585 | ||
05d564fe | 4586 | status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); |
c1d51931 TM |
4587 | if (status != -EIO) |
4588 | nfs_increment_open_seqid(status, res->seqid); | |
07d30434 BH |
4589 | if (!status) |
4590 | status = decode_stateid(xdr, &res->stateid); | |
4591 | return status; | |
1da177e4 LT |
4592 | } |
4593 | ||
4594 | static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) | |
4595 | { | |
1da177e4 LT |
4596 | int status; |
4597 | ||
4598 | status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); | |
c1d51931 TM |
4599 | if (status != -EIO) |
4600 | nfs_increment_open_seqid(status, res->seqid); | |
07d30434 BH |
4601 | if (!status) |
4602 | status = decode_stateid(xdr, &res->stateid); | |
4603 | return status; | |
1da177e4 LT |
4604 | } |
4605 | ||
4606 | static int decode_putfh(struct xdr_stream *xdr) | |
4607 | { | |
4608 | return decode_op_hdr(xdr, OP_PUTFH); | |
4609 | } | |
4610 | ||
4611 | static int decode_putrootfh(struct xdr_stream *xdr) | |
4612 | { | |
4613 | return decode_op_hdr(xdr, OP_PUTROOTFH); | |
4614 | } | |
4615 | ||
4616 | static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) | |
4617 | { | |
4618 | struct kvec *iov = req->rq_rcv_buf.head; | |
8687b63a | 4619 | __be32 *p; |
1da177e4 LT |
4620 | uint32_t count, eof, recvd, hdrlen; |
4621 | int status; | |
4622 | ||
4623 | status = decode_op_hdr(xdr, OP_READ); | |
4624 | if (status) | |
4625 | return status; | |
c0eae66e BH |
4626 | p = xdr_inline_decode(xdr, 8); |
4627 | if (unlikely(!p)) | |
4628 | goto out_overflow; | |
6f723f77 | 4629 | eof = be32_to_cpup(p++); |
cccddf4f | 4630 | count = be32_to_cpup(p); |
8111f373 | 4631 | hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; |
1da177e4 LT |
4632 | recvd = req->rq_rcv_buf.len - hdrlen; |
4633 | if (count > recvd) { | |
fe82a183 | 4634 | dprintk("NFS: server cheating in read reply: " |
1da177e4 LT |
4635 | "count %u > recvd %u\n", count, recvd); |
4636 | count = recvd; | |
4637 | eof = 0; | |
4638 | } | |
4639 | xdr_read_pages(xdr, count); | |
4640 | res->eof = eof; | |
4641 | res->count = count; | |
4642 | return 0; | |
c0eae66e BH |
4643 | out_overflow: |
4644 | print_overflow_msg(__func__, xdr); | |
4645 | return -EIO; | |
1da177e4 LT |
4646 | } |
4647 | ||
4648 | static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) | |
4649 | { | |
4650 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; | |
1da177e4 | 4651 | struct kvec *iov = rcvbuf->head; |
bcecff77 CL |
4652 | size_t hdrlen; |
4653 | u32 recvd, pglen = rcvbuf->page_len; | |
bcecff77 | 4654 | int status; |
1da177e4 LT |
4655 | |
4656 | status = decode_op_hdr(xdr, OP_READDIR); | |
db942bbd BH |
4657 | if (!status) |
4658 | status = decode_verifier(xdr, readdir->verifier.data); | |
4659 | if (unlikely(status)) | |
1da177e4 | 4660 | return status; |
44109241 FI |
4661 | dprintk("%s: verifier = %08x:%08x\n", |
4662 | __func__, | |
eadf4598 TM |
4663 | ((u32 *)readdir->verifier.data)[0], |
4664 | ((u32 *)readdir->verifier.data)[1]); | |
4665 | ||
1da177e4 | 4666 | |
db942bbd | 4667 | hdrlen = (char *) xdr->p - (char *) iov->iov_base; |
1da177e4 LT |
4668 | recvd = rcvbuf->len - hdrlen; |
4669 | if (pglen > recvd) | |
4670 | pglen = recvd; | |
4671 | xdr_read_pages(xdr, pglen); | |
4672 | ||
afa8ccc9 | 4673 | |
ac396128 | 4674 | return pglen; |
1da177e4 LT |
4675 | } |
4676 | ||
4677 | static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) | |
4678 | { | |
4679 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; | |
4680 | struct kvec *iov = rcvbuf->head; | |
bcecff77 CL |
4681 | size_t hdrlen; |
4682 | u32 len, recvd; | |
8687b63a | 4683 | __be32 *p; |
1da177e4 LT |
4684 | int status; |
4685 | ||
4686 | status = decode_op_hdr(xdr, OP_READLINK); | |
4687 | if (status) | |
4688 | return status; | |
4689 | ||
4690 | /* Convert length of symlink */ | |
c0eae66e BH |
4691 | p = xdr_inline_decode(xdr, 4); |
4692 | if (unlikely(!p)) | |
4693 | goto out_overflow; | |
cccddf4f | 4694 | len = be32_to_cpup(p); |
1da177e4 | 4695 | if (len >= rcvbuf->page_len || len <= 0) { |
fe82a183 | 4696 | dprintk("nfs: server returned giant symlink!\n"); |
1da177e4 LT |
4697 | return -ENAMETOOLONG; |
4698 | } | |
4699 | hdrlen = (char *) xdr->p - (char *) iov->iov_base; | |
4700 | recvd = req->rq_rcv_buf.len - hdrlen; | |
4701 | if (recvd < len) { | |
fe82a183 | 4702 | dprintk("NFS: server cheating in readlink reply: " |
1da177e4 LT |
4703 | "count %u > recvd %u\n", len, recvd); |
4704 | return -EIO; | |
4705 | } | |
4706 | xdr_read_pages(xdr, len); | |
4707 | /* | |
4708 | * The XDR encode routine has set things up so that | |
4709 | * the link text will be copied directly into the | |
4710 | * buffer. We just have to do overflow-checking, | |
4711 | * and and null-terminate the text (the VFS expects | |
4712 | * null-termination). | |
4713 | */ | |
b4687da7 | 4714 | xdr_terminate_string(rcvbuf, len); |
1da177e4 | 4715 | return 0; |
c0eae66e BH |
4716 | out_overflow: |
4717 | print_overflow_msg(__func__, xdr); | |
4718 | return -EIO; | |
1da177e4 LT |
4719 | } |
4720 | ||
4721 | static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
4722 | { | |
4723 | int status; | |
4724 | ||
4725 | status = decode_op_hdr(xdr, OP_REMOVE); | |
4726 | if (status) | |
4727 | goto out; | |
4728 | status = decode_change_info(xdr, cinfo); | |
4729 | out: | |
4730 | return status; | |
4731 | } | |
4732 | ||
4733 | static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, | |
4734 | struct nfs4_change_info *new_cinfo) | |
4735 | { | |
4736 | int status; | |
4737 | ||
4738 | status = decode_op_hdr(xdr, OP_RENAME); | |
4739 | if (status) | |
4740 | goto out; | |
4741 | if ((status = decode_change_info(xdr, old_cinfo))) | |
4742 | goto out; | |
4743 | status = decode_change_info(xdr, new_cinfo); | |
4744 | out: | |
4745 | return status; | |
4746 | } | |
4747 | ||
4748 | static int decode_renew(struct xdr_stream *xdr) | |
4749 | { | |
4750 | return decode_op_hdr(xdr, OP_RENEW); | |
4751 | } | |
4752 | ||
56ae19f3 TM |
4753 | static int |
4754 | decode_restorefh(struct xdr_stream *xdr) | |
4755 | { | |
4756 | return decode_op_hdr(xdr, OP_RESTOREFH); | |
4757 | } | |
4758 | ||
029d105e BF |
4759 | static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, |
4760 | size_t *acl_len) | |
4761 | { | |
8687b63a | 4762 | __be32 *savep; |
029d105e BF |
4763 | uint32_t attrlen, |
4764 | bitmap[2] = {0}; | |
4765 | struct kvec *iov = req->rq_rcv_buf.head; | |
4766 | int status; | |
4767 | ||
4768 | *acl_len = 0; | |
4769 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
4770 | goto out; | |
4771 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
4772 | goto out; | |
4773 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
4774 | goto out; | |
4775 | ||
4776 | if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) | |
4777 | return -EIO; | |
4778 | if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { | |
bcecff77 CL |
4779 | size_t hdrlen; |
4780 | u32 recvd; | |
029d105e BF |
4781 | |
4782 | /* We ignore &savep and don't do consistency checks on | |
4783 | * the attr length. Let userspace figure it out.... */ | |
4784 | hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; | |
4785 | recvd = req->rq_rcv_buf.len - hdrlen; | |
4786 | if (attrlen > recvd) { | |
fe82a183 | 4787 | dprintk("NFS: server cheating in getattr" |
029d105e BF |
4788 | " acl reply: attrlen %u > recvd %u\n", |
4789 | attrlen, recvd); | |
4790 | return -EINVAL; | |
4791 | } | |
c04871e6 | 4792 | xdr_read_pages(xdr, attrlen); |
029d105e | 4793 | *acl_len = attrlen; |
8c233cf9 BF |
4794 | } else |
4795 | status = -EOPNOTSUPP; | |
029d105e BF |
4796 | |
4797 | out: | |
4798 | return status; | |
4799 | } | |
4800 | ||
1da177e4 LT |
4801 | static int |
4802 | decode_savefh(struct xdr_stream *xdr) | |
4803 | { | |
4804 | return decode_op_hdr(xdr, OP_SAVEFH); | |
4805 | } | |
4806 | ||
9e9ecc03 | 4807 | static int decode_setattr(struct xdr_stream *xdr) |
1da177e4 | 4808 | { |
8687b63a | 4809 | __be32 *p; |
1da177e4 LT |
4810 | uint32_t bmlen; |
4811 | int status; | |
4812 | ||
1da177e4 LT |
4813 | status = decode_op_hdr(xdr, OP_SETATTR); |
4814 | if (status) | |
4815 | return status; | |
c0eae66e BH |
4816 | p = xdr_inline_decode(xdr, 4); |
4817 | if (unlikely(!p)) | |
4818 | goto out_overflow; | |
cccddf4f | 4819 | bmlen = be32_to_cpup(p); |
c0eae66e BH |
4820 | p = xdr_inline_decode(xdr, bmlen << 2); |
4821 | if (likely(p)) | |
4822 | return 0; | |
4823 | out_overflow: | |
4824 | print_overflow_msg(__func__, xdr); | |
4825 | return -EIO; | |
1da177e4 LT |
4826 | } |
4827 | ||
bb8b27e5 | 4828 | static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) |
1da177e4 | 4829 | { |
8687b63a | 4830 | __be32 *p; |
1da177e4 LT |
4831 | uint32_t opnum; |
4832 | int32_t nfserr; | |
4833 | ||
c0eae66e BH |
4834 | p = xdr_inline_decode(xdr, 8); |
4835 | if (unlikely(!p)) | |
4836 | goto out_overflow; | |
6f723f77 | 4837 | opnum = be32_to_cpup(p++); |
1da177e4 | 4838 | if (opnum != OP_SETCLIENTID) { |
fe82a183 | 4839 | dprintk("nfs: decode_setclientid: Server returned operation" |
6c0195a4 | 4840 | " %d\n", opnum); |
1da177e4 LT |
4841 | return -EIO; |
4842 | } | |
cccddf4f | 4843 | nfserr = be32_to_cpup(p); |
1da177e4 | 4844 | if (nfserr == NFS_OK) { |
c0eae66e BH |
4845 | p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); |
4846 | if (unlikely(!p)) | |
4847 | goto out_overflow; | |
bb8b27e5 TM |
4848 | p = xdr_decode_hyper(p, &res->clientid); |
4849 | memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); | |
1da177e4 LT |
4850 | } else if (nfserr == NFSERR_CLID_INUSE) { |
4851 | uint32_t len; | |
4852 | ||
4853 | /* skip netid string */ | |
c0eae66e BH |
4854 | p = xdr_inline_decode(xdr, 4); |
4855 | if (unlikely(!p)) | |
4856 | goto out_overflow; | |
cccddf4f | 4857 | len = be32_to_cpup(p); |
c0eae66e BH |
4858 | p = xdr_inline_decode(xdr, len); |
4859 | if (unlikely(!p)) | |
4860 | goto out_overflow; | |
1da177e4 LT |
4861 | |
4862 | /* skip uaddr string */ | |
c0eae66e BH |
4863 | p = xdr_inline_decode(xdr, 4); |
4864 | if (unlikely(!p)) | |
4865 | goto out_overflow; | |
cccddf4f | 4866 | len = be32_to_cpup(p); |
c0eae66e BH |
4867 | p = xdr_inline_decode(xdr, len); |
4868 | if (unlikely(!p)) | |
4869 | goto out_overflow; | |
1da177e4 LT |
4870 | return -NFSERR_CLID_INUSE; |
4871 | } else | |
856dff3d | 4872 | return nfs4_stat_to_errno(nfserr); |
1da177e4 LT |
4873 | |
4874 | return 0; | |
c0eae66e BH |
4875 | out_overflow: |
4876 | print_overflow_msg(__func__, xdr); | |
4877 | return -EIO; | |
1da177e4 LT |
4878 | } |
4879 | ||
4880 | static int decode_setclientid_confirm(struct xdr_stream *xdr) | |
4881 | { | |
4882 | return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); | |
4883 | } | |
4884 | ||
4885 | static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) | |
4886 | { | |
8687b63a | 4887 | __be32 *p; |
1da177e4 LT |
4888 | int status; |
4889 | ||
4890 | status = decode_op_hdr(xdr, OP_WRITE); | |
4891 | if (status) | |
4892 | return status; | |
4893 | ||
c0eae66e BH |
4894 | p = xdr_inline_decode(xdr, 16); |
4895 | if (unlikely(!p)) | |
4896 | goto out_overflow; | |
6f723f77 BH |
4897 | res->count = be32_to_cpup(p++); |
4898 | res->verf->committed = be32_to_cpup(p++); | |
99398d06 | 4899 | memcpy(res->verf->verifier, p, 8); |
1da177e4 | 4900 | return 0; |
c0eae66e BH |
4901 | out_overflow: |
4902 | print_overflow_msg(__func__, xdr); | |
4903 | return -EIO; | |
1da177e4 LT |
4904 | } |
4905 | ||
4906 | static int decode_delegreturn(struct xdr_stream *xdr) | |
4907 | { | |
4908 | return decode_op_hdr(xdr, OP_DELEGRETURN); | |
4909 | } | |
4910 | ||
5a5ea0d4 BS |
4911 | static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor) |
4912 | { | |
4913 | __be32 *p; | |
4914 | ||
4915 | p = xdr_inline_decode(xdr, 4); | |
4916 | if (unlikely(!p)) | |
4917 | goto out_overflow; | |
4918 | flavor->gss.sec_oid4.len = be32_to_cpup(p); | |
4919 | if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN) | |
4920 | goto out_err; | |
4921 | ||
4922 | p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len); | |
4923 | if (unlikely(!p)) | |
4924 | goto out_overflow; | |
4925 | memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len); | |
4926 | ||
4927 | p = xdr_inline_decode(xdr, 8); | |
4928 | if (unlikely(!p)) | |
4929 | goto out_overflow; | |
4930 | flavor->gss.qop4 = be32_to_cpup(p++); | |
4931 | flavor->gss.service = be32_to_cpup(p); | |
4932 | ||
4933 | return 0; | |
4934 | ||
4935 | out_overflow: | |
4936 | print_overflow_msg(__func__, xdr); | |
4937 | return -EIO; | |
4938 | out_err: | |
4939 | return -EINVAL; | |
4940 | } | |
4941 | ||
4942 | static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) | |
4943 | { | |
4944 | struct nfs4_secinfo_flavor *sec_flavor; | |
4945 | int status; | |
4946 | __be32 *p; | |
c3dfc280 | 4947 | int i, num_flavors; |
5a5ea0d4 BS |
4948 | |
4949 | status = decode_op_hdr(xdr, OP_SECINFO); | |
613e901e BS |
4950 | if (status) |
4951 | goto out; | |
5a5ea0d4 BS |
4952 | p = xdr_inline_decode(xdr, 4); |
4953 | if (unlikely(!p)) | |
4954 | goto out_overflow; | |
5a5ea0d4 | 4955 | |
c3dfc280 BS |
4956 | res->flavors->num_flavors = 0; |
4957 | num_flavors = be32_to_cpup(p); | |
4958 | ||
4959 | for (i = 0; i < num_flavors; i++) { | |
5a5ea0d4 | 4960 | sec_flavor = &res->flavors->flavors[i]; |
c3dfc280 | 4961 | if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) |
5a5ea0d4 BS |
4962 | break; |
4963 | ||
4964 | p = xdr_inline_decode(xdr, 4); | |
4965 | if (unlikely(!p)) | |
4966 | goto out_overflow; | |
4967 | sec_flavor->flavor = be32_to_cpup(p); | |
4968 | ||
4969 | if (sec_flavor->flavor == RPC_AUTH_GSS) { | |
613e901e BS |
4970 | status = decode_secinfo_gss(xdr, sec_flavor); |
4971 | if (status) | |
4972 | goto out; | |
5a5ea0d4 | 4973 | } |
c3dfc280 | 4974 | res->flavors->num_flavors++; |
5a5ea0d4 BS |
4975 | } |
4976 | ||
613e901e BS |
4977 | out: |
4978 | return status; | |
5a5ea0d4 BS |
4979 | out_overflow: |
4980 | print_overflow_msg(__func__, xdr); | |
4981 | return -EIO; | |
4982 | } | |
4983 | ||
99fe60d0 BH |
4984 | #if defined(CONFIG_NFS_V4_1) |
4985 | static int decode_exchange_id(struct xdr_stream *xdr, | |
4986 | struct nfs41_exchange_id_res *res) | |
4987 | { | |
4988 | __be32 *p; | |
4989 | uint32_t dummy; | |
2460ba57 | 4990 | char *dummy_str; |
99fe60d0 BH |
4991 | int status; |
4992 | struct nfs_client *clp = res->client; | |
4993 | ||
4994 | status = decode_op_hdr(xdr, OP_EXCHANGE_ID); | |
4995 | if (status) | |
4996 | return status; | |
4997 | ||
c0eae66e BH |
4998 | p = xdr_inline_decode(xdr, 8); |
4999 | if (unlikely(!p)) | |
5000 | goto out_overflow; | |
114f64b5 | 5001 | xdr_decode_hyper(p, &clp->cl_clientid); |
c0eae66e BH |
5002 | p = xdr_inline_decode(xdr, 12); |
5003 | if (unlikely(!p)) | |
5004 | goto out_overflow; | |
6f723f77 BH |
5005 | clp->cl_seqid = be32_to_cpup(p++); |
5006 | clp->cl_exchange_flags = be32_to_cpup(p++); | |
99fe60d0 BH |
5007 | |
5008 | /* We ask for SP4_NONE */ | |
cccddf4f | 5009 | dummy = be32_to_cpup(p); |
99fe60d0 BH |
5010 | if (dummy != SP4_NONE) |
5011 | return -EIO; | |
5012 | ||
5013 | /* Throw away minor_id */ | |
c0eae66e BH |
5014 | p = xdr_inline_decode(xdr, 8); |
5015 | if (unlikely(!p)) | |
5016 | goto out_overflow; | |
99fe60d0 BH |
5017 | |
5018 | /* Throw away Major id */ | |
2460ba57 BH |
5019 | status = decode_opaque_inline(xdr, &dummy, &dummy_str); |
5020 | if (unlikely(status)) | |
5021 | return status; | |
99fe60d0 | 5022 | |
78fe0f41 | 5023 | /* Save server_scope */ |
2460ba57 BH |
5024 | status = decode_opaque_inline(xdr, &dummy, &dummy_str); |
5025 | if (unlikely(status)) | |
5026 | return status; | |
99fe60d0 | 5027 | |
78fe0f41 WAA |
5028 | if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) |
5029 | return -EIO; | |
5030 | ||
5031 | memcpy(res->server_scope->server_scope, dummy_str, dummy); | |
5032 | res->server_scope->server_scope_sz = dummy; | |
5033 | ||
99fe60d0 | 5034 | /* Throw away Implementation id array */ |
2460ba57 BH |
5035 | status = decode_opaque_inline(xdr, &dummy, &dummy_str); |
5036 | if (unlikely(status)) | |
5037 | return status; | |
99fe60d0 BH |
5038 | |
5039 | return 0; | |
c0eae66e BH |
5040 | out_overflow: |
5041 | print_overflow_msg(__func__, xdr); | |
5042 | return -EIO; | |
99fe60d0 | 5043 | } |
fc931582 AA |
5044 | |
5045 | static int decode_chan_attrs(struct xdr_stream *xdr, | |
5046 | struct nfs4_channel_attrs *attrs) | |
5047 | { | |
5048 | __be32 *p; | |
c9c30dd5 | 5049 | u32 nr_attrs, val; |
fc931582 | 5050 | |
c0eae66e BH |
5051 | p = xdr_inline_decode(xdr, 28); |
5052 | if (unlikely(!p)) | |
5053 | goto out_overflow; | |
c9c30dd5 BH |
5054 | val = be32_to_cpup(p++); /* headerpadsz */ |
5055 | if (val) | |
5056 | return -EINVAL; /* no support for header padding yet */ | |
6f723f77 BH |
5057 | attrs->max_rqst_sz = be32_to_cpup(p++); |
5058 | attrs->max_resp_sz = be32_to_cpup(p++); | |
5059 | attrs->max_resp_sz_cached = be32_to_cpup(p++); | |
5060 | attrs->max_ops = be32_to_cpup(p++); | |
5061 | attrs->max_reqs = be32_to_cpup(p++); | |
cccddf4f | 5062 | nr_attrs = be32_to_cpup(p); |
fc931582 AA |
5063 | if (unlikely(nr_attrs > 1)) { |
5064 | printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n", | |
5065 | __func__, nr_attrs); | |
5066 | return -EINVAL; | |
5067 | } | |
c0eae66e BH |
5068 | if (nr_attrs == 1) { |
5069 | p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ | |
5070 | if (unlikely(!p)) | |
5071 | goto out_overflow; | |
5072 | } | |
fc931582 | 5073 | return 0; |
c0eae66e BH |
5074 | out_overflow: |
5075 | print_overflow_msg(__func__, xdr); | |
5076 | return -EIO; | |
fc931582 AA |
5077 | } |
5078 | ||
e78291e4 BH |
5079 | static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) |
5080 | { | |
5081 | return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); | |
fc931582 AA |
5082 | } |
5083 | ||
5084 | static int decode_create_session(struct xdr_stream *xdr, | |
5085 | struct nfs41_create_session_res *res) | |
5086 | { | |
5087 | __be32 *p; | |
5088 | int status; | |
5089 | struct nfs_client *clp = res->client; | |
5090 | struct nfs4_session *session = clp->cl_session; | |
5091 | ||
5092 | status = decode_op_hdr(xdr, OP_CREATE_SESSION); | |
e78291e4 BH |
5093 | if (!status) |
5094 | status = decode_sessionid(xdr, &session->sess_id); | |
5095 | if (unlikely(status)) | |
fc931582 AA |
5096 | return status; |
5097 | ||
fc931582 | 5098 | /* seqid, flags */ |
c0eae66e BH |
5099 | p = xdr_inline_decode(xdr, 8); |
5100 | if (unlikely(!p)) | |
5101 | goto out_overflow; | |
6f723f77 | 5102 | clp->cl_seqid = be32_to_cpup(p++); |
cccddf4f | 5103 | session->flags = be32_to_cpup(p); |
fc931582 AA |
5104 | |
5105 | /* Channel attributes */ | |
5106 | status = decode_chan_attrs(xdr, &session->fc_attrs); | |
5107 | if (!status) | |
5108 | status = decode_chan_attrs(xdr, &session->bc_attrs); | |
5109 | return status; | |
c0eae66e BH |
5110 | out_overflow: |
5111 | print_overflow_msg(__func__, xdr); | |
5112 | return -EIO; | |
fc931582 | 5113 | } |
0f3e66c6 AA |
5114 | |
5115 | static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) | |
5116 | { | |
5117 | return decode_op_hdr(xdr, OP_DESTROY_SESSION); | |
5118 | } | |
18019753 RL |
5119 | |
5120 | static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) | |
5121 | { | |
5122 | return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); | |
5123 | } | |
99fe60d0 BH |
5124 | #endif /* CONFIG_NFS_V4_1 */ |
5125 | ||
9b7b9fcc AA |
5126 | static int decode_sequence(struct xdr_stream *xdr, |
5127 | struct nfs4_sequence_res *res, | |
5128 | struct rpc_rqst *rqstp) | |
5129 | { | |
5130 | #if defined(CONFIG_NFS_V4_1) | |
fc01cea9 AA |
5131 | struct nfs4_sessionid id; |
5132 | u32 dummy; | |
5133 | int status; | |
5134 | __be32 *p; | |
5135 | ||
9b7b9fcc AA |
5136 | if (!res->sr_session) |
5137 | return 0; | |
5138 | ||
fc01cea9 | 5139 | status = decode_op_hdr(xdr, OP_SEQUENCE); |
e78291e4 BH |
5140 | if (!status) |
5141 | status = decode_sessionid(xdr, &id); | |
5142 | if (unlikely(status)) | |
fc01cea9 | 5143 | goto out_err; |
9b7b9fcc | 5144 | |
fc01cea9 AA |
5145 | /* |
5146 | * If the server returns different values for sessionID, slotID or | |
5147 | * sequence number, the server is looney tunes. | |
5148 | */ | |
fdcb4577 | 5149 | status = -EREMOTEIO; |
fc01cea9 | 5150 | |
fc01cea9 AA |
5151 | if (memcmp(id.data, res->sr_session->sess_id.data, |
5152 | NFS4_MAX_SESSIONID_LEN)) { | |
5153 | dprintk("%s Invalid session id\n", __func__); | |
5154 | goto out_err; | |
5155 | } | |
e78291e4 | 5156 | |
c0eae66e BH |
5157 | p = xdr_inline_decode(xdr, 20); |
5158 | if (unlikely(!p)) | |
5159 | goto out_overflow; | |
e78291e4 | 5160 | |
fc01cea9 | 5161 | /* seqid */ |
6f723f77 | 5162 | dummy = be32_to_cpup(p++); |
dfb4f309 | 5163 | if (dummy != res->sr_slot->seq_nr) { |
fc01cea9 AA |
5164 | dprintk("%s Invalid sequence number\n", __func__); |
5165 | goto out_err; | |
5166 | } | |
5167 | /* slot id */ | |
6f723f77 | 5168 | dummy = be32_to_cpup(p++); |
dfb4f309 | 5169 | if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) { |
fc01cea9 AA |
5170 | dprintk("%s Invalid slot id\n", __func__); |
5171 | goto out_err; | |
5172 | } | |
5173 | /* highest slot id - currently not processed */ | |
6f723f77 | 5174 | dummy = be32_to_cpup(p++); |
fc01cea9 | 5175 | /* target highest slot id - currently not processed */ |
6f723f77 | 5176 | dummy = be32_to_cpup(p++); |
0629e370 AB |
5177 | /* result flags */ |
5178 | res->sr_status_flags = be32_to_cpup(p); | |
fc01cea9 AA |
5179 | status = 0; |
5180 | out_err: | |
5181 | res->sr_status = status; | |
5182 | return status; | |
c0eae66e BH |
5183 | out_overflow: |
5184 | print_overflow_msg(__func__, xdr); | |
5185 | status = -EIO; | |
5186 | goto out_err; | |
fc01cea9 | 5187 | #else /* CONFIG_NFS_V4_1 */ |
9b7b9fcc | 5188 | return 0; |
fc01cea9 | 5189 | #endif /* CONFIG_NFS_V4_1 */ |
9b7b9fcc AA |
5190 | } |
5191 | ||
b1f69b75 AA |
5192 | #if defined(CONFIG_NFS_V4_1) |
5193 | ||
5194 | static int decode_getdeviceinfo(struct xdr_stream *xdr, | |
5195 | struct pnfs_device *pdev) | |
5196 | { | |
5197 | __be32 *p; | |
5198 | uint32_t len, type; | |
5199 | int status; | |
5200 | ||
5201 | status = decode_op_hdr(xdr, OP_GETDEVICEINFO); | |
5202 | if (status) { | |
5203 | if (status == -ETOOSMALL) { | |
5204 | p = xdr_inline_decode(xdr, 4); | |
5205 | if (unlikely(!p)) | |
5206 | goto out_overflow; | |
5207 | pdev->mincount = be32_to_cpup(p); | |
5208 | dprintk("%s: Min count too small. mincnt = %u\n", | |
5209 | __func__, pdev->mincount); | |
5210 | } | |
5211 | return status; | |
5212 | } | |
5213 | ||
5214 | p = xdr_inline_decode(xdr, 8); | |
5215 | if (unlikely(!p)) | |
5216 | goto out_overflow; | |
5217 | type = be32_to_cpup(p++); | |
5218 | if (type != pdev->layout_type) { | |
5219 | dprintk("%s: layout mismatch req: %u pdev: %u\n", | |
5220 | __func__, pdev->layout_type, type); | |
5221 | return -EINVAL; | |
5222 | } | |
5223 | /* | |
5224 | * Get the length of the opaque device_addr4. xdr_read_pages places | |
5225 | * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) | |
5226 | * and places the remaining xdr data in xdr_buf->tail | |
5227 | */ | |
5228 | pdev->mincount = be32_to_cpup(p); | |
5229 | xdr_read_pages(xdr, pdev->mincount); /* include space for the length */ | |
5230 | ||
5231 | /* Parse notification bitmap, verifying that it is zero. */ | |
5232 | p = xdr_inline_decode(xdr, 4); | |
5233 | if (unlikely(!p)) | |
5234 | goto out_overflow; | |
5235 | len = be32_to_cpup(p); | |
5236 | if (len) { | |
ead00597 | 5237 | uint32_t i; |
b1f69b75 AA |
5238 | |
5239 | p = xdr_inline_decode(xdr, 4 * len); | |
5240 | if (unlikely(!p)) | |
5241 | goto out_overflow; | |
5242 | for (i = 0; i < len; i++, p++) { | |
5243 | if (be32_to_cpup(p)) { | |
5244 | dprintk("%s: notifications not supported\n", | |
5245 | __func__); | |
5246 | return -EIO; | |
5247 | } | |
5248 | } | |
5249 | } | |
5250 | return 0; | |
5251 | out_overflow: | |
5252 | print_overflow_msg(__func__, xdr); | |
5253 | return -EIO; | |
5254 | } | |
5255 | ||
5256 | static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, | |
5257 | struct nfs4_layoutget_res *res) | |
5258 | { | |
5259 | __be32 *p; | |
5260 | int status; | |
5261 | u32 layout_count; | |
35124a09 WAA |
5262 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; |
5263 | struct kvec *iov = rcvbuf->head; | |
5264 | u32 hdrlen, recvd; | |
b1f69b75 AA |
5265 | |
5266 | status = decode_op_hdr(xdr, OP_LAYOUTGET); | |
5267 | if (status) | |
5268 | return status; | |
5269 | p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE); | |
5270 | if (unlikely(!p)) | |
5271 | goto out_overflow; | |
5272 | res->return_on_close = be32_to_cpup(p++); | |
5273 | p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE); | |
5274 | layout_count = be32_to_cpup(p); | |
5275 | if (!layout_count) { | |
5276 | dprintk("%s: server responded with empty layout array\n", | |
5277 | __func__); | |
5278 | return -EINVAL; | |
5279 | } | |
5280 | ||
35124a09 | 5281 | p = xdr_inline_decode(xdr, 28); |
b1f69b75 AA |
5282 | if (unlikely(!p)) |
5283 | goto out_overflow; | |
5284 | p = xdr_decode_hyper(p, &res->range.offset); | |
5285 | p = xdr_decode_hyper(p, &res->range.length); | |
5286 | res->range.iomode = be32_to_cpup(p++); | |
5287 | res->type = be32_to_cpup(p++); | |
35124a09 | 5288 | res->layoutp->len = be32_to_cpup(p); |
b1f69b75 AA |
5289 | |
5290 | dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", | |
5291 | __func__, | |
5292 | (unsigned long)res->range.offset, | |
5293 | (unsigned long)res->range.length, | |
5294 | res->range.iomode, | |
5295 | res->type, | |
35124a09 WAA |
5296 | res->layoutp->len); |
5297 | ||
5298 | hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; | |
5299 | recvd = req->rq_rcv_buf.len - hdrlen; | |
5300 | if (res->layoutp->len > recvd) { | |
5301 | dprintk("NFS: server cheating in layoutget reply: " | |
5302 | "layout len %u > recvd %u\n", | |
5303 | res->layoutp->len, recvd); | |
5304 | return -EINVAL; | |
5305 | } | |
b1f69b75 | 5306 | |
35124a09 | 5307 | xdr_read_pages(xdr, res->layoutp->len); |
b1f69b75 AA |
5308 | |
5309 | if (layout_count > 1) { | |
5310 | /* We only handle a length one array at the moment. Any | |
5311 | * further entries are just ignored. Note that this means | |
5312 | * the client may see a response that is less than the | |
5313 | * minimum it requested. | |
5314 | */ | |
5315 | dprintk("%s: server responded with %d layouts, dropping tail\n", | |
5316 | __func__, layout_count); | |
5317 | } | |
5318 | ||
5319 | return 0; | |
5320 | out_overflow: | |
5321 | print_overflow_msg(__func__, xdr); | |
5322 | return -EIO; | |
5323 | } | |
863a3c6c | 5324 | |
cbe82603 BH |
5325 | static int decode_layoutreturn(struct xdr_stream *xdr, |
5326 | struct nfs4_layoutreturn_res *res) | |
5327 | { | |
5328 | __be32 *p; | |
5329 | int status; | |
5330 | ||
5331 | status = decode_op_hdr(xdr, OP_LAYOUTRETURN); | |
5332 | if (status) | |
5333 | return status; | |
5334 | p = xdr_inline_decode(xdr, 4); | |
5335 | if (unlikely(!p)) | |
5336 | goto out_overflow; | |
5337 | res->lrs_present = be32_to_cpup(p); | |
5338 | if (res->lrs_present) | |
5339 | status = decode_stateid(xdr, &res->stateid); | |
5340 | return status; | |
5341 | out_overflow: | |
5342 | print_overflow_msg(__func__, xdr); | |
5343 | return -EIO; | |
5344 | } | |
5345 | ||
863a3c6c AA |
5346 | static int decode_layoutcommit(struct xdr_stream *xdr, |
5347 | struct rpc_rqst *req, | |
5348 | struct nfs4_layoutcommit_res *res) | |
5349 | { | |
5350 | __be32 *p; | |
5351 | __u32 sizechanged; | |
5352 | int status; | |
5353 | ||
5354 | status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); | |
5355 | if (status) | |
5356 | return status; | |
5357 | ||
5358 | p = xdr_inline_decode(xdr, 4); | |
5359 | if (unlikely(!p)) | |
5360 | goto out_overflow; | |
5361 | sizechanged = be32_to_cpup(p); | |
5362 | ||
5363 | if (sizechanged) { | |
5364 | /* throw away new size */ | |
5365 | p = xdr_inline_decode(xdr, 8); | |
5366 | if (unlikely(!p)) | |
5367 | goto out_overflow; | |
5368 | } | |
5369 | return 0; | |
5370 | out_overflow: | |
5371 | print_overflow_msg(__func__, xdr); | |
5372 | return -EIO; | |
5373 | } | |
b1f69b75 AA |
5374 | #endif /* CONFIG_NFS_V4_1 */ |
5375 | ||
49c2559e BH |
5376 | /* |
5377 | * END OF "GENERIC" DECODE ROUTINES. | |
5378 | */ | |
5379 | ||
1da177e4 LT |
5380 | /* |
5381 | * Decode OPEN_DOWNGRADE response | |
5382 | */ | |
bf269551 CL |
5383 | static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, |
5384 | struct xdr_stream *xdr, | |
5385 | struct nfs_closeres *res) | |
1da177e4 | 5386 | { |
05d564fe AA |
5387 | struct compound_hdr hdr; |
5388 | int status; | |
5389 | ||
bf269551 | 5390 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5391 | if (status) |
5392 | goto out; | |
bf269551 | 5393 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
05d564fe AA |
5394 | if (status) |
5395 | goto out; | |
bf269551 | 5396 | status = decode_putfh(xdr); |
05d564fe AA |
5397 | if (status) |
5398 | goto out; | |
bf269551 | 5399 | status = decode_open_downgrade(xdr, res); |
516a6af6 TM |
5400 | if (status != 0) |
5401 | goto out; | |
bf269551 | 5402 | decode_getfattr(xdr, res->fattr, res->server, |
80e52ace | 5403 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 | 5404 | out: |
05d564fe | 5405 | return status; |
1da177e4 LT |
5406 | } |
5407 | ||
1da177e4 LT |
5408 | /* |
5409 | * Decode ACCESS response | |
5410 | */ | |
bf269551 CL |
5411 | static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5412 | struct nfs4_accessres *res) | |
1da177e4 | 5413 | { |
1da177e4 LT |
5414 | struct compound_hdr hdr; |
5415 | int status; | |
6c0195a4 | 5416 | |
bf269551 | 5417 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5418 | if (status) |
5419 | goto out; | |
bf269551 | 5420 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
9b7b9fcc | 5421 | if (status) |
1da177e4 | 5422 | goto out; |
bf269551 | 5423 | status = decode_putfh(xdr); |
76b32999 TM |
5424 | if (status != 0) |
5425 | goto out; | |
bf269551 | 5426 | status = decode_access(xdr, res); |
76b32999 TM |
5427 | if (status != 0) |
5428 | goto out; | |
bf269551 | 5429 | decode_getfattr(xdr, res->fattr, res->server, |
80e52ace | 5430 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 LT |
5431 | out: |
5432 | return status; | |
5433 | } | |
5434 | ||
5435 | /* | |
5436 | * Decode LOOKUP response | |
5437 | */ | |
bf269551 CL |
5438 | static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5439 | struct nfs4_lookup_res *res) | |
1da177e4 | 5440 | { |
1da177e4 LT |
5441 | struct compound_hdr hdr; |
5442 | int status; | |
6c0195a4 | 5443 | |
bf269551 | 5444 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5445 | if (status) |
5446 | goto out; | |
bf269551 | 5447 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
9b7b9fcc | 5448 | if (status) |
1da177e4 | 5449 | goto out; |
bf269551 CL |
5450 | status = decode_putfh(xdr); |
5451 | if (status) | |
1da177e4 | 5452 | goto out; |
bf269551 CL |
5453 | status = decode_lookup(xdr); |
5454 | if (status) | |
1da177e4 | 5455 | goto out; |
bf269551 CL |
5456 | status = decode_getfh(xdr, res->fh); |
5457 | if (status) | |
1da177e4 | 5458 | goto out; |
bf269551 | 5459 | status = decode_getfattr(xdr, res->fattr, res->server |
80e52ace | 5460 | ,!RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 LT |
5461 | out: |
5462 | return status; | |
5463 | } | |
5464 | ||
5465 | /* | |
5466 | * Decode LOOKUP_ROOT response | |
5467 | */ | |
bf269551 CL |
5468 | static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, |
5469 | struct xdr_stream *xdr, | |
5470 | struct nfs4_lookup_res *res) | |
1da177e4 | 5471 | { |
1da177e4 LT |
5472 | struct compound_hdr hdr; |
5473 | int status; | |
6c0195a4 | 5474 | |
bf269551 | 5475 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5476 | if (status) |
5477 | goto out; | |
bf269551 | 5478 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
9b7b9fcc | 5479 | if (status) |
1da177e4 | 5480 | goto out; |
bf269551 CL |
5481 | status = decode_putrootfh(xdr); |
5482 | if (status) | |
1da177e4 | 5483 | goto out; |
bf269551 CL |
5484 | status = decode_getfh(xdr, res->fh); |
5485 | if (status == 0) | |
5486 | status = decode_getfattr(xdr, res->fattr, res->server, | |
80e52ace | 5487 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 LT |
5488 | out: |
5489 | return status; | |
5490 | } | |
5491 | ||
5492 | /* | |
5493 | * Decode REMOVE response | |
5494 | */ | |
bf269551 CL |
5495 | static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5496 | struct nfs_removeres *res) | |
1da177e4 | 5497 | { |
1da177e4 LT |
5498 | struct compound_hdr hdr; |
5499 | int status; | |
6c0195a4 | 5500 | |
bf269551 | 5501 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5502 | if (status) |
5503 | goto out; | |
bf269551 | 5504 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
9b7b9fcc | 5505 | if (status) |
1da177e4 | 5506 | goto out; |
bf269551 CL |
5507 | status = decode_putfh(xdr); |
5508 | if (status) | |
16e42959 | 5509 | goto out; |
bf269551 CL |
5510 | status = decode_remove(xdr, &res->cinfo); |
5511 | if (status) | |
16e42959 | 5512 | goto out; |
bf269551 | 5513 | decode_getfattr(xdr, res->dir_attr, res->server, |
80e52ace | 5514 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 LT |
5515 | out: |
5516 | return status; | |
5517 | } | |
5518 | ||
5519 | /* | |
5520 | * Decode RENAME response | |
5521 | */ | |
bf269551 CL |
5522 | static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5523 | struct nfs_renameres *res) | |
1da177e4 | 5524 | { |
1da177e4 LT |
5525 | struct compound_hdr hdr; |
5526 | int status; | |
6c0195a4 | 5527 | |
bf269551 | 5528 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5529 | if (status) |
5530 | goto out; | |
bf269551 | 5531 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
9b7b9fcc | 5532 | if (status) |
1da177e4 | 5533 | goto out; |
bf269551 CL |
5534 | status = decode_putfh(xdr); |
5535 | if (status) | |
1da177e4 | 5536 | goto out; |
bf269551 CL |
5537 | status = decode_savefh(xdr); |
5538 | if (status) | |
1da177e4 | 5539 | goto out; |
bf269551 CL |
5540 | status = decode_putfh(xdr); |
5541 | if (status) | |
1da177e4 | 5542 | goto out; |
bf269551 CL |
5543 | status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); |
5544 | if (status) | |
6caf2c82 TM |
5545 | goto out; |
5546 | /* Current FH is target directory */ | |
bf269551 | 5547 | if (decode_getfattr(xdr, res->new_fattr, res->server, |
80e52ace | 5548 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) |
6caf2c82 | 5549 | goto out; |
bf269551 CL |
5550 | status = decode_restorefh(xdr); |
5551 | if (status) | |
6caf2c82 | 5552 | goto out; |
bf269551 | 5553 | decode_getfattr(xdr, res->old_fattr, res->server, |
80e52ace | 5554 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 LT |
5555 | out: |
5556 | return status; | |
5557 | } | |
5558 | ||
5559 | /* | |
5560 | * Decode LINK response | |
5561 | */ | |
bf269551 CL |
5562 | static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5563 | struct nfs4_link_res *res) | |
1da177e4 | 5564 | { |
1da177e4 LT |
5565 | struct compound_hdr hdr; |
5566 | int status; | |
6c0195a4 | 5567 | |
bf269551 | 5568 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5569 | if (status) |
5570 | goto out; | |
bf269551 | 5571 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
9b7b9fcc | 5572 | if (status) |
1da177e4 | 5573 | goto out; |
bf269551 CL |
5574 | status = decode_putfh(xdr); |
5575 | if (status) | |
1da177e4 | 5576 | goto out; |
bf269551 CL |
5577 | status = decode_savefh(xdr); |
5578 | if (status) | |
1da177e4 | 5579 | goto out; |
bf269551 CL |
5580 | status = decode_putfh(xdr); |
5581 | if (status) | |
1da177e4 | 5582 | goto out; |
bf269551 CL |
5583 | status = decode_link(xdr, &res->cinfo); |
5584 | if (status) | |
91ba2eee TM |
5585 | goto out; |
5586 | /* | |
5587 | * Note order: OP_LINK leaves the directory as the current | |
5588 | * filehandle. | |
5589 | */ | |
bf269551 | 5590 | if (decode_getfattr(xdr, res->dir_attr, res->server, |
80e52ace | 5591 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) |
91ba2eee | 5592 | goto out; |
bf269551 CL |
5593 | status = decode_restorefh(xdr); |
5594 | if (status) | |
91ba2eee | 5595 | goto out; |
bf269551 | 5596 | decode_getfattr(xdr, res->fattr, res->server, |
80e52ace | 5597 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 LT |
5598 | out: |
5599 | return status; | |
5600 | } | |
5601 | ||
5602 | /* | |
5603 | * Decode CREATE response | |
5604 | */ | |
bf269551 CL |
5605 | static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5606 | struct nfs4_create_res *res) | |
1da177e4 | 5607 | { |
1da177e4 LT |
5608 | struct compound_hdr hdr; |
5609 | int status; | |
6c0195a4 | 5610 | |
bf269551 | 5611 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5612 | if (status) |
5613 | goto out; | |
bf269551 | 5614 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
9b7b9fcc | 5615 | if (status) |
1da177e4 | 5616 | goto out; |
bf269551 CL |
5617 | status = decode_putfh(xdr); |
5618 | if (status) | |
1da177e4 | 5619 | goto out; |
bf269551 CL |
5620 | status = decode_savefh(xdr); |
5621 | if (status) | |
56ae19f3 | 5622 | goto out; |
bf269551 CL |
5623 | status = decode_create(xdr, &res->dir_cinfo); |
5624 | if (status) | |
1da177e4 | 5625 | goto out; |
bf269551 CL |
5626 | status = decode_getfh(xdr, res->fh); |
5627 | if (status) | |
1da177e4 | 5628 | goto out; |
bf269551 | 5629 | if (decode_getfattr(xdr, res->fattr, res->server, |
80e52ace | 5630 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) |
56ae19f3 | 5631 | goto out; |
bf269551 CL |
5632 | status = decode_restorefh(xdr); |
5633 | if (status) | |
56ae19f3 | 5634 | goto out; |
bf269551 | 5635 | decode_getfattr(xdr, res->dir_fattr, res->server, |
80e52ace | 5636 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 LT |
5637 | out: |
5638 | return status; | |
5639 | } | |
5640 | ||
5641 | /* | |
5642 | * Decode SYMLINK response | |
5643 | */ | |
bf269551 CL |
5644 | static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5645 | struct nfs4_create_res *res) | |
1da177e4 | 5646 | { |
bf269551 | 5647 | return nfs4_xdr_dec_create(rqstp, xdr, res); |
1da177e4 LT |
5648 | } |
5649 | ||
5650 | /* | |
5651 | * Decode GETATTR response | |
5652 | */ | |
bf269551 CL |
5653 | static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5654 | struct nfs4_getattr_res *res) | |
1da177e4 | 5655 | { |
1da177e4 LT |
5656 | struct compound_hdr hdr; |
5657 | int status; | |
6c0195a4 | 5658 | |
bf269551 | 5659 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5660 | if (status) |
5661 | goto out; | |
bf269551 | 5662 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
1da177e4 LT |
5663 | if (status) |
5664 | goto out; | |
bf269551 | 5665 | status = decode_putfh(xdr); |
1da177e4 LT |
5666 | if (status) |
5667 | goto out; | |
bf269551 | 5668 | status = decode_getfattr(xdr, res->fattr, res->server, |
80e52ace | 5669 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 LT |
5670 | out: |
5671 | return status; | |
1da177e4 LT |
5672 | } |
5673 | ||
23ec6965 BF |
5674 | /* |
5675 | * Encode an SETACL request | |
5676 | */ | |
9f06c719 CL |
5677 | static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, |
5678 | struct nfs_setaclargs *args) | |
23ec6965 | 5679 | { |
05d564fe | 5680 | struct compound_hdr hdr = { |
66cc0429 | 5681 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
05d564fe | 5682 | }; |
05d564fe | 5683 | |
9f06c719 CL |
5684 | encode_compound_hdr(xdr, req, &hdr); |
5685 | encode_sequence(xdr, &args->seq_args, &hdr); | |
5686 | encode_putfh(xdr, args->fh, &hdr); | |
5687 | encode_setacl(xdr, args, &hdr); | |
d017931c | 5688 | encode_nops(&hdr); |
23ec6965 | 5689 | } |
05d564fe | 5690 | |
23ec6965 BF |
5691 | /* |
5692 | * Decode SETACL response | |
5693 | */ | |
5694 | static int | |
bf269551 | 5695 | nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
73c403a9 | 5696 | struct nfs_setaclres *res) |
23ec6965 | 5697 | { |
23ec6965 BF |
5698 | struct compound_hdr hdr; |
5699 | int status; | |
5700 | ||
bf269551 | 5701 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5702 | if (status) |
5703 | goto out; | |
bf269551 | 5704 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
23ec6965 BF |
5705 | if (status) |
5706 | goto out; | |
bf269551 | 5707 | status = decode_putfh(xdr); |
23ec6965 BF |
5708 | if (status) |
5709 | goto out; | |
bf269551 | 5710 | status = decode_setattr(xdr); |
23ec6965 BF |
5711 | out: |
5712 | return status; | |
5713 | } | |
1da177e4 | 5714 | |
029d105e BF |
5715 | /* |
5716 | * Decode GETACL response | |
5717 | */ | |
5718 | static int | |
bf269551 | 5719 | nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
663c79b3 | 5720 | struct nfs_getaclres *res) |
029d105e | 5721 | { |
029d105e BF |
5722 | struct compound_hdr hdr; |
5723 | int status; | |
5724 | ||
bf269551 | 5725 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5726 | if (status) |
5727 | goto out; | |
bf269551 | 5728 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
029d105e BF |
5729 | if (status) |
5730 | goto out; | |
bf269551 | 5731 | status = decode_putfh(xdr); |
029d105e BF |
5732 | if (status) |
5733 | goto out; | |
bf269551 | 5734 | status = decode_getacl(xdr, rqstp, &res->acl_len); |
029d105e BF |
5735 | |
5736 | out: | |
5737 | return status; | |
5738 | } | |
5739 | ||
1da177e4 LT |
5740 | /* |
5741 | * Decode CLOSE response | |
5742 | */ | |
bf269551 CL |
5743 | static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5744 | struct nfs_closeres *res) | |
1da177e4 | 5745 | { |
05d564fe AA |
5746 | struct compound_hdr hdr; |
5747 | int status; | |
5748 | ||
bf269551 | 5749 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5750 | if (status) |
5751 | goto out; | |
bf269551 | 5752 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
05d564fe AA |
5753 | if (status) |
5754 | goto out; | |
bf269551 | 5755 | status = decode_putfh(xdr); |
05d564fe AA |
5756 | if (status) |
5757 | goto out; | |
bf269551 | 5758 | status = decode_close(xdr, res); |
516a6af6 TM |
5759 | if (status != 0) |
5760 | goto out; | |
5761 | /* | |
5762 | * Note: Server may do delete on close for this file | |
5763 | * in which case the getattr call will fail with | |
5764 | * an ESTALE error. Shouldn't be a problem, | |
5765 | * though, since fattr->valid will remain unset. | |
5766 | */ | |
bf269551 | 5767 | decode_getfattr(xdr, res->fattr, res->server, |
80e52ace | 5768 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 | 5769 | out: |
05d564fe | 5770 | return status; |
1da177e4 LT |
5771 | } |
5772 | ||
5773 | /* | |
5774 | * Decode OPEN response | |
5775 | */ | |
bf269551 CL |
5776 | static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5777 | struct nfs_openres *res) | |
1da177e4 | 5778 | { |
05d564fe AA |
5779 | struct compound_hdr hdr; |
5780 | int status; | |
5781 | ||
bf269551 | 5782 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5783 | if (status) |
5784 | goto out; | |
bf269551 | 5785 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
05d564fe AA |
5786 | if (status) |
5787 | goto out; | |
bf269551 | 5788 | status = decode_putfh(xdr); |
05d564fe AA |
5789 | if (status) |
5790 | goto out; | |
bf269551 | 5791 | status = decode_savefh(xdr); |
05d564fe AA |
5792 | if (status) |
5793 | goto out; | |
bf269551 | 5794 | status = decode_open(xdr, res); |
56ae19f3 TM |
5795 | if (status) |
5796 | goto out; | |
bf269551 | 5797 | if (decode_getfh(xdr, &res->fh) != 0) |
1da177e4 | 5798 | goto out; |
bf269551 | 5799 | if (decode_getfattr(xdr, res->f_attr, res->server, |
80e52ace | 5800 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) |
56ae19f3 | 5801 | goto out; |
bf269551 | 5802 | if (decode_restorefh(xdr) != 0) |
56ae19f3 | 5803 | goto out; |
bf269551 | 5804 | decode_getfattr(xdr, res->dir_attr, res->server, |
80e52ace | 5805 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 | 5806 | out: |
05d564fe | 5807 | return status; |
1da177e4 LT |
5808 | } |
5809 | ||
5810 | /* | |
5811 | * Decode OPEN_CONFIRM response | |
5812 | */ | |
bf269551 CL |
5813 | static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, |
5814 | struct xdr_stream *xdr, | |
5815 | struct nfs_open_confirmres *res) | |
1da177e4 | 5816 | { |
05d564fe AA |
5817 | struct compound_hdr hdr; |
5818 | int status; | |
5819 | ||
bf269551 | 5820 | status = decode_compound_hdr(xdr, &hdr); |
05d564fe AA |
5821 | if (status) |
5822 | goto out; | |
bf269551 | 5823 | status = decode_putfh(xdr); |
05d564fe AA |
5824 | if (status) |
5825 | goto out; | |
bf269551 | 5826 | status = decode_open_confirm(xdr, res); |
1da177e4 | 5827 | out: |
05d564fe | 5828 | return status; |
1da177e4 LT |
5829 | } |
5830 | ||
5831 | /* | |
5832 | * Decode OPEN response | |
5833 | */ | |
bf269551 CL |
5834 | static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, |
5835 | struct xdr_stream *xdr, | |
5836 | struct nfs_openres *res) | |
1da177e4 | 5837 | { |
05d564fe AA |
5838 | struct compound_hdr hdr; |
5839 | int status; | |
5840 | ||
bf269551 | 5841 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5842 | if (status) |
5843 | goto out; | |
bf269551 | 5844 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
05d564fe AA |
5845 | if (status) |
5846 | goto out; | |
bf269551 | 5847 | status = decode_putfh(xdr); |
05d564fe AA |
5848 | if (status) |
5849 | goto out; | |
bf269551 | 5850 | status = decode_open(xdr, res); |
05d564fe AA |
5851 | if (status) |
5852 | goto out; | |
bf269551 | 5853 | decode_getfattr(xdr, res->f_attr, res->server, |
80e52ace | 5854 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 | 5855 | out: |
05d564fe | 5856 | return status; |
1da177e4 LT |
5857 | } |
5858 | ||
5859 | /* | |
5860 | * Decode SETATTR response | |
5861 | */ | |
bf269551 CL |
5862 | static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, |
5863 | struct xdr_stream *xdr, | |
5864 | struct nfs_setattrres *res) | |
1da177e4 | 5865 | { |
05d564fe AA |
5866 | struct compound_hdr hdr; |
5867 | int status; | |
5868 | ||
bf269551 | 5869 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5870 | if (status) |
5871 | goto out; | |
bf269551 | 5872 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
05d564fe AA |
5873 | if (status) |
5874 | goto out; | |
bf269551 | 5875 | status = decode_putfh(xdr); |
05d564fe AA |
5876 | if (status) |
5877 | goto out; | |
bf269551 | 5878 | status = decode_setattr(xdr); |
05d564fe AA |
5879 | if (status) |
5880 | goto out; | |
bf269551 | 5881 | decode_getfattr(xdr, res->fattr, res->server, |
80e52ace | 5882 | !RPC_IS_ASYNC(rqstp->rq_task)); |
1da177e4 | 5883 | out: |
05d564fe | 5884 | return status; |
1da177e4 LT |
5885 | } |
5886 | ||
5887 | /* | |
5888 | * Decode LOCK response | |
5889 | */ | |
bf269551 CL |
5890 | static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5891 | struct nfs_lock_res *res) | |
1da177e4 | 5892 | { |
1da177e4 LT |
5893 | struct compound_hdr hdr; |
5894 | int status; | |
5895 | ||
bf269551 | 5896 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5897 | if (status) |
5898 | goto out; | |
bf269551 | 5899 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
1da177e4 LT |
5900 | if (status) |
5901 | goto out; | |
bf269551 | 5902 | status = decode_putfh(xdr); |
1da177e4 LT |
5903 | if (status) |
5904 | goto out; | |
bf269551 | 5905 | status = decode_lock(xdr, res); |
1da177e4 LT |
5906 | out: |
5907 | return status; | |
5908 | } | |
5909 | ||
5910 | /* | |
5911 | * Decode LOCKT response | |
5912 | */ | |
bf269551 CL |
5913 | static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5914 | struct nfs_lockt_res *res) | |
1da177e4 | 5915 | { |
1da177e4 LT |
5916 | struct compound_hdr hdr; |
5917 | int status; | |
5918 | ||
bf269551 | 5919 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5920 | if (status) |
5921 | goto out; | |
bf269551 | 5922 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
1da177e4 LT |
5923 | if (status) |
5924 | goto out; | |
bf269551 | 5925 | status = decode_putfh(xdr); |
1da177e4 LT |
5926 | if (status) |
5927 | goto out; | |
bf269551 | 5928 | status = decode_lockt(xdr, res); |
1da177e4 LT |
5929 | out: |
5930 | return status; | |
5931 | } | |
5932 | ||
5933 | /* | |
5934 | * Decode LOCKU response | |
5935 | */ | |
bf269551 CL |
5936 | static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5937 | struct nfs_locku_res *res) | |
1da177e4 | 5938 | { |
1da177e4 LT |
5939 | struct compound_hdr hdr; |
5940 | int status; | |
5941 | ||
bf269551 | 5942 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5943 | if (status) |
5944 | goto out; | |
bf269551 | 5945 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
1da177e4 LT |
5946 | if (status) |
5947 | goto out; | |
bf269551 | 5948 | status = decode_putfh(xdr); |
1da177e4 LT |
5949 | if (status) |
5950 | goto out; | |
bf269551 | 5951 | status = decode_locku(xdr, res); |
1da177e4 LT |
5952 | out: |
5953 | return status; | |
5954 | } | |
5955 | ||
bf269551 CL |
5956 | static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, |
5957 | struct xdr_stream *xdr, void *dummy) | |
d3c7b7cc | 5958 | { |
d3c7b7cc TM |
5959 | struct compound_hdr hdr; |
5960 | int status; | |
5961 | ||
bf269551 | 5962 | status = decode_compound_hdr(xdr, &hdr); |
d3c7b7cc | 5963 | if (!status) |
bf269551 | 5964 | status = decode_release_lockowner(xdr); |
d3c7b7cc TM |
5965 | return status; |
5966 | } | |
5967 | ||
1da177e4 LT |
5968 | /* |
5969 | * Decode READLINK response | |
5970 | */ | |
bf269551 CL |
5971 | static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, |
5972 | struct xdr_stream *xdr, | |
f50c7000 | 5973 | struct nfs4_readlink_res *res) |
1da177e4 | 5974 | { |
1da177e4 LT |
5975 | struct compound_hdr hdr; |
5976 | int status; | |
5977 | ||
bf269551 | 5978 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
5979 | if (status) |
5980 | goto out; | |
bf269551 | 5981 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
1da177e4 LT |
5982 | if (status) |
5983 | goto out; | |
bf269551 | 5984 | status = decode_putfh(xdr); |
1da177e4 LT |
5985 | if (status) |
5986 | goto out; | |
bf269551 | 5987 | status = decode_readlink(xdr, rqstp); |
1da177e4 LT |
5988 | out: |
5989 | return status; | |
5990 | } | |
5991 | ||
5992 | /* | |
5993 | * Decode READDIR response | |
5994 | */ | |
bf269551 CL |
5995 | static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5996 | struct nfs4_readdir_res *res) | |
1da177e4 | 5997 | { |
1da177e4 LT |
5998 | struct compound_hdr hdr; |
5999 | int status; | |
6000 | ||
bf269551 | 6001 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
6002 | if (status) |
6003 | goto out; | |
bf269551 | 6004 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
1da177e4 LT |
6005 | if (status) |
6006 | goto out; | |
bf269551 | 6007 | status = decode_putfh(xdr); |
1da177e4 LT |
6008 | if (status) |
6009 | goto out; | |
bf269551 | 6010 | status = decode_readdir(xdr, rqstp, res); |
1da177e4 LT |
6011 | out: |
6012 | return status; | |
6013 | } | |
6014 | ||
6015 | /* | |
6016 | * Decode Read response | |
6017 | */ | |
bf269551 CL |
6018 | static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
6019 | struct nfs_readres *res) | |
1da177e4 | 6020 | { |
1da177e4 LT |
6021 | struct compound_hdr hdr; |
6022 | int status; | |
6023 | ||
bf269551 | 6024 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
6025 | if (status) |
6026 | goto out; | |
bf269551 | 6027 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
1da177e4 LT |
6028 | if (status) |
6029 | goto out; | |
bf269551 | 6030 | status = decode_putfh(xdr); |
1da177e4 LT |
6031 | if (status) |
6032 | goto out; | |
bf269551 | 6033 | status = decode_read(xdr, rqstp, res); |
1da177e4 LT |
6034 | if (!status) |
6035 | status = res->count; | |
6036 | out: | |
6037 | return status; | |
6038 | } | |
6039 | ||
6040 | /* | |
6041 | * Decode WRITE response | |
6042 | */ | |
bf269551 CL |
6043 | static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
6044 | struct nfs_writeres *res) | |
1da177e4 | 6045 | { |
1da177e4 LT |
6046 | struct compound_hdr hdr; |
6047 | int status; | |
6048 | ||
bf269551 | 6049 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
6050 | if (status) |
6051 | goto out; | |
bf269551 | 6052 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
1da177e4 LT |
6053 | if (status) |
6054 | goto out; | |
bf269551 | 6055 | status = decode_putfh(xdr); |
1da177e4 LT |
6056 | if (status) |
6057 | goto out; | |
bf269551 | 6058 | status = decode_write(xdr, res); |
4f9838c7 TM |
6059 | if (status) |
6060 | goto out; | |
7ffd1064 FI |
6061 | if (res->fattr) |
6062 | decode_getfattr(xdr, res->fattr, res->server, | |
6063 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
6064 | if (!status) |
6065 | status = res->count; | |
6066 | out: | |
6067 | return status; | |
6068 | } | |
6069 | ||
6070 | /* | |
6071 | * Decode COMMIT response | |
6072 | */ | |
bf269551 CL |
6073 | static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
6074 | struct nfs_writeres *res) | |
1da177e4 | 6075 | { |
1da177e4 LT |
6076 | struct compound_hdr hdr; |
6077 | int status; | |
6078 | ||
bf269551 | 6079 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
6080 | if (status) |
6081 | goto out; | |
bf269551 | 6082 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
1da177e4 LT |
6083 | if (status) |
6084 | goto out; | |
bf269551 | 6085 | status = decode_putfh(xdr); |
1da177e4 LT |
6086 | if (status) |
6087 | goto out; | |
bf269551 | 6088 | status = decode_commit(xdr, res); |
4f9838c7 TM |
6089 | if (status) |
6090 | goto out; | |
988b6dce FI |
6091 | if (res->fattr) |
6092 | decode_getfattr(xdr, res->fattr, res->server, | |
6093 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
6094 | out: |
6095 | return status; | |
6096 | } | |
6097 | ||
6098 | /* | |
8b173218 | 6099 | * Decode FSINFO response |
1da177e4 | 6100 | */ |
bf269551 | 6101 | static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, |
3dda5e43 | 6102 | struct nfs4_fsinfo_res *res) |
1da177e4 | 6103 | { |
1da177e4 LT |
6104 | struct compound_hdr hdr; |
6105 | int status; | |
6106 | ||
bf269551 | 6107 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc | 6108 | if (!status) |
bf269551 | 6109 | status = decode_sequence(xdr, &res->seq_res, req); |
1da177e4 | 6110 | if (!status) |
bf269551 | 6111 | status = decode_putfh(xdr); |
1da177e4 | 6112 | if (!status) |
bf269551 | 6113 | status = decode_fsinfo(xdr, res->fsinfo); |
1da177e4 LT |
6114 | return status; |
6115 | } | |
6116 | ||
6117 | /* | |
8b173218 | 6118 | * Decode PATHCONF response |
1da177e4 | 6119 | */ |
bf269551 | 6120 | static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, |
d45b2989 | 6121 | struct nfs4_pathconf_res *res) |
1da177e4 | 6122 | { |
1da177e4 LT |
6123 | struct compound_hdr hdr; |
6124 | int status; | |
6125 | ||
bf269551 | 6126 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc | 6127 | if (!status) |
bf269551 | 6128 | status = decode_sequence(xdr, &res->seq_res, req); |
1da177e4 | 6129 | if (!status) |
bf269551 | 6130 | status = decode_putfh(xdr); |
1da177e4 | 6131 | if (!status) |
bf269551 | 6132 | status = decode_pathconf(xdr, res->pathconf); |
1da177e4 LT |
6133 | return status; |
6134 | } | |
6135 | ||
6136 | /* | |
8b173218 | 6137 | * Decode STATFS response |
1da177e4 | 6138 | */ |
bf269551 | 6139 | static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, |
24ad148a | 6140 | struct nfs4_statfs_res *res) |
1da177e4 | 6141 | { |
1da177e4 LT |
6142 | struct compound_hdr hdr; |
6143 | int status; | |
6144 | ||
bf269551 | 6145 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc | 6146 | if (!status) |
bf269551 | 6147 | status = decode_sequence(xdr, &res->seq_res, req); |
1da177e4 | 6148 | if (!status) |
bf269551 | 6149 | status = decode_putfh(xdr); |
1da177e4 | 6150 | if (!status) |
bf269551 | 6151 | status = decode_statfs(xdr, res->fsstat); |
1da177e4 LT |
6152 | return status; |
6153 | } | |
6154 | ||
6155 | /* | |
8b173218 | 6156 | * Decode GETATTR_BITMAP response |
1da177e4 | 6157 | */ |
bf269551 CL |
6158 | static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, |
6159 | struct xdr_stream *xdr, | |
6160 | struct nfs4_server_caps_res *res) | |
1da177e4 | 6161 | { |
1da177e4 LT |
6162 | struct compound_hdr hdr; |
6163 | int status; | |
6164 | ||
bf269551 | 6165 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
6166 | if (status) |
6167 | goto out; | |
bf269551 | 6168 | status = decode_sequence(xdr, &res->seq_res, req); |
9b7b9fcc | 6169 | if (status) |
1da177e4 | 6170 | goto out; |
bf269551 CL |
6171 | status = decode_putfh(xdr); |
6172 | if (status) | |
1da177e4 | 6173 | goto out; |
bf269551 | 6174 | status = decode_server_caps(xdr, res); |
1da177e4 LT |
6175 | out: |
6176 | return status; | |
6177 | } | |
6178 | ||
6179 | /* | |
6180 | * Decode RENEW response | |
6181 | */ | |
bf269551 CL |
6182 | static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
6183 | void *__unused) | |
1da177e4 | 6184 | { |
1da177e4 LT |
6185 | struct compound_hdr hdr; |
6186 | int status; | |
6187 | ||
bf269551 | 6188 | status = decode_compound_hdr(xdr, &hdr); |
1da177e4 | 6189 | if (!status) |
bf269551 | 6190 | status = decode_renew(xdr); |
1da177e4 LT |
6191 | return status; |
6192 | } | |
6193 | ||
6194 | /* | |
8b173218 | 6195 | * Decode SETCLIENTID response |
1da177e4 | 6196 | */ |
bf269551 CL |
6197 | static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, |
6198 | struct xdr_stream *xdr, | |
6199 | struct nfs4_setclientid_res *res) | |
1da177e4 | 6200 | { |
1da177e4 LT |
6201 | struct compound_hdr hdr; |
6202 | int status; | |
6203 | ||
bf269551 | 6204 | status = decode_compound_hdr(xdr, &hdr); |
1da177e4 | 6205 | if (!status) |
bf269551 | 6206 | status = decode_setclientid(xdr, res); |
1da177e4 LT |
6207 | return status; |
6208 | } | |
6209 | ||
6210 | /* | |
8b173218 | 6211 | * Decode SETCLIENTID_CONFIRM response |
1da177e4 | 6212 | */ |
bf269551 CL |
6213 | static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, |
6214 | struct xdr_stream *xdr, | |
6215 | struct nfs_fsinfo *fsinfo) | |
1da177e4 | 6216 | { |
1da177e4 LT |
6217 | struct compound_hdr hdr; |
6218 | int status; | |
6219 | ||
bf269551 | 6220 | status = decode_compound_hdr(xdr, &hdr); |
1da177e4 | 6221 | if (!status) |
bf269551 | 6222 | status = decode_setclientid_confirm(xdr); |
1da177e4 | 6223 | if (!status) |
bf269551 | 6224 | status = decode_putrootfh(xdr); |
1da177e4 | 6225 | if (!status) |
bf269551 | 6226 | status = decode_fsinfo(xdr, fsinfo); |
1da177e4 LT |
6227 | return status; |
6228 | } | |
6229 | ||
6230 | /* | |
8b173218 | 6231 | * Decode DELEGRETURN response |
1da177e4 | 6232 | */ |
bf269551 CL |
6233 | static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, |
6234 | struct xdr_stream *xdr, | |
6235 | struct nfs4_delegreturnres *res) | |
1da177e4 | 6236 | { |
1da177e4 LT |
6237 | struct compound_hdr hdr; |
6238 | int status; | |
6239 | ||
bf269551 | 6240 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
6241 | if (status) |
6242 | goto out; | |
bf269551 | 6243 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
9b7b9fcc | 6244 | if (status) |
fa178f29 | 6245 | goto out; |
bf269551 | 6246 | status = decode_putfh(xdr); |
fa178f29 TM |
6247 | if (status != 0) |
6248 | goto out; | |
bf269551 | 6249 | status = decode_delegreturn(xdr); |
556ae3bb JL |
6250 | if (status != 0) |
6251 | goto out; | |
bf269551 | 6252 | decode_getfattr(xdr, res->fattr, res->server, |
80e52ace | 6253 | !RPC_IS_ASYNC(rqstp->rq_task)); |
fa178f29 | 6254 | out: |
1da177e4 LT |
6255 | return status; |
6256 | } | |
6257 | ||
683b57b4 | 6258 | /* |
8b173218 | 6259 | * Decode FS_LOCATIONS response |
683b57b4 | 6260 | */ |
bf269551 CL |
6261 | static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, |
6262 | struct xdr_stream *xdr, | |
22958463 | 6263 | struct nfs4_fs_locations_res *res) |
683b57b4 | 6264 | { |
683b57b4 TM |
6265 | struct compound_hdr hdr; |
6266 | int status; | |
6267 | ||
bf269551 | 6268 | status = decode_compound_hdr(xdr, &hdr); |
9b7b9fcc AA |
6269 | if (status) |
6270 | goto out; | |
bf269551 | 6271 | status = decode_sequence(xdr, &res->seq_res, req); |
9b7b9fcc | 6272 | if (status) |
683b57b4 | 6273 | goto out; |
bf269551 CL |
6274 | status = decode_putfh(xdr); |
6275 | if (status) | |
683b57b4 | 6276 | goto out; |
bf269551 CL |
6277 | status = decode_lookup(xdr); |
6278 | if (status) | |
683b57b4 | 6279 | goto out; |
bf269551 CL |
6280 | xdr_enter_page(xdr, PAGE_SIZE); |
6281 | status = decode_getfattr(xdr, &res->fs_locations->fattr, | |
80e52ace TM |
6282 | res->fs_locations->server, |
6283 | !RPC_IS_ASYNC(req->rq_task)); | |
683b57b4 TM |
6284 | out: |
6285 | return status; | |
6286 | } | |
6287 | ||
5a5ea0d4 BS |
6288 | /* |
6289 | * Decode SECINFO response | |
6290 | */ | |
6291 | static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, | |
6292 | struct xdr_stream *xdr, | |
6293 | struct nfs4_secinfo_res *res) | |
6294 | { | |
6295 | struct compound_hdr hdr; | |
6296 | int status; | |
6297 | ||
6298 | status = decode_compound_hdr(xdr, &hdr); | |
6299 | if (status) | |
6300 | goto out; | |
6301 | status = decode_sequence(xdr, &res->seq_res, rqstp); | |
6302 | if (status) | |
6303 | goto out; | |
6304 | status = decode_putfh(xdr); | |
6305 | if (status) | |
6306 | goto out; | |
6307 | status = decode_secinfo(xdr, res); | |
6308 | if (status) | |
6309 | goto out; | |
6310 | out: | |
6311 | return status; | |
6312 | } | |
6313 | ||
99fe60d0 BH |
6314 | #if defined(CONFIG_NFS_V4_1) |
6315 | /* | |
8b173218 | 6316 | * Decode EXCHANGE_ID response |
99fe60d0 | 6317 | */ |
bf269551 CL |
6318 | static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, |
6319 | struct xdr_stream *xdr, | |
99fe60d0 BH |
6320 | void *res) |
6321 | { | |
99fe60d0 BH |
6322 | struct compound_hdr hdr; |
6323 | int status; | |
6324 | ||
bf269551 | 6325 | status = decode_compound_hdr(xdr, &hdr); |
99fe60d0 | 6326 | if (!status) |
bf269551 | 6327 | status = decode_exchange_id(xdr, res); |
99fe60d0 BH |
6328 | return status; |
6329 | } | |
2050f0cc | 6330 | |
fc931582 | 6331 | /* |
8b173218 | 6332 | * Decode CREATE_SESSION response |
fc931582 | 6333 | */ |
bf269551 CL |
6334 | static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, |
6335 | struct xdr_stream *xdr, | |
fc931582 AA |
6336 | struct nfs41_create_session_res *res) |
6337 | { | |
fc931582 AA |
6338 | struct compound_hdr hdr; |
6339 | int status; | |
6340 | ||
bf269551 | 6341 | status = decode_compound_hdr(xdr, &hdr); |
fc931582 | 6342 | if (!status) |
bf269551 | 6343 | status = decode_create_session(xdr, res); |
fc931582 AA |
6344 | return status; |
6345 | } | |
6346 | ||
0f3e66c6 | 6347 | /* |
8b173218 | 6348 | * Decode DESTROY_SESSION response |
0f3e66c6 | 6349 | */ |
bf269551 CL |
6350 | static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, |
6351 | struct xdr_stream *xdr, | |
6352 | void *res) | |
0f3e66c6 | 6353 | { |
0f3e66c6 AA |
6354 | struct compound_hdr hdr; |
6355 | int status; | |
6356 | ||
bf269551 | 6357 | status = decode_compound_hdr(xdr, &hdr); |
0f3e66c6 | 6358 | if (!status) |
bf269551 | 6359 | status = decode_destroy_session(xdr, res); |
0f3e66c6 AA |
6360 | return status; |
6361 | } | |
6362 | ||
fc01cea9 | 6363 | /* |
8b173218 | 6364 | * Decode SEQUENCE response |
fc01cea9 | 6365 | */ |
bf269551 CL |
6366 | static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, |
6367 | struct xdr_stream *xdr, | |
fc01cea9 AA |
6368 | struct nfs4_sequence_res *res) |
6369 | { | |
fc01cea9 AA |
6370 | struct compound_hdr hdr; |
6371 | int status; | |
6372 | ||
bf269551 | 6373 | status = decode_compound_hdr(xdr, &hdr); |
fc01cea9 | 6374 | if (!status) |
bf269551 | 6375 | status = decode_sequence(xdr, res, rqstp); |
fc01cea9 AA |
6376 | return status; |
6377 | } | |
6378 | ||
2050f0cc | 6379 | /* |
8b173218 | 6380 | * Decode GET_LEASE_TIME response |
2050f0cc | 6381 | */ |
bf269551 CL |
6382 | static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, |
6383 | struct xdr_stream *xdr, | |
2050f0cc AA |
6384 | struct nfs4_get_lease_time_res *res) |
6385 | { | |
2050f0cc AA |
6386 | struct compound_hdr hdr; |
6387 | int status; | |
6388 | ||
bf269551 | 6389 | status = decode_compound_hdr(xdr, &hdr); |
2050f0cc | 6390 | if (!status) |
bf269551 | 6391 | status = decode_sequence(xdr, &res->lr_seq_res, rqstp); |
2050f0cc | 6392 | if (!status) |
bf269551 | 6393 | status = decode_putrootfh(xdr); |
2050f0cc | 6394 | if (!status) |
bf269551 | 6395 | status = decode_fsinfo(xdr, res->lr_fsinfo); |
2050f0cc AA |
6396 | return status; |
6397 | } | |
18019753 RL |
6398 | |
6399 | /* | |
6400 | * Decode RECLAIM_COMPLETE response | |
6401 | */ | |
bf269551 CL |
6402 | static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, |
6403 | struct xdr_stream *xdr, | |
18019753 RL |
6404 | struct nfs41_reclaim_complete_res *res) |
6405 | { | |
18019753 RL |
6406 | struct compound_hdr hdr; |
6407 | int status; | |
6408 | ||
bf269551 | 6409 | status = decode_compound_hdr(xdr, &hdr); |
18019753 | 6410 | if (!status) |
bf269551 | 6411 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
18019753 | 6412 | if (!status) |
bf269551 | 6413 | status = decode_reclaim_complete(xdr, (void *)NULL); |
18019753 RL |
6414 | return status; |
6415 | } | |
b1f69b75 AA |
6416 | |
6417 | /* | |
6418 | * Decode GETDEVINFO response | |
6419 | */ | |
bf269551 CL |
6420 | static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, |
6421 | struct xdr_stream *xdr, | |
b1f69b75 AA |
6422 | struct nfs4_getdeviceinfo_res *res) |
6423 | { | |
b1f69b75 AA |
6424 | struct compound_hdr hdr; |
6425 | int status; | |
6426 | ||
bf269551 | 6427 | status = decode_compound_hdr(xdr, &hdr); |
b1f69b75 AA |
6428 | if (status != 0) |
6429 | goto out; | |
bf269551 | 6430 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
b1f69b75 AA |
6431 | if (status != 0) |
6432 | goto out; | |
bf269551 | 6433 | status = decode_getdeviceinfo(xdr, res->pdev); |
b1f69b75 AA |
6434 | out: |
6435 | return status; | |
6436 | } | |
6437 | ||
6438 | /* | |
6439 | * Decode LAYOUTGET response | |
6440 | */ | |
bf269551 CL |
6441 | static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, |
6442 | struct xdr_stream *xdr, | |
b1f69b75 AA |
6443 | struct nfs4_layoutget_res *res) |
6444 | { | |
b1f69b75 AA |
6445 | struct compound_hdr hdr; |
6446 | int status; | |
6447 | ||
bf269551 | 6448 | status = decode_compound_hdr(xdr, &hdr); |
b1f69b75 AA |
6449 | if (status) |
6450 | goto out; | |
bf269551 | 6451 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
b1f69b75 AA |
6452 | if (status) |
6453 | goto out; | |
bf269551 | 6454 | status = decode_putfh(xdr); |
b1f69b75 AA |
6455 | if (status) |
6456 | goto out; | |
bf269551 | 6457 | status = decode_layoutget(xdr, rqstp, res); |
b1f69b75 AA |
6458 | out: |
6459 | return status; | |
6460 | } | |
863a3c6c | 6461 | |
cbe82603 BH |
6462 | /* |
6463 | * Decode LAYOUTRETURN response | |
6464 | */ | |
6465 | static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, | |
6466 | struct xdr_stream *xdr, | |
6467 | struct nfs4_layoutreturn_res *res) | |
6468 | { | |
6469 | struct compound_hdr hdr; | |
6470 | int status; | |
6471 | ||
6472 | status = decode_compound_hdr(xdr, &hdr); | |
6473 | if (status) | |
6474 | goto out; | |
6475 | status = decode_sequence(xdr, &res->seq_res, rqstp); | |
6476 | if (status) | |
6477 | goto out; | |
6478 | status = decode_putfh(xdr); | |
6479 | if (status) | |
6480 | goto out; | |
6481 | status = decode_layoutreturn(xdr, res); | |
6482 | out: | |
6483 | return status; | |
6484 | } | |
6485 | ||
863a3c6c AA |
6486 | /* |
6487 | * Decode LAYOUTCOMMIT response | |
6488 | */ | |
6489 | static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, | |
6490 | struct xdr_stream *xdr, | |
6491 | struct nfs4_layoutcommit_res *res) | |
6492 | { | |
6493 | struct compound_hdr hdr; | |
6494 | int status; | |
6495 | ||
6496 | status = decode_compound_hdr(xdr, &hdr); | |
6497 | if (status) | |
6498 | goto out; | |
6499 | status = decode_sequence(xdr, &res->seq_res, rqstp); | |
6500 | if (status) | |
6501 | goto out; | |
6502 | status = decode_putfh(xdr); | |
6503 | if (status) | |
6504 | goto out; | |
6505 | status = decode_layoutcommit(xdr, rqstp, res); | |
6506 | if (status) | |
6507 | goto out; | |
6508 | decode_getfattr(xdr, res->fattr, res->server, | |
6509 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
6510 | out: | |
6511 | return status; | |
6512 | } | |
fca78d6d BS |
6513 | |
6514 | /* | |
6515 | * Decode SECINFO_NO_NAME response | |
6516 | */ | |
6517 | static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, | |
6518 | struct xdr_stream *xdr, | |
6519 | struct nfs4_secinfo_res *res) | |
6520 | { | |
6521 | struct compound_hdr hdr; | |
6522 | int status; | |
6523 | ||
6524 | status = decode_compound_hdr(xdr, &hdr); | |
6525 | if (status) | |
6526 | goto out; | |
6527 | status = decode_sequence(xdr, &res->seq_res, rqstp); | |
6528 | if (status) | |
6529 | goto out; | |
6530 | status = decode_putrootfh(xdr); | |
6531 | if (status) | |
6532 | goto out; | |
6533 | status = decode_secinfo(xdr, res); | |
6534 | out: | |
6535 | return status; | |
6536 | } | |
99fe60d0 BH |
6537 | #endif /* CONFIG_NFS_V4_1 */ |
6538 | ||
573c4e1e CL |
6539 | /** |
6540 | * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in | |
6541 | * the local page cache. | |
6542 | * @xdr: XDR stream where entry resides | |
6543 | * @entry: buffer to fill in with entry data | |
6544 | * @plus: boolean indicating whether this should be a readdirplus entry | |
6545 | * | |
6546 | * Returns zero if successful, otherwise a negative errno value is | |
6547 | * returned. | |
6548 | * | |
6549 | * This function is not invoked during READDIR reply decoding, but | |
6550 | * rather whenever an application invokes the getdents(2) system call | |
6551 | * on a directory already in our cache. | |
6552 | */ | |
6553 | int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, | |
6554 | int plus) | |
1da177e4 LT |
6555 | { |
6556 | uint32_t bitmap[2] = {0}; | |
6557 | uint32_t len; | |
babddc72 BS |
6558 | __be32 *p = xdr_inline_decode(xdr, 4); |
6559 | if (unlikely(!p)) | |
6560 | goto out_overflow; | |
c08e76d0 | 6561 | if (*p == xdr_zero) { |
babddc72 BS |
6562 | p = xdr_inline_decode(xdr, 4); |
6563 | if (unlikely(!p)) | |
6564 | goto out_overflow; | |
c08e76d0 | 6565 | if (*p == xdr_zero) |
573c4e1e | 6566 | return -EAGAIN; |
1da177e4 | 6567 | entry->eof = 1; |
573c4e1e | 6568 | return -EBADCOOKIE; |
1da177e4 LT |
6569 | } |
6570 | ||
babddc72 BS |
6571 | p = xdr_inline_decode(xdr, 12); |
6572 | if (unlikely(!p)) | |
6573 | goto out_overflow; | |
1da177e4 LT |
6574 | entry->prev_cookie = entry->cookie; |
6575 | p = xdr_decode_hyper(p, &entry->cookie); | |
c08e76d0 | 6576 | entry->len = be32_to_cpup(p); |
babddc72 | 6577 | |
9af8c222 | 6578 | p = xdr_inline_decode(xdr, entry->len); |
babddc72 BS |
6579 | if (unlikely(!p)) |
6580 | goto out_overflow; | |
1da177e4 | 6581 | entry->name = (const char *) p; |
1da177e4 LT |
6582 | |
6583 | /* | |
6584 | * In case the server doesn't return an inode number, | |
6585 | * we fake one here. (We don't use inode number 0, | |
6586 | * since glibc seems to choke on it...) | |
6587 | */ | |
6588 | entry->ino = 1; | |
4f082222 | 6589 | entry->fattr->valid = 0; |
1da177e4 | 6590 | |
9af8c222 TM |
6591 | if (decode_attr_bitmap(xdr, bitmap) < 0) |
6592 | goto out_overflow; | |
6593 | ||
6594 | if (decode_attr_length(xdr, &len, &p) < 0) | |
6595 | goto out_overflow; | |
6596 | ||
573c4e1e CL |
6597 | if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, |
6598 | entry->server, 1) < 0) | |
9af8c222 | 6599 | goto out_overflow; |
28331a46 TM |
6600 | if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) |
6601 | entry->ino = entry->fattr->mounted_on_fileid; | |
6602 | else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) | |
9af8c222 TM |
6603 | entry->ino = entry->fattr->fileid; |
6604 | ||
0b26a0bf TM |
6605 | entry->d_type = DT_UNKNOWN; |
6606 | if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) | |
6607 | entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); | |
6608 | ||
573c4e1e | 6609 | return 0; |
babddc72 BS |
6610 | |
6611 | out_overflow: | |
6612 | print_overflow_msg(__func__, xdr); | |
573c4e1e | 6613 | return -EAGAIN; |
1da177e4 LT |
6614 | } |
6615 | ||
6616 | /* | |
6617 | * We need to translate between nfs status return values and | |
6618 | * the local errno values which may not be the same. | |
6619 | */ | |
6620 | static struct { | |
6621 | int stat; | |
6622 | int errno; | |
6623 | } nfs_errtbl[] = { | |
6624 | { NFS4_OK, 0 }, | |
856dff3d BH |
6625 | { NFS4ERR_PERM, -EPERM }, |
6626 | { NFS4ERR_NOENT, -ENOENT }, | |
6627 | { NFS4ERR_IO, -errno_NFSERR_IO}, | |
6628 | { NFS4ERR_NXIO, -ENXIO }, | |
6629 | { NFS4ERR_ACCESS, -EACCES }, | |
6630 | { NFS4ERR_EXIST, -EEXIST }, | |
6631 | { NFS4ERR_XDEV, -EXDEV }, | |
6632 | { NFS4ERR_NOTDIR, -ENOTDIR }, | |
6633 | { NFS4ERR_ISDIR, -EISDIR }, | |
6634 | { NFS4ERR_INVAL, -EINVAL }, | |
6635 | { NFS4ERR_FBIG, -EFBIG }, | |
6636 | { NFS4ERR_NOSPC, -ENOSPC }, | |
6637 | { NFS4ERR_ROFS, -EROFS }, | |
6638 | { NFS4ERR_MLINK, -EMLINK }, | |
6639 | { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, | |
6640 | { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, | |
6641 | { NFS4ERR_DQUOT, -EDQUOT }, | |
6642 | { NFS4ERR_STALE, -ESTALE }, | |
6643 | { NFS4ERR_BADHANDLE, -EBADHANDLE }, | |
856dff3d BH |
6644 | { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, |
6645 | { NFS4ERR_NOTSUPP, -ENOTSUPP }, | |
6646 | { NFS4ERR_TOOSMALL, -ETOOSMALL }, | |
fdcb4577 | 6647 | { NFS4ERR_SERVERFAULT, -EREMOTEIO }, |
856dff3d BH |
6648 | { NFS4ERR_BADTYPE, -EBADTYPE }, |
6649 | { NFS4ERR_LOCKED, -EAGAIN }, | |
856dff3d BH |
6650 | { NFS4ERR_SYMLINK, -ELOOP }, |
6651 | { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, | |
6652 | { NFS4ERR_DEADLOCK, -EDEADLK }, | |
856dff3d | 6653 | { -1, -EIO } |
1da177e4 LT |
6654 | }; |
6655 | ||
6656 | /* | |
6657 | * Convert an NFS error code to a local one. | |
6658 | * This one is used jointly by NFSv2 and NFSv3. | |
6659 | */ | |
6660 | static int | |
0a8ea437 | 6661 | nfs4_stat_to_errno(int stat) |
1da177e4 LT |
6662 | { |
6663 | int i; | |
6664 | for (i = 0; nfs_errtbl[i].stat != -1; i++) { | |
6665 | if (nfs_errtbl[i].stat == stat) | |
6666 | return nfs_errtbl[i].errno; | |
6667 | } | |
6668 | if (stat <= 10000 || stat > 10100) { | |
6669 | /* The server is looney tunes. */ | |
fdcb4577 | 6670 | return -EREMOTEIO; |
1da177e4 LT |
6671 | } |
6672 | /* If we cannot translate the error, the recovery routines should | |
6673 | * handle it. | |
6674 | * Note: remaining NFSv4 error codes have values > 10000, so should | |
6675 | * not conflict with native Linux error codes. | |
6676 | */ | |
856dff3d | 6677 | return -stat; |
1da177e4 LT |
6678 | } |
6679 | ||
1da177e4 LT |
6680 | #define PROC(proc, argtype, restype) \ |
6681 | [NFSPROC4_CLNT_##proc] = { \ | |
6682 | .p_proc = NFSPROC4_COMPOUND, \ | |
9f06c719 | 6683 | .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ |
bf269551 | 6684 | .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ |
2bea90d4 CL |
6685 | .p_arglen = NFS4_##argtype##_sz, \ |
6686 | .p_replen = NFS4_##restype##_sz, \ | |
cc0175c1 CL |
6687 | .p_statidx = NFSPROC4_CLNT_##proc, \ |
6688 | .p_name = #proc, \ | |
05d564fe | 6689 | } |
1da177e4 LT |
6690 | |
6691 | struct rpc_procinfo nfs4_procedures[] = { | |
7d93bd71 CL |
6692 | PROC(READ, enc_read, dec_read), |
6693 | PROC(WRITE, enc_write, dec_write), | |
6694 | PROC(COMMIT, enc_commit, dec_commit), | |
6695 | PROC(OPEN, enc_open, dec_open), | |
6696 | PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), | |
6697 | PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), | |
6698 | PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), | |
6699 | PROC(CLOSE, enc_close, dec_close), | |
6700 | PROC(SETATTR, enc_setattr, dec_setattr), | |
6701 | PROC(FSINFO, enc_fsinfo, dec_fsinfo), | |
6702 | PROC(RENEW, enc_renew, dec_renew), | |
6703 | PROC(SETCLIENTID, enc_setclientid, dec_setclientid), | |
6704 | PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), | |
6705 | PROC(LOCK, enc_lock, dec_lock), | |
6706 | PROC(LOCKT, enc_lockt, dec_lockt), | |
6707 | PROC(LOCKU, enc_locku, dec_locku), | |
6708 | PROC(ACCESS, enc_access, dec_access), | |
6709 | PROC(GETATTR, enc_getattr, dec_getattr), | |
6710 | PROC(LOOKUP, enc_lookup, dec_lookup), | |
6711 | PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), | |
6712 | PROC(REMOVE, enc_remove, dec_remove), | |
6713 | PROC(RENAME, enc_rename, dec_rename), | |
6714 | PROC(LINK, enc_link, dec_link), | |
6715 | PROC(SYMLINK, enc_symlink, dec_symlink), | |
6716 | PROC(CREATE, enc_create, dec_create), | |
6717 | PROC(PATHCONF, enc_pathconf, dec_pathconf), | |
6718 | PROC(STATFS, enc_statfs, dec_statfs), | |
6719 | PROC(READLINK, enc_readlink, dec_readlink), | |
6720 | PROC(READDIR, enc_readdir, dec_readdir), | |
6721 | PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), | |
6722 | PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), | |
6723 | PROC(GETACL, enc_getacl, dec_getacl), | |
6724 | PROC(SETACL, enc_setacl, dec_setacl), | |
6725 | PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), | |
6726 | PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), | |
5a5ea0d4 | 6727 | PROC(SECINFO, enc_secinfo, dec_secinfo), |
99fe60d0 | 6728 | #if defined(CONFIG_NFS_V4_1) |
7d93bd71 CL |
6729 | PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), |
6730 | PROC(CREATE_SESSION, enc_create_session, dec_create_session), | |
6731 | PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), | |
6732 | PROC(SEQUENCE, enc_sequence, dec_sequence), | |
6733 | PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), | |
6734 | PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), | |
6735 | PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), | |
6736 | PROC(LAYOUTGET, enc_layoutget, dec_layoutget), | |
863a3c6c | 6737 | PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), |
cbe82603 | 6738 | PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), |
fca78d6d | 6739 | PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), |
99fe60d0 | 6740 | #endif /* CONFIG_NFS_V4_1 */ |
1da177e4 LT |
6741 | }; |
6742 | ||
6743 | struct rpc_version nfs_version4 = { | |
6744 | .number = 4, | |
e8c96f8c | 6745 | .nrprocs = ARRAY_SIZE(nfs4_procedures), |
1da177e4 LT |
6746 | .procs = nfs4_procedures |
6747 | }; | |
6748 | ||
6749 | /* | |
6750 | * Local variables: | |
6751 | * c-basic-offset: 8 | |
6752 | * End: | |
6753 | */ |