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