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