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