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