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