NFSv4: Fix an embarassing typo in encode_attrs()
[sfrench/cifs-2.6.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/nfs.h>
50 #include <linux/nfs4.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/nfs_idmap.h>
53 #include "nfs4_fs.h"
54 #include "internal.h"
55
56 #define NFSDBG_FACILITY         NFSDBG_XDR
57
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO         EIO
60
61 static int nfs4_stat_to_errno(int);
62
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64 #ifdef DEBUG
65 #define NFS4_MAXTAGLEN          20
66 #else
67 #define NFS4_MAXTAGLEN          0
68 #endif
69
70 /* lock,open owner id:
71  * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
72  */
73 #define open_owner_id_maxsz     (1 + 4)
74 #define lock_owner_id_maxsz     (1 + 4)
75 #define decode_lockowner_maxsz  (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76 #define compound_encode_hdr_maxsz       (3 + (NFS4_MAXTAGLEN >> 2))
77 #define compound_decode_hdr_maxsz       (3 + (NFS4_MAXTAGLEN >> 2))
78 #define op_encode_hdr_maxsz     (1)
79 #define op_decode_hdr_maxsz     (2)
80 #define encode_stateid_maxsz    (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define decode_stateid_maxsz    (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define encode_verifier_maxsz   (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define decode_verifier_maxsz   (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define encode_putfh_maxsz      (op_encode_hdr_maxsz + 1 + \
85                                 (NFS4_FHSIZE >> 2))
86 #define decode_putfh_maxsz      (op_decode_hdr_maxsz)
87 #define encode_putrootfh_maxsz  (op_encode_hdr_maxsz)
88 #define decode_putrootfh_maxsz  (op_decode_hdr_maxsz)
89 #define encode_getfh_maxsz      (op_encode_hdr_maxsz)
90 #define decode_getfh_maxsz      (op_decode_hdr_maxsz + 1 + \
91                                 ((3+NFS4_FHSIZE) >> 2))
92 #define nfs4_fattr_bitmap_maxsz 3
93 #define encode_getattr_maxsz    (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
94 #define nfs4_name_maxsz         (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95 #define nfs4_path_maxsz         (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96 #define nfs4_owner_maxsz        (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 #define nfs4_group_maxsz        (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 /* This is based on getfattr, which uses the most attributes: */
99 #define nfs4_fattr_value_maxsz  (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
100                                 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
101 #define nfs4_fattr_maxsz        (nfs4_fattr_bitmap_maxsz + \
102                                 nfs4_fattr_value_maxsz)
103 #define decode_getattr_maxsz    (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
104 #define encode_attrs_maxsz      (nfs4_fattr_bitmap_maxsz + \
105                                  1 + 2 + 1 + \
106                                 nfs4_owner_maxsz + \
107                                 nfs4_group_maxsz + \
108                                 4 + 4)
109 #define encode_savefh_maxsz     (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz     (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz  (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz     (encode_getattr_maxsz)
114 #define decode_fsinfo_maxsz     (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz      (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz      (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118                                 (op_encode_hdr_maxsz + \
119                                 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120                                 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
121                                 1 /* sc_prog */ + \
122                                 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123                                 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
124                                 1) /* sc_cb_ident */
125 #define decode_setclientid_maxsz \
126                                 (op_decode_hdr_maxsz + \
127                                 2 + \
128                                 1024) /* large value for CLID_INUSE */
129 #define encode_setclientid_confirm_maxsz \
130                                 (op_encode_hdr_maxsz + \
131                                 3 + (NFS4_VERIFIER_SIZE >> 2))
132 #define decode_setclientid_confirm_maxsz \
133                                 (op_decode_hdr_maxsz)
134 #define encode_lookup_maxsz     (op_encode_hdr_maxsz + nfs4_name_maxsz)
135 #define decode_lookup_maxsz     (op_decode_hdr_maxsz)
136 #define encode_share_access_maxsz \
137                                 (2)
138 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
139 #define encode_opentype_maxsz   (1 + encode_createmode_maxsz)
140 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141 #define encode_open_maxsz       (op_encode_hdr_maxsz + \
142                                 2 + encode_share_access_maxsz + 2 + \
143                                 open_owner_id_maxsz + \
144                                 encode_opentype_maxsz + \
145                                 encode_claim_null_maxsz)
146 #define decode_ace_maxsz        (3 + nfs4_owner_maxsz)
147 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
148                                 decode_ace_maxsz)
149 #define decode_change_info_maxsz        (5)
150 #define decode_open_maxsz       (op_decode_hdr_maxsz + \
151                                 decode_stateid_maxsz + \
152                                 decode_change_info_maxsz + 1 + \
153                                 nfs4_fattr_bitmap_maxsz + \
154                                 decode_delegation_maxsz)
155 #define encode_open_confirm_maxsz \
156                                 (op_encode_hdr_maxsz + \
157                                  encode_stateid_maxsz + 1)
158 #define decode_open_confirm_maxsz \
159                                 (op_decode_hdr_maxsz + \
160                                  decode_stateid_maxsz)
161 #define encode_open_downgrade_maxsz \
162                                 (op_encode_hdr_maxsz + \
163                                  encode_stateid_maxsz + 1 + \
164                                  encode_share_access_maxsz)
165 #define decode_open_downgrade_maxsz \
166                                 (op_decode_hdr_maxsz + \
167                                  decode_stateid_maxsz)
168 #define encode_close_maxsz      (op_encode_hdr_maxsz + \
169                                  1 + encode_stateid_maxsz)
170 #define decode_close_maxsz      (op_decode_hdr_maxsz + \
171                                  decode_stateid_maxsz)
172 #define encode_setattr_maxsz    (op_encode_hdr_maxsz + \
173                                  encode_stateid_maxsz + \
174                                  encode_attrs_maxsz)
175 #define decode_setattr_maxsz    (op_decode_hdr_maxsz + \
176                                  nfs4_fattr_bitmap_maxsz)
177 #define encode_read_maxsz       (op_encode_hdr_maxsz + \
178                                  encode_stateid_maxsz + 3)
179 #define decode_read_maxsz       (op_decode_hdr_maxsz + 2)
180 #define encode_readdir_maxsz    (op_encode_hdr_maxsz + \
181                                  2 + encode_verifier_maxsz + 5)
182 #define decode_readdir_maxsz    (op_decode_hdr_maxsz + \
183                                  decode_verifier_maxsz)
184 #define encode_readlink_maxsz   (op_encode_hdr_maxsz)
185 #define decode_readlink_maxsz   (op_decode_hdr_maxsz + 1)
186 #define encode_write_maxsz      (op_encode_hdr_maxsz + \
187                                  encode_stateid_maxsz + 4)
188 #define decode_write_maxsz      (op_decode_hdr_maxsz + \
189                                  2 + decode_verifier_maxsz)
190 #define encode_commit_maxsz     (op_encode_hdr_maxsz + 3)
191 #define decode_commit_maxsz     (op_decode_hdr_maxsz + \
192                                  decode_verifier_maxsz)
193 #define encode_remove_maxsz     (op_encode_hdr_maxsz + \
194                                 nfs4_name_maxsz)
195 #define decode_remove_maxsz     (op_decode_hdr_maxsz + \
196                                  decode_change_info_maxsz)
197 #define encode_rename_maxsz     (op_encode_hdr_maxsz + \
198                                 2 * nfs4_name_maxsz)
199 #define decode_rename_maxsz     (op_decode_hdr_maxsz + \
200                                  decode_change_info_maxsz + \
201                                  decode_change_info_maxsz)
202 #define encode_link_maxsz       (op_encode_hdr_maxsz + \
203                                 nfs4_name_maxsz)
204 #define decode_link_maxsz       (op_decode_hdr_maxsz + decode_change_info_maxsz)
205 #define encode_lock_maxsz       (op_encode_hdr_maxsz + \
206                                  7 + \
207                                  1 + encode_stateid_maxsz + 8)
208 #define decode_lock_denied_maxsz \
209                                 (8 + decode_lockowner_maxsz)
210 #define decode_lock_maxsz       (op_decode_hdr_maxsz + \
211                                  decode_lock_denied_maxsz)
212 #define encode_lockt_maxsz      (op_encode_hdr_maxsz + 12)
213 #define decode_lockt_maxsz      (op_decode_hdr_maxsz + \
214                                  decode_lock_denied_maxsz)
215 #define encode_locku_maxsz      (op_encode_hdr_maxsz + 3 + \
216                                  encode_stateid_maxsz + \
217                                  4)
218 #define decode_locku_maxsz      (op_decode_hdr_maxsz + \
219                                  decode_stateid_maxsz)
220 #define encode_access_maxsz     (op_encode_hdr_maxsz + 1)
221 #define decode_access_maxsz     (op_decode_hdr_maxsz + 2)
222 #define encode_symlink_maxsz    (op_encode_hdr_maxsz + \
223                                 1 + nfs4_name_maxsz + \
224                                 1 + \
225                                 nfs4_fattr_maxsz)
226 #define decode_symlink_maxsz    (op_decode_hdr_maxsz + 8)
227 #define encode_create_maxsz     (op_encode_hdr_maxsz + \
228                                 1 + 2 + nfs4_name_maxsz + \
229                                 encode_attrs_maxsz)
230 #define decode_create_maxsz     (op_decode_hdr_maxsz + \
231                                 decode_change_info_maxsz + \
232                                 nfs4_fattr_bitmap_maxsz)
233 #define encode_statfs_maxsz     (encode_getattr_maxsz)
234 #define decode_statfs_maxsz     (decode_getattr_maxsz)
235 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
237 #define encode_getacl_maxsz     (encode_getattr_maxsz)
238 #define decode_getacl_maxsz     (op_decode_hdr_maxsz + \
239                                  nfs4_fattr_bitmap_maxsz + 1)
240 #define encode_setacl_maxsz     (op_encode_hdr_maxsz + \
241                                  encode_stateid_maxsz + 3)
242 #define decode_setacl_maxsz     (decode_setattr_maxsz)
243 #define encode_fs_locations_maxsz \
244                                 (encode_getattr_maxsz)
245 #define decode_fs_locations_maxsz \
246                                 (0)
247
248 #if defined(CONFIG_NFS_V4_1)
249 #define NFS4_MAX_MACHINE_NAME_LEN (64)
250
251 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
252                                 encode_verifier_maxsz + \
253                                 1 /* co_ownerid.len */ + \
254                                 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
255                                 1 /* flags */ + \
256                                 1 /* spa_how */ + \
257                                 0 /* SP4_NONE (for now) */ + \
258                                 1 /* zero implemetation id array */)
259 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
260                                 2 /* eir_clientid */ + \
261                                 1 /* eir_sequenceid */ + \
262                                 1 /* eir_flags */ + \
263                                 1 /* spr_how */ + \
264                                 0 /* SP4_NONE (for now) */ + \
265                                 2 /* eir_server_owner.so_minor_id */ + \
266                                 /* eir_server_owner.so_major_id<> */ \
267                                 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
268                                 /* eir_server_scope<> */ \
269                                 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
270                                 1 /* eir_server_impl_id array length */ + \
271                                 0 /* ignored eir_server_impl_id contents */)
272 #define encode_channel_attrs_maxsz  (6 + 1 /* ca_rdma_ird.len (0) */)
273 #define decode_channel_attrs_maxsz  (6 + \
274                                      1 /* ca_rdma_ird.len */ + \
275                                      1 /* ca_rdma_ird */)
276 #define encode_create_session_maxsz  (op_encode_hdr_maxsz + \
277                                      2 /* csa_clientid */ + \
278                                      1 /* csa_sequence */ + \
279                                      1 /* csa_flags */ + \
280                                      encode_channel_attrs_maxsz + \
281                                      encode_channel_attrs_maxsz + \
282                                      1 /* csa_cb_program */ + \
283                                      1 /* csa_sec_parms.len (1) */ + \
284                                      1 /* cb_secflavor (AUTH_SYS) */ + \
285                                      1 /* stamp */ + \
286                                      1 /* machinename.len */ + \
287                                      XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
288                                      1 /* uid */ + \
289                                      1 /* gid */ + \
290                                      1 /* gids.len (0) */)
291 #define decode_create_session_maxsz  (op_decode_hdr_maxsz +     \
292                                      XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
293                                      1 /* csr_sequence */ + \
294                                      1 /* csr_flags */ + \
295                                      decode_channel_attrs_maxsz + \
296                                      decode_channel_attrs_maxsz)
297 #define encode_destroy_session_maxsz    (op_encode_hdr_maxsz + 4)
298 #define decode_destroy_session_maxsz    (op_decode_hdr_maxsz)
299 #define encode_sequence_maxsz   (op_encode_hdr_maxsz + \
300                                 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
301 #define decode_sequence_maxsz   (op_decode_hdr_maxsz + \
302                                 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
303 #define encode_reclaim_complete_maxsz   (op_encode_hdr_maxsz + 4)
304 #define decode_reclaim_complete_maxsz   (op_decode_hdr_maxsz + 4)
305 #else /* CONFIG_NFS_V4_1 */
306 #define encode_sequence_maxsz   0
307 #define decode_sequence_maxsz   0
308 #endif /* CONFIG_NFS_V4_1 */
309
310 #define NFS4_enc_compound_sz    (1024)  /* XXX: large enough? */
311 #define NFS4_dec_compound_sz    (1024)  /* XXX: large enough? */
312 #define NFS4_enc_read_sz        (compound_encode_hdr_maxsz + \
313                                 encode_sequence_maxsz + \
314                                 encode_putfh_maxsz + \
315                                 encode_read_maxsz)
316 #define NFS4_dec_read_sz        (compound_decode_hdr_maxsz + \
317                                 decode_sequence_maxsz + \
318                                 decode_putfh_maxsz + \
319                                 decode_read_maxsz)
320 #define NFS4_enc_readlink_sz    (compound_encode_hdr_maxsz + \
321                                 encode_sequence_maxsz + \
322                                 encode_putfh_maxsz + \
323                                 encode_readlink_maxsz)
324 #define NFS4_dec_readlink_sz    (compound_decode_hdr_maxsz + \
325                                 decode_sequence_maxsz + \
326                                 decode_putfh_maxsz + \
327                                 decode_readlink_maxsz)
328 #define NFS4_enc_readdir_sz     (compound_encode_hdr_maxsz + \
329                                 encode_sequence_maxsz + \
330                                 encode_putfh_maxsz + \
331                                 encode_readdir_maxsz)
332 #define NFS4_dec_readdir_sz     (compound_decode_hdr_maxsz + \
333                                 decode_sequence_maxsz + \
334                                 decode_putfh_maxsz + \
335                                 decode_readdir_maxsz)
336 #define NFS4_enc_write_sz       (compound_encode_hdr_maxsz + \
337                                 encode_sequence_maxsz + \
338                                 encode_putfh_maxsz + \
339                                 encode_write_maxsz + \
340                                 encode_getattr_maxsz)
341 #define NFS4_dec_write_sz       (compound_decode_hdr_maxsz + \
342                                 decode_sequence_maxsz + \
343                                 decode_putfh_maxsz + \
344                                 decode_write_maxsz + \
345                                 decode_getattr_maxsz)
346 #define NFS4_enc_commit_sz      (compound_encode_hdr_maxsz + \
347                                 encode_sequence_maxsz + \
348                                 encode_putfh_maxsz + \
349                                 encode_commit_maxsz + \
350                                 encode_getattr_maxsz)
351 #define NFS4_dec_commit_sz      (compound_decode_hdr_maxsz + \
352                                 decode_sequence_maxsz + \
353                                 decode_putfh_maxsz + \
354                                 decode_commit_maxsz + \
355                                 decode_getattr_maxsz)
356 #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
357                                 encode_sequence_maxsz + \
358                                 encode_putfh_maxsz + \
359                                 encode_savefh_maxsz + \
360                                 encode_open_maxsz + \
361                                 encode_getfh_maxsz + \
362                                 encode_getattr_maxsz + \
363                                 encode_restorefh_maxsz + \
364                                 encode_getattr_maxsz)
365 #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
366                                 decode_sequence_maxsz + \
367                                 decode_putfh_maxsz + \
368                                 decode_savefh_maxsz + \
369                                 decode_open_maxsz + \
370                                 decode_getfh_maxsz + \
371                                 decode_getattr_maxsz + \
372                                 decode_restorefh_maxsz + \
373                                 decode_getattr_maxsz)
374 #define NFS4_enc_open_confirm_sz \
375                                 (compound_encode_hdr_maxsz + \
376                                  encode_putfh_maxsz + \
377                                  encode_open_confirm_maxsz)
378 #define NFS4_dec_open_confirm_sz \
379                                 (compound_decode_hdr_maxsz + \
380                                  decode_putfh_maxsz + \
381                                  decode_open_confirm_maxsz)
382 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
383                                         encode_sequence_maxsz + \
384                                         encode_putfh_maxsz + \
385                                         encode_open_maxsz + \
386                                         encode_getattr_maxsz)
387 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
388                                         decode_sequence_maxsz + \
389                                         decode_putfh_maxsz + \
390                                         decode_open_maxsz + \
391                                         decode_getattr_maxsz)
392 #define NFS4_enc_open_downgrade_sz \
393                                 (compound_encode_hdr_maxsz + \
394                                  encode_sequence_maxsz + \
395                                  encode_putfh_maxsz + \
396                                  encode_open_downgrade_maxsz + \
397                                  encode_getattr_maxsz)
398 #define NFS4_dec_open_downgrade_sz \
399                                 (compound_decode_hdr_maxsz + \
400                                  decode_sequence_maxsz + \
401                                  decode_putfh_maxsz + \
402                                  decode_open_downgrade_maxsz + \
403                                  decode_getattr_maxsz)
404 #define NFS4_enc_close_sz       (compound_encode_hdr_maxsz + \
405                                  encode_sequence_maxsz + \
406                                  encode_putfh_maxsz + \
407                                  encode_close_maxsz + \
408                                  encode_getattr_maxsz)
409 #define NFS4_dec_close_sz       (compound_decode_hdr_maxsz + \
410                                  decode_sequence_maxsz + \
411                                  decode_putfh_maxsz + \
412                                  decode_close_maxsz + \
413                                  decode_getattr_maxsz)
414 #define NFS4_enc_setattr_sz     (compound_encode_hdr_maxsz + \
415                                  encode_sequence_maxsz + \
416                                  encode_putfh_maxsz + \
417                                  encode_setattr_maxsz + \
418                                  encode_getattr_maxsz)
419 #define NFS4_dec_setattr_sz     (compound_decode_hdr_maxsz + \
420                                  decode_sequence_maxsz + \
421                                  decode_putfh_maxsz + \
422                                  decode_setattr_maxsz + \
423                                  decode_getattr_maxsz)
424 #define NFS4_enc_fsinfo_sz      (compound_encode_hdr_maxsz + \
425                                 encode_sequence_maxsz + \
426                                 encode_putfh_maxsz + \
427                                 encode_fsinfo_maxsz)
428 #define NFS4_dec_fsinfo_sz      (compound_decode_hdr_maxsz + \
429                                 decode_sequence_maxsz + \
430                                 decode_putfh_maxsz + \
431                                 decode_fsinfo_maxsz)
432 #define NFS4_enc_renew_sz       (compound_encode_hdr_maxsz + \
433                                 encode_renew_maxsz)
434 #define NFS4_dec_renew_sz       (compound_decode_hdr_maxsz + \
435                                 decode_renew_maxsz)
436 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
437                                 encode_setclientid_maxsz)
438 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
439                                 decode_setclientid_maxsz)
440 #define NFS4_enc_setclientid_confirm_sz \
441                                 (compound_encode_hdr_maxsz + \
442                                 encode_setclientid_confirm_maxsz + \
443                                 encode_putrootfh_maxsz + \
444                                 encode_fsinfo_maxsz)
445 #define NFS4_dec_setclientid_confirm_sz \
446                                 (compound_decode_hdr_maxsz + \
447                                 decode_setclientid_confirm_maxsz + \
448                                 decode_putrootfh_maxsz + \
449                                 decode_fsinfo_maxsz)
450 #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
451                                 encode_sequence_maxsz + \
452                                 encode_putfh_maxsz + \
453                                 encode_lock_maxsz)
454 #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
455                                 decode_sequence_maxsz + \
456                                 decode_putfh_maxsz + \
457                                 decode_lock_maxsz)
458 #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
459                                 encode_sequence_maxsz + \
460                                 encode_putfh_maxsz + \
461                                 encode_lockt_maxsz)
462 #define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
463                                  decode_sequence_maxsz + \
464                                  decode_putfh_maxsz + \
465                                  decode_lockt_maxsz)
466 #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
467                                 encode_sequence_maxsz + \
468                                 encode_putfh_maxsz + \
469                                 encode_locku_maxsz)
470 #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
471                                 decode_sequence_maxsz + \
472                                 decode_putfh_maxsz + \
473                                 decode_locku_maxsz)
474 #define NFS4_enc_access_sz      (compound_encode_hdr_maxsz + \
475                                 encode_sequence_maxsz + \
476                                 encode_putfh_maxsz + \
477                                 encode_access_maxsz + \
478                                 encode_getattr_maxsz)
479 #define NFS4_dec_access_sz      (compound_decode_hdr_maxsz + \
480                                 decode_sequence_maxsz + \
481                                 decode_putfh_maxsz + \
482                                 decode_access_maxsz + \
483                                 decode_getattr_maxsz)
484 #define NFS4_enc_getattr_sz     (compound_encode_hdr_maxsz + \
485                                 encode_sequence_maxsz + \
486                                 encode_putfh_maxsz + \
487                                 encode_getattr_maxsz)
488 #define NFS4_dec_getattr_sz     (compound_decode_hdr_maxsz + \
489                                 decode_sequence_maxsz + \
490                                 decode_putfh_maxsz + \
491                                 decode_getattr_maxsz)
492 #define NFS4_enc_lookup_sz      (compound_encode_hdr_maxsz + \
493                                 encode_sequence_maxsz + \
494                                 encode_putfh_maxsz + \
495                                 encode_lookup_maxsz + \
496                                 encode_getattr_maxsz + \
497                                 encode_getfh_maxsz)
498 #define NFS4_dec_lookup_sz      (compound_decode_hdr_maxsz + \
499                                 decode_sequence_maxsz + \
500                                 decode_putfh_maxsz + \
501                                 decode_lookup_maxsz + \
502                                 decode_getattr_maxsz + \
503                                 decode_getfh_maxsz)
504 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
505                                 encode_sequence_maxsz + \
506                                 encode_putrootfh_maxsz + \
507                                 encode_getattr_maxsz + \
508                                 encode_getfh_maxsz)
509 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
510                                 decode_sequence_maxsz + \
511                                 decode_putrootfh_maxsz + \
512                                 decode_getattr_maxsz + \
513                                 decode_getfh_maxsz)
514 #define NFS4_enc_remove_sz      (compound_encode_hdr_maxsz + \
515                                 encode_sequence_maxsz + \
516                                 encode_putfh_maxsz + \
517                                 encode_remove_maxsz + \
518                                 encode_getattr_maxsz)
519 #define NFS4_dec_remove_sz      (compound_decode_hdr_maxsz + \
520                                 decode_sequence_maxsz + \
521                                 decode_putfh_maxsz + \
522                                 decode_remove_maxsz + \
523                                 decode_getattr_maxsz)
524 #define NFS4_enc_rename_sz      (compound_encode_hdr_maxsz + \
525                                 encode_sequence_maxsz + \
526                                 encode_putfh_maxsz + \
527                                 encode_savefh_maxsz + \
528                                 encode_putfh_maxsz + \
529                                 encode_rename_maxsz + \
530                                 encode_getattr_maxsz + \
531                                 encode_restorefh_maxsz + \
532                                 encode_getattr_maxsz)
533 #define NFS4_dec_rename_sz      (compound_decode_hdr_maxsz + \
534                                 decode_sequence_maxsz + \
535                                 decode_putfh_maxsz + \
536                                 decode_savefh_maxsz + \
537                                 decode_putfh_maxsz + \
538                                 decode_rename_maxsz + \
539                                 decode_getattr_maxsz + \
540                                 decode_restorefh_maxsz + \
541                                 decode_getattr_maxsz)
542 #define NFS4_enc_link_sz        (compound_encode_hdr_maxsz + \
543                                 encode_sequence_maxsz + \
544                                 encode_putfh_maxsz + \
545                                 encode_savefh_maxsz + \
546                                 encode_putfh_maxsz + \
547                                 encode_link_maxsz + \
548                                 decode_getattr_maxsz + \
549                                 encode_restorefh_maxsz + \
550                                 decode_getattr_maxsz)
551 #define NFS4_dec_link_sz        (compound_decode_hdr_maxsz + \
552                                 decode_sequence_maxsz + \
553                                 decode_putfh_maxsz + \
554                                 decode_savefh_maxsz + \
555                                 decode_putfh_maxsz + \
556                                 decode_link_maxsz + \
557                                 decode_getattr_maxsz + \
558                                 decode_restorefh_maxsz + \
559                                 decode_getattr_maxsz)
560 #define NFS4_enc_symlink_sz     (compound_encode_hdr_maxsz + \
561                                 encode_sequence_maxsz + \
562                                 encode_putfh_maxsz + \
563                                 encode_symlink_maxsz + \
564                                 encode_getattr_maxsz + \
565                                 encode_getfh_maxsz)
566 #define NFS4_dec_symlink_sz     (compound_decode_hdr_maxsz + \
567                                 decode_sequence_maxsz + \
568                                 decode_putfh_maxsz + \
569                                 decode_symlink_maxsz + \
570                                 decode_getattr_maxsz + \
571                                 decode_getfh_maxsz)
572 #define NFS4_enc_create_sz      (compound_encode_hdr_maxsz + \
573                                 encode_sequence_maxsz + \
574                                 encode_putfh_maxsz + \
575                                 encode_savefh_maxsz + \
576                                 encode_create_maxsz + \
577                                 encode_getfh_maxsz + \
578                                 encode_getattr_maxsz + \
579                                 encode_restorefh_maxsz + \
580                                 encode_getattr_maxsz)
581 #define NFS4_dec_create_sz      (compound_decode_hdr_maxsz + \
582                                 decode_sequence_maxsz + \
583                                 decode_putfh_maxsz + \
584                                 decode_savefh_maxsz + \
585                                 decode_create_maxsz + \
586                                 decode_getfh_maxsz + \
587                                 decode_getattr_maxsz + \
588                                 decode_restorefh_maxsz + \
589                                 decode_getattr_maxsz)
590 #define NFS4_enc_pathconf_sz    (compound_encode_hdr_maxsz + \
591                                 encode_sequence_maxsz + \
592                                 encode_putfh_maxsz + \
593                                 encode_getattr_maxsz)
594 #define NFS4_dec_pathconf_sz    (compound_decode_hdr_maxsz + \
595                                 decode_sequence_maxsz + \
596                                 decode_putfh_maxsz + \
597                                 decode_getattr_maxsz)
598 #define NFS4_enc_statfs_sz      (compound_encode_hdr_maxsz + \
599                                 encode_sequence_maxsz + \
600                                 encode_putfh_maxsz + \
601                                 encode_statfs_maxsz)
602 #define NFS4_dec_statfs_sz      (compound_decode_hdr_maxsz + \
603                                 decode_sequence_maxsz + \
604                                 decode_putfh_maxsz + \
605                                 decode_statfs_maxsz)
606 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
607                                 encode_sequence_maxsz + \
608                                 encode_putfh_maxsz + \
609                                 encode_getattr_maxsz)
610 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
611                                 decode_sequence_maxsz + \
612                                 decode_putfh_maxsz + \
613                                 decode_getattr_maxsz)
614 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
615                                 encode_sequence_maxsz + \
616                                 encode_putfh_maxsz + \
617                                 encode_delegreturn_maxsz + \
618                                 encode_getattr_maxsz)
619 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
620                                 decode_sequence_maxsz + \
621                                 decode_delegreturn_maxsz + \
622                                 decode_getattr_maxsz)
623 #define NFS4_enc_getacl_sz      (compound_encode_hdr_maxsz + \
624                                 encode_sequence_maxsz + \
625                                 encode_putfh_maxsz + \
626                                 encode_getacl_maxsz)
627 #define NFS4_dec_getacl_sz      (compound_decode_hdr_maxsz + \
628                                 decode_sequence_maxsz + \
629                                 decode_putfh_maxsz + \
630                                 decode_getacl_maxsz)
631 #define NFS4_enc_setacl_sz      (compound_encode_hdr_maxsz + \
632                                 encode_sequence_maxsz + \
633                                 encode_putfh_maxsz + \
634                                 encode_setacl_maxsz)
635 #define NFS4_dec_setacl_sz      (compound_decode_hdr_maxsz + \
636                                 decode_sequence_maxsz + \
637                                 decode_putfh_maxsz + \
638                                 decode_setacl_maxsz)
639 #define NFS4_enc_fs_locations_sz \
640                                 (compound_encode_hdr_maxsz + \
641                                  encode_sequence_maxsz + \
642                                  encode_putfh_maxsz + \
643                                  encode_lookup_maxsz + \
644                                  encode_fs_locations_maxsz)
645 #define NFS4_dec_fs_locations_sz \
646                                 (compound_decode_hdr_maxsz + \
647                                  decode_sequence_maxsz + \
648                                  decode_putfh_maxsz + \
649                                  decode_lookup_maxsz + \
650                                  decode_fs_locations_maxsz)
651 #if defined(CONFIG_NFS_V4_1)
652 #define NFS4_enc_exchange_id_sz \
653                                 (compound_encode_hdr_maxsz + \
654                                  encode_exchange_id_maxsz)
655 #define NFS4_dec_exchange_id_sz \
656                                 (compound_decode_hdr_maxsz + \
657                                  decode_exchange_id_maxsz)
658 #define NFS4_enc_create_session_sz \
659                                 (compound_encode_hdr_maxsz + \
660                                  encode_create_session_maxsz)
661 #define NFS4_dec_create_session_sz \
662                                 (compound_decode_hdr_maxsz + \
663                                  decode_create_session_maxsz)
664 #define NFS4_enc_destroy_session_sz     (compound_encode_hdr_maxsz + \
665                                          encode_destroy_session_maxsz)
666 #define NFS4_dec_destroy_session_sz     (compound_decode_hdr_maxsz + \
667                                          decode_destroy_session_maxsz)
668 #define NFS4_enc_sequence_sz \
669                                 (compound_decode_hdr_maxsz + \
670                                  encode_sequence_maxsz)
671 #define NFS4_dec_sequence_sz \
672                                 (compound_decode_hdr_maxsz + \
673                                  decode_sequence_maxsz)
674 #define NFS4_enc_get_lease_time_sz      (compound_encode_hdr_maxsz + \
675                                          encode_sequence_maxsz + \
676                                          encode_putrootfh_maxsz + \
677                                          encode_fsinfo_maxsz)
678 #define NFS4_dec_get_lease_time_sz      (compound_decode_hdr_maxsz + \
679                                          decode_sequence_maxsz + \
680                                          decode_putrootfh_maxsz + \
681                                          decode_fsinfo_maxsz)
682 #define NFS4_enc_reclaim_complete_sz    (compound_encode_hdr_maxsz + \
683                                          encode_sequence_maxsz + \
684                                          encode_reclaim_complete_maxsz)
685 #define NFS4_dec_reclaim_complete_sz    (compound_decode_hdr_maxsz + \
686                                          decode_sequence_maxsz + \
687                                          decode_reclaim_complete_maxsz)
688
689 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
690                                       compound_encode_hdr_maxsz +
691                                       encode_sequence_maxsz +
692                                       encode_putfh_maxsz +
693                                       encode_getattr_maxsz) *
694                                      XDR_UNIT);
695
696 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
697                                      compound_decode_hdr_maxsz +
698                                      decode_sequence_maxsz +
699                                      decode_putfh_maxsz) *
700                                     XDR_UNIT);
701 #endif /* CONFIG_NFS_V4_1 */
702
703 static const umode_t nfs_type2fmt[] = {
704         [NF4BAD] = 0,
705         [NF4REG] = S_IFREG,
706         [NF4DIR] = S_IFDIR,
707         [NF4BLK] = S_IFBLK,
708         [NF4CHR] = S_IFCHR,
709         [NF4LNK] = S_IFLNK,
710         [NF4SOCK] = S_IFSOCK,
711         [NF4FIFO] = S_IFIFO,
712         [NF4ATTRDIR] = 0,
713         [NF4NAMEDATTR] = 0,
714 };
715
716 struct compound_hdr {
717         int32_t         status;
718         uint32_t        nops;
719         __be32 *        nops_p;
720         uint32_t        taglen;
721         char *          tag;
722         uint32_t        replen;         /* expected reply words */
723         u32             minorversion;
724 };
725
726 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
727 {
728         __be32 *p = xdr_reserve_space(xdr, nbytes);
729         BUG_ON(!p);
730         return p;
731 }
732
733 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
734 {
735         __be32 *p;
736
737         p = xdr_reserve_space(xdr, 4 + len);
738         BUG_ON(p == NULL);
739         xdr_encode_opaque(p, str, len);
740 }
741
742 static void encode_compound_hdr(struct xdr_stream *xdr,
743                                 struct rpc_rqst *req,
744                                 struct compound_hdr *hdr)
745 {
746         __be32 *p;
747         struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
748
749         /* initialize running count of expected bytes in reply.
750          * NOTE: the replied tag SHOULD be the same is the one sent,
751          * but this is not required as a MUST for the server to do so. */
752         hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
753
754         dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
755         BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
756         p = reserve_space(xdr, 4 + hdr->taglen + 8);
757         p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
758         *p++ = cpu_to_be32(hdr->minorversion);
759         hdr->nops_p = p;
760         *p = cpu_to_be32(hdr->nops);
761 }
762
763 static void encode_nops(struct compound_hdr *hdr)
764 {
765         BUG_ON(hdr->nops > NFS4_MAX_OPS);
766         *hdr->nops_p = htonl(hdr->nops);
767 }
768
769 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
770 {
771         __be32 *p;
772
773         p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
774         BUG_ON(p == NULL);
775         xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
776 }
777
778 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
779 {
780         char owner_name[IDMAP_NAMESZ];
781         char owner_group[IDMAP_NAMESZ];
782         int owner_namelen = 0;
783         int owner_grouplen = 0;
784         __be32 *p;
785         __be32 *q;
786         int len;
787         uint32_t bmval0 = 0;
788         uint32_t bmval1 = 0;
789
790         /*
791          * We reserve enough space to write the entire attribute buffer at once.
792          * In the worst-case, this would be
793          *   12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
794          *          = 36 bytes, plus any contribution from variable-length fields
795          *            such as owner/group.
796          */
797         len = 16;
798
799         /* Sigh */
800         if (iap->ia_valid & ATTR_SIZE)
801                 len += 8;
802         if (iap->ia_valid & ATTR_MODE)
803                 len += 4;
804         if (iap->ia_valid & ATTR_UID) {
805                 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
806                 if (owner_namelen < 0) {
807                         dprintk("nfs: couldn't resolve uid %d to string\n",
808                                         iap->ia_uid);
809                         /* XXX */
810                         strcpy(owner_name, "nobody");
811                         owner_namelen = sizeof("nobody") - 1;
812                         /* goto out; */
813                 }
814                 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
815         }
816         if (iap->ia_valid & ATTR_GID) {
817                 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
818                 if (owner_grouplen < 0) {
819                         dprintk("nfs: couldn't resolve gid %d to string\n",
820                                         iap->ia_gid);
821                         strcpy(owner_group, "nobody");
822                         owner_grouplen = sizeof("nobody") - 1;
823                         /* goto out; */
824                 }
825                 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
826         }
827         if (iap->ia_valid & ATTR_ATIME_SET)
828                 len += 16;
829         else if (iap->ia_valid & ATTR_ATIME)
830                 len += 4;
831         if (iap->ia_valid & ATTR_MTIME_SET)
832                 len += 16;
833         else if (iap->ia_valid & ATTR_MTIME)
834                 len += 4;
835         p = reserve_space(xdr, len);
836
837         /*
838          * We write the bitmap length now, but leave the bitmap and the attribute
839          * buffer length to be backfilled at the end of this routine.
840          */
841         *p++ = cpu_to_be32(2);
842         q = p;
843         p += 3;
844
845         if (iap->ia_valid & ATTR_SIZE) {
846                 bmval0 |= FATTR4_WORD0_SIZE;
847                 p = xdr_encode_hyper(p, iap->ia_size);
848         }
849         if (iap->ia_valid & ATTR_MODE) {
850                 bmval1 |= FATTR4_WORD1_MODE;
851                 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
852         }
853         if (iap->ia_valid & ATTR_UID) {
854                 bmval1 |= FATTR4_WORD1_OWNER;
855                 p = xdr_encode_opaque(p, owner_name, owner_namelen);
856         }
857         if (iap->ia_valid & ATTR_GID) {
858                 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
859                 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
860         }
861         if (iap->ia_valid & ATTR_ATIME_SET) {
862                 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
863                 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
864                 *p++ = cpu_to_be32(0);
865                 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
866                 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
867         }
868         else if (iap->ia_valid & ATTR_ATIME) {
869                 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
870                 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
871         }
872         if (iap->ia_valid & ATTR_MTIME_SET) {
873                 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
874                 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
875                 *p++ = cpu_to_be32(0);
876                 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
877                 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
878         }
879         else if (iap->ia_valid & ATTR_MTIME) {
880                 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
881                 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
882         }
883
884         /*
885          * Now we backfill the bitmap and the attribute buffer length.
886          */
887         if (len != ((char *)p - (char *)q) + 4) {
888                 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
889                                 len, ((char *)p - (char *)q) + 4);
890                 BUG();
891         }
892         len = (char *)p - (char *)q - 12;
893         *q++ = htonl(bmval0);
894         *q++ = htonl(bmval1);
895         *q = htonl(len);
896
897 /* out: */
898 }
899
900 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
901 {
902         __be32 *p;
903
904         p = reserve_space(xdr, 8);
905         *p++ = cpu_to_be32(OP_ACCESS);
906         *p = cpu_to_be32(access);
907         hdr->nops++;
908         hdr->replen += decode_access_maxsz;
909 }
910
911 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
912 {
913         __be32 *p;
914
915         p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
916         *p++ = cpu_to_be32(OP_CLOSE);
917         *p++ = cpu_to_be32(arg->seqid->sequence->counter);
918         xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
919         hdr->nops++;
920         hdr->replen += decode_close_maxsz;
921 }
922
923 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
924 {
925         __be32 *p;
926
927         p = reserve_space(xdr, 16);
928         *p++ = cpu_to_be32(OP_COMMIT);
929         p = xdr_encode_hyper(p, args->offset);
930         *p = cpu_to_be32(args->count);
931         hdr->nops++;
932         hdr->replen += decode_commit_maxsz;
933 }
934
935 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
936 {
937         __be32 *p;
938
939         p = reserve_space(xdr, 8);
940         *p++ = cpu_to_be32(OP_CREATE);
941         *p = cpu_to_be32(create->ftype);
942
943         switch (create->ftype) {
944         case NF4LNK:
945                 p = reserve_space(xdr, 4);
946                 *p = cpu_to_be32(create->u.symlink.len);
947                 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
948                 break;
949
950         case NF4BLK: case NF4CHR:
951                 p = reserve_space(xdr, 8);
952                 *p++ = cpu_to_be32(create->u.device.specdata1);
953                 *p = cpu_to_be32(create->u.device.specdata2);
954                 break;
955
956         default:
957                 break;
958         }
959
960         encode_string(xdr, create->name->len, create->name->name);
961         hdr->nops++;
962         hdr->replen += decode_create_maxsz;
963
964         encode_attrs(xdr, create->attrs, create->server);
965 }
966
967 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
968 {
969         __be32 *p;
970
971         p = reserve_space(xdr, 12);
972         *p++ = cpu_to_be32(OP_GETATTR);
973         *p++ = cpu_to_be32(1);
974         *p = cpu_to_be32(bitmap);
975         hdr->nops++;
976         hdr->replen += decode_getattr_maxsz;
977 }
978
979 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
980 {
981         __be32 *p;
982
983         p = reserve_space(xdr, 16);
984         *p++ = cpu_to_be32(OP_GETATTR);
985         *p++ = cpu_to_be32(2);
986         *p++ = cpu_to_be32(bm0);
987         *p = cpu_to_be32(bm1);
988         hdr->nops++;
989         hdr->replen += decode_getattr_maxsz;
990 }
991
992 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
993 {
994         encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
995                            bitmask[1] & nfs4_fattr_bitmap[1], hdr);
996 }
997
998 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
999 {
1000         encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1001                            bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
1002 }
1003
1004 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1005 {
1006         encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1007                            bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1008 }
1009
1010 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1011 {
1012         __be32 *p;
1013
1014         p = reserve_space(xdr, 4);
1015         *p = cpu_to_be32(OP_GETFH);
1016         hdr->nops++;
1017         hdr->replen += decode_getfh_maxsz;
1018 }
1019
1020 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1021 {
1022         __be32 *p;
1023
1024         p = reserve_space(xdr, 8 + name->len);
1025         *p++ = cpu_to_be32(OP_LINK);
1026         xdr_encode_opaque(p, name->name, name->len);
1027         hdr->nops++;
1028         hdr->replen += decode_link_maxsz;
1029 }
1030
1031 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1032 {
1033         if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1034                 return block ? NFS4_READW_LT : NFS4_READ_LT;
1035         return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1036 }
1037
1038 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1039 {
1040         if (fl->fl_end == OFFSET_MAX)
1041                 return ~(uint64_t)0;
1042         return fl->fl_end - fl->fl_start + 1;
1043 }
1044
1045 /*
1046  * opcode,type,reclaim,offset,length,new_lock_owner = 32
1047  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1048  */
1049 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1050 {
1051         __be32 *p;
1052
1053         p = reserve_space(xdr, 32);
1054         *p++ = cpu_to_be32(OP_LOCK);
1055         *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1056         *p++ = cpu_to_be32(args->reclaim);
1057         p = xdr_encode_hyper(p, args->fl->fl_start);
1058         p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1059         *p = cpu_to_be32(args->new_lock_owner);
1060         if (args->new_lock_owner){
1061                 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+32);
1062                 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
1063                 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1064                 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1065                 p = xdr_encode_hyper(p, args->lock_owner.clientid);
1066                 *p++ = cpu_to_be32(16);
1067                 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1068                 xdr_encode_hyper(p, args->lock_owner.id);
1069         }
1070         else {
1071                 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
1072                 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
1073                 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1074         }
1075         hdr->nops++;
1076         hdr->replen += decode_lock_maxsz;
1077 }
1078
1079 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1080 {
1081         __be32 *p;
1082
1083         p = reserve_space(xdr, 52);
1084         *p++ = cpu_to_be32(OP_LOCKT);
1085         *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1086         p = xdr_encode_hyper(p, args->fl->fl_start);
1087         p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1088         p = xdr_encode_hyper(p, args->lock_owner.clientid);
1089         *p++ = cpu_to_be32(16);
1090         p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1091         xdr_encode_hyper(p, args->lock_owner.id);
1092         hdr->nops++;
1093         hdr->replen += decode_lockt_maxsz;
1094 }
1095
1096 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1097 {
1098         __be32 *p;
1099
1100         p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1101         *p++ = cpu_to_be32(OP_LOCKU);
1102         *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1103         *p++ = cpu_to_be32(args->seqid->sequence->counter);
1104         p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1105         p = xdr_encode_hyper(p, args->fl->fl_start);
1106         xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1107         hdr->nops++;
1108         hdr->replen += decode_locku_maxsz;
1109 }
1110
1111 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1112 {
1113         int len = name->len;
1114         __be32 *p;
1115
1116         p = reserve_space(xdr, 8 + len);
1117         *p++ = cpu_to_be32(OP_LOOKUP);
1118         xdr_encode_opaque(p, name->name, len);
1119         hdr->nops++;
1120         hdr->replen += decode_lookup_maxsz;
1121 }
1122
1123 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1124 {
1125         __be32 *p;
1126
1127         p = reserve_space(xdr, 8);
1128         switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1129         case FMODE_READ:
1130                 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1131                 break;
1132         case FMODE_WRITE:
1133                 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1134                 break;
1135         case FMODE_READ|FMODE_WRITE:
1136                 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1137                 break;
1138         default:
1139                 *p++ = cpu_to_be32(0);
1140         }
1141         *p = cpu_to_be32(0);            /* for linux, share_deny = 0 always */
1142 }
1143
1144 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1145 {
1146         __be32 *p;
1147  /*
1148  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1149  * owner 4 = 32
1150  */
1151         p = reserve_space(xdr, 8);
1152         *p++ = cpu_to_be32(OP_OPEN);
1153         *p = cpu_to_be32(arg->seqid->sequence->counter);
1154         encode_share_access(xdr, arg->fmode);
1155         p = reserve_space(xdr, 28);
1156         p = xdr_encode_hyper(p, arg->clientid);
1157         *p++ = cpu_to_be32(16);
1158         p = xdr_encode_opaque_fixed(p, "open id:", 8);
1159         xdr_encode_hyper(p, arg->id);
1160 }
1161
1162 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1163 {
1164         __be32 *p;
1165         struct nfs_client *clp;
1166
1167         p = reserve_space(xdr, 4);
1168         switch(arg->open_flags & O_EXCL) {
1169         case 0:
1170                 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1171                 encode_attrs(xdr, arg->u.attrs, arg->server);
1172                 break;
1173         default:
1174                 clp = arg->server->nfs_client;
1175                 if (clp->cl_minorversion > 0) {
1176                         if (nfs4_has_persistent_session(clp)) {
1177                                 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1178                                 encode_attrs(xdr, arg->u.attrs, arg->server);
1179                         } else {
1180                                 struct iattr dummy;
1181
1182                                 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1183                                 encode_nfs4_verifier(xdr, &arg->u.verifier);
1184                                 dummy.ia_valid = 0;
1185                                 encode_attrs(xdr, &dummy, arg->server);
1186                         }
1187                 } else {
1188                         *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1189                         encode_nfs4_verifier(xdr, &arg->u.verifier);
1190                 }
1191         }
1192 }
1193
1194 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1195 {
1196         __be32 *p;
1197
1198         p = reserve_space(xdr, 4);
1199         switch (arg->open_flags & O_CREAT) {
1200         case 0:
1201                 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1202                 break;
1203         default:
1204                 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1205                 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1206                 encode_createmode(xdr, arg);
1207         }
1208 }
1209
1210 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1211 {
1212         __be32 *p;
1213
1214         p = reserve_space(xdr, 4);
1215         switch (delegation_type) {
1216         case 0:
1217                 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1218                 break;
1219         case FMODE_READ:
1220                 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1221                 break;
1222         case FMODE_WRITE|FMODE_READ:
1223                 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1224                 break;
1225         default:
1226                 BUG();
1227         }
1228 }
1229
1230 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1231 {
1232         __be32 *p;
1233
1234         p = reserve_space(xdr, 4);
1235         *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1236         encode_string(xdr, name->len, name->name);
1237 }
1238
1239 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1240 {
1241         __be32 *p;
1242
1243         p = reserve_space(xdr, 4);
1244         *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1245         encode_delegation_type(xdr, type);
1246 }
1247
1248 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1249 {
1250         __be32 *p;
1251
1252         p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1253         *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1254         xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1255         encode_string(xdr, name->len, name->name);
1256 }
1257
1258 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1259 {
1260         encode_openhdr(xdr, arg);
1261         encode_opentype(xdr, arg);
1262         switch (arg->claim) {
1263         case NFS4_OPEN_CLAIM_NULL:
1264                 encode_claim_null(xdr, arg->name);
1265                 break;
1266         case NFS4_OPEN_CLAIM_PREVIOUS:
1267                 encode_claim_previous(xdr, arg->u.delegation_type);
1268                 break;
1269         case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1270                 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1271                 break;
1272         default:
1273                 BUG();
1274         }
1275         hdr->nops++;
1276         hdr->replen += decode_open_maxsz;
1277 }
1278
1279 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1280 {
1281         __be32 *p;
1282
1283         p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1284         *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1285         p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1286         *p = cpu_to_be32(arg->seqid->sequence->counter);
1287         hdr->nops++;
1288         hdr->replen += decode_open_confirm_maxsz;
1289 }
1290
1291 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1292 {
1293         __be32 *p;
1294
1295         p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1296         *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1297         p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1298         *p = cpu_to_be32(arg->seqid->sequence->counter);
1299         encode_share_access(xdr, arg->fmode);
1300         hdr->nops++;
1301         hdr->replen += decode_open_downgrade_maxsz;
1302 }
1303
1304 static void
1305 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1306 {
1307         int len = fh->size;
1308         __be32 *p;
1309
1310         p = reserve_space(xdr, 8 + len);
1311         *p++ = cpu_to_be32(OP_PUTFH);
1312         xdr_encode_opaque(p, fh->data, len);
1313         hdr->nops++;
1314         hdr->replen += decode_putfh_maxsz;
1315 }
1316
1317 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1318 {
1319         __be32 *p;
1320
1321         p = reserve_space(xdr, 4);
1322         *p = cpu_to_be32(OP_PUTROOTFH);
1323         hdr->nops++;
1324         hdr->replen += decode_putrootfh_maxsz;
1325 }
1326
1327 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1328 {
1329         nfs4_stateid stateid;
1330         __be32 *p;
1331
1332         p = reserve_space(xdr, NFS4_STATEID_SIZE);
1333         if (ctx->state != NULL) {
1334                 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1335                 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1336         } else
1337                 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1338 }
1339
1340 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1341 {
1342         __be32 *p;
1343
1344         p = reserve_space(xdr, 4);
1345         *p = cpu_to_be32(OP_READ);
1346
1347         encode_stateid(xdr, args->context);
1348
1349         p = reserve_space(xdr, 12);
1350         p = xdr_encode_hyper(p, args->offset);
1351         *p = cpu_to_be32(args->count);
1352         hdr->nops++;
1353         hdr->replen += decode_read_maxsz;
1354 }
1355
1356 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1357 {
1358         uint32_t attrs[2] = {
1359                 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1360                 FATTR4_WORD1_MOUNTED_ON_FILEID,
1361         };
1362         __be32 *p;
1363
1364         p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
1365         *p++ = cpu_to_be32(OP_READDIR);
1366         p = xdr_encode_hyper(p, readdir->cookie);
1367         p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
1368         *p++ = cpu_to_be32(readdir->count >> 1);  /* We're not doing readdirplus */
1369         *p++ = cpu_to_be32(readdir->count);
1370         *p++ = cpu_to_be32(2);
1371         /* Switch to mounted_on_fileid if the server supports it */
1372         if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1373                 attrs[0] &= ~FATTR4_WORD0_FILEID;
1374         else
1375                 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1376         *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1377         *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1378         hdr->nops++;
1379         hdr->replen += decode_readdir_maxsz;
1380         dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1381                         __func__,
1382                         (unsigned long long)readdir->cookie,
1383                         ((u32 *)readdir->verifier.data)[0],
1384                         ((u32 *)readdir->verifier.data)[1],
1385                         attrs[0] & readdir->bitmask[0],
1386                         attrs[1] & readdir->bitmask[1]);
1387 }
1388
1389 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1390 {
1391         __be32 *p;
1392
1393         p = reserve_space(xdr, 4);
1394         *p = cpu_to_be32(OP_READLINK);
1395         hdr->nops++;
1396         hdr->replen += decode_readlink_maxsz;
1397 }
1398
1399 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1400 {
1401         __be32 *p;
1402
1403         p = reserve_space(xdr, 8 + name->len);
1404         *p++ = cpu_to_be32(OP_REMOVE);
1405         xdr_encode_opaque(p, name->name, name->len);
1406         hdr->nops++;
1407         hdr->replen += decode_remove_maxsz;
1408 }
1409
1410 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1411 {
1412         __be32 *p;
1413
1414         p = reserve_space(xdr, 4);
1415         *p = cpu_to_be32(OP_RENAME);
1416         encode_string(xdr, oldname->len, oldname->name);
1417         encode_string(xdr, newname->len, newname->name);
1418         hdr->nops++;
1419         hdr->replen += decode_rename_maxsz;
1420 }
1421
1422 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1423 {
1424         __be32 *p;
1425
1426         p = reserve_space(xdr, 12);
1427         *p++ = cpu_to_be32(OP_RENEW);
1428         xdr_encode_hyper(p, client_stateid->cl_clientid);
1429         hdr->nops++;
1430         hdr->replen += decode_renew_maxsz;
1431 }
1432
1433 static void
1434 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1435 {
1436         __be32 *p;
1437
1438         p = reserve_space(xdr, 4);
1439         *p = cpu_to_be32(OP_RESTOREFH);
1440         hdr->nops++;
1441         hdr->replen += decode_restorefh_maxsz;
1442 }
1443
1444 static int
1445 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1446 {
1447         __be32 *p;
1448
1449         p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1450         *p++ = cpu_to_be32(OP_SETATTR);
1451         xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1452         p = reserve_space(xdr, 2*4);
1453         *p++ = cpu_to_be32(1);
1454         *p = cpu_to_be32(FATTR4_WORD0_ACL);
1455         if (arg->acl_len % 4)
1456                 return -EINVAL;
1457         p = reserve_space(xdr, 4);
1458         *p = cpu_to_be32(arg->acl_len);
1459         xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1460         hdr->nops++;
1461         hdr->replen += decode_setacl_maxsz;
1462         return 0;
1463 }
1464
1465 static void
1466 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1467 {
1468         __be32 *p;
1469
1470         p = reserve_space(xdr, 4);
1471         *p = cpu_to_be32(OP_SAVEFH);
1472         hdr->nops++;
1473         hdr->replen += decode_savefh_maxsz;
1474 }
1475
1476 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1477 {
1478         __be32 *p;
1479
1480         p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1481         *p++ = cpu_to_be32(OP_SETATTR);
1482         xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1483         hdr->nops++;
1484         hdr->replen += decode_setattr_maxsz;
1485         encode_attrs(xdr, arg->iap, server);
1486 }
1487
1488 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1489 {
1490         __be32 *p;
1491
1492         p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1493         *p++ = cpu_to_be32(OP_SETCLIENTID);
1494         xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1495
1496         encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1497         p = reserve_space(xdr, 4);
1498         *p = cpu_to_be32(setclientid->sc_prog);
1499         encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1500         encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1501         p = reserve_space(xdr, 4);
1502         *p = cpu_to_be32(setclientid->sc_cb_ident);
1503         hdr->nops++;
1504         hdr->replen += decode_setclientid_maxsz;
1505 }
1506
1507 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1508 {
1509         __be32 *p;
1510
1511         p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1512         *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1513         p = xdr_encode_hyper(p, arg->clientid);
1514         xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1515         hdr->nops++;
1516         hdr->replen += decode_setclientid_confirm_maxsz;
1517 }
1518
1519 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1520 {
1521         __be32 *p;
1522
1523         p = reserve_space(xdr, 4);
1524         *p = cpu_to_be32(OP_WRITE);
1525
1526         encode_stateid(xdr, args->context);
1527
1528         p = reserve_space(xdr, 16);
1529         p = xdr_encode_hyper(p, args->offset);
1530         *p++ = cpu_to_be32(args->stable);
1531         *p = cpu_to_be32(args->count);
1532
1533         xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1534         hdr->nops++;
1535         hdr->replen += decode_write_maxsz;
1536 }
1537
1538 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1539 {
1540         __be32 *p;
1541
1542         p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1543
1544         *p++ = cpu_to_be32(OP_DELEGRETURN);
1545         xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1546         hdr->nops++;
1547         hdr->replen += decode_delegreturn_maxsz;
1548 }
1549
1550 #if defined(CONFIG_NFS_V4_1)
1551 /* NFSv4.1 operations */
1552 static void encode_exchange_id(struct xdr_stream *xdr,
1553                                struct nfs41_exchange_id_args *args,
1554                                struct compound_hdr *hdr)
1555 {
1556         __be32 *p;
1557
1558         p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1559         *p++ = cpu_to_be32(OP_EXCHANGE_ID);
1560         xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1561
1562         encode_string(xdr, args->id_len, args->id);
1563
1564         p = reserve_space(xdr, 12);
1565         *p++ = cpu_to_be32(args->flags);
1566         *p++ = cpu_to_be32(0);  /* zero length state_protect4_a */
1567         *p = cpu_to_be32(0);    /* zero length implementation id array */
1568         hdr->nops++;
1569         hdr->replen += decode_exchange_id_maxsz;
1570 }
1571
1572 static void encode_create_session(struct xdr_stream *xdr,
1573                                   struct nfs41_create_session_args *args,
1574                                   struct compound_hdr *hdr)
1575 {
1576         __be32 *p;
1577         char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1578         uint32_t len;
1579         struct nfs_client *clp = args->client;
1580         u32 max_resp_sz_cached;
1581
1582         /*
1583          * Assumes OPEN is the biggest non-idempotent compound.
1584          * 2 is the verifier.
1585          */
1586         max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1587                               RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1588
1589         len = scnprintf(machine_name, sizeof(machine_name), "%s",
1590                         clp->cl_ipaddr);
1591
1592         p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1593         *p++ = cpu_to_be32(OP_CREATE_SESSION);
1594         p = xdr_encode_hyper(p, clp->cl_ex_clid);
1595         *p++ = cpu_to_be32(clp->cl_seqid);                      /*Sequence id */
1596         *p++ = cpu_to_be32(args->flags);                        /*flags */
1597
1598         /* Fore Channel */
1599         *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1600         *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1601         *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1602         *p++ = cpu_to_be32(max_resp_sz_cached);         /* Max resp sz cached */
1603         *p++ = cpu_to_be32(args->fc_attrs.max_ops);     /* max operations */
1604         *p++ = cpu_to_be32(args->fc_attrs.max_reqs);    /* max requests */
1605         *p++ = cpu_to_be32(0);                          /* rdmachannel_attrs */
1606
1607         /* Back Channel */
1608         *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1609         *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1610         *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1611         *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);  /* Max resp sz cached */
1612         *p++ = cpu_to_be32(args->bc_attrs.max_ops);     /* max operations */
1613         *p++ = cpu_to_be32(args->bc_attrs.max_reqs);    /* max requests */
1614         *p++ = cpu_to_be32(0);                          /* rdmachannel_attrs */
1615
1616         *p++ = cpu_to_be32(args->cb_program);           /* cb_program */
1617         *p++ = cpu_to_be32(1);
1618         *p++ = cpu_to_be32(RPC_AUTH_UNIX);                      /* auth_sys */
1619
1620         /* authsys_parms rfc1831 */
1621         *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec);     /* stamp */
1622         p = xdr_encode_opaque(p, machine_name, len);
1623         *p++ = cpu_to_be32(0);                          /* UID */
1624         *p++ = cpu_to_be32(0);                          /* GID */
1625         *p = cpu_to_be32(0);                            /* No more gids */
1626         hdr->nops++;
1627         hdr->replen += decode_create_session_maxsz;
1628 }
1629
1630 static void encode_destroy_session(struct xdr_stream *xdr,
1631                                    struct nfs4_session *session,
1632                                    struct compound_hdr *hdr)
1633 {
1634         __be32 *p;
1635         p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1636         *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1637         xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1638         hdr->nops++;
1639         hdr->replen += decode_destroy_session_maxsz;
1640 }
1641
1642 static void encode_reclaim_complete(struct xdr_stream *xdr,
1643                                     struct nfs41_reclaim_complete_args *args,
1644                                     struct compound_hdr *hdr)
1645 {
1646         __be32 *p;
1647
1648         p = reserve_space(xdr, 8);
1649         *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1650         *p++ = cpu_to_be32(args->one_fs);
1651         hdr->nops++;
1652         hdr->replen += decode_reclaim_complete_maxsz;
1653 }
1654 #endif /* CONFIG_NFS_V4_1 */
1655
1656 static void encode_sequence(struct xdr_stream *xdr,
1657                             const struct nfs4_sequence_args *args,
1658                             struct compound_hdr *hdr)
1659 {
1660 #if defined(CONFIG_NFS_V4_1)
1661         struct nfs4_session *session = args->sa_session;
1662         struct nfs4_slot_table *tp;
1663         struct nfs4_slot *slot;
1664         __be32 *p;
1665
1666         if (!session)
1667                 return;
1668
1669         tp = &session->fc_slot_table;
1670
1671         WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1672         slot = tp->slots + args->sa_slotid;
1673
1674         p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1675         *p++ = cpu_to_be32(OP_SEQUENCE);
1676
1677         /*
1678          * Sessionid + seqid + slotid + max slotid + cache_this
1679          */
1680         dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1681                 "max_slotid=%d cache_this=%d\n",
1682                 __func__,
1683                 ((u32 *)session->sess_id.data)[0],
1684                 ((u32 *)session->sess_id.data)[1],
1685                 ((u32 *)session->sess_id.data)[2],
1686                 ((u32 *)session->sess_id.data)[3],
1687                 slot->seq_nr, args->sa_slotid,
1688                 tp->highest_used_slotid, args->sa_cache_this);
1689         p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1690         *p++ = cpu_to_be32(slot->seq_nr);
1691         *p++ = cpu_to_be32(args->sa_slotid);
1692         *p++ = cpu_to_be32(tp->highest_used_slotid);
1693         *p = cpu_to_be32(args->sa_cache_this);
1694         hdr->nops++;
1695         hdr->replen += decode_sequence_maxsz;
1696 #endif /* CONFIG_NFS_V4_1 */
1697 }
1698
1699 /*
1700  * END OF "GENERIC" ENCODE ROUTINES.
1701  */
1702
1703 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1704 {
1705 #if defined(CONFIG_NFS_V4_1)
1706         if (args->sa_session)
1707                 return args->sa_session->clp->cl_minorversion;
1708 #endif /* CONFIG_NFS_V4_1 */
1709         return 0;
1710 }
1711
1712 /*
1713  * Encode an ACCESS request
1714  */
1715 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1716 {
1717         struct xdr_stream xdr;
1718         struct compound_hdr hdr = {
1719                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1720         };
1721
1722         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1723         encode_compound_hdr(&xdr, req, &hdr);
1724         encode_sequence(&xdr, &args->seq_args, &hdr);
1725         encode_putfh(&xdr, args->fh, &hdr);
1726         encode_access(&xdr, args->access, &hdr);
1727         encode_getfattr(&xdr, args->bitmask, &hdr);
1728         encode_nops(&hdr);
1729         return 0;
1730 }
1731
1732 /*
1733  * Encode LOOKUP request
1734  */
1735 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1736 {
1737         struct xdr_stream xdr;
1738         struct compound_hdr hdr = {
1739                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1740         };
1741
1742         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1743         encode_compound_hdr(&xdr, req, &hdr);
1744         encode_sequence(&xdr, &args->seq_args, &hdr);
1745         encode_putfh(&xdr, args->dir_fh, &hdr);
1746         encode_lookup(&xdr, args->name, &hdr);
1747         encode_getfh(&xdr, &hdr);
1748         encode_getfattr(&xdr, args->bitmask, &hdr);
1749         encode_nops(&hdr);
1750         return 0;
1751 }
1752
1753 /*
1754  * Encode LOOKUP_ROOT request
1755  */
1756 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1757 {
1758         struct xdr_stream xdr;
1759         struct compound_hdr hdr = {
1760                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1761         };
1762
1763         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1764         encode_compound_hdr(&xdr, req, &hdr);
1765         encode_sequence(&xdr, &args->seq_args, &hdr);
1766         encode_putrootfh(&xdr, &hdr);
1767         encode_getfh(&xdr, &hdr);
1768         encode_getfattr(&xdr, args->bitmask, &hdr);
1769         encode_nops(&hdr);
1770         return 0;
1771 }
1772
1773 /*
1774  * Encode REMOVE request
1775  */
1776 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1777 {
1778         struct xdr_stream xdr;
1779         struct compound_hdr hdr = {
1780                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1781         };
1782
1783         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1784         encode_compound_hdr(&xdr, req, &hdr);
1785         encode_sequence(&xdr, &args->seq_args, &hdr);
1786         encode_putfh(&xdr, args->fh, &hdr);
1787         encode_remove(&xdr, &args->name, &hdr);
1788         encode_getfattr(&xdr, args->bitmask, &hdr);
1789         encode_nops(&hdr);
1790         return 0;
1791 }
1792
1793 /*
1794  * Encode RENAME request
1795  */
1796 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1797 {
1798         struct xdr_stream xdr;
1799         struct compound_hdr hdr = {
1800                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1801         };
1802
1803         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1804         encode_compound_hdr(&xdr, req, &hdr);
1805         encode_sequence(&xdr, &args->seq_args, &hdr);
1806         encode_putfh(&xdr, args->old_dir, &hdr);
1807         encode_savefh(&xdr, &hdr);
1808         encode_putfh(&xdr, args->new_dir, &hdr);
1809         encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1810         encode_getfattr(&xdr, args->bitmask, &hdr);
1811         encode_restorefh(&xdr, &hdr);
1812         encode_getfattr(&xdr, args->bitmask, &hdr);
1813         encode_nops(&hdr);
1814         return 0;
1815 }
1816
1817 /*
1818  * Encode LINK request
1819  */
1820 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1821 {
1822         struct xdr_stream xdr;
1823         struct compound_hdr hdr = {
1824                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1825         };
1826
1827         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1828         encode_compound_hdr(&xdr, req, &hdr);
1829         encode_sequence(&xdr, &args->seq_args, &hdr);
1830         encode_putfh(&xdr, args->fh, &hdr);
1831         encode_savefh(&xdr, &hdr);
1832         encode_putfh(&xdr, args->dir_fh, &hdr);
1833         encode_link(&xdr, args->name, &hdr);
1834         encode_getfattr(&xdr, args->bitmask, &hdr);
1835         encode_restorefh(&xdr, &hdr);
1836         encode_getfattr(&xdr, args->bitmask, &hdr);
1837         encode_nops(&hdr);
1838         return 0;
1839 }
1840
1841 /*
1842  * Encode CREATE request
1843  */
1844 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1845 {
1846         struct xdr_stream xdr;
1847         struct compound_hdr hdr = {
1848                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1849         };
1850
1851         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1852         encode_compound_hdr(&xdr, req, &hdr);
1853         encode_sequence(&xdr, &args->seq_args, &hdr);
1854         encode_putfh(&xdr, args->dir_fh, &hdr);
1855         encode_savefh(&xdr, &hdr);
1856         encode_create(&xdr, args, &hdr);
1857         encode_getfh(&xdr, &hdr);
1858         encode_getfattr(&xdr, args->bitmask, &hdr);
1859         encode_restorefh(&xdr, &hdr);
1860         encode_getfattr(&xdr, args->bitmask, &hdr);
1861         encode_nops(&hdr);
1862         return 0;
1863 }
1864
1865 /*
1866  * Encode SYMLINK request
1867  */
1868 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1869 {
1870         return nfs4_xdr_enc_create(req, p, args);
1871 }
1872
1873 /*
1874  * Encode GETATTR request
1875  */
1876 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1877 {
1878         struct xdr_stream xdr;
1879         struct compound_hdr hdr = {
1880                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1881         };
1882
1883         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1884         encode_compound_hdr(&xdr, req, &hdr);
1885         encode_sequence(&xdr, &args->seq_args, &hdr);
1886         encode_putfh(&xdr, args->fh, &hdr);
1887         encode_getfattr(&xdr, args->bitmask, &hdr);
1888         encode_nops(&hdr);
1889         return 0;
1890 }
1891
1892 /*
1893  * Encode a CLOSE request
1894  */
1895 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1896 {
1897         struct xdr_stream xdr;
1898         struct compound_hdr hdr = {
1899                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1900         };
1901
1902         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1903         encode_compound_hdr(&xdr, req, &hdr);
1904         encode_sequence(&xdr, &args->seq_args, &hdr);
1905         encode_putfh(&xdr, args->fh, &hdr);
1906         encode_close(&xdr, args, &hdr);
1907         encode_getfattr(&xdr, args->bitmask, &hdr);
1908         encode_nops(&hdr);
1909         return 0;
1910 }
1911
1912 /*
1913  * Encode an OPEN request
1914  */
1915 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1916 {
1917         struct xdr_stream xdr;
1918         struct compound_hdr hdr = {
1919                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1920         };
1921
1922         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1923         encode_compound_hdr(&xdr, req, &hdr);
1924         encode_sequence(&xdr, &args->seq_args, &hdr);
1925         encode_putfh(&xdr, args->fh, &hdr);
1926         encode_savefh(&xdr, &hdr);
1927         encode_open(&xdr, args, &hdr);
1928         encode_getfh(&xdr, &hdr);
1929         encode_getfattr(&xdr, args->bitmask, &hdr);
1930         encode_restorefh(&xdr, &hdr);
1931         encode_getfattr(&xdr, args->bitmask, &hdr);
1932         encode_nops(&hdr);
1933         return 0;
1934 }
1935
1936 /*
1937  * Encode an OPEN_CONFIRM request
1938  */
1939 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1940 {
1941         struct xdr_stream xdr;
1942         struct compound_hdr hdr = {
1943                 .nops   = 0,
1944         };
1945
1946         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1947         encode_compound_hdr(&xdr, req, &hdr);
1948         encode_putfh(&xdr, args->fh, &hdr);
1949         encode_open_confirm(&xdr, args, &hdr);
1950         encode_nops(&hdr);
1951         return 0;
1952 }
1953
1954 /*
1955  * Encode an OPEN request with no attributes.
1956  */
1957 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1958 {
1959         struct xdr_stream xdr;
1960         struct compound_hdr hdr = {
1961                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1962         };
1963
1964         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1965         encode_compound_hdr(&xdr, req, &hdr);
1966         encode_sequence(&xdr, &args->seq_args, &hdr);
1967         encode_putfh(&xdr, args->fh, &hdr);
1968         encode_open(&xdr, args, &hdr);
1969         encode_getfattr(&xdr, args->bitmask, &hdr);
1970         encode_nops(&hdr);
1971         return 0;
1972 }
1973
1974 /*
1975  * Encode an OPEN_DOWNGRADE request
1976  */
1977 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1978 {
1979         struct xdr_stream xdr;
1980         struct compound_hdr hdr = {
1981                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1982         };
1983
1984         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1985         encode_compound_hdr(&xdr, req, &hdr);
1986         encode_sequence(&xdr, &args->seq_args, &hdr);
1987         encode_putfh(&xdr, args->fh, &hdr);
1988         encode_open_downgrade(&xdr, args, &hdr);
1989         encode_getfattr(&xdr, args->bitmask, &hdr);
1990         encode_nops(&hdr);
1991         return 0;
1992 }
1993
1994 /*
1995  * Encode a LOCK request
1996  */
1997 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1998 {
1999         struct xdr_stream xdr;
2000         struct compound_hdr hdr = {
2001                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2002         };
2003
2004         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2005         encode_compound_hdr(&xdr, req, &hdr);
2006         encode_sequence(&xdr, &args->seq_args, &hdr);
2007         encode_putfh(&xdr, args->fh, &hdr);
2008         encode_lock(&xdr, args, &hdr);
2009         encode_nops(&hdr);
2010         return 0;
2011 }
2012
2013 /*
2014  * Encode a LOCKT request
2015  */
2016 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
2017 {
2018         struct xdr_stream xdr;
2019         struct compound_hdr hdr = {
2020                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2021         };
2022
2023         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2024         encode_compound_hdr(&xdr, req, &hdr);
2025         encode_sequence(&xdr, &args->seq_args, &hdr);
2026         encode_putfh(&xdr, args->fh, &hdr);
2027         encode_lockt(&xdr, args, &hdr);
2028         encode_nops(&hdr);
2029         return 0;
2030 }
2031
2032 /*
2033  * Encode a LOCKU request
2034  */
2035 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
2036 {
2037         struct xdr_stream xdr;
2038         struct compound_hdr hdr = {
2039                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2040         };
2041
2042         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2043         encode_compound_hdr(&xdr, req, &hdr);
2044         encode_sequence(&xdr, &args->seq_args, &hdr);
2045         encode_putfh(&xdr, args->fh, &hdr);
2046         encode_locku(&xdr, args, &hdr);
2047         encode_nops(&hdr);
2048         return 0;
2049 }
2050
2051 /*
2052  * Encode a READLINK request
2053  */
2054 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
2055 {
2056         struct xdr_stream xdr;
2057         struct compound_hdr hdr = {
2058                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2059         };
2060
2061         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2062         encode_compound_hdr(&xdr, req, &hdr);
2063         encode_sequence(&xdr, &args->seq_args, &hdr);
2064         encode_putfh(&xdr, args->fh, &hdr);
2065         encode_readlink(&xdr, args, req, &hdr);
2066
2067         xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2068                         args->pgbase, args->pglen);
2069         encode_nops(&hdr);
2070         return 0;
2071 }
2072
2073 /*
2074  * Encode a READDIR request
2075  */
2076 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
2077 {
2078         struct xdr_stream xdr;
2079         struct compound_hdr hdr = {
2080                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2081         };
2082
2083         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2084         encode_compound_hdr(&xdr, req, &hdr);
2085         encode_sequence(&xdr, &args->seq_args, &hdr);
2086         encode_putfh(&xdr, args->fh, &hdr);
2087         encode_readdir(&xdr, args, req, &hdr);
2088
2089         xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2090                          args->pgbase, args->count);
2091         dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2092                         __func__, hdr.replen << 2, args->pages,
2093                         args->pgbase, args->count);
2094         encode_nops(&hdr);
2095         return 0;
2096 }
2097
2098 /*
2099  * Encode a READ request
2100  */
2101 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
2102 {
2103         struct xdr_stream xdr;
2104         struct compound_hdr hdr = {
2105                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2106         };
2107
2108         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2109         encode_compound_hdr(&xdr, req, &hdr);
2110         encode_sequence(&xdr, &args->seq_args, &hdr);
2111         encode_putfh(&xdr, args->fh, &hdr);
2112         encode_read(&xdr, args, &hdr);
2113
2114         xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2115                          args->pages, args->pgbase, args->count);
2116         req->rq_rcv_buf.flags |= XDRBUF_READ;
2117         encode_nops(&hdr);
2118         return 0;
2119 }
2120
2121 /*
2122  * Encode an SETATTR request
2123  */
2124 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
2125 {
2126         struct xdr_stream xdr;
2127         struct compound_hdr hdr = {
2128                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2129         };
2130
2131         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2132         encode_compound_hdr(&xdr, req, &hdr);
2133         encode_sequence(&xdr, &args->seq_args, &hdr);
2134         encode_putfh(&xdr, args->fh, &hdr);
2135         encode_setattr(&xdr, args, args->server, &hdr);
2136         encode_getfattr(&xdr, args->bitmask, &hdr);
2137         encode_nops(&hdr);
2138         return 0;
2139 }
2140
2141 /*
2142  * Encode a GETACL request
2143  */
2144 static int
2145 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
2146                 struct nfs_getaclargs *args)
2147 {
2148         struct xdr_stream xdr;
2149         struct compound_hdr hdr = {
2150                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2151         };
2152         uint32_t replen;
2153
2154         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2155         encode_compound_hdr(&xdr, req, &hdr);
2156         encode_sequence(&xdr, &args->seq_args, &hdr);
2157         encode_putfh(&xdr, args->fh, &hdr);
2158         replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
2159         encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2160
2161         xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2162                 args->acl_pages, args->acl_pgbase, args->acl_len);
2163         encode_nops(&hdr);
2164         return 0;
2165 }
2166
2167 /*
2168  * Encode a WRITE request
2169  */
2170 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
2171 {
2172         struct xdr_stream xdr;
2173         struct compound_hdr hdr = {
2174                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2175         };
2176
2177         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2178         encode_compound_hdr(&xdr, req, &hdr);
2179         encode_sequence(&xdr, &args->seq_args, &hdr);
2180         encode_putfh(&xdr, args->fh, &hdr);
2181         encode_write(&xdr, args, &hdr);
2182         req->rq_snd_buf.flags |= XDRBUF_WRITE;
2183         encode_getfattr(&xdr, args->bitmask, &hdr);
2184         encode_nops(&hdr);
2185         return 0;
2186 }
2187
2188 /*
2189  *  a COMMIT request
2190  */
2191 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
2192 {
2193         struct xdr_stream xdr;
2194         struct compound_hdr hdr = {
2195                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2196         };
2197
2198         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2199         encode_compound_hdr(&xdr, req, &hdr);
2200         encode_sequence(&xdr, &args->seq_args, &hdr);
2201         encode_putfh(&xdr, args->fh, &hdr);
2202         encode_commit(&xdr, args, &hdr);
2203         encode_getfattr(&xdr, args->bitmask, &hdr);
2204         encode_nops(&hdr);
2205         return 0;
2206 }
2207
2208 /*
2209  * FSINFO request
2210  */
2211 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
2212 {
2213         struct xdr_stream xdr;
2214         struct compound_hdr hdr = {
2215                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2216         };
2217
2218         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2219         encode_compound_hdr(&xdr, req, &hdr);
2220         encode_sequence(&xdr, &args->seq_args, &hdr);
2221         encode_putfh(&xdr, args->fh, &hdr);
2222         encode_fsinfo(&xdr, args->bitmask, &hdr);
2223         encode_nops(&hdr);
2224         return 0;
2225 }
2226
2227 /*
2228  * a PATHCONF request
2229  */
2230 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
2231 {
2232         struct xdr_stream xdr;
2233         struct compound_hdr hdr = {
2234                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2235         };
2236
2237         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2238         encode_compound_hdr(&xdr, req, &hdr);
2239         encode_sequence(&xdr, &args->seq_args, &hdr);
2240         encode_putfh(&xdr, args->fh, &hdr);
2241         encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2242                            &hdr);
2243         encode_nops(&hdr);
2244         return 0;
2245 }
2246
2247 /*
2248  * a STATFS request
2249  */
2250 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
2251 {
2252         struct xdr_stream xdr;
2253         struct compound_hdr hdr = {
2254                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2255         };
2256
2257         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2258         encode_compound_hdr(&xdr, req, &hdr);
2259         encode_sequence(&xdr, &args->seq_args, &hdr);
2260         encode_putfh(&xdr, args->fh, &hdr);
2261         encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2262                            args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2263         encode_nops(&hdr);
2264         return 0;
2265 }
2266
2267 /*
2268  * GETATTR_BITMAP request
2269  */
2270 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2271                                     struct nfs4_server_caps_arg *args)
2272 {
2273         struct xdr_stream xdr;
2274         struct compound_hdr hdr = {
2275                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2276         };
2277
2278         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2279         encode_compound_hdr(&xdr, req, &hdr);
2280         encode_sequence(&xdr, &args->seq_args, &hdr);
2281         encode_putfh(&xdr, args->fhandle, &hdr);
2282         encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2283                            FATTR4_WORD0_LINK_SUPPORT|
2284                            FATTR4_WORD0_SYMLINK_SUPPORT|
2285                            FATTR4_WORD0_ACLSUPPORT, &hdr);
2286         encode_nops(&hdr);
2287         return 0;
2288 }
2289
2290 /*
2291  * a RENEW request
2292  */
2293 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2294 {
2295         struct xdr_stream xdr;
2296         struct compound_hdr hdr = {
2297                 .nops   = 0,
2298         };
2299
2300         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2301         encode_compound_hdr(&xdr, req, &hdr);
2302         encode_renew(&xdr, clp, &hdr);
2303         encode_nops(&hdr);
2304         return 0;
2305 }
2306
2307 /*
2308  * a SETCLIENTID request
2309  */
2310 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2311 {
2312         struct xdr_stream xdr;
2313         struct compound_hdr hdr = {
2314                 .nops   = 0,
2315         };
2316
2317         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2318         encode_compound_hdr(&xdr, req, &hdr);
2319         encode_setclientid(&xdr, sc, &hdr);
2320         encode_nops(&hdr);
2321         return 0;
2322 }
2323
2324 /*
2325  * a SETCLIENTID_CONFIRM request
2326  */
2327 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid_res *arg)
2328 {
2329         struct xdr_stream xdr;
2330         struct compound_hdr hdr = {
2331                 .nops   = 0,
2332         };
2333         const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2334
2335         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2336         encode_compound_hdr(&xdr, req, &hdr);
2337         encode_setclientid_confirm(&xdr, arg, &hdr);
2338         encode_putrootfh(&xdr, &hdr);
2339         encode_fsinfo(&xdr, lease_bitmap, &hdr);
2340         encode_nops(&hdr);
2341         return 0;
2342 }
2343
2344 /*
2345  * DELEGRETURN request
2346  */
2347 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2348 {
2349         struct xdr_stream xdr;
2350         struct compound_hdr hdr = {
2351                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2352         };
2353
2354         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2355         encode_compound_hdr(&xdr, req, &hdr);
2356         encode_sequence(&xdr, &args->seq_args, &hdr);
2357         encode_putfh(&xdr, args->fhandle, &hdr);
2358         encode_delegreturn(&xdr, args->stateid, &hdr);
2359         encode_getfattr(&xdr, args->bitmask, &hdr);
2360         encode_nops(&hdr);
2361         return 0;
2362 }
2363
2364 /*
2365  * Encode FS_LOCATIONS request
2366  */
2367 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2368 {
2369         struct xdr_stream xdr;
2370         struct compound_hdr hdr = {
2371                 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2372         };
2373         uint32_t replen;
2374
2375         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2376         encode_compound_hdr(&xdr, req, &hdr);
2377         encode_sequence(&xdr, &args->seq_args, &hdr);
2378         encode_putfh(&xdr, args->dir_fh, &hdr);
2379         encode_lookup(&xdr, args->name, &hdr);
2380         replen = hdr.replen;    /* get the attribute into args->page */
2381         encode_fs_locations(&xdr, args->bitmask, &hdr);
2382
2383         xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2384                         0, PAGE_SIZE);
2385         encode_nops(&hdr);
2386         return 0;
2387 }
2388
2389 #if defined(CONFIG_NFS_V4_1)
2390 /*
2391  * EXCHANGE_ID request
2392  */
2393 static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2394                                     struct nfs41_exchange_id_args *args)
2395 {
2396         struct xdr_stream xdr;
2397         struct compound_hdr hdr = {
2398                 .minorversion = args->client->cl_minorversion,
2399         };
2400
2401         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2402         encode_compound_hdr(&xdr, req, &hdr);
2403         encode_exchange_id(&xdr, args, &hdr);
2404         encode_nops(&hdr);
2405         return 0;
2406 }
2407
2408 /*
2409  * a CREATE_SESSION request
2410  */
2411 static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2412                                        struct nfs41_create_session_args *args)
2413 {
2414         struct xdr_stream xdr;
2415         struct compound_hdr hdr = {
2416                 .minorversion = args->client->cl_minorversion,
2417         };
2418
2419         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2420         encode_compound_hdr(&xdr, req, &hdr);
2421         encode_create_session(&xdr, args, &hdr);
2422         encode_nops(&hdr);
2423         return 0;
2424 }
2425
2426 /*
2427  * a DESTROY_SESSION request
2428  */
2429 static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2430                                         struct nfs4_session *session)
2431 {
2432         struct xdr_stream xdr;
2433         struct compound_hdr hdr = {
2434                 .minorversion = session->clp->cl_minorversion,
2435         };
2436
2437         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2438         encode_compound_hdr(&xdr, req, &hdr);
2439         encode_destroy_session(&xdr, session, &hdr);
2440         encode_nops(&hdr);
2441         return 0;
2442 }
2443
2444 /*
2445  * a SEQUENCE request
2446  */
2447 static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2448                                  struct nfs4_sequence_args *args)
2449 {
2450         struct xdr_stream xdr;
2451         struct compound_hdr hdr = {
2452                 .minorversion = nfs4_xdr_minorversion(args),
2453         };
2454
2455         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2456         encode_compound_hdr(&xdr, req, &hdr);
2457         encode_sequence(&xdr, args, &hdr);
2458         encode_nops(&hdr);
2459         return 0;
2460 }
2461
2462 /*
2463  * a GET_LEASE_TIME request
2464  */
2465 static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2466                                        struct nfs4_get_lease_time_args *args)
2467 {
2468         struct xdr_stream xdr;
2469         struct compound_hdr hdr = {
2470                 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2471         };
2472         const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2473
2474         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2475         encode_compound_hdr(&xdr, req, &hdr);
2476         encode_sequence(&xdr, &args->la_seq_args, &hdr);
2477         encode_putrootfh(&xdr, &hdr);
2478         encode_fsinfo(&xdr, lease_bitmap, &hdr);
2479         encode_nops(&hdr);
2480         return 0;
2481 }
2482
2483 /*
2484  * a RECLAIM_COMPLETE request
2485  */
2486 static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, uint32_t *p,
2487                                      struct nfs41_reclaim_complete_args *args)
2488 {
2489         struct xdr_stream xdr;
2490         struct compound_hdr hdr = {
2491                 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2492         };
2493
2494         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2495         encode_compound_hdr(&xdr, req, &hdr);
2496         encode_sequence(&xdr, &args->seq_args, &hdr);
2497         encode_reclaim_complete(&xdr, args, &hdr);
2498         encode_nops(&hdr);
2499         return 0;
2500 }
2501
2502 #endif /* CONFIG_NFS_V4_1 */
2503
2504 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2505 {
2506         dprintk("nfs: %s: prematurely hit end of receive buffer. "
2507                 "Remaining buffer length is %tu words.\n",
2508                 func, xdr->end - xdr->p);
2509 }
2510
2511 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2512 {
2513         __be32 *p;
2514
2515         p = xdr_inline_decode(xdr, 4);
2516         if (unlikely(!p))
2517                 goto out_overflow;
2518         *len = be32_to_cpup(p);
2519         p = xdr_inline_decode(xdr, *len);
2520         if (unlikely(!p))
2521                 goto out_overflow;
2522         *string = (char *)p;
2523         return 0;
2524 out_overflow:
2525         print_overflow_msg(__func__, xdr);
2526         return -EIO;
2527 }
2528
2529 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2530 {
2531         __be32 *p;
2532
2533         p = xdr_inline_decode(xdr, 8);
2534         if (unlikely(!p))
2535                 goto out_overflow;
2536         hdr->status = be32_to_cpup(p++);
2537         hdr->taglen = be32_to_cpup(p);
2538
2539         p = xdr_inline_decode(xdr, hdr->taglen + 4);
2540         if (unlikely(!p))
2541                 goto out_overflow;
2542         hdr->tag = (char *)p;
2543         p += XDR_QUADLEN(hdr->taglen);
2544         hdr->nops = be32_to_cpup(p);
2545         if (unlikely(hdr->nops < 1))
2546                 return nfs4_stat_to_errno(hdr->status);
2547         return 0;
2548 out_overflow:
2549         print_overflow_msg(__func__, xdr);
2550         return -EIO;
2551 }
2552
2553 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2554 {
2555         __be32 *p;
2556         uint32_t opnum;
2557         int32_t nfserr;
2558
2559         p = xdr_inline_decode(xdr, 8);
2560         if (unlikely(!p))
2561                 goto out_overflow;
2562         opnum = be32_to_cpup(p++);
2563         if (opnum != expected) {
2564                 dprintk("nfs: Server returned operation"
2565                         " %d but we issued a request for %d\n",
2566                                 opnum, expected);
2567                 return -EIO;
2568         }
2569         nfserr = be32_to_cpup(p);
2570         if (nfserr != NFS_OK)
2571                 return nfs4_stat_to_errno(nfserr);
2572         return 0;
2573 out_overflow:
2574         print_overflow_msg(__func__, xdr);
2575         return -EIO;
2576 }
2577
2578 /* Dummy routine */
2579 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2580 {
2581         __be32 *p;
2582         unsigned int strlen;
2583         char *str;
2584
2585         p = xdr_inline_decode(xdr, 12);
2586         if (likely(p))
2587                 return decode_opaque_inline(xdr, &strlen, &str);
2588         print_overflow_msg(__func__, xdr);
2589         return -EIO;
2590 }
2591
2592 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2593 {
2594         uint32_t bmlen;
2595         __be32 *p;
2596
2597         p = xdr_inline_decode(xdr, 4);
2598         if (unlikely(!p))
2599                 goto out_overflow;
2600         bmlen = be32_to_cpup(p);
2601
2602         bitmap[0] = bitmap[1] = 0;
2603         p = xdr_inline_decode(xdr, (bmlen << 2));
2604         if (unlikely(!p))
2605                 goto out_overflow;
2606         if (bmlen > 0) {
2607                 bitmap[0] = be32_to_cpup(p++);
2608                 if (bmlen > 1)
2609                         bitmap[1] = be32_to_cpup(p);
2610         }
2611         return 0;
2612 out_overflow:
2613         print_overflow_msg(__func__, xdr);
2614         return -EIO;
2615 }
2616
2617 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2618 {
2619         __be32 *p;
2620
2621         p = xdr_inline_decode(xdr, 4);
2622         if (unlikely(!p))
2623                 goto out_overflow;
2624         *attrlen = be32_to_cpup(p);
2625         *savep = xdr->p;
2626         return 0;
2627 out_overflow:
2628         print_overflow_msg(__func__, xdr);
2629         return -EIO;
2630 }
2631
2632 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2633 {
2634         if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2635                 decode_attr_bitmap(xdr, bitmask);
2636                 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2637         } else
2638                 bitmask[0] = bitmask[1] = 0;
2639         dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2640         return 0;
2641 }
2642
2643 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2644 {
2645         __be32 *p;
2646         int ret = 0;
2647
2648         *type = 0;
2649         if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2650                 return -EIO;
2651         if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2652                 p = xdr_inline_decode(xdr, 4);
2653                 if (unlikely(!p))
2654                         goto out_overflow;
2655                 *type = be32_to_cpup(p);
2656                 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2657                         dprintk("%s: bad type %d\n", __func__, *type);
2658                         return -EIO;
2659                 }
2660                 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2661                 ret = NFS_ATTR_FATTR_TYPE;
2662         }
2663         dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2664         return ret;
2665 out_overflow:
2666         print_overflow_msg(__func__, xdr);
2667         return -EIO;
2668 }
2669
2670 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2671 {
2672         __be32 *p;
2673         int ret = 0;
2674
2675         *change = 0;
2676         if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2677                 return -EIO;
2678         if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2679                 p = xdr_inline_decode(xdr, 8);
2680                 if (unlikely(!p))
2681                         goto out_overflow;
2682                 xdr_decode_hyper(p, change);
2683                 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2684                 ret = NFS_ATTR_FATTR_CHANGE;
2685         }
2686         dprintk("%s: change attribute=%Lu\n", __func__,
2687                         (unsigned long long)*change);
2688         return ret;
2689 out_overflow:
2690         print_overflow_msg(__func__, xdr);
2691         return -EIO;
2692 }
2693
2694 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2695 {
2696         __be32 *p;
2697         int ret = 0;
2698
2699         *size = 0;
2700         if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2701                 return -EIO;
2702         if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2703                 p = xdr_inline_decode(xdr, 8);
2704                 if (unlikely(!p))
2705                         goto out_overflow;
2706                 xdr_decode_hyper(p, size);
2707                 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2708                 ret = NFS_ATTR_FATTR_SIZE;
2709         }
2710         dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2711         return ret;
2712 out_overflow:
2713         print_overflow_msg(__func__, xdr);
2714         return -EIO;
2715 }
2716
2717 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2718 {
2719         __be32 *p;
2720
2721         *res = 0;
2722         if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2723                 return -EIO;
2724         if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2725                 p = xdr_inline_decode(xdr, 4);
2726                 if (unlikely(!p))
2727                         goto out_overflow;
2728                 *res = be32_to_cpup(p);
2729                 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2730         }
2731         dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2732         return 0;
2733 out_overflow:
2734         print_overflow_msg(__func__, xdr);
2735         return -EIO;
2736 }
2737
2738 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2739 {
2740         __be32 *p;
2741
2742         *res = 0;
2743         if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2744                 return -EIO;
2745         if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2746                 p = xdr_inline_decode(xdr, 4);
2747                 if (unlikely(!p))
2748                         goto out_overflow;
2749                 *res = be32_to_cpup(p);
2750                 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2751         }
2752         dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2753         return 0;
2754 out_overflow:
2755         print_overflow_msg(__func__, xdr);
2756         return -EIO;
2757 }
2758
2759 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2760 {
2761         __be32 *p;
2762         int ret = 0;
2763
2764         fsid->major = 0;
2765         fsid->minor = 0;
2766         if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2767                 return -EIO;
2768         if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2769                 p = xdr_inline_decode(xdr, 16);
2770                 if (unlikely(!p))
2771                         goto out_overflow;
2772                 p = xdr_decode_hyper(p, &fsid->major);
2773                 xdr_decode_hyper(p, &fsid->minor);
2774                 bitmap[0] &= ~FATTR4_WORD0_FSID;
2775                 ret = NFS_ATTR_FATTR_FSID;
2776         }
2777         dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2778                         (unsigned long long)fsid->major,
2779                         (unsigned long long)fsid->minor);
2780         return ret;
2781 out_overflow:
2782         print_overflow_msg(__func__, xdr);
2783         return -EIO;
2784 }
2785
2786 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2787 {
2788         __be32 *p;
2789
2790         *res = 60;
2791         if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2792                 return -EIO;
2793         if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2794                 p = xdr_inline_decode(xdr, 4);
2795                 if (unlikely(!p))
2796                         goto out_overflow;
2797                 *res = be32_to_cpup(p);
2798                 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2799         }
2800         dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2801         return 0;
2802 out_overflow:
2803         print_overflow_msg(__func__, xdr);
2804         return -EIO;
2805 }
2806
2807 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2808 {
2809         __be32 *p;
2810
2811         *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2812         if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2813                 return -EIO;
2814         if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2815                 p = xdr_inline_decode(xdr, 4);
2816                 if (unlikely(!p))
2817                         goto out_overflow;
2818                 *res = be32_to_cpup(p);
2819                 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2820         }
2821         dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2822         return 0;
2823 out_overflow:
2824         print_overflow_msg(__func__, xdr);
2825         return -EIO;
2826 }
2827
2828 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2829 {
2830         __be32 *p;
2831         int ret = 0;
2832
2833         *fileid = 0;
2834         if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2835                 return -EIO;
2836         if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2837                 p = xdr_inline_decode(xdr, 8);
2838                 if (unlikely(!p))
2839                         goto out_overflow;
2840                 xdr_decode_hyper(p, fileid);
2841                 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2842                 ret = NFS_ATTR_FATTR_FILEID;
2843         }
2844         dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2845         return ret;
2846 out_overflow:
2847         print_overflow_msg(__func__, xdr);
2848         return -EIO;
2849 }
2850
2851 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2852 {
2853         __be32 *p;
2854         int ret = 0;
2855
2856         *fileid = 0;
2857         if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2858                 return -EIO;
2859         if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2860                 p = xdr_inline_decode(xdr, 8);
2861                 if (unlikely(!p))
2862                         goto out_overflow;
2863                 xdr_decode_hyper(p, fileid);
2864                 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2865                 ret = NFS_ATTR_FATTR_FILEID;
2866         }
2867         dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2868         return ret;
2869 out_overflow:
2870         print_overflow_msg(__func__, xdr);
2871         return -EIO;
2872 }
2873
2874 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2875 {
2876         __be32 *p;
2877         int status = 0;
2878
2879         *res = 0;
2880         if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2881                 return -EIO;
2882         if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2883                 p = xdr_inline_decode(xdr, 8);
2884                 if (unlikely(!p))
2885                         goto out_overflow;
2886                 xdr_decode_hyper(p, res);
2887                 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2888         }
2889         dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
2890         return status;
2891 out_overflow:
2892         print_overflow_msg(__func__, xdr);
2893         return -EIO;
2894 }
2895
2896 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2897 {
2898         __be32 *p;
2899         int status = 0;
2900
2901         *res = 0;
2902         if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2903                 return -EIO;
2904         if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2905                 p = xdr_inline_decode(xdr, 8);
2906                 if (unlikely(!p))
2907                         goto out_overflow;
2908                 xdr_decode_hyper(p, res);
2909                 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2910         }
2911         dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
2912         return status;
2913 out_overflow:
2914         print_overflow_msg(__func__, xdr);
2915         return -EIO;
2916 }
2917
2918 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2919 {
2920         __be32 *p;
2921         int status = 0;
2922
2923         *res = 0;
2924         if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2925                 return -EIO;
2926         if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2927                 p = xdr_inline_decode(xdr, 8);
2928                 if (unlikely(!p))
2929                         goto out_overflow;
2930                 xdr_decode_hyper(p, res);
2931                 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2932         }
2933         dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
2934         return status;
2935 out_overflow:
2936         print_overflow_msg(__func__, xdr);
2937         return -EIO;
2938 }
2939
2940 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2941 {
2942         u32 n;
2943         __be32 *p;
2944         int status = 0;
2945
2946         p = xdr_inline_decode(xdr, 4);
2947         if (unlikely(!p))
2948                 goto out_overflow;
2949         n = be32_to_cpup(p);
2950         if (n == 0)
2951                 goto root_path;
2952         dprintk("path ");
2953         path->ncomponents = 0;
2954         while (path->ncomponents < n) {
2955                 struct nfs4_string *component = &path->components[path->ncomponents];
2956                 status = decode_opaque_inline(xdr, &component->len, &component->data);
2957                 if (unlikely(status != 0))
2958                         goto out_eio;
2959                 if (path->ncomponents != n)
2960                         dprintk("/");
2961                 dprintk("%s", component->data);
2962                 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2963                         path->ncomponents++;
2964                 else {
2965                         dprintk("cannot parse %d components in path\n", n);
2966                         goto out_eio;
2967                 }
2968         }
2969 out:
2970         dprintk("\n");
2971         return status;
2972 root_path:
2973 /* a root pathname is sent as a zero component4 */
2974         path->ncomponents = 1;
2975         path->components[0].len=0;
2976         path->components[0].data=NULL;
2977         dprintk("path /\n");
2978         goto out;
2979 out_eio:
2980         dprintk(" status %d", status);
2981         status = -EIO;
2982         goto out;
2983 out_overflow:
2984         print_overflow_msg(__func__, xdr);
2985         return -EIO;
2986 }
2987
2988 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2989 {
2990         int n;
2991         __be32 *p;
2992         int status = -EIO;
2993
2994         if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2995                 goto out;
2996         status = 0;
2997         if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2998                 goto out;
2999         dprintk("%s: fsroot ", __func__);
3000         status = decode_pathname(xdr, &res->fs_path);
3001         if (unlikely(status != 0))
3002                 goto out;
3003         p = xdr_inline_decode(xdr, 4);
3004         if (unlikely(!p))
3005                 goto out_overflow;
3006         n = be32_to_cpup(p);
3007         if (n <= 0)
3008                 goto out_eio;
3009         res->nlocations = 0;
3010         while (res->nlocations < n) {
3011                 u32 m;
3012                 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3013
3014                 p = xdr_inline_decode(xdr, 4);
3015                 if (unlikely(!p))
3016                         goto out_overflow;
3017                 m = be32_to_cpup(p);
3018
3019                 loc->nservers = 0;
3020                 dprintk("%s: servers ", __func__);
3021                 while (loc->nservers < m) {
3022                         struct nfs4_string *server = &loc->servers[loc->nservers];
3023                         status = decode_opaque_inline(xdr, &server->len, &server->data);
3024                         if (unlikely(status != 0))
3025                                 goto out_eio;
3026                         dprintk("%s ", server->data);
3027                         if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3028                                 loc->nservers++;
3029                         else {
3030                                 unsigned int i;
3031                                 dprintk("%s: using first %u of %u servers "
3032                                         "returned for location %u\n",
3033                                                 __func__,
3034                                                 NFS4_FS_LOCATION_MAXSERVERS,
3035                                                 m, res->nlocations);
3036                                 for (i = loc->nservers; i < m; i++) {
3037                                         unsigned int len;
3038                                         char *data;
3039                                         status = decode_opaque_inline(xdr, &len, &data);
3040                                         if (unlikely(status != 0))
3041                                                 goto out_eio;
3042                                 }
3043                         }
3044                 }
3045                 status = decode_pathname(xdr, &loc->rootpath);
3046                 if (unlikely(status != 0))
3047                         goto out_eio;
3048                 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3049                         res->nlocations++;
3050         }
3051         if (res->nlocations != 0)
3052                 status = NFS_ATTR_FATTR_V4_REFERRAL;
3053 out:
3054         dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3055         return status;
3056 out_overflow:
3057         print_overflow_msg(__func__, xdr);
3058 out_eio:
3059         status = -EIO;
3060         goto out;
3061 }
3062
3063 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3064 {
3065         __be32 *p;
3066         int status = 0;
3067
3068         *res = 0;
3069         if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3070                 return -EIO;
3071         if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3072                 p = xdr_inline_decode(xdr, 8);
3073                 if (unlikely(!p))
3074                         goto out_overflow;
3075                 xdr_decode_hyper(p, res);
3076                 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3077         }
3078         dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3079         return status;
3080 out_overflow:
3081         print_overflow_msg(__func__, xdr);
3082         return -EIO;
3083 }
3084
3085 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3086 {
3087         __be32 *p;
3088         int status = 0;
3089
3090         *maxlink = 1;
3091         if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3092                 return -EIO;
3093         if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3094                 p = xdr_inline_decode(xdr, 4);
3095                 if (unlikely(!p))
3096                         goto out_overflow;
3097                 *maxlink = be32_to_cpup(p);
3098                 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3099         }
3100         dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3101         return status;
3102 out_overflow:
3103         print_overflow_msg(__func__, xdr);
3104         return -EIO;
3105 }
3106
3107 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3108 {
3109         __be32 *p;
3110         int status = 0;
3111
3112         *maxname = 1024;
3113         if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3114                 return -EIO;
3115         if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3116                 p = xdr_inline_decode(xdr, 4);
3117                 if (unlikely(!p))
3118                         goto out_overflow;
3119                 *maxname = be32_to_cpup(p);
3120                 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3121         }
3122         dprintk("%s: maxname=%u\n", __func__, *maxname);
3123         return status;
3124 out_overflow:
3125         print_overflow_msg(__func__, xdr);
3126         return -EIO;
3127 }
3128
3129 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3130 {
3131         __be32 *p;
3132         int status = 0;
3133
3134         *res = 1024;
3135         if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3136                 return -EIO;
3137         if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3138                 uint64_t maxread;
3139                 p = xdr_inline_decode(xdr, 8);
3140                 if (unlikely(!p))
3141                         goto out_overflow;
3142                 xdr_decode_hyper(p, &maxread);
3143                 if (maxread > 0x7FFFFFFF)
3144                         maxread = 0x7FFFFFFF;
3145                 *res = (uint32_t)maxread;
3146                 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3147         }
3148         dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3149         return status;
3150 out_overflow:
3151         print_overflow_msg(__func__, xdr);
3152         return -EIO;
3153 }
3154
3155 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3156 {
3157         __be32 *p;
3158         int status = 0;
3159
3160         *res = 1024;
3161         if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3162                 return -EIO;
3163         if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3164                 uint64_t maxwrite;
3165                 p = xdr_inline_decode(xdr, 8);
3166                 if (unlikely(!p))
3167                         goto out_overflow;
3168                 xdr_decode_hyper(p, &maxwrite);
3169                 if (maxwrite > 0x7FFFFFFF)
3170                         maxwrite = 0x7FFFFFFF;
3171                 *res = (uint32_t)maxwrite;
3172                 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3173         }
3174         dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3175         return status;
3176 out_overflow:
3177         print_overflow_msg(__func__, xdr);
3178         return -EIO;
3179 }
3180
3181 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3182 {
3183         uint32_t tmp;
3184         __be32 *p;
3185         int ret = 0;
3186
3187         *mode = 0;
3188         if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3189                 return -EIO;
3190         if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3191                 p = xdr_inline_decode(xdr, 4);
3192                 if (unlikely(!p))
3193                         goto out_overflow;
3194                 tmp = be32_to_cpup(p);
3195                 *mode = tmp & ~S_IFMT;
3196                 bitmap[1] &= ~FATTR4_WORD1_MODE;
3197                 ret = NFS_ATTR_FATTR_MODE;
3198         }
3199         dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3200         return ret;
3201 out_overflow:
3202         print_overflow_msg(__func__, xdr);
3203         return -EIO;
3204 }
3205
3206 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3207 {
3208         __be32 *p;
3209         int ret = 0;
3210
3211         *nlink = 1;
3212         if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3213                 return -EIO;
3214         if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3215                 p = xdr_inline_decode(xdr, 4);
3216                 if (unlikely(!p))
3217                         goto out_overflow;
3218                 *nlink = be32_to_cpup(p);
3219                 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3220                 ret = NFS_ATTR_FATTR_NLINK;
3221         }
3222         dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3223         return ret;
3224 out_overflow:
3225         print_overflow_msg(__func__, xdr);
3226         return -EIO;
3227 }
3228
3229 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,