Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/param.h> |
| 39 | #include <linux/time.h> |
| 40 | #include <linux/mm.h> |
| 41 | #include <linux/slab.h> |
| 42 | #include <linux/utsname.h> |
| 43 | #include <linux/errno.h> |
| 44 | #include <linux/string.h> |
| 45 | #include <linux/in.h> |
| 46 | #include <linux/pagemap.h> |
| 47 | #include <linux/proc_fs.h> |
| 48 | #include <linux/kdev_t.h> |
| 49 | #include <linux/sunrpc/clnt.h> |
| 50 | #include <linux/nfs.h> |
| 51 | #include <linux/nfs4.h> |
| 52 | #include <linux/nfs_fs.h> |
| 53 | #include <linux/nfs_idmap.h> |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 54 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | #define NFSDBG_FACILITY NFSDBG_XDR |
| 57 | |
| 58 | /* Mapping from NFS error code to "errno" error code. */ |
| 59 | #define errno_NFSERR_IO EIO |
| 60 | |
David Howells | 0a8ea43 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 61 | static int nfs4_stat_to_errno(int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ |
| 64 | #ifdef DEBUG |
| 65 | #define NFS4_MAXTAGLEN 20 |
| 66 | #else |
| 67 | #define NFS4_MAXTAGLEN 0 |
| 68 | #endif |
| 69 | |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 70 | /* lock,open owner id: |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 71 | * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 73 | #define open_owner_id_maxsz (1 + 4) |
| 74 | #define lock_owner_id_maxsz (1 + 4) |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 75 | #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) |
| 77 | #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) |
| 78 | #define op_encode_hdr_maxsz (1) |
| 79 | #define op_decode_hdr_maxsz (2) |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 80 | #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) |
| 81 | #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) |
| 82 | #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) |
| 83 | #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ |
| 85 | (NFS4_FHSIZE >> 2)) |
| 86 | #define decode_putfh_maxsz (op_decode_hdr_maxsz) |
| 87 | #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) |
| 88 | #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) |
| 89 | #define encode_getfh_maxsz (op_encode_hdr_maxsz) |
| 90 | #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ |
| 91 | ((3+NFS4_FHSIZE) >> 2)) |
J. Bruce Fields | 9692820 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 92 | #define nfs4_fattr_bitmap_maxsz 3 |
| 93 | #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) |
| 95 | #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) |
Trond Myklebust | bd625ba | 2007-07-08 18:38:23 -0400 | [diff] [blame] | 96 | #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) |
| 97 | #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) |
J. Bruce Fields | 9692820 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 98 | /* This is based on getfattr, which uses the most attributes: */ |
| 99 | #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ |
Trond Myklebust | bd625ba | 2007-07-08 18:38:23 -0400 | [diff] [blame] | 100 | 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz)) |
J. Bruce Fields | 9692820 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 101 | #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ |
| 102 | nfs4_fattr_value_maxsz) |
| 103 | #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 104 | #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ |
| 105 | 1 + 2 + 1 + \ |
| 106 | nfs4_owner_maxsz + \ |
| 107 | nfs4_group_maxsz + \ |
| 108 | 4 + 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | #define encode_savefh_maxsz (op_encode_hdr_maxsz) |
| 110 | #define decode_savefh_maxsz (op_decode_hdr_maxsz) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 111 | #define encode_restorefh_maxsz (op_encode_hdr_maxsz) |
| 112 | #define decode_restorefh_maxsz (op_decode_hdr_maxsz) |
Fred Isaman | 2f42b5d | 2008-03-13 15:26:30 +0200 | [diff] [blame] | 113 | #define encode_fsinfo_maxsz (encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11) |
| 115 | #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) |
| 116 | #define decode_renew_maxsz (op_decode_hdr_maxsz) |
| 117 | #define encode_setclientid_maxsz \ |
| 118 | (op_encode_hdr_maxsz + \ |
Chuck Lever | cc38bac | 2007-12-10 14:56:54 -0500 | [diff] [blame] | 119 | XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ |
| 120 | XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \ |
| 121 | 1 /* sc_prog */ + \ |
| 122 | XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ |
| 123 | XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ |
| 124 | 1) /* sc_cb_ident */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | #define decode_setclientid_maxsz \ |
| 126 | (op_decode_hdr_maxsz + \ |
| 127 | 2 + \ |
| 128 | 1024) /* large value for CLID_INUSE */ |
| 129 | #define encode_setclientid_confirm_maxsz \ |
| 130 | (op_encode_hdr_maxsz + \ |
| 131 | 3 + (NFS4_VERIFIER_SIZE >> 2)) |
| 132 | #define decode_setclientid_confirm_maxsz \ |
| 133 | (op_decode_hdr_maxsz) |
Trond Myklebust | e688962 | 2007-07-02 13:58:30 -0400 | [diff] [blame] | 134 | #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) |
| 135 | #define decode_lookup_maxsz (op_decode_hdr_maxsz) |
Trond Myklebust | 2cebf82 | 2007-07-02 13:57:28 -0400 | [diff] [blame] | 136 | #define encode_share_access_maxsz \ |
| 137 | (2) |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 138 | #define encode_createmode_maxsz (1 + encode_attrs_maxsz) |
Trond Myklebust | 2cebf82 | 2007-07-02 13:57:28 -0400 | [diff] [blame] | 139 | #define encode_opentype_maxsz (1 + encode_createmode_maxsz) |
| 140 | #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) |
| 141 | #define encode_open_maxsz (op_encode_hdr_maxsz + \ |
| 142 | 2 + encode_share_access_maxsz + 2 + \ |
| 143 | open_owner_id_maxsz + \ |
| 144 | encode_opentype_maxsz + \ |
| 145 | encode_claim_null_maxsz) |
| 146 | #define decode_ace_maxsz (3 + nfs4_owner_maxsz) |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 147 | #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ |
Trond Myklebust | 2cebf82 | 2007-07-02 13:57:28 -0400 | [diff] [blame] | 148 | decode_ace_maxsz) |
| 149 | #define decode_change_info_maxsz (5) |
| 150 | #define decode_open_maxsz (op_decode_hdr_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 151 | decode_stateid_maxsz + \ |
Trond Myklebust | 2cebf82 | 2007-07-02 13:57:28 -0400 | [diff] [blame] | 152 | decode_change_info_maxsz + 1 + \ |
| 153 | nfs4_fattr_bitmap_maxsz + \ |
| 154 | decode_delegation_maxsz) |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 155 | #define encode_open_confirm_maxsz \ |
| 156 | (op_encode_hdr_maxsz + \ |
| 157 | encode_stateid_maxsz + 1) |
| 158 | #define decode_open_confirm_maxsz \ |
| 159 | (op_decode_hdr_maxsz + \ |
| 160 | decode_stateid_maxsz) |
| 161 | #define encode_open_downgrade_maxsz \ |
| 162 | (op_encode_hdr_maxsz + \ |
| 163 | encode_stateid_maxsz + 1 + \ |
| 164 | encode_share_access_maxsz) |
| 165 | #define decode_open_downgrade_maxsz \ |
| 166 | (op_decode_hdr_maxsz + \ |
| 167 | decode_stateid_maxsz) |
| 168 | #define encode_close_maxsz (op_encode_hdr_maxsz + \ |
| 169 | 1 + encode_stateid_maxsz) |
| 170 | #define decode_close_maxsz (op_decode_hdr_maxsz + \ |
| 171 | decode_stateid_maxsz) |
| 172 | #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ |
| 173 | encode_stateid_maxsz + \ |
| 174 | encode_attrs_maxsz) |
| 175 | #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ |
| 176 | nfs4_fattr_bitmap_maxsz) |
| 177 | #define encode_read_maxsz (op_encode_hdr_maxsz + \ |
| 178 | encode_stateid_maxsz + 3) |
| 179 | #define decode_read_maxsz (op_decode_hdr_maxsz + 2) |
| 180 | #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ |
| 181 | 2 + encode_verifier_maxsz + 5) |
| 182 | #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ |
| 183 | decode_verifier_maxsz) |
| 184 | #define encode_readlink_maxsz (op_encode_hdr_maxsz) |
| 185 | #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) |
| 186 | #define encode_write_maxsz (op_encode_hdr_maxsz + \ |
| 187 | encode_stateid_maxsz + 4) |
| 188 | #define decode_write_maxsz (op_decode_hdr_maxsz + \ |
| 189 | 2 + decode_verifier_maxsz) |
| 190 | #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) |
| 191 | #define decode_commit_maxsz (op_decode_hdr_maxsz + \ |
| 192 | decode_verifier_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | #define encode_remove_maxsz (op_encode_hdr_maxsz + \ |
| 194 | nfs4_name_maxsz) |
Benny Halevy | 6ce1839 | 2009-04-01 09:22:06 -0400 | [diff] [blame] | 195 | #define decode_remove_maxsz (op_decode_hdr_maxsz + \ |
| 196 | decode_change_info_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | #define encode_rename_maxsz (op_encode_hdr_maxsz + \ |
| 198 | 2 * nfs4_name_maxsz) |
Benny Halevy | 6ce1839 | 2009-04-01 09:22:06 -0400 | [diff] [blame] | 199 | #define decode_rename_maxsz (op_decode_hdr_maxsz + \ |
| 200 | decode_change_info_maxsz + \ |
| 201 | decode_change_info_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | #define encode_link_maxsz (op_encode_hdr_maxsz + \ |
| 203 | nfs4_name_maxsz) |
Benny Halevy | 6ce1839 | 2009-04-01 09:22:06 -0400 | [diff] [blame] | 204 | #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 205 | #define encode_lock_maxsz (op_encode_hdr_maxsz + \ |
| 206 | 7 + \ |
| 207 | 1 + encode_stateid_maxsz + 8) |
| 208 | #define decode_lock_denied_maxsz \ |
| 209 | (8 + decode_lockowner_maxsz) |
| 210 | #define decode_lock_maxsz (op_decode_hdr_maxsz + \ |
| 211 | decode_lock_denied_maxsz) |
| 212 | #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12) |
| 213 | #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ |
| 214 | decode_lock_denied_maxsz) |
| 215 | #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ |
| 216 | encode_stateid_maxsz + \ |
| 217 | 4) |
| 218 | #define decode_locku_maxsz (op_decode_hdr_maxsz + \ |
| 219 | decode_stateid_maxsz) |
| 220 | #define encode_access_maxsz (op_encode_hdr_maxsz + 1) |
| 221 | #define decode_access_maxsz (op_decode_hdr_maxsz + 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ |
| 223 | 1 + nfs4_name_maxsz + \ |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 224 | 1 + \ |
J. Bruce Fields | 9692820 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 225 | nfs4_fattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) |
| 227 | #define encode_create_maxsz (op_encode_hdr_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 228 | 1 + 2 + nfs4_name_maxsz + \ |
| 229 | encode_attrs_maxsz) |
Trond Myklebust | 2cebf82 | 2007-07-02 13:57:28 -0400 | [diff] [blame] | 230 | #define decode_create_maxsz (op_decode_hdr_maxsz + \ |
| 231 | decode_change_info_maxsz + \ |
| 232 | nfs4_fattr_bitmap_maxsz) |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 233 | #define encode_statfs_maxsz (encode_getattr_maxsz) |
| 234 | #define decode_statfs_maxsz (decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) |
| 236 | #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 237 | #define encode_getacl_maxsz (encode_getattr_maxsz) |
| 238 | #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ |
| 239 | nfs4_fattr_bitmap_maxsz + 1) |
| 240 | #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ |
| 241 | encode_stateid_maxsz + 3) |
| 242 | #define decode_setacl_maxsz (decode_setattr_maxsz) |
Trond Myklebust | e688962 | 2007-07-02 13:58:30 -0400 | [diff] [blame] | 243 | #define encode_fs_locations_maxsz \ |
| 244 | (encode_getattr_maxsz) |
| 245 | #define decode_fs_locations_maxsz \ |
| 246 | (0) |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 247 | |
| 248 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 249 | #define NFS4_MAX_MACHINE_NAME_LEN (64) |
| 250 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 251 | #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ |
| 252 | encode_verifier_maxsz + \ |
| 253 | 1 /* co_ownerid.len */ + \ |
| 254 | XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \ |
| 255 | 1 /* flags */ + \ |
| 256 | 1 /* spa_how */ + \ |
| 257 | 0 /* SP4_NONE (for now) */ + \ |
| 258 | 1 /* zero implemetation id array */) |
| 259 | #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ |
| 260 | 2 /* eir_clientid */ + \ |
| 261 | 1 /* eir_sequenceid */ + \ |
| 262 | 1 /* eir_flags */ + \ |
| 263 | 1 /* spr_how */ + \ |
| 264 | 0 /* SP4_NONE (for now) */ + \ |
| 265 | 2 /* eir_server_owner.so_minor_id */ + \ |
| 266 | /* eir_server_owner.so_major_id<> */ \ |
| 267 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ |
| 268 | /* eir_server_scope<> */ \ |
| 269 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ |
| 270 | 1 /* eir_server_impl_id array length */ + \ |
| 271 | 0 /* ignored eir_server_impl_id contents */) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 272 | #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) |
| 273 | #define decode_channel_attrs_maxsz (6 + \ |
| 274 | 1 /* ca_rdma_ird.len */ + \ |
| 275 | 1 /* ca_rdma_ird */) |
| 276 | #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ |
| 277 | 2 /* csa_clientid */ + \ |
| 278 | 1 /* csa_sequence */ + \ |
| 279 | 1 /* csa_flags */ + \ |
| 280 | encode_channel_attrs_maxsz + \ |
| 281 | encode_channel_attrs_maxsz + \ |
| 282 | 1 /* csa_cb_program */ + \ |
| 283 | 1 /* csa_sec_parms.len (1) */ + \ |
| 284 | 1 /* cb_secflavor (AUTH_SYS) */ + \ |
| 285 | 1 /* stamp */ + \ |
| 286 | 1 /* machinename.len */ + \ |
| 287 | XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ |
| 288 | 1 /* uid */ + \ |
| 289 | 1 /* gid */ + \ |
| 290 | 1 /* gids.len (0) */) |
| 291 | #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ |
| 292 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ |
| 293 | 1 /* csr_sequence */ + \ |
| 294 | 1 /* csr_flags */ + \ |
| 295 | decode_channel_attrs_maxsz + \ |
| 296 | decode_channel_attrs_maxsz) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 297 | #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) |
| 298 | #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 299 | #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ |
| 300 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) |
| 301 | #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ |
| 302 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 303 | #else /* CONFIG_NFS_V4_1 */ |
| 304 | #define encode_sequence_maxsz 0 |
| 305 | #define decode_sequence_maxsz 0 |
| 306 | #endif /* CONFIG_NFS_V4_1 */ |
| 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ |
| 309 | #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ |
| 310 | #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 311 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 313 | encode_read_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 315 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | decode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 317 | decode_read_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 319 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 321 | encode_readlink_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 323 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | decode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 325 | decode_readlink_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 327 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 329 | encode_readdir_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 331 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | decode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 333 | decode_readdir_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 335 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 337 | encode_write_maxsz + \ |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 338 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 340 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | decode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 342 | decode_write_maxsz + \ |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 343 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 345 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 347 | encode_commit_maxsz + \ |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 348 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 350 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | decode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 352 | decode_commit_maxsz + \ |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 353 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 355 | encode_sequence_maxsz + \ |
Trond Myklebust | 2cebf82 | 2007-07-02 13:57:28 -0400 | [diff] [blame] | 356 | encode_putfh_maxsz + \ |
| 357 | encode_savefh_maxsz + \ |
| 358 | encode_open_maxsz + \ |
| 359 | encode_getfh_maxsz + \ |
| 360 | encode_getattr_maxsz + \ |
| 361 | encode_restorefh_maxsz + \ |
| 362 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 364 | decode_sequence_maxsz + \ |
Trond Myklebust | 2cebf82 | 2007-07-02 13:57:28 -0400 | [diff] [blame] | 365 | decode_putfh_maxsz + \ |
| 366 | decode_savefh_maxsz + \ |
| 367 | decode_open_maxsz + \ |
| 368 | decode_getfh_maxsz + \ |
| 369 | decode_getattr_maxsz + \ |
| 370 | decode_restorefh_maxsz + \ |
| 371 | decode_getattr_maxsz) |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 372 | #define NFS4_enc_open_confirm_sz \ |
| 373 | (compound_encode_hdr_maxsz + \ |
| 374 | encode_putfh_maxsz + \ |
| 375 | encode_open_confirm_maxsz) |
| 376 | #define NFS4_dec_open_confirm_sz \ |
| 377 | (compound_decode_hdr_maxsz + \ |
| 378 | decode_putfh_maxsz + \ |
| 379 | decode_open_confirm_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 381 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | encode_putfh_maxsz + \ |
Trond Myklebust | 2cebf82 | 2007-07-02 13:57:28 -0400 | [diff] [blame] | 383 | encode_open_maxsz + \ |
| 384 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 386 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | decode_putfh_maxsz + \ |
Trond Myklebust | 2cebf82 | 2007-07-02 13:57:28 -0400 | [diff] [blame] | 388 | decode_open_maxsz + \ |
| 389 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | #define NFS4_enc_open_downgrade_sz \ |
| 391 | (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 392 | encode_sequence_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 393 | encode_putfh_maxsz + \ |
| 394 | encode_open_downgrade_maxsz + \ |
| 395 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | #define NFS4_dec_open_downgrade_sz \ |
| 397 | (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 398 | decode_sequence_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 399 | decode_putfh_maxsz + \ |
| 400 | decode_open_downgrade_maxsz + \ |
| 401 | decode_getattr_maxsz) |
| 402 | #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 403 | encode_sequence_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 404 | encode_putfh_maxsz + \ |
| 405 | encode_close_maxsz + \ |
| 406 | encode_getattr_maxsz) |
| 407 | #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 408 | decode_sequence_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 409 | decode_putfh_maxsz + \ |
| 410 | decode_close_maxsz + \ |
| 411 | decode_getattr_maxsz) |
| 412 | #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 413 | encode_sequence_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 414 | encode_putfh_maxsz + \ |
| 415 | encode_setattr_maxsz + \ |
| 416 | encode_getattr_maxsz) |
| 417 | #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 418 | decode_sequence_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 419 | decode_putfh_maxsz + \ |
| 420 | decode_setattr_maxsz + \ |
| 421 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 423 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | encode_putfh_maxsz + \ |
| 425 | encode_fsinfo_maxsz) |
| 426 | #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 427 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | decode_putfh_maxsz + \ |
| 429 | decode_fsinfo_maxsz) |
| 430 | #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ |
| 431 | encode_renew_maxsz) |
| 432 | #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ |
| 433 | decode_renew_maxsz) |
| 434 | #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ |
| 435 | encode_setclientid_maxsz) |
| 436 | #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ |
| 437 | decode_setclientid_maxsz) |
| 438 | #define NFS4_enc_setclientid_confirm_sz \ |
| 439 | (compound_encode_hdr_maxsz + \ |
| 440 | encode_setclientid_confirm_maxsz + \ |
| 441 | encode_putrootfh_maxsz + \ |
| 442 | encode_fsinfo_maxsz) |
| 443 | #define NFS4_dec_setclientid_confirm_sz \ |
| 444 | (compound_decode_hdr_maxsz + \ |
| 445 | decode_setclientid_confirm_maxsz + \ |
| 446 | decode_putrootfh_maxsz + \ |
| 447 | decode_fsinfo_maxsz) |
| 448 | #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 449 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 451 | encode_lock_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 453 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | decode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 455 | decode_lock_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 457 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 459 | encode_lockt_maxsz) |
| 460 | #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 461 | decode_sequence_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 462 | decode_putfh_maxsz + \ |
| 463 | decode_lockt_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 465 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 467 | encode_locku_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 469 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | decode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 471 | decode_locku_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 473 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | encode_putfh_maxsz + \ |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 475 | encode_access_maxsz + \ |
| 476 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 478 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | decode_putfh_maxsz + \ |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 480 | decode_access_maxsz + \ |
| 481 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 483 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | encode_putfh_maxsz + \ |
| 485 | encode_getattr_maxsz) |
| 486 | #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 487 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | decode_putfh_maxsz + \ |
| 489 | decode_getattr_maxsz) |
| 490 | #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 491 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | encode_putfh_maxsz + \ |
| 493 | encode_lookup_maxsz + \ |
| 494 | encode_getattr_maxsz + \ |
| 495 | encode_getfh_maxsz) |
| 496 | #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 497 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | decode_putfh_maxsz + \ |
Trond Myklebust | e688962 | 2007-07-02 13:58:30 -0400 | [diff] [blame] | 499 | decode_lookup_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | decode_getattr_maxsz + \ |
| 501 | decode_getfh_maxsz) |
| 502 | #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 503 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | encode_putrootfh_maxsz + \ |
| 505 | encode_getattr_maxsz + \ |
| 506 | encode_getfh_maxsz) |
| 507 | #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 508 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | decode_putrootfh_maxsz + \ |
| 510 | decode_getattr_maxsz + \ |
| 511 | decode_getfh_maxsz) |
| 512 | #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 513 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | encode_putfh_maxsz + \ |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 515 | encode_remove_maxsz + \ |
| 516 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 518 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | decode_putfh_maxsz + \ |
Benny Halevy | 6ce1839 | 2009-04-01 09:22:06 -0400 | [diff] [blame] | 520 | decode_remove_maxsz + \ |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 521 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 523 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | encode_putfh_maxsz + \ |
| 525 | encode_savefh_maxsz + \ |
| 526 | encode_putfh_maxsz + \ |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 527 | encode_rename_maxsz + \ |
| 528 | encode_getattr_maxsz + \ |
| 529 | encode_restorefh_maxsz + \ |
| 530 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 532 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | decode_putfh_maxsz + \ |
| 534 | decode_savefh_maxsz + \ |
| 535 | decode_putfh_maxsz + \ |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 536 | decode_rename_maxsz + \ |
| 537 | decode_getattr_maxsz + \ |
| 538 | decode_restorefh_maxsz + \ |
| 539 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 541 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | encode_putfh_maxsz + \ |
| 543 | encode_savefh_maxsz + \ |
| 544 | encode_putfh_maxsz + \ |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 545 | encode_link_maxsz + \ |
| 546 | decode_getattr_maxsz + \ |
| 547 | encode_restorefh_maxsz + \ |
| 548 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 550 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | decode_putfh_maxsz + \ |
| 552 | decode_savefh_maxsz + \ |
| 553 | decode_putfh_maxsz + \ |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 554 | decode_link_maxsz + \ |
| 555 | decode_getattr_maxsz + \ |
| 556 | decode_restorefh_maxsz + \ |
| 557 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 559 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | encode_putfh_maxsz + \ |
| 561 | encode_symlink_maxsz + \ |
| 562 | encode_getattr_maxsz + \ |
| 563 | encode_getfh_maxsz) |
| 564 | #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 565 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | decode_putfh_maxsz + \ |
| 567 | decode_symlink_maxsz + \ |
| 568 | decode_getattr_maxsz + \ |
| 569 | decode_getfh_maxsz) |
| 570 | #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 571 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | encode_putfh_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 573 | encode_savefh_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | encode_create_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 575 | encode_getfh_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | encode_getattr_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 577 | encode_restorefh_maxsz + \ |
| 578 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 580 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | decode_putfh_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 582 | decode_savefh_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | decode_create_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 584 | decode_getfh_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | decode_getattr_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 586 | decode_restorefh_maxsz + \ |
| 587 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 589 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | encode_putfh_maxsz + \ |
| 591 | encode_getattr_maxsz) |
| 592 | #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 593 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | decode_putfh_maxsz + \ |
| 595 | decode_getattr_maxsz) |
| 596 | #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 597 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 599 | encode_statfs_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 601 | decode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | decode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 603 | decode_statfs_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 605 | encode_sequence_maxsz + \ |
Trond Myklebust | ab91f26 | 2007-02-02 14:47:17 -0800 | [diff] [blame] | 606 | encode_putfh_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | encode_getattr_maxsz) |
| 608 | #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 609 | decode_sequence_maxsz + \ |
Trond Myklebust | ab91f26 | 2007-02-02 14:47:17 -0800 | [diff] [blame] | 610 | decode_putfh_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | decode_getattr_maxsz) |
| 612 | #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 613 | encode_sequence_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | encode_putfh_maxsz + \ |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 615 | encode_delegreturn_maxsz + \ |
| 616 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 618 | decode_sequence_maxsz + \ |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 619 | decode_delegreturn_maxsz + \ |
| 620 | decode_getattr_maxsz) |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 621 | #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 622 | encode_sequence_maxsz + \ |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 623 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 624 | encode_getacl_maxsz) |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 625 | #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 626 | decode_sequence_maxsz + \ |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 627 | decode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 628 | decode_getacl_maxsz) |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 629 | #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 630 | encode_sequence_maxsz + \ |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 631 | encode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 632 | encode_setacl_maxsz) |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 633 | #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 634 | decode_sequence_maxsz + \ |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 635 | decode_putfh_maxsz + \ |
Trond Myklebust | 9104a55 | 2007-07-17 21:52:42 -0400 | [diff] [blame] | 636 | decode_setacl_maxsz) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 637 | #define NFS4_enc_fs_locations_sz \ |
| 638 | (compound_encode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 639 | encode_sequence_maxsz + \ |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 640 | encode_putfh_maxsz + \ |
Trond Myklebust | e688962 | 2007-07-02 13:58:30 -0400 | [diff] [blame] | 641 | encode_lookup_maxsz + \ |
| 642 | encode_fs_locations_maxsz) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 643 | #define NFS4_dec_fs_locations_sz \ |
| 644 | (compound_decode_hdr_maxsz + \ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 645 | decode_sequence_maxsz + \ |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 646 | decode_putfh_maxsz + \ |
Trond Myklebust | e688962 | 2007-07-02 13:58:30 -0400 | [diff] [blame] | 647 | decode_lookup_maxsz + \ |
| 648 | decode_fs_locations_maxsz) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 649 | #if defined(CONFIG_NFS_V4_1) |
| 650 | #define NFS4_enc_exchange_id_sz \ |
| 651 | (compound_encode_hdr_maxsz + \ |
| 652 | encode_exchange_id_maxsz) |
| 653 | #define NFS4_dec_exchange_id_sz \ |
| 654 | (compound_decode_hdr_maxsz + \ |
| 655 | decode_exchange_id_maxsz) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 656 | #define NFS4_enc_create_session_sz \ |
| 657 | (compound_encode_hdr_maxsz + \ |
| 658 | encode_create_session_maxsz) |
| 659 | #define NFS4_dec_create_session_sz \ |
| 660 | (compound_decode_hdr_maxsz + \ |
| 661 | decode_create_session_maxsz) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 662 | #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ |
| 663 | encode_destroy_session_maxsz) |
| 664 | #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ |
| 665 | decode_destroy_session_maxsz) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 666 | #define NFS4_enc_sequence_sz \ |
| 667 | (compound_decode_hdr_maxsz + \ |
| 668 | encode_sequence_maxsz) |
| 669 | #define NFS4_dec_sequence_sz \ |
| 670 | (compound_decode_hdr_maxsz + \ |
| 671 | decode_sequence_maxsz) |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 672 | #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ |
| 673 | encode_sequence_maxsz + \ |
| 674 | encode_putrootfh_maxsz + \ |
| 675 | encode_fsinfo_maxsz) |
| 676 | #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ |
| 677 | decode_sequence_maxsz + \ |
| 678 | decode_putrootfh_maxsz + \ |
| 679 | decode_fsinfo_maxsz) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 680 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
Trond Myklebust | bca7947 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 682 | static const umode_t nfs_type2fmt[] = { |
| 683 | [NF4BAD] = 0, |
| 684 | [NF4REG] = S_IFREG, |
| 685 | [NF4DIR] = S_IFDIR, |
| 686 | [NF4BLK] = S_IFBLK, |
| 687 | [NF4CHR] = S_IFCHR, |
| 688 | [NF4LNK] = S_IFLNK, |
| 689 | [NF4SOCK] = S_IFSOCK, |
| 690 | [NF4FIFO] = S_IFIFO, |
| 691 | [NF4ATTRDIR] = 0, |
| 692 | [NF4NAMEDATTR] = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | }; |
| 694 | |
| 695 | struct compound_hdr { |
| 696 | int32_t status; |
| 697 | uint32_t nops; |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 698 | __be32 * nops_p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | uint32_t taglen; |
| 700 | char * tag; |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 701 | uint32_t replen; /* expected reply words */ |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 702 | u32 minorversion; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | }; |
| 704 | |
| 705 | /* |
| 706 | * START OF "GENERIC" ENCODE ROUTINES. |
| 707 | * These may look a little ugly since they are imported from a "generic" |
| 708 | * set of XDR encode/decode routines which are intended to be shared by |
| 709 | * all of our NFSv4 implementations (OpenBSD, MacOS X...). |
| 710 | * |
| 711 | * If the pain of reading these is too great, it should be a straightforward |
| 712 | * task to translate them into Linux-specific versions which are more |
| 713 | * consistent with the style used in NFSv2/v3... |
| 714 | */ |
| 715 | #define WRITE32(n) *p++ = htonl(n) |
| 716 | #define WRITE64(n) do { \ |
| 717 | *p++ = htonl((uint32_t)((n) >> 32)); \ |
| 718 | *p++ = htonl((uint32_t)(n)); \ |
| 719 | } while (0) |
| 720 | #define WRITEMEM(ptr,nbytes) do { \ |
| 721 | p = xdr_encode_opaque_fixed(p, ptr, nbytes); \ |
| 722 | } while (0) |
| 723 | |
| 724 | #define RESERVE_SPACE(nbytes) do { \ |
| 725 | p = xdr_reserve_space(xdr, nbytes); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | BUG_ON(!p); \ |
| 727 | } while (0) |
| 728 | |
| 729 | static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) |
| 730 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 731 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
| 733 | p = xdr_reserve_space(xdr, 4 + len); |
| 734 | BUG_ON(p == NULL); |
| 735 | xdr_encode_opaque(p, str, len); |
| 736 | } |
| 737 | |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 738 | static void encode_compound_hdr(struct xdr_stream *xdr, |
| 739 | struct rpc_rqst *req, |
| 740 | struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 742 | __be32 *p; |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 743 | struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth; |
| 744 | |
| 745 | /* initialize running count of expected bytes in reply. |
| 746 | * NOTE: the replied tag SHOULD be the same is the one sent, |
| 747 | * but this is not required as a MUST for the server to do so. */ |
| 748 | hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
| 750 | dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag); |
| 751 | BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); |
| 752 | RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2)); |
| 753 | WRITE32(hdr->taglen); |
| 754 | WRITEMEM(hdr->tag, hdr->taglen); |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 755 | WRITE32(hdr->minorversion); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 756 | hdr->nops_p = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | WRITE32(hdr->nops); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | static void encode_nops(struct compound_hdr *hdr) |
| 761 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 762 | BUG_ON(hdr->nops > NFS4_MAX_OPS); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 763 | *hdr->nops_p = htonl(hdr->nops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) |
| 767 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 768 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
| 770 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 771 | BUG_ON(p == NULL); |
| 772 | xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE); |
| 773 | } |
| 774 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 775 | static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
| 777 | char owner_name[IDMAP_NAMESZ]; |
| 778 | char owner_group[IDMAP_NAMESZ]; |
| 779 | int owner_namelen = 0; |
| 780 | int owner_grouplen = 0; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 781 | __be32 *p; |
| 782 | __be32 *q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | int len; |
| 784 | uint32_t bmval0 = 0; |
| 785 | uint32_t bmval1 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | /* |
| 788 | * We reserve enough space to write the entire attribute buffer at once. |
| 789 | * In the worst-case, this would be |
| 790 | * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) |
| 791 | * = 36 bytes, plus any contribution from variable-length fields |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 792 | * such as owner/group. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | */ |
| 794 | len = 16; |
| 795 | |
| 796 | /* Sigh */ |
| 797 | if (iap->ia_valid & ATTR_SIZE) |
| 798 | len += 8; |
| 799 | if (iap->ia_valid & ATTR_MODE) |
| 800 | len += 4; |
| 801 | if (iap->ia_valid & ATTR_UID) { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 802 | owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | if (owner_namelen < 0) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 804 | dprintk("nfs: couldn't resolve uid %d to string\n", |
| 805 | iap->ia_uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | /* XXX */ |
| 807 | strcpy(owner_name, "nobody"); |
| 808 | owner_namelen = sizeof("nobody") - 1; |
| 809 | /* goto out; */ |
| 810 | } |
| 811 | len += 4 + (XDR_QUADLEN(owner_namelen) << 2); |
| 812 | } |
| 813 | if (iap->ia_valid & ATTR_GID) { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 814 | owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | if (owner_grouplen < 0) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 816 | dprintk("nfs: couldn't resolve gid %d to string\n", |
| 817 | iap->ia_gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | strcpy(owner_group, "nobody"); |
| 819 | owner_grouplen = sizeof("nobody") - 1; |
| 820 | /* goto out; */ |
| 821 | } |
| 822 | len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); |
| 823 | } |
| 824 | if (iap->ia_valid & ATTR_ATIME_SET) |
| 825 | len += 16; |
| 826 | else if (iap->ia_valid & ATTR_ATIME) |
| 827 | len += 4; |
| 828 | if (iap->ia_valid & ATTR_MTIME_SET) |
| 829 | len += 16; |
| 830 | else if (iap->ia_valid & ATTR_MTIME) |
| 831 | len += 4; |
| 832 | RESERVE_SPACE(len); |
| 833 | |
| 834 | /* |
| 835 | * We write the bitmap length now, but leave the bitmap and the attribute |
| 836 | * buffer length to be backfilled at the end of this routine. |
| 837 | */ |
| 838 | WRITE32(2); |
| 839 | q = p; |
| 840 | p += 3; |
| 841 | |
| 842 | if (iap->ia_valid & ATTR_SIZE) { |
| 843 | bmval0 |= FATTR4_WORD0_SIZE; |
| 844 | WRITE64(iap->ia_size); |
| 845 | } |
| 846 | if (iap->ia_valid & ATTR_MODE) { |
| 847 | bmval1 |= FATTR4_WORD1_MODE; |
Trond Myklebust | cf3fff5 | 2006-01-03 09:55:53 +0100 | [diff] [blame] | 848 | WRITE32(iap->ia_mode & S_IALLUGO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | } |
| 850 | if (iap->ia_valid & ATTR_UID) { |
| 851 | bmval1 |= FATTR4_WORD1_OWNER; |
| 852 | WRITE32(owner_namelen); |
| 853 | WRITEMEM(owner_name, owner_namelen); |
| 854 | } |
| 855 | if (iap->ia_valid & ATTR_GID) { |
| 856 | bmval1 |= FATTR4_WORD1_OWNER_GROUP; |
| 857 | WRITE32(owner_grouplen); |
| 858 | WRITEMEM(owner_group, owner_grouplen); |
| 859 | } |
| 860 | if (iap->ia_valid & ATTR_ATIME_SET) { |
| 861 | bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; |
| 862 | WRITE32(NFS4_SET_TO_CLIENT_TIME); |
| 863 | WRITE32(0); |
| 864 | WRITE32(iap->ia_mtime.tv_sec); |
| 865 | WRITE32(iap->ia_mtime.tv_nsec); |
| 866 | } |
| 867 | else if (iap->ia_valid & ATTR_ATIME) { |
| 868 | bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; |
| 869 | WRITE32(NFS4_SET_TO_SERVER_TIME); |
| 870 | } |
| 871 | if (iap->ia_valid & ATTR_MTIME_SET) { |
| 872 | bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; |
| 873 | WRITE32(NFS4_SET_TO_CLIENT_TIME); |
| 874 | WRITE32(0); |
| 875 | WRITE32(iap->ia_mtime.tv_sec); |
| 876 | WRITE32(iap->ia_mtime.tv_nsec); |
| 877 | } |
| 878 | else if (iap->ia_valid & ATTR_MTIME) { |
| 879 | bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; |
| 880 | WRITE32(NFS4_SET_TO_SERVER_TIME); |
| 881 | } |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | /* |
| 884 | * Now we backfill the bitmap and the attribute buffer length. |
| 885 | */ |
| 886 | if (len != ((char *)p - (char *)q) + 4) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 887 | printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | len, ((char *)p - (char *)q) + 4); |
| 889 | BUG(); |
| 890 | } |
| 891 | len = (char *)p - (char *)q - 12; |
| 892 | *q++ = htonl(bmval0); |
| 893 | *q++ = htonl(bmval1); |
| 894 | *q++ = htonl(len); |
| 895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | /* out: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 899 | static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 901 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
| 903 | RESERVE_SPACE(8); |
| 904 | WRITE32(OP_ACCESS); |
| 905 | WRITE32(access); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 906 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 907 | hdr->replen += decode_access_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 910 | static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 912 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 914 | RESERVE_SPACE(8+NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | WRITE32(OP_CLOSE); |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 916 | WRITE32(arg->seqid->sequence->counter); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 917 | WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 918 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 919 | hdr->replen += decode_close_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 922 | static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 924 | __be32 *p; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 925 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 926 | RESERVE_SPACE(16); |
| 927 | WRITE32(OP_COMMIT); |
| 928 | WRITE64(args->offset); |
| 929 | WRITE32(args->count); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 930 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 931 | hdr->replen += decode_commit_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 934 | static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 936 | __be32 *p; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | RESERVE_SPACE(8); |
| 939 | WRITE32(OP_CREATE); |
| 940 | WRITE32(create->ftype); |
| 941 | |
| 942 | switch (create->ftype) { |
| 943 | case NF4LNK: |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 944 | RESERVE_SPACE(4); |
| 945 | WRITE32(create->u.symlink.len); |
| 946 | xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | break; |
| 948 | |
| 949 | case NF4BLK: case NF4CHR: |
| 950 | RESERVE_SPACE(8); |
| 951 | WRITE32(create->u.device.specdata1); |
| 952 | WRITE32(create->u.device.specdata2); |
| 953 | break; |
| 954 | |
| 955 | default: |
| 956 | break; |
| 957 | } |
| 958 | |
| 959 | RESERVE_SPACE(4 + create->name->len); |
| 960 | WRITE32(create->name->len); |
| 961 | WRITEMEM(create->name->name, create->name->len); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 962 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 963 | hdr->replen += decode_create_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 965 | encode_attrs(xdr, create->attrs, create->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 968 | static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 970 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 972 | RESERVE_SPACE(12); |
| 973 | WRITE32(OP_GETATTR); |
| 974 | WRITE32(1); |
| 975 | WRITE32(bitmap); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 976 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 977 | hdr->replen += decode_getattr_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 980 | static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 982 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 984 | RESERVE_SPACE(16); |
| 985 | WRITE32(OP_GETATTR); |
| 986 | WRITE32(2); |
| 987 | WRITE32(bm0); |
| 988 | WRITE32(bm1); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 989 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 990 | hdr->replen += decode_getattr_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 993 | static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | { |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 995 | encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0], |
| 996 | bitmask[1] & nfs4_fattr_bitmap[1], hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | } |
| 998 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 999 | static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | { |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1001 | encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0], |
| 1002 | bitmask[1] & nfs4_fsinfo_bitmap[1], hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1005 | static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 1006 | { |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1007 | encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], |
| 1008 | bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 1009 | } |
| 1010 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1011 | static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1013 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
| 1015 | RESERVE_SPACE(4); |
| 1016 | WRITE32(OP_GETFH); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1017 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1018 | hdr->replen += decode_getfh_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1021 | static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1023 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
| 1025 | RESERVE_SPACE(8 + name->len); |
| 1026 | WRITE32(OP_LINK); |
| 1027 | WRITE32(name->len); |
| 1028 | WRITEMEM(name->name, name->len); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1029 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1030 | hdr->replen += decode_link_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1033 | static inline int nfs4_lock_type(struct file_lock *fl, int block) |
| 1034 | { |
| 1035 | if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK) |
| 1036 | return block ? NFS4_READW_LT : NFS4_READ_LT; |
| 1037 | return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; |
| 1038 | } |
| 1039 | |
| 1040 | static inline uint64_t nfs4_lock_length(struct file_lock *fl) |
| 1041 | { |
| 1042 | if (fl->fl_end == OFFSET_MAX) |
| 1043 | return ~(uint64_t)0; |
| 1044 | return fl->fl_end - fl->fl_start + 1; |
| 1045 | } |
| 1046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | /* |
| 1048 | * opcode,type,reclaim,offset,length,new_lock_owner = 32 |
| 1049 | * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 |
| 1050 | */ |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1051 | static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1053 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | |
| 1055 | RESERVE_SPACE(32); |
| 1056 | WRITE32(OP_LOCK); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1057 | WRITE32(nfs4_lock_type(args->fl, args->block)); |
| 1058 | WRITE32(args->reclaim); |
| 1059 | WRITE64(args->fl->fl_start); |
| 1060 | WRITE64(nfs4_lock_length(args->fl)); |
| 1061 | WRITE32(args->new_lock_owner); |
| 1062 | if (args->new_lock_owner){ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1063 | RESERVE_SPACE(4+NFS4_STATEID_SIZE+32); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1064 | WRITE32(args->open_seqid->sequence->counter); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1065 | WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1066 | WRITE32(args->lock_seqid->sequence->counter); |
| 1067 | WRITE64(args->lock_owner.clientid); |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1068 | WRITE32(16); |
| 1069 | WRITEMEM("lock id:", 8); |
| 1070 | WRITE64(args->lock_owner.id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | } |
| 1072 | else { |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1073 | RESERVE_SPACE(NFS4_STATEID_SIZE+4); |
| 1074 | WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1075 | WRITE32(args->lock_seqid->sequence->counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | } |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1077 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1078 | hdr->replen += decode_lock_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1081 | static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1083 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1085 | RESERVE_SPACE(52); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | WRITE32(OP_LOCKT); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1087 | WRITE32(nfs4_lock_type(args->fl, 0)); |
| 1088 | WRITE64(args->fl->fl_start); |
| 1089 | WRITE64(nfs4_lock_length(args->fl)); |
| 1090 | WRITE64(args->lock_owner.clientid); |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1091 | WRITE32(16); |
| 1092 | WRITEMEM("lock id:", 8); |
| 1093 | WRITE64(args->lock_owner.id); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1094 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1095 | hdr->replen += decode_lockt_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1098 | static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1100 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1102 | RESERVE_SPACE(12+NFS4_STATEID_SIZE+16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | WRITE32(OP_LOCKU); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1104 | WRITE32(nfs4_lock_type(args->fl, 0)); |
| 1105 | WRITE32(args->seqid->sequence->counter); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1106 | WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1107 | WRITE64(args->fl->fl_start); |
| 1108 | WRITE64(nfs4_lock_length(args->fl)); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1109 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1110 | hdr->replen += decode_locku_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1113 | static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | { |
| 1115 | int len = name->len; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1116 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
| 1118 | RESERVE_SPACE(8 + len); |
| 1119 | WRITE32(OP_LOOKUP); |
| 1120 | WRITE32(len); |
| 1121 | WRITEMEM(name->name, len); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1122 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1123 | hdr->replen += decode_lookup_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1126 | static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1128 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
| 1130 | RESERVE_SPACE(8); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1131 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1132 | case FMODE_READ: |
| 1133 | WRITE32(NFS4_SHARE_ACCESS_READ); |
| 1134 | break; |
| 1135 | case FMODE_WRITE: |
| 1136 | WRITE32(NFS4_SHARE_ACCESS_WRITE); |
| 1137 | break; |
| 1138 | case FMODE_READ|FMODE_WRITE: |
| 1139 | WRITE32(NFS4_SHARE_ACCESS_BOTH); |
| 1140 | break; |
| 1141 | default: |
| 1142 | WRITE32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
| 1144 | WRITE32(0); /* for linux, share_deny = 0 always */ |
| 1145 | } |
| 1146 | |
| 1147 | static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) |
| 1148 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1149 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | /* |
| 1151 | * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, |
| 1152 | * owner 4 = 32 |
| 1153 | */ |
| 1154 | RESERVE_SPACE(8); |
| 1155 | WRITE32(OP_OPEN); |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1156 | WRITE32(arg->seqid->sequence->counter); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1157 | encode_share_access(xdr, arg->fmode); |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1158 | RESERVE_SPACE(28); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | WRITE64(arg->clientid); |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1160 | WRITE32(16); |
| 1161 | WRITEMEM("open id:", 8); |
| 1162 | WRITE64(arg->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) |
| 1166 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1167 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | |
| 1169 | RESERVE_SPACE(4); |
| 1170 | switch(arg->open_flags & O_EXCL) { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1171 | case 0: |
| 1172 | WRITE32(NFS4_CREATE_UNCHECKED); |
| 1173 | encode_attrs(xdr, arg->u.attrs, arg->server); |
| 1174 | break; |
| 1175 | default: |
| 1176 | WRITE32(NFS4_CREATE_EXCLUSIVE); |
| 1177 | encode_nfs4_verifier(xdr, &arg->u.verifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) |
| 1182 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1183 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | |
| 1185 | RESERVE_SPACE(4); |
| 1186 | switch (arg->open_flags & O_CREAT) { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1187 | case 0: |
| 1188 | WRITE32(NFS4_OPEN_NOCREATE); |
| 1189 | break; |
| 1190 | default: |
| 1191 | BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); |
| 1192 | WRITE32(NFS4_OPEN_CREATE); |
| 1193 | encode_createmode(xdr, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | |
Trond Myklebust | bd7bf9d | 2008-12-23 15:21:53 -0500 | [diff] [blame] | 1197 | static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1199 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
| 1201 | RESERVE_SPACE(4); |
| 1202 | switch (delegation_type) { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1203 | case 0: |
| 1204 | WRITE32(NFS4_OPEN_DELEGATE_NONE); |
| 1205 | break; |
| 1206 | case FMODE_READ: |
| 1207 | WRITE32(NFS4_OPEN_DELEGATE_READ); |
| 1208 | break; |
| 1209 | case FMODE_WRITE|FMODE_READ: |
| 1210 | WRITE32(NFS4_OPEN_DELEGATE_WRITE); |
| 1211 | break; |
| 1212 | default: |
| 1213 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) |
| 1218 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1219 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
| 1221 | RESERVE_SPACE(4); |
| 1222 | WRITE32(NFS4_OPEN_CLAIM_NULL); |
| 1223 | encode_string(xdr, name->len, name->name); |
| 1224 | } |
| 1225 | |
Trond Myklebust | bd7bf9d | 2008-12-23 15:21:53 -0500 | [diff] [blame] | 1226 | static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1228 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | |
| 1230 | RESERVE_SPACE(4); |
| 1231 | WRITE32(NFS4_OPEN_CLAIM_PREVIOUS); |
| 1232 | encode_delegation_type(xdr, type); |
| 1233 | } |
| 1234 | |
| 1235 | static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) |
| 1236 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1237 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1239 | RESERVE_SPACE(4+NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1241 | WRITEMEM(stateid->data, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | encode_string(xdr, name->len, name->name); |
| 1243 | } |
| 1244 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1245 | static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | { |
| 1247 | encode_openhdr(xdr, arg); |
| 1248 | encode_opentype(xdr, arg); |
| 1249 | switch (arg->claim) { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1250 | case NFS4_OPEN_CLAIM_NULL: |
| 1251 | encode_claim_null(xdr, arg->name); |
| 1252 | break; |
| 1253 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1254 | encode_claim_previous(xdr, arg->u.delegation_type); |
| 1255 | break; |
| 1256 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1257 | encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); |
| 1258 | break; |
| 1259 | default: |
| 1260 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | } |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1262 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1263 | hdr->replen += decode_open_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1266 | static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1268 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1270 | RESERVE_SPACE(4+NFS4_STATEID_SIZE+4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | WRITE32(OP_OPEN_CONFIRM); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1272 | WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE); |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1273 | WRITE32(arg->seqid->sequence->counter); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1274 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1275 | hdr->replen += decode_open_confirm_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1278 | static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1280 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1282 | RESERVE_SPACE(4+NFS4_STATEID_SIZE+4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | WRITE32(OP_OPEN_DOWNGRADE); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1284 | WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE); |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1285 | WRITE32(arg->seqid->sequence->counter); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1286 | encode_share_access(xdr, arg->fmode); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1287 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1288 | hdr->replen += decode_open_downgrade_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1291 | static void |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1292 | encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | { |
| 1294 | int len = fh->size; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1295 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
| 1297 | RESERVE_SPACE(8 + len); |
| 1298 | WRITE32(OP_PUTFH); |
| 1299 | WRITE32(len); |
| 1300 | WRITEMEM(fh->data, len); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1301 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1302 | hdr->replen += decode_putfh_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1305 | static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1307 | __be32 *p; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1308 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1309 | RESERVE_SPACE(4); |
| 1310 | WRITE32(OP_PUTROOTFH); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1311 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1312 | hdr->replen += decode_putrootfh_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx) |
| 1316 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | nfs4_stateid stateid; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1318 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1320 | RESERVE_SPACE(NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | if (ctx->state != NULL) { |
| 1322 | nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1323 | WRITEMEM(stateid.data, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | } else |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1325 | WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1328 | static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1330 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | |
| 1332 | RESERVE_SPACE(4); |
| 1333 | WRITE32(OP_READ); |
| 1334 | |
| 1335 | encode_stateid(xdr, args->context); |
| 1336 | |
| 1337 | RESERVE_SPACE(12); |
| 1338 | WRITE64(args->offset); |
| 1339 | WRITE32(args->count); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1340 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1341 | hdr->replen += decode_read_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1344 | static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | { |
Manoj Naik | 97d312d | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 1346 | uint32_t attrs[2] = { |
| 1347 | FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID, |
| 1348 | FATTR4_WORD1_MOUNTED_ON_FILEID, |
| 1349 | }; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1350 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1352 | RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | WRITE32(OP_READDIR); |
| 1354 | WRITE64(readdir->cookie); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1355 | WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | WRITE32(readdir->count >> 1); /* We're not doing readdirplus */ |
| 1357 | WRITE32(readdir->count); |
| 1358 | WRITE32(2); |
Manoj Naik | 97d312d | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 1359 | /* Switch to mounted_on_fileid if the server supports it */ |
| 1360 | if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 1361 | attrs[0] &= ~FATTR4_WORD0_FILEID; |
| 1362 | else |
| 1363 | attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 1364 | WRITE32(attrs[0] & readdir->bitmask[0]); |
| 1365 | WRITE32(attrs[1] & readdir->bitmask[1]); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1366 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1367 | hdr->replen += decode_readdir_maxsz; |
Fred Isaman | 4410924 | 2008-04-02 15:21:15 +0300 | [diff] [blame] | 1368 | dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", |
| 1369 | __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 1370 | (unsigned long long)readdir->cookie, |
| 1371 | ((u32 *)readdir->verifier.data)[0], |
| 1372 | ((u32 *)readdir->verifier.data)[1], |
| 1373 | attrs[0] & readdir->bitmask[0], |
| 1374 | attrs[1] & readdir->bitmask[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1377 | static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1379 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | |
| 1381 | RESERVE_SPACE(4); |
| 1382 | WRITE32(OP_READLINK); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1383 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1384 | hdr->replen += decode_readlink_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1387 | static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1389 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | |
| 1391 | RESERVE_SPACE(8 + name->len); |
| 1392 | WRITE32(OP_REMOVE); |
| 1393 | WRITE32(name->len); |
| 1394 | WRITEMEM(name->name, name->len); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1395 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1396 | hdr->replen += decode_remove_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1399 | static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1401 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
| 1403 | RESERVE_SPACE(8 + oldname->len); |
| 1404 | WRITE32(OP_RENAME); |
| 1405 | WRITE32(oldname->len); |
| 1406 | WRITEMEM(oldname->name, oldname->len); |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | RESERVE_SPACE(4 + newname->len); |
| 1409 | WRITE32(newname->len); |
| 1410 | WRITEMEM(newname->name, newname->len); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1411 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1412 | hdr->replen += decode_rename_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1415 | static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1417 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | |
| 1419 | RESERVE_SPACE(12); |
| 1420 | WRITE32(OP_RENEW); |
| 1421 | WRITE64(client_stateid->cl_clientid); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1422 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1423 | hdr->replen += decode_renew_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1426 | static void |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1427 | encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1428 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1429 | __be32 *p; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1430 | |
| 1431 | RESERVE_SPACE(4); |
| 1432 | WRITE32(OP_RESTOREFH); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1433 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1434 | hdr->replen += decode_restorefh_maxsz; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | static int |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1438 | encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 1439 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1440 | __be32 *p; |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 1441 | |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1442 | RESERVE_SPACE(4+NFS4_STATEID_SIZE); |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 1443 | WRITE32(OP_SETATTR); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1444 | WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE); |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 1445 | RESERVE_SPACE(2*4); |
| 1446 | WRITE32(1); |
| 1447 | WRITE32(FATTR4_WORD0_ACL); |
| 1448 | if (arg->acl_len % 4) |
| 1449 | return -EINVAL; |
| 1450 | RESERVE_SPACE(4); |
| 1451 | WRITE32(arg->acl_len); |
| 1452 | xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1453 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1454 | hdr->replen += decode_setacl_maxsz; |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 1455 | return 0; |
| 1456 | } |
| 1457 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1458 | static void |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1459 | encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1461 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | |
| 1463 | RESERVE_SPACE(4); |
| 1464 | WRITE32(OP_SAVEFH); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1465 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1466 | hdr->replen += decode_savefh_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1469 | static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1471 | __be32 *p; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1472 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1473 | RESERVE_SPACE(4+NFS4_STATEID_SIZE); |
| 1474 | WRITE32(OP_SETATTR); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1475 | WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1476 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1477 | hdr->replen += decode_setattr_maxsz; |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1478 | encode_attrs(xdr, arg->iap, server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1481 | static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1483 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1485 | RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | WRITE32(OP_SETCLIENTID); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1487 | WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
| 1489 | encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); |
| 1490 | RESERVE_SPACE(4); |
| 1491 | WRITE32(setclientid->sc_prog); |
| 1492 | encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); |
| 1493 | encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); |
| 1494 | RESERVE_SPACE(4); |
| 1495 | WRITE32(setclientid->sc_cb_ident); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1496 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1497 | hdr->replen += decode_setclientid_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1500 | static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1502 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1504 | RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE); |
| 1505 | WRITE32(OP_SETCLIENTID_CONFIRM); |
| 1506 | WRITE64(client_state->cl_clientid); |
| 1507 | WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1508 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1509 | hdr->replen += decode_setclientid_confirm_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1512 | static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1514 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | |
| 1516 | RESERVE_SPACE(4); |
| 1517 | WRITE32(OP_WRITE); |
| 1518 | |
| 1519 | encode_stateid(xdr, args->context); |
| 1520 | |
| 1521 | RESERVE_SPACE(16); |
| 1522 | WRITE64(args->offset); |
| 1523 | WRITE32(args->stable); |
| 1524 | WRITE32(args->count); |
| 1525 | |
| 1526 | xdr_write_pages(xdr, args->pages, args->pgbase, args->count); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1527 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1528 | hdr->replen += decode_write_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1531 | static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1533 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1535 | RESERVE_SPACE(4+NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | |
| 1537 | WRITE32(OP_DELEGRETURN); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 1538 | WRITEMEM(stateid->data, NFS4_STATEID_SIZE); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1539 | hdr->nops++; |
Benny Halevy | dadf0c2 | 2009-04-01 09:22:08 -0400 | [diff] [blame] | 1540 | hdr->replen += decode_delegreturn_maxsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | } |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1542 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 1543 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1544 | /* NFSv4.1 operations */ |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 1545 | static void encode_exchange_id(struct xdr_stream *xdr, |
| 1546 | struct nfs41_exchange_id_args *args, |
| 1547 | struct compound_hdr *hdr) |
| 1548 | { |
| 1549 | __be32 *p; |
| 1550 | |
| 1551 | RESERVE_SPACE(4 + sizeof(args->verifier->data)); |
| 1552 | WRITE32(OP_EXCHANGE_ID); |
| 1553 | WRITEMEM(args->verifier->data, sizeof(args->verifier->data)); |
| 1554 | |
| 1555 | encode_string(xdr, args->id_len, args->id); |
| 1556 | |
| 1557 | RESERVE_SPACE(12); |
| 1558 | WRITE32(args->flags); |
| 1559 | WRITE32(0); /* zero length state_protect4_a */ |
| 1560 | WRITE32(0); /* zero length implementation id array */ |
| 1561 | hdr->nops++; |
| 1562 | hdr->replen += decode_exchange_id_maxsz; |
| 1563 | } |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 1564 | |
| 1565 | static void encode_create_session(struct xdr_stream *xdr, |
| 1566 | struct nfs41_create_session_args *args, |
| 1567 | struct compound_hdr *hdr) |
| 1568 | { |
| 1569 | __be32 *p; |
| 1570 | char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; |
| 1571 | uint32_t len; |
| 1572 | struct nfs_client *clp = args->client; |
| 1573 | |
| 1574 | RESERVE_SPACE(4); |
| 1575 | WRITE32(OP_CREATE_SESSION); |
| 1576 | |
| 1577 | RESERVE_SPACE(8); |
| 1578 | WRITE64(clp->cl_ex_clid); |
| 1579 | |
| 1580 | RESERVE_SPACE(8); |
| 1581 | WRITE32(clp->cl_seqid); /*Sequence id */ |
| 1582 | WRITE32(args->flags); /*flags */ |
| 1583 | |
| 1584 | RESERVE_SPACE(2*28); /* 2 channel_attrs */ |
| 1585 | /* Fore Channel */ |
| 1586 | WRITE32(args->fc_attrs.headerpadsz); /* header padding size */ |
| 1587 | WRITE32(args->fc_attrs.max_rqst_sz); /* max req size */ |
| 1588 | WRITE32(args->fc_attrs.max_resp_sz); /* max resp size */ |
| 1589 | WRITE32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */ |
| 1590 | WRITE32(args->fc_attrs.max_ops); /* max operations */ |
| 1591 | WRITE32(args->fc_attrs.max_reqs); /* max requests */ |
| 1592 | WRITE32(0); /* rdmachannel_attrs */ |
| 1593 | |
| 1594 | /* Back Channel */ |
| 1595 | WRITE32(args->fc_attrs.headerpadsz); /* header padding size */ |
| 1596 | WRITE32(args->bc_attrs.max_rqst_sz); /* max req size */ |
| 1597 | WRITE32(args->bc_attrs.max_resp_sz); /* max resp size */ |
| 1598 | WRITE32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ |
| 1599 | WRITE32(args->bc_attrs.max_ops); /* max operations */ |
| 1600 | WRITE32(args->bc_attrs.max_reqs); /* max requests */ |
| 1601 | WRITE32(0); /* rdmachannel_attrs */ |
| 1602 | |
| 1603 | RESERVE_SPACE(4); |
| 1604 | WRITE32(args->cb_program); /* cb_program */ |
| 1605 | |
| 1606 | RESERVE_SPACE(4); /* # of security flavors */ |
| 1607 | WRITE32(1); |
| 1608 | |
| 1609 | RESERVE_SPACE(4); |
| 1610 | WRITE32(RPC_AUTH_UNIX); /* auth_sys */ |
| 1611 | |
| 1612 | /* authsys_parms rfc1831 */ |
| 1613 | RESERVE_SPACE(4); |
| 1614 | WRITE32((u32)clp->cl_boot_time.tv_nsec); /* stamp */ |
| 1615 | len = scnprintf(machine_name, sizeof(machine_name), "%s", |
| 1616 | clp->cl_ipaddr); |
| 1617 | RESERVE_SPACE(16 + len); |
| 1618 | WRITE32(len); |
| 1619 | WRITEMEM(machine_name, len); |
| 1620 | WRITE32(0); /* UID */ |
| 1621 | WRITE32(0); /* GID */ |
| 1622 | WRITE32(0); /* No more gids */ |
| 1623 | hdr->nops++; |
| 1624 | hdr->replen += decode_create_session_maxsz; |
| 1625 | } |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 1626 | |
| 1627 | static void encode_destroy_session(struct xdr_stream *xdr, |
| 1628 | struct nfs4_session *session, |
| 1629 | struct compound_hdr *hdr) |
| 1630 | { |
| 1631 | __be32 *p; |
| 1632 | RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN); |
| 1633 | WRITE32(OP_DESTROY_SESSION); |
| 1634 | WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN); |
| 1635 | hdr->nops++; |
| 1636 | hdr->replen += decode_destroy_session_maxsz; |
| 1637 | } |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 1638 | #endif /* CONFIG_NFS_V4_1 */ |
| 1639 | |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1640 | static void encode_sequence(struct xdr_stream *xdr, |
| 1641 | const struct nfs4_sequence_args *args, |
| 1642 | struct compound_hdr *hdr) |
| 1643 | { |
| 1644 | #if defined(CONFIG_NFS_V4_1) |
| 1645 | struct nfs4_session *session = args->sa_session; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 1646 | struct nfs4_slot_table *tp; |
| 1647 | struct nfs4_slot *slot; |
| 1648 | __be32 *p; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1649 | |
| 1650 | if (!session) |
| 1651 | return; |
| 1652 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 1653 | tp = &session->fc_slot_table; |
| 1654 | |
| 1655 | WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); |
| 1656 | slot = tp->slots + args->sa_slotid; |
| 1657 | |
| 1658 | RESERVE_SPACE(4); |
| 1659 | WRITE32(OP_SEQUENCE); |
| 1660 | |
| 1661 | /* |
| 1662 | * Sessionid + seqid + slotid + max slotid + cache_this |
| 1663 | */ |
| 1664 | dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " |
| 1665 | "max_slotid=%d cache_this=%d\n", |
| 1666 | __func__, |
| 1667 | ((u32 *)session->sess_id.data)[0], |
| 1668 | ((u32 *)session->sess_id.data)[1], |
| 1669 | ((u32 *)session->sess_id.data)[2], |
| 1670 | ((u32 *)session->sess_id.data)[3], |
| 1671 | slot->seq_nr, args->sa_slotid, |
| 1672 | tp->highest_used_slotid, args->sa_cache_this); |
| 1673 | RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 16); |
| 1674 | WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN); |
| 1675 | WRITE32(slot->seq_nr); |
| 1676 | WRITE32(args->sa_slotid); |
| 1677 | WRITE32(tp->highest_used_slotid); |
| 1678 | WRITE32(args->sa_cache_this); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1679 | hdr->nops++; |
| 1680 | hdr->replen += decode_sequence_maxsz; |
| 1681 | #endif /* CONFIG_NFS_V4_1 */ |
| 1682 | } |
| 1683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | /* |
| 1685 | * END OF "GENERIC" ENCODE ROUTINES. |
| 1686 | */ |
| 1687 | |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1688 | static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) |
| 1689 | { |
| 1690 | #if defined(CONFIG_NFS_V4_1) |
| 1691 | if (args->sa_session) |
| 1692 | return args->sa_session->clp->cl_minorversion; |
| 1693 | #endif /* CONFIG_NFS_V4_1 */ |
| 1694 | return 0; |
| 1695 | } |
| 1696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | /* |
| 1698 | * Encode an ACCESS request |
| 1699 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1700 | static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | { |
| 1702 | struct xdr_stream xdr; |
| 1703 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1704 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | |
| 1707 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1708 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1709 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1710 | encode_putfh(&xdr, args->fh, &hdr); |
| 1711 | encode_access(&xdr, args->access, &hdr); |
| 1712 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1713 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1714 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | /* |
| 1718 | * Encode LOOKUP request |
| 1719 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1720 | static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | { |
| 1722 | struct xdr_stream xdr; |
| 1723 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1724 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
| 1727 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1728 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1729 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1730 | encode_putfh(&xdr, args->dir_fh, &hdr); |
| 1731 | encode_lookup(&xdr, args->name, &hdr); |
| 1732 | encode_getfh(&xdr, &hdr); |
| 1733 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1734 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1735 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | /* |
| 1739 | * Encode LOOKUP_ROOT request |
| 1740 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1741 | static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | { |
| 1743 | struct xdr_stream xdr; |
| 1744 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1745 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | |
| 1748 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1749 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1750 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1751 | encode_putrootfh(&xdr, &hdr); |
| 1752 | encode_getfh(&xdr, &hdr); |
| 1753 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1754 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1755 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | /* |
| 1759 | * Encode REMOVE request |
| 1760 | */ |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 1761 | static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | { |
| 1763 | struct xdr_stream xdr; |
| 1764 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1765 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | |
| 1768 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1769 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1770 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1771 | encode_putfh(&xdr, args->fh, &hdr); |
| 1772 | encode_remove(&xdr, &args->name, &hdr); |
| 1773 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1774 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1775 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | /* |
| 1779 | * Encode RENAME request |
| 1780 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1781 | static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | { |
| 1783 | struct xdr_stream xdr; |
| 1784 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1785 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
| 1788 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1789 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1790 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1791 | encode_putfh(&xdr, args->old_dir, &hdr); |
| 1792 | encode_savefh(&xdr, &hdr); |
| 1793 | encode_putfh(&xdr, args->new_dir, &hdr); |
| 1794 | encode_rename(&xdr, args->old_name, args->new_name, &hdr); |
| 1795 | encode_getfattr(&xdr, args->bitmask, &hdr); |
| 1796 | encode_restorefh(&xdr, &hdr); |
| 1797 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1798 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1799 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | /* |
| 1803 | * Encode LINK request |
| 1804 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1805 | static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | { |
| 1807 | struct xdr_stream xdr; |
| 1808 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1809 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | |
| 1812 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1813 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1814 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1815 | encode_putfh(&xdr, args->fh, &hdr); |
| 1816 | encode_savefh(&xdr, &hdr); |
| 1817 | encode_putfh(&xdr, args->dir_fh, &hdr); |
| 1818 | encode_link(&xdr, args->name, &hdr); |
| 1819 | encode_getfattr(&xdr, args->bitmask, &hdr); |
| 1820 | encode_restorefh(&xdr, &hdr); |
| 1821 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1822 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1823 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | /* |
| 1827 | * Encode CREATE request |
| 1828 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1829 | static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | { |
| 1831 | struct xdr_stream xdr; |
| 1832 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1833 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | |
| 1836 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1837 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1838 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1839 | encode_putfh(&xdr, args->dir_fh, &hdr); |
| 1840 | encode_savefh(&xdr, &hdr); |
| 1841 | encode_create(&xdr, args, &hdr); |
| 1842 | encode_getfh(&xdr, &hdr); |
| 1843 | encode_getfattr(&xdr, args->bitmask, &hdr); |
| 1844 | encode_restorefh(&xdr, &hdr); |
| 1845 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1846 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1847 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | /* |
| 1851 | * Encode SYMLINK request |
| 1852 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1853 | static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | { |
| 1855 | return nfs4_xdr_enc_create(req, p, args); |
| 1856 | } |
| 1857 | |
| 1858 | /* |
| 1859 | * Encode GETATTR request |
| 1860 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1861 | static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | { |
| 1863 | struct xdr_stream xdr; |
| 1864 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1865 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | |
| 1868 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1869 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1870 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1871 | encode_putfh(&xdr, args->fh, &hdr); |
| 1872 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1873 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1874 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | /* |
| 1878 | * Encode a CLOSE request |
| 1879 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1880 | static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1882 | struct xdr_stream xdr; |
| 1883 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1884 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1885 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 1887 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1888 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1889 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1890 | encode_putfh(&xdr, args->fh, &hdr); |
| 1891 | encode_close(&xdr, args, &hdr); |
| 1892 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1893 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1894 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | /* |
| 1898 | * Encode an OPEN request |
| 1899 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1900 | static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | { |
| 1902 | struct xdr_stream xdr; |
| 1903 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1904 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | |
| 1907 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1908 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1909 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1910 | encode_putfh(&xdr, args->fh, &hdr); |
| 1911 | encode_savefh(&xdr, &hdr); |
| 1912 | encode_open(&xdr, args, &hdr); |
| 1913 | encode_getfh(&xdr, &hdr); |
| 1914 | encode_getfattr(&xdr, args->bitmask, &hdr); |
| 1915 | encode_restorefh(&xdr, &hdr); |
| 1916 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1917 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1918 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | /* |
| 1922 | * Encode an OPEN_CONFIRM request |
| 1923 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1924 | static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | { |
| 1926 | struct xdr_stream xdr; |
| 1927 | struct compound_hdr hdr = { |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1928 | .nops = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | |
| 1931 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1932 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1933 | encode_putfh(&xdr, args->fh, &hdr); |
| 1934 | encode_open_confirm(&xdr, args, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1935 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1936 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | /* |
| 1940 | * Encode an OPEN request with no attributes. |
| 1941 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1942 | static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | { |
| 1944 | struct xdr_stream xdr; |
| 1945 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1946 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | |
| 1949 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1950 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1951 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1952 | encode_putfh(&xdr, args->fh, &hdr); |
| 1953 | encode_open(&xdr, args, &hdr); |
| 1954 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1955 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1956 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | /* |
| 1960 | * Encode an OPEN_DOWNGRADE request |
| 1961 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1962 | static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | { |
| 1964 | struct xdr_stream xdr; |
| 1965 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1966 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | |
| 1969 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1970 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1971 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1972 | encode_putfh(&xdr, args->fh, &hdr); |
| 1973 | encode_open_downgrade(&xdr, args, &hdr); |
| 1974 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1975 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1976 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | /* |
| 1980 | * Encode a LOCK request |
| 1981 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 1982 | static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | { |
| 1984 | struct xdr_stream xdr; |
| 1985 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 1986 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | |
| 1989 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 1990 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 1991 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1992 | encode_putfh(&xdr, args->fh, &hdr); |
| 1993 | encode_lock(&xdr, args, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 1994 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 1995 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | /* |
| 1999 | * Encode a LOCKT request |
| 2000 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2001 | static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | { |
| 2003 | struct xdr_stream xdr; |
| 2004 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2005 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | |
| 2008 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2009 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2010 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2011 | encode_putfh(&xdr, args->fh, &hdr); |
| 2012 | encode_lockt(&xdr, args, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2013 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2014 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | /* |
| 2018 | * Encode a LOCKU request |
| 2019 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2020 | static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | { |
| 2022 | struct xdr_stream xdr; |
| 2023 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2024 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | |
| 2027 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2028 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2029 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2030 | encode_putfh(&xdr, args->fh, &hdr); |
| 2031 | encode_locku(&xdr, args, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2032 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2033 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | /* |
| 2037 | * Encode a READLINK request |
| 2038 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2039 | static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | { |
| 2041 | struct xdr_stream xdr; |
| 2042 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2043 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | |
| 2046 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2047 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2048 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2049 | encode_putfh(&xdr, args->fh, &hdr); |
| 2050 | encode_readlink(&xdr, args, req, &hdr); |
Trond Myklebust | e3a535e | 2007-07-19 10:03:38 -0400 | [diff] [blame] | 2051 | |
Benny Halevy | 28f5669 | 2009-04-01 09:22:09 -0400 | [diff] [blame] | 2052 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, |
Trond Myklebust | e3a535e | 2007-07-19 10:03:38 -0400 | [diff] [blame] | 2053 | args->pgbase, args->pglen); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2054 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2055 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | /* |
| 2059 | * Encode a READDIR request |
| 2060 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2061 | static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | { |
| 2063 | struct xdr_stream xdr; |
| 2064 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2065 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | |
| 2068 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2069 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2070 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2071 | encode_putfh(&xdr, args->fh, &hdr); |
| 2072 | encode_readdir(&xdr, args, req, &hdr); |
Trond Myklebust | d6ac02d | 2007-07-19 10:03:37 -0400 | [diff] [blame] | 2073 | |
Benny Halevy | 28f5669 | 2009-04-01 09:22:09 -0400 | [diff] [blame] | 2074 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, |
Trond Myklebust | d6ac02d | 2007-07-19 10:03:37 -0400 | [diff] [blame] | 2075 | args->pgbase, args->count); |
| 2076 | dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", |
Benny Halevy | 28f5669 | 2009-04-01 09:22:09 -0400 | [diff] [blame] | 2077 | __func__, hdr.replen << 2, args->pages, |
Trond Myklebust | d6ac02d | 2007-07-19 10:03:37 -0400 | [diff] [blame] | 2078 | args->pgbase, args->count); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2079 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2080 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | /* |
| 2084 | * Encode a READ request |
| 2085 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2086 | static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | struct xdr_stream xdr; |
| 2089 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2090 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | |
| 2093 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2094 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2095 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2096 | encode_putfh(&xdr, args->fh, &hdr); |
| 2097 | encode_read(&xdr, args, &hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | |
Benny Halevy | 28f5669 | 2009-04-01 09:22:09 -0400 | [diff] [blame] | 2099 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | args->pages, args->pgbase, args->count); |
\"Talpey, Thomas\ | 4f22ccc | 2007-09-10 13:44:58 -0400 | [diff] [blame] | 2101 | req->rq_rcv_buf.flags |= XDRBUF_READ; |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2102 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2103 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | /* |
| 2107 | * Encode an SETATTR request |
| 2108 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2109 | static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 2111 | struct xdr_stream xdr; |
| 2112 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2113 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 2114 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 2116 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2117 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2118 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2119 | encode_putfh(&xdr, args->fh, &hdr); |
| 2120 | encode_setattr(&xdr, args, args->server, &hdr); |
| 2121 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2122 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2123 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | /* |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2127 | * Encode a GETACL request |
| 2128 | */ |
| 2129 | static int |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2130 | nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p, |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2131 | struct nfs_getaclargs *args) |
| 2132 | { |
| 2133 | struct xdr_stream xdr; |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2134 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2135 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2136 | }; |
Benny Halevy | 28f5669 | 2009-04-01 09:22:09 -0400 | [diff] [blame] | 2137 | uint32_t replen; |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2138 | |
| 2139 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2140 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2141 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2142 | encode_putfh(&xdr, args->fh, &hdr); |
Benny Halevy | 28f5669 | 2009-04-01 09:22:09 -0400 | [diff] [blame] | 2143 | replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1; |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2144 | encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr); |
| 2145 | |
Benny Halevy | 28f5669 | 2009-04-01 09:22:09 -0400 | [diff] [blame] | 2146 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2147 | args->acl_pages, args->acl_pgbase, args->acl_len); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2148 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2149 | return 0; |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | * Encode a WRITE request |
| 2154 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2155 | static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | { |
| 2157 | struct xdr_stream xdr; |
| 2158 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2159 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | |
| 2162 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2163 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2164 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2165 | encode_putfh(&xdr, args->fh, &hdr); |
| 2166 | encode_write(&xdr, args, &hdr); |
\"Talpey, Thomas\ | 4f22ccc | 2007-09-10 13:44:58 -0400 | [diff] [blame] | 2167 | req->rq_snd_buf.flags |= XDRBUF_WRITE; |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2168 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2169 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2170 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | /* |
| 2174 | * a COMMIT request |
| 2175 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2176 | static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | { |
| 2178 | struct xdr_stream xdr; |
| 2179 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2180 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | |
| 2183 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2184 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2185 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2186 | encode_putfh(&xdr, args->fh, &hdr); |
| 2187 | encode_commit(&xdr, args, &hdr); |
| 2188 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2189 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2190 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | /* |
| 2194 | * FSINFO request |
| 2195 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2196 | static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | { |
| 2198 | struct xdr_stream xdr; |
| 2199 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2200 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | |
| 2203 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2204 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2205 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2206 | encode_putfh(&xdr, args->fh, &hdr); |
| 2207 | encode_fsinfo(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2208 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2209 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | /* |
| 2213 | * a PATHCONF request |
| 2214 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2215 | static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | struct xdr_stream xdr; |
| 2218 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2219 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | |
| 2222 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2223 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2224 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2225 | encode_putfh(&xdr, args->fh, &hdr); |
| 2226 | encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], |
| 2227 | &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2228 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2229 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | /* |
| 2233 | * a STATFS request |
| 2234 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2235 | static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | struct xdr_stream xdr; |
| 2238 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2239 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | |
| 2242 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2243 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2244 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2245 | encode_putfh(&xdr, args->fh, &hdr); |
| 2246 | encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], |
| 2247 | args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2248 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2249 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | /* |
| 2253 | * GETATTR_BITMAP request |
| 2254 | */ |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2255 | static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, |
| 2256 | struct nfs4_server_caps_arg *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | { |
| 2258 | struct xdr_stream xdr; |
| 2259 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2260 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | |
| 2263 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2264 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2265 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2266 | encode_putfh(&xdr, args->fhandle, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2267 | encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS| |
| 2268 | FATTR4_WORD0_LINK_SUPPORT| |
| 2269 | FATTR4_WORD0_SYMLINK_SUPPORT| |
| 2270 | FATTR4_WORD0_ACLSUPPORT, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2271 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2272 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | /* |
| 2276 | * a RENEW request |
| 2277 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2278 | static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | { |
| 2280 | struct xdr_stream xdr; |
| 2281 | struct compound_hdr hdr = { |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2282 | .nops = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | }; |
| 2284 | |
| 2285 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2286 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2287 | encode_renew(&xdr, clp, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2288 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2289 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | /* |
| 2293 | * a SETCLIENTID request |
| 2294 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2295 | static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | { |
| 2297 | struct xdr_stream xdr; |
| 2298 | struct compound_hdr hdr = { |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2299 | .nops = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | }; |
| 2301 | |
| 2302 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2303 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2304 | encode_setclientid(&xdr, sc, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2305 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2306 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | /* |
| 2310 | * a SETCLIENTID_CONFIRM request |
| 2311 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2312 | static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | { |
| 2314 | struct xdr_stream xdr; |
| 2315 | struct compound_hdr hdr = { |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2316 | .nops = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | }; |
| 2318 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | |
| 2320 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2321 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2322 | encode_setclientid_confirm(&xdr, clp, &hdr); |
| 2323 | encode_putrootfh(&xdr, &hdr); |
| 2324 | encode_fsinfo(&xdr, lease_bitmap, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2325 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2326 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | /* |
| 2330 | * DELEGRETURN request |
| 2331 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2332 | static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | { |
| 2334 | struct xdr_stream xdr; |
| 2335 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2336 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | |
| 2339 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2340 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2341 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2342 | encode_putfh(&xdr, args->fhandle, &hdr); |
| 2343 | encode_delegreturn(&xdr, args->stateid, &hdr); |
| 2344 | encode_getfattr(&xdr, args->bitmask, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2345 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2346 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | /* |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2350 | * Encode FS_LOCATIONS request |
| 2351 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2352 | static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2353 | { |
| 2354 | struct xdr_stream xdr; |
| 2355 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 2356 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2357 | }; |
Benny Halevy | 28f5669 | 2009-04-01 09:22:09 -0400 | [diff] [blame] | 2358 | uint32_t replen; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2359 | |
| 2360 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 2361 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 2362 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2363 | encode_putfh(&xdr, args->dir_fh, &hdr); |
| 2364 | encode_lookup(&xdr, args->name, &hdr); |
Benny Halevy | 28f5669 | 2009-04-01 09:22:09 -0400 | [diff] [blame] | 2365 | replen = hdr.replen; /* get the attribute into args->page */ |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2366 | encode_fs_locations(&xdr, args->bitmask, &hdr); |
| 2367 | |
Benny Halevy | 28f5669 | 2009-04-01 09:22:09 -0400 | [diff] [blame] | 2368 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2369 | 0, PAGE_SIZE); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 2370 | encode_nops(&hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 2371 | return 0; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2372 | } |
| 2373 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 2374 | #if defined(CONFIG_NFS_V4_1) |
| 2375 | /* |
| 2376 | * EXCHANGE_ID request |
| 2377 | */ |
| 2378 | static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p, |
| 2379 | struct nfs41_exchange_id_args *args) |
| 2380 | { |
| 2381 | struct xdr_stream xdr; |
| 2382 | struct compound_hdr hdr = { |
| 2383 | .minorversion = args->client->cl_minorversion, |
| 2384 | }; |
| 2385 | |
| 2386 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 2387 | encode_compound_hdr(&xdr, req, &hdr); |
| 2388 | encode_exchange_id(&xdr, args, &hdr); |
| 2389 | encode_nops(&hdr); |
| 2390 | return 0; |
| 2391 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 2392 | |
| 2393 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 2394 | * a CREATE_SESSION request |
| 2395 | */ |
| 2396 | static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p, |
| 2397 | struct nfs41_create_session_args *args) |
| 2398 | { |
| 2399 | struct xdr_stream xdr; |
| 2400 | struct compound_hdr hdr = { |
| 2401 | .minorversion = args->client->cl_minorversion, |
| 2402 | }; |
| 2403 | |
| 2404 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 2405 | encode_compound_hdr(&xdr, req, &hdr); |
| 2406 | encode_create_session(&xdr, args, &hdr); |
| 2407 | encode_nops(&hdr); |
| 2408 | return 0; |
| 2409 | } |
| 2410 | |
| 2411 | /* |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 2412 | * a DESTROY_SESSION request |
| 2413 | */ |
| 2414 | static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p, |
| 2415 | struct nfs4_session *session) |
| 2416 | { |
| 2417 | struct xdr_stream xdr; |
| 2418 | struct compound_hdr hdr = { |
| 2419 | .minorversion = session->clp->cl_minorversion, |
| 2420 | }; |
| 2421 | |
| 2422 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 2423 | encode_compound_hdr(&xdr, req, &hdr); |
| 2424 | encode_destroy_session(&xdr, session, &hdr); |
| 2425 | encode_nops(&hdr); |
| 2426 | return 0; |
| 2427 | } |
| 2428 | |
| 2429 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 2430 | * a SEQUENCE request |
| 2431 | */ |
| 2432 | static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p, |
| 2433 | struct nfs4_sequence_args *args) |
| 2434 | { |
| 2435 | struct xdr_stream xdr; |
| 2436 | struct compound_hdr hdr = { |
| 2437 | .minorversion = nfs4_xdr_minorversion(args), |
| 2438 | }; |
| 2439 | |
| 2440 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 2441 | encode_compound_hdr(&xdr, req, &hdr); |
| 2442 | encode_sequence(&xdr, args, &hdr); |
| 2443 | encode_nops(&hdr); |
| 2444 | return 0; |
| 2445 | } |
| 2446 | |
| 2447 | /* |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 2448 | * a GET_LEASE_TIME request |
| 2449 | */ |
| 2450 | static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p, |
| 2451 | struct nfs4_get_lease_time_args *args) |
| 2452 | { |
| 2453 | struct xdr_stream xdr; |
| 2454 | struct compound_hdr hdr = { |
| 2455 | .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), |
| 2456 | }; |
| 2457 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; |
| 2458 | |
| 2459 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 2460 | encode_compound_hdr(&xdr, req, &hdr); |
| 2461 | encode_sequence(&xdr, &args->la_seq_args, &hdr); |
| 2462 | encode_putrootfh(&xdr, &hdr); |
| 2463 | encode_fsinfo(&xdr, lease_bitmap, &hdr); |
| 2464 | encode_nops(&hdr); |
| 2465 | return 0; |
| 2466 | } |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 2467 | #endif /* CONFIG_NFS_V4_1 */ |
| 2468 | |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2469 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | * START OF "GENERIC" DECODE ROUTINES. |
| 2471 | * These may look a little ugly since they are imported from a "generic" |
| 2472 | * set of XDR encode/decode routines which are intended to be shared by |
| 2473 | * all of our NFSv4 implementations (OpenBSD, MacOS X...). |
| 2474 | * |
| 2475 | * If the pain of reading these is too great, it should be a straightforward |
| 2476 | * task to translate them into Linux-specific versions which are more |
| 2477 | * consistent with the style used in NFSv2/v3... |
| 2478 | */ |
| 2479 | #define READ32(x) (x) = ntohl(*p++) |
| 2480 | #define READ64(x) do { \ |
| 2481 | (x) = (u64)ntohl(*p++) << 32; \ |
| 2482 | (x) |= ntohl(*p++); \ |
| 2483 | } while (0) |
| 2484 | #define READTIME(x) do { \ |
| 2485 | p++; \ |
| 2486 | (x.tv_sec) = ntohl(*p++); \ |
| 2487 | (x.tv_nsec) = ntohl(*p++); \ |
| 2488 | } while (0) |
| 2489 | #define COPYMEM(x,nbytes) do { \ |
| 2490 | memcpy((x), p, nbytes); \ |
| 2491 | p += XDR_QUADLEN(nbytes); \ |
| 2492 | } while (0) |
| 2493 | |
| 2494 | #define READ_BUF(nbytes) do { \ |
| 2495 | p = xdr_inline_decode(xdr, nbytes); \ |
Chuck Lever | e4cc6ee | 2007-05-08 18:23:28 -0400 | [diff] [blame] | 2496 | if (unlikely(!p)) { \ |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 2497 | dprintk("nfs: %s: prematurely hit end of receive" \ |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2498 | " buffer\n", __func__); \ |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 2499 | dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \ |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2500 | __func__, xdr->p, nbytes, xdr->end); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | return -EIO; \ |
| 2502 | } \ |
| 2503 | } while (0) |
| 2504 | |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2505 | static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2507 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | |
| 2509 | READ_BUF(4); |
| 2510 | READ32(*len); |
| 2511 | READ_BUF(*len); |
| 2512 | *string = (char *)p; |
| 2513 | return 0; |
| 2514 | } |
| 2515 | |
| 2516 | static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) |
| 2517 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2518 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | |
| 2520 | READ_BUF(8); |
| 2521 | READ32(hdr->status); |
| 2522 | READ32(hdr->taglen); |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 2523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | READ_BUF(hdr->taglen + 4); |
| 2525 | hdr->tag = (char *)p; |
| 2526 | p += XDR_QUADLEN(hdr->taglen); |
| 2527 | READ32(hdr->nops); |
Benny Halevy | aadf615 | 2008-12-23 16:06:13 -0500 | [diff] [blame] | 2528 | if (unlikely(hdr->nops < 1)) |
| 2529 | return nfs4_stat_to_errno(hdr->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | return 0; |
| 2531 | } |
| 2532 | |
| 2533 | static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) |
| 2534 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2535 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | uint32_t opnum; |
| 2537 | int32_t nfserr; |
| 2538 | |
| 2539 | READ_BUF(8); |
| 2540 | READ32(opnum); |
| 2541 | if (opnum != expected) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 2542 | dprintk("nfs: Server returned operation" |
| 2543 | " %d but we issued a request for %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | opnum, expected); |
| 2545 | return -EIO; |
| 2546 | } |
| 2547 | READ32(nfserr); |
| 2548 | if (nfserr != NFS_OK) |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 2549 | return nfs4_stat_to_errno(nfserr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | return 0; |
| 2551 | } |
| 2552 | |
| 2553 | /* Dummy routine */ |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 2554 | static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2556 | __be32 *p; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2557 | unsigned int strlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | char *str; |
| 2559 | |
| 2560 | READ_BUF(12); |
| 2561 | return decode_opaque_inline(xdr, &strlen, &str); |
| 2562 | } |
| 2563 | |
| 2564 | static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) |
| 2565 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2566 | uint32_t bmlen; |
| 2567 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | |
| 2569 | READ_BUF(4); |
| 2570 | READ32(bmlen); |
| 2571 | |
| 2572 | bitmap[0] = bitmap[1] = 0; |
| 2573 | READ_BUF((bmlen << 2)); |
| 2574 | if (bmlen > 0) { |
| 2575 | READ32(bitmap[0]); |
| 2576 | if (bmlen > 1) |
| 2577 | READ32(bitmap[1]); |
| 2578 | } |
| 2579 | return 0; |
| 2580 | } |
| 2581 | |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2582 | static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2584 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | |
| 2586 | READ_BUF(4); |
| 2587 | READ32(*attrlen); |
| 2588 | *savep = xdr->p; |
| 2589 | return 0; |
| 2590 | } |
| 2591 | |
| 2592 | static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) |
| 2593 | { |
| 2594 | if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { |
| 2595 | decode_attr_bitmap(xdr, bitmask); |
| 2596 | bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; |
| 2597 | } else |
| 2598 | bitmask[0] = bitmask[1] = 0; |
Fred Isaman | 4410924 | 2008-04-02 15:21:15 +0300 | [diff] [blame] | 2599 | dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | return 0; |
| 2601 | } |
| 2602 | |
| 2603 | static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) |
| 2604 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2605 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2606 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | |
| 2608 | *type = 0; |
| 2609 | if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) |
| 2610 | return -EIO; |
| 2611 | if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { |
| 2612 | READ_BUF(4); |
| 2613 | READ32(*type); |
| 2614 | if (*type < NF4REG || *type > NF4NAMEDATTR) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2615 | dprintk("%s: bad type %d\n", __func__, *type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | return -EIO; |
| 2617 | } |
| 2618 | bitmap[0] &= ~FATTR4_WORD0_TYPE; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2619 | ret = NFS_ATTR_FATTR_TYPE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | } |
Trond Myklebust | bca7947 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 2621 | dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2622 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) |
| 2626 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2627 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2628 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | |
| 2630 | *change = 0; |
| 2631 | if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) |
| 2632 | return -EIO; |
| 2633 | if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { |
| 2634 | READ_BUF(8); |
| 2635 | READ64(*change); |
| 2636 | bitmap[0] &= ~FATTR4_WORD0_CHANGE; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2637 | ret = NFS_ATTR_FATTR_CHANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2639 | dprintk("%s: change attribute=%Lu\n", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | (unsigned long long)*change); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2641 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) |
| 2645 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2646 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2647 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | |
| 2649 | *size = 0; |
| 2650 | if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) |
| 2651 | return -EIO; |
| 2652 | if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { |
| 2653 | READ_BUF(8); |
| 2654 | READ64(*size); |
| 2655 | bitmap[0] &= ~FATTR4_WORD0_SIZE; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2656 | ret = NFS_ATTR_FATTR_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2658 | dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2659 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2663 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2664 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | |
| 2666 | *res = 0; |
| 2667 | if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) |
| 2668 | return -EIO; |
| 2669 | if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { |
| 2670 | READ_BUF(4); |
| 2671 | READ32(*res); |
| 2672 | bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; |
| 2673 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2674 | dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | return 0; |
| 2676 | } |
| 2677 | |
| 2678 | static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2679 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2680 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | |
| 2682 | *res = 0; |
| 2683 | if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) |
| 2684 | return -EIO; |
| 2685 | if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { |
| 2686 | READ_BUF(4); |
| 2687 | READ32(*res); |
| 2688 | bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; |
| 2689 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2690 | dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | return 0; |
| 2692 | } |
| 2693 | |
Trond Myklebust | 8b4bdcf | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2694 | static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2696 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2697 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | |
| 2699 | fsid->major = 0; |
| 2700 | fsid->minor = 0; |
| 2701 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) |
| 2702 | return -EIO; |
| 2703 | if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { |
| 2704 | READ_BUF(16); |
| 2705 | READ64(fsid->major); |
| 2706 | READ64(fsid->minor); |
| 2707 | bitmap[0] &= ~FATTR4_WORD0_FSID; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2708 | ret = NFS_ATTR_FATTR_FSID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2710 | dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | (unsigned long long)fsid->major, |
| 2712 | (unsigned long long)fsid->minor); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2713 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2717 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2718 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | |
| 2720 | *res = 60; |
| 2721 | if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) |
| 2722 | return -EIO; |
| 2723 | if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { |
| 2724 | READ_BUF(4); |
| 2725 | READ32(*res); |
| 2726 | bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; |
| 2727 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2728 | dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | return 0; |
| 2730 | } |
| 2731 | |
| 2732 | static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2733 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2734 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | |
| 2736 | *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; |
| 2737 | if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) |
| 2738 | return -EIO; |
| 2739 | if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { |
| 2740 | READ_BUF(4); |
| 2741 | READ32(*res); |
| 2742 | bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; |
| 2743 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2744 | dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | return 0; |
| 2746 | } |
| 2747 | |
| 2748 | static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) |
| 2749 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2750 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2751 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | |
| 2753 | *fileid = 0; |
| 2754 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) |
| 2755 | return -EIO; |
| 2756 | if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { |
| 2757 | READ_BUF(8); |
| 2758 | READ64(*fileid); |
| 2759 | bitmap[0] &= ~FATTR4_WORD0_FILEID; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2760 | ret = NFS_ATTR_FATTR_FILEID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2762 | dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2763 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
Manoj Naik | 99baf62 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 2766 | static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) |
| 2767 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2768 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2769 | int ret = 0; |
Manoj Naik | 99baf62 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 2770 | |
| 2771 | *fileid = 0; |
| 2772 | if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) |
| 2773 | return -EIO; |
| 2774 | if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { |
| 2775 | READ_BUF(8); |
| 2776 | READ64(*fileid); |
| 2777 | bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2778 | ret = NFS_ATTR_FATTR_FILEID; |
Manoj Naik | 99baf62 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 2779 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2780 | dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2781 | return ret; |
Manoj Naik | 99baf62 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 2782 | } |
| 2783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2785 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2786 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | int status = 0; |
| 2788 | |
| 2789 | *res = 0; |
| 2790 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) |
| 2791 | return -EIO; |
| 2792 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { |
| 2793 | READ_BUF(8); |
| 2794 | READ64(*res); |
| 2795 | bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; |
| 2796 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2797 | dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | return status; |
| 2799 | } |
| 2800 | |
| 2801 | static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2802 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2803 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | int status = 0; |
| 2805 | |
| 2806 | *res = 0; |
| 2807 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) |
| 2808 | return -EIO; |
| 2809 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { |
| 2810 | READ_BUF(8); |
| 2811 | READ64(*res); |
| 2812 | bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; |
| 2813 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2814 | dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | return status; |
| 2816 | } |
| 2817 | |
| 2818 | static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2819 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2820 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | int status = 0; |
| 2822 | |
| 2823 | *res = 0; |
| 2824 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) |
| 2825 | return -EIO; |
| 2826 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { |
| 2827 | READ_BUF(8); |
| 2828 | READ64(*res); |
| 2829 | bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; |
| 2830 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2831 | dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | return status; |
| 2833 | } |
| 2834 | |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2835 | static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) |
| 2836 | { |
Chuck Lever | 464ad6b | 2007-10-26 13:32:08 -0400 | [diff] [blame] | 2837 | u32 n; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2838 | __be32 *p; |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2839 | int status = 0; |
| 2840 | |
| 2841 | READ_BUF(4); |
| 2842 | READ32(n); |
Andy Adamson | 33a43f2 | 2006-06-09 09:34:30 -0400 | [diff] [blame] | 2843 | if (n == 0) |
| 2844 | goto root_path; |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2845 | dprintk("path "); |
| 2846 | path->ncomponents = 0; |
| 2847 | while (path->ncomponents < n) { |
| 2848 | struct nfs4_string *component = &path->components[path->ncomponents]; |
| 2849 | status = decode_opaque_inline(xdr, &component->len, &component->data); |
| 2850 | if (unlikely(status != 0)) |
| 2851 | goto out_eio; |
| 2852 | if (path->ncomponents != n) |
| 2853 | dprintk("/"); |
| 2854 | dprintk("%s", component->data); |
| 2855 | if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) |
| 2856 | path->ncomponents++; |
| 2857 | else { |
| 2858 | dprintk("cannot parse %d components in path\n", n); |
| 2859 | goto out_eio; |
| 2860 | } |
| 2861 | } |
| 2862 | out: |
| 2863 | dprintk("\n"); |
| 2864 | return status; |
Andy Adamson | 33a43f2 | 2006-06-09 09:34:30 -0400 | [diff] [blame] | 2865 | root_path: |
| 2866 | /* a root pathname is sent as a zero component4 */ |
| 2867 | path->ncomponents = 1; |
| 2868 | path->components[0].len=0; |
| 2869 | path->components[0].data=NULL; |
| 2870 | dprintk("path /\n"); |
| 2871 | goto out; |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2872 | out_eio: |
| 2873 | dprintk(" status %d", status); |
| 2874 | status = -EIO; |
| 2875 | goto out; |
| 2876 | } |
| 2877 | |
| 2878 | static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2879 | { |
| 2880 | int n; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2881 | __be32 *p; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2882 | int status = -EIO; |
| 2883 | |
| 2884 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) |
| 2885 | goto out; |
| 2886 | status = 0; |
| 2887 | if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) |
| 2888 | goto out; |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2889 | dprintk("%s: fsroot ", __func__); |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2890 | status = decode_pathname(xdr, &res->fs_path); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2891 | if (unlikely(status != 0)) |
| 2892 | goto out; |
| 2893 | READ_BUF(4); |
| 2894 | READ32(n); |
| 2895 | if (n <= 0) |
| 2896 | goto out_eio; |
| 2897 | res->nlocations = 0; |
| 2898 | while (res->nlocations < n) { |
Chuck Lever | 464ad6b | 2007-10-26 13:32:08 -0400 | [diff] [blame] | 2899 | u32 m; |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2900 | struct nfs4_fs_location *loc = &res->locations[res->nlocations]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2901 | |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2902 | READ_BUF(4); |
| 2903 | READ32(m); |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2904 | |
| 2905 | loc->nservers = 0; |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2906 | dprintk("%s: servers ", __func__); |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2907 | while (loc->nservers < m) { |
| 2908 | struct nfs4_string *server = &loc->servers[loc->nservers]; |
| 2909 | status = decode_opaque_inline(xdr, &server->len, &server->data); |
| 2910 | if (unlikely(status != 0)) |
| 2911 | goto out_eio; |
| 2912 | dprintk("%s ", server->data); |
| 2913 | if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) |
| 2914 | loc->nservers++; |
| 2915 | else { |
Chuck Lever | 464ad6b | 2007-10-26 13:32:08 -0400 | [diff] [blame] | 2916 | unsigned int i; |
| 2917 | dprintk("%s: using first %u of %u servers " |
| 2918 | "returned for location %u\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2919 | __func__, |
Chuck Lever | 464ad6b | 2007-10-26 13:32:08 -0400 | [diff] [blame] | 2920 | NFS4_FS_LOCATION_MAXSERVERS, |
| 2921 | m, res->nlocations); |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2922 | for (i = loc->nservers; i < m; i++) { |
Trond Myklebust | 2e42c3e | 2007-05-14 17:20:41 -0400 | [diff] [blame] | 2923 | unsigned int len; |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2924 | char *data; |
| 2925 | status = decode_opaque_inline(xdr, &len, &data); |
| 2926 | if (unlikely(status != 0)) |
| 2927 | goto out_eio; |
| 2928 | } |
| 2929 | } |
| 2930 | } |
| 2931 | status = decode_pathname(xdr, &loc->rootpath); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2932 | if (unlikely(status != 0)) |
| 2933 | goto out_eio; |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 2934 | if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2935 | res->nlocations++; |
| 2936 | } |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 2937 | if (res->nlocations != 0) |
| 2938 | status = NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2939 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2940 | dprintk("%s: fs_locations done, error = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2941 | return status; |
| 2942 | out_eio: |
| 2943 | status = -EIO; |
| 2944 | goto out; |
| 2945 | } |
| 2946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2948 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2949 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | int status = 0; |
| 2951 | |
| 2952 | *res = 0; |
| 2953 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) |
| 2954 | return -EIO; |
| 2955 | if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { |
| 2956 | READ_BUF(8); |
| 2957 | READ64(*res); |
| 2958 | bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; |
| 2959 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2960 | dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | return status; |
| 2962 | } |
| 2963 | |
| 2964 | static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) |
| 2965 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2966 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | int status = 0; |
| 2968 | |
| 2969 | *maxlink = 1; |
| 2970 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) |
| 2971 | return -EIO; |
| 2972 | if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { |
| 2973 | READ_BUF(4); |
| 2974 | READ32(*maxlink); |
| 2975 | bitmap[0] &= ~FATTR4_WORD0_MAXLINK; |
| 2976 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2977 | dprintk("%s: maxlink=%u\n", __func__, *maxlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | return status; |
| 2979 | } |
| 2980 | |
| 2981 | static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) |
| 2982 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 2983 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | int status = 0; |
| 2985 | |
| 2986 | *maxname = 1024; |
| 2987 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) |
| 2988 | return -EIO; |
| 2989 | if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { |
| 2990 | READ_BUF(4); |
| 2991 | READ32(*maxname); |
| 2992 | bitmap[0] &= ~FATTR4_WORD0_MAXNAME; |
| 2993 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2994 | dprintk("%s: maxname=%u\n", __func__, *maxname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | return status; |
| 2996 | } |
| 2997 | |
| 2998 | static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2999 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3000 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | int status = 0; |
| 3002 | |
| 3003 | *res = 1024; |
| 3004 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) |
| 3005 | return -EIO; |
| 3006 | if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { |
| 3007 | uint64_t maxread; |
| 3008 | READ_BUF(8); |
| 3009 | READ64(maxread); |
| 3010 | if (maxread > 0x7FFFFFFF) |
| 3011 | maxread = 0x7FFFFFFF; |
| 3012 | *res = (uint32_t)maxread; |
| 3013 | bitmap[0] &= ~FATTR4_WORD0_MAXREAD; |
| 3014 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3015 | dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | return status; |
| 3017 | } |
| 3018 | |
| 3019 | static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 3020 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3021 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | int status = 0; |
| 3023 | |
| 3024 | *res = 1024; |
| 3025 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) |
| 3026 | return -EIO; |
| 3027 | if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { |
| 3028 | uint64_t maxwrite; |
| 3029 | READ_BUF(8); |
| 3030 | READ64(maxwrite); |
| 3031 | if (maxwrite > 0x7FFFFFFF) |
| 3032 | maxwrite = 0x7FFFFFFF; |
| 3033 | *res = (uint32_t)maxwrite; |
| 3034 | bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; |
| 3035 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3036 | dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | return status; |
| 3038 | } |
| 3039 | |
Trond Myklebust | bca7947 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3040 | static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | { |
Trond Myklebust | bca7947 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3042 | uint32_t tmp; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3043 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3044 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | |
| 3046 | *mode = 0; |
| 3047 | if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) |
| 3048 | return -EIO; |
| 3049 | if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { |
| 3050 | READ_BUF(4); |
Trond Myklebust | bca7947 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3051 | READ32(tmp); |
| 3052 | *mode = tmp & ~S_IFMT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | bitmap[1] &= ~FATTR4_WORD1_MODE; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3054 | ret = NFS_ATTR_FATTR_MODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3056 | dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3057 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) |
| 3061 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3062 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3063 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | |
| 3065 | *nlink = 1; |
| 3066 | if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) |
| 3067 | return -EIO; |
| 3068 | if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { |
| 3069 | READ_BUF(4); |
| 3070 | READ32(*nlink); |
| 3071 | bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3072 | ret = NFS_ATTR_FATTR_NLINK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3074 | dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3075 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
Trond Myklebust | 2e42c3e | 2007-05-14 17:20:41 -0400 | [diff] [blame] | 3078 | static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3080 | uint32_t len; |
| 3081 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3082 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | |
| 3084 | *uid = -2; |
| 3085 | if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) |
| 3086 | return -EIO; |
| 3087 | if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { |
| 3088 | READ_BUF(4); |
| 3089 | READ32(len); |
| 3090 | READ_BUF(len); |
| 3091 | if (len < XDR_MAX_NETOBJ) { |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3092 | if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0) |
| 3093 | ret = NFS_ATTR_FATTR_OWNER; |
| 3094 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | dprintk("%s: nfs_map_name_to_uid failed!\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3096 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | } else |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 3098 | dprintk("%s: name too long (%u)!\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3099 | __func__, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | bitmap[1] &= ~FATTR4_WORD1_OWNER; |
| 3101 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3102 | dprintk("%s: uid=%d\n", __func__, (int)*uid); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3103 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | } |
| 3105 | |
Trond Myklebust | 2e42c3e | 2007-05-14 17:20:41 -0400 | [diff] [blame] | 3106 | static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3108 | uint32_t len; |
| 3109 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3110 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | |
| 3112 | *gid = -2; |
| 3113 | if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) |
| 3114 | return -EIO; |
| 3115 | if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { |
| 3116 | READ_BUF(4); |
| 3117 | READ32(len); |
| 3118 | READ_BUF(len); |
| 3119 | if (len < XDR_MAX_NETOBJ) { |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3120 | if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0) |
| 3121 | ret = NFS_ATTR_FATTR_GROUP; |
| 3122 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | dprintk("%s: nfs_map_group_to_gid failed!\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3124 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | } else |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 3126 | dprintk("%s: name too long (%u)!\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3127 | __func__, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; |
| 3129 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3130 | dprintk("%s: gid=%d\n", __func__, (int)*gid); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3131 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | } |
| 3133 | |
| 3134 | static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) |
| 3135 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3136 | uint32_t major = 0, minor = 0; |
| 3137 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3138 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | |
| 3140 | *rdev = MKDEV(0,0); |
| 3141 | if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) |
| 3142 | return -EIO; |
| 3143 | if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { |
| 3144 | dev_t tmp; |
| 3145 | |
| 3146 | READ_BUF(8); |
| 3147 | READ32(major); |
| 3148 | READ32(minor); |
| 3149 | tmp = MKDEV(major, minor); |
| 3150 | if (MAJOR(tmp) == major && MINOR(tmp) == minor) |
| 3151 | *rdev = tmp; |
| 3152 | bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3153 | ret = NFS_ATTR_FATTR_RDEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3155 | dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3156 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 3160 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3161 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | int status = 0; |
| 3163 | |
| 3164 | *res = 0; |
| 3165 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) |
| 3166 | return -EIO; |
| 3167 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { |
| 3168 | READ_BUF(8); |
| 3169 | READ64(*res); |
| 3170 | bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; |
| 3171 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3172 | dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | return status; |
| 3174 | } |
| 3175 | |
| 3176 | static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 3177 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3178 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | int status = 0; |
| 3180 | |
| 3181 | *res = 0; |
| 3182 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) |
| 3183 | return -EIO; |
| 3184 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { |
| 3185 | READ_BUF(8); |
| 3186 | READ64(*res); |
| 3187 | bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; |
| 3188 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3189 | dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | return status; |
| 3191 | } |
| 3192 | |
| 3193 | static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 3194 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3195 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | int status = 0; |
| 3197 | |
| 3198 | *res = 0; |
| 3199 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) |
| 3200 | return -EIO; |
| 3201 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { |
| 3202 | READ_BUF(8); |
| 3203 | READ64(*res); |
| 3204 | bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; |
| 3205 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3206 | dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | return status; |
| 3208 | } |
| 3209 | |
| 3210 | static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) |
| 3211 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3212 | __be32 *p; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3213 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | |
| 3215 | *used = 0; |
| 3216 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) |
| 3217 | return -EIO; |
| 3218 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { |
| 3219 | READ_BUF(8); |
| 3220 | READ64(*used); |
| 3221 | bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3222 | ret = NFS_ATTR_FATTR_SPACE_USED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3224 | dprintk("%s: space used=%Lu\n", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | (unsigned long long)*used); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3226 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) |
| 3230 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3231 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | uint64_t sec; |
| 3233 | uint32_t nsec; |
| 3234 | |
| 3235 | READ_BUF(12); |
| 3236 | READ64(sec); |
| 3237 | READ32(nsec); |
| 3238 | time->tv_sec = (time_t)sec; |
| 3239 | time->tv_nsec = (long)nsec; |
| 3240 | return 0; |
| 3241 | } |
| 3242 | |
| 3243 | static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) |
| 3244 | { |
| 3245 | int status = 0; |
| 3246 | |
| 3247 | time->tv_sec = 0; |
| 3248 | time->tv_nsec = 0; |
| 3249 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) |
| 3250 | return -EIO; |
| 3251 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { |
| 3252 | status = decode_attr_time(xdr, time); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3253 | if (status == 0) |
| 3254 | status = NFS_ATTR_FATTR_ATIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; |
| 3256 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3257 | dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | return status; |
| 3259 | } |
| 3260 | |
| 3261 | static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) |
| 3262 | { |
| 3263 | int status = 0; |
| 3264 | |
| 3265 | time->tv_sec = 0; |
| 3266 | time->tv_nsec = 0; |
| 3267 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) |
| 3268 | return -EIO; |
| 3269 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { |
| 3270 | status = decode_attr_time(xdr, time); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3271 | if (status == 0) |
| 3272 | status = NFS_ATTR_FATTR_CTIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; |
| 3274 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3275 | dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | return status; |
| 3277 | } |
| 3278 | |
| 3279 | static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) |
| 3280 | { |
| 3281 | int status = 0; |
| 3282 | |
| 3283 | time->tv_sec = 0; |
| 3284 | time->tv_nsec = 0; |
| 3285 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) |
| 3286 | return -EIO; |
| 3287 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { |
| 3288 | status = decode_attr_time(xdr, time); |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3289 | if (status == 0) |
| 3290 | status = NFS_ATTR_FATTR_MTIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; |
| 3292 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3293 | dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | return status; |
| 3295 | } |
| 3296 | |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3297 | static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | { |
| 3299 | unsigned int attrwords = XDR_QUADLEN(attrlen); |
| 3300 | unsigned int nwords = xdr->p - savep; |
| 3301 | |
| 3302 | if (unlikely(attrwords != nwords)) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 3303 | dprintk("%s: server returned incorrect attribute length: " |
| 3304 | "%u %c %u\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3305 | __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | attrwords << 2, |
| 3307 | (attrwords < nwords) ? '<' : '>', |
| 3308 | nwords << 2); |
| 3309 | return -EIO; |
| 3310 | } |
| 3311 | return 0; |
| 3312 | } |
| 3313 | |
| 3314 | static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) |
| 3315 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3316 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | |
| 3318 | READ_BUF(20); |
| 3319 | READ32(cinfo->atomic); |
| 3320 | READ64(cinfo->before); |
| 3321 | READ64(cinfo->after); |
| 3322 | return 0; |
| 3323 | } |
| 3324 | |
| 3325 | static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) |
| 3326 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3327 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | uint32_t supp, acc; |
| 3329 | int status; |
| 3330 | |
| 3331 | status = decode_op_hdr(xdr, OP_ACCESS); |
| 3332 | if (status) |
| 3333 | return status; |
| 3334 | READ_BUF(8); |
| 3335 | READ32(supp); |
| 3336 | READ32(acc); |
| 3337 | access->supported = supp; |
| 3338 | access->access = acc; |
| 3339 | return 0; |
| 3340 | } |
| 3341 | |
| 3342 | static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) |
| 3343 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3344 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | int status; |
| 3346 | |
| 3347 | status = decode_op_hdr(xdr, OP_CLOSE); |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3348 | if (status != -EIO) |
| 3349 | nfs_increment_open_seqid(status, res->seqid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | if (status) |
| 3351 | return status; |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 3352 | READ_BUF(NFS4_STATEID_SIZE); |
| 3353 | COPYMEM(res->stateid.data, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | return 0; |
| 3355 | } |
| 3356 | |
| 3357 | static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) |
| 3358 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3359 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | int status; |
| 3361 | |
| 3362 | status = decode_op_hdr(xdr, OP_COMMIT); |
| 3363 | if (status) |
| 3364 | return status; |
| 3365 | READ_BUF(8); |
| 3366 | COPYMEM(res->verf->verifier, 8); |
| 3367 | return 0; |
| 3368 | } |
| 3369 | |
| 3370 | static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) |
| 3371 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3372 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | uint32_t bmlen; |
| 3374 | int status; |
| 3375 | |
| 3376 | status = decode_op_hdr(xdr, OP_CREATE); |
| 3377 | if (status) |
| 3378 | return status; |
| 3379 | if ((status = decode_change_info(xdr, cinfo))) |
| 3380 | return status; |
| 3381 | READ_BUF(4); |
| 3382 | READ32(bmlen); |
| 3383 | READ_BUF(bmlen << 2); |
| 3384 | return 0; |
| 3385 | } |
| 3386 | |
| 3387 | static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) |
| 3388 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3389 | __be32 *savep; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3390 | uint32_t attrlen, bitmap[2] = {0}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | int status; |
| 3392 | |
| 3393 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 3394 | goto xdr_error; |
| 3395 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 3396 | goto xdr_error; |
| 3397 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 3398 | goto xdr_error; |
| 3399 | if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) |
| 3400 | goto xdr_error; |
| 3401 | if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) |
| 3402 | goto xdr_error; |
| 3403 | if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) |
| 3404 | goto xdr_error; |
| 3405 | if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) |
| 3406 | goto xdr_error; |
| 3407 | status = verify_attr_len(xdr, savep, attrlen); |
| 3408 | xdr_error: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3409 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | return status; |
| 3411 | } |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) |
| 3414 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3415 | __be32 *savep; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3416 | uint32_t attrlen, bitmap[2] = {0}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 3420 | goto xdr_error; |
| 3421 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 3422 | goto xdr_error; |
| 3423 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 3424 | goto xdr_error; |
| 3425 | |
| 3426 | if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) |
| 3427 | goto xdr_error; |
| 3428 | if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) |
| 3429 | goto xdr_error; |
| 3430 | if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) |
| 3431 | goto xdr_error; |
| 3432 | if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) |
| 3433 | goto xdr_error; |
| 3434 | if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) |
| 3435 | goto xdr_error; |
| 3436 | if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) |
| 3437 | goto xdr_error; |
| 3438 | |
| 3439 | status = verify_attr_len(xdr, savep, attrlen); |
| 3440 | xdr_error: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3441 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | return status; |
| 3443 | } |
| 3444 | |
| 3445 | static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) |
| 3446 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3447 | __be32 *savep; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3448 | uint32_t attrlen, bitmap[2] = {0}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 3452 | goto xdr_error; |
| 3453 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 3454 | goto xdr_error; |
| 3455 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 3456 | goto xdr_error; |
| 3457 | |
| 3458 | if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) |
| 3459 | goto xdr_error; |
| 3460 | if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) |
| 3461 | goto xdr_error; |
| 3462 | |
| 3463 | status = verify_attr_len(xdr, savep, attrlen); |
| 3464 | xdr_error: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3465 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | return status; |
| 3467 | } |
| 3468 | |
| 3469 | static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server) |
| 3470 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3471 | __be32 *savep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | uint32_t attrlen, |
| 3473 | bitmap[2] = {0}, |
| 3474 | type; |
Trond Myklebust | bca7947 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3475 | int status; |
| 3476 | umode_t fmode = 0; |
Manoj Naik | 99baf62 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 3477 | uint64_t fileid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3479 | status = decode_op_hdr(xdr, OP_GETATTR); |
| 3480 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 | goto xdr_error; |
| 3482 | |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3483 | status = decode_attr_bitmap(xdr, bitmap); |
| 3484 | if (status < 0) |
| 3485 | goto xdr_error; |
| 3486 | |
| 3487 | status = decode_attr_length(xdr, &attrlen, &savep); |
| 3488 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | goto xdr_error; |
| 3490 | |
| 3491 | |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3492 | status = decode_attr_type(xdr, bitmap, &type); |
| 3493 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3495 | fattr->mode = 0; |
| 3496 | if (status != 0) { |
| 3497 | fattr->mode |= nfs_type2fmt[type]; |
| 3498 | fattr->valid |= status; |
| 3499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3501 | status = decode_attr_change(xdr, bitmap, &fattr->change_attr); |
| 3502 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3504 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3505 | |
| 3506 | status = decode_attr_size(xdr, bitmap, &fattr->size); |
| 3507 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3509 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3510 | |
| 3511 | status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); |
| 3512 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3514 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3515 | |
| 3516 | status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); |
| 3517 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3519 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3520 | |
| 3521 | status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 3522 | struct nfs4_fs_locations, |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3523 | fattr)); |
| 3524 | if (status < 0) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 3525 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3526 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3527 | |
| 3528 | status = decode_attr_mode(xdr, bitmap, &fmode); |
| 3529 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3531 | if (status != 0) { |
| 3532 | fattr->mode |= fmode; |
| 3533 | fattr->valid |= status; |
| 3534 | } |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3535 | |
| 3536 | status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); |
| 3537 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3539 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3540 | |
| 3541 | status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid); |
| 3542 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3544 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3545 | |
| 3546 | status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid); |
| 3547 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3549 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3550 | |
| 3551 | status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); |
| 3552 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3554 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3555 | |
| 3556 | status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); |
| 3557 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3559 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3560 | |
| 3561 | status = decode_attr_time_access(xdr, bitmap, &fattr->atime); |
| 3562 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3564 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3565 | |
| 3566 | status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); |
| 3567 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3569 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3570 | |
| 3571 | status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); |
| 3572 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3574 | fattr->valid |= status; |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3575 | |
| 3576 | status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid); |
| 3577 | if (status < 0) |
Manoj Naik | 99baf62 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 3578 | goto xdr_error; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3579 | if (status != 0 && !(fattr->valid & status)) { |
Manoj Naik | 99baf62 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 3580 | fattr->fileid = fileid; |
Trond Myklebust | 409924e | 2009-03-11 14:10:27 -0400 | [diff] [blame] | 3581 | fattr->valid |= status; |
| 3582 | } |
Trond Myklebust | f26c7a7 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 3583 | |
| 3584 | status = verify_attr_len(xdr, savep, attrlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | xdr_error: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3586 | dprintk("%s: xdr returned %d\n", __func__, -status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | return status; |
| 3588 | } |
| 3589 | |
| 3590 | |
| 3591 | static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) |
| 3592 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3593 | __be32 *savep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | uint32_t attrlen, bitmap[2]; |
| 3595 | int status; |
| 3596 | |
| 3597 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 3598 | goto xdr_error; |
| 3599 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 3600 | goto xdr_error; |
| 3601 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 3602 | goto xdr_error; |
| 3603 | |
| 3604 | fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ |
| 3605 | |
| 3606 | if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) |
| 3607 | goto xdr_error; |
| 3608 | if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) |
| 3609 | goto xdr_error; |
| 3610 | if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) |
| 3611 | goto xdr_error; |
| 3612 | fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; |
| 3613 | if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) |
| 3614 | goto xdr_error; |
| 3615 | fsinfo->wtpref = fsinfo->wtmax; |
| 3616 | |
| 3617 | status = verify_attr_len(xdr, savep, attrlen); |
| 3618 | xdr_error: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3619 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | return status; |
| 3621 | } |
| 3622 | |
| 3623 | static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) |
| 3624 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3625 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | uint32_t len; |
| 3627 | int status; |
| 3628 | |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 3629 | /* Zero handle first to allow comparisons */ |
| 3630 | memset(fh, 0, sizeof(*fh)); |
| 3631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | status = decode_op_hdr(xdr, OP_GETFH); |
| 3633 | if (status) |
| 3634 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | |
| 3636 | READ_BUF(4); |
| 3637 | READ32(len); |
| 3638 | if (len > NFS4_FHSIZE) |
| 3639 | return -EIO; |
| 3640 | fh->size = len; |
| 3641 | READ_BUF(len); |
| 3642 | COPYMEM(fh->data, len); |
| 3643 | return 0; |
| 3644 | } |
| 3645 | |
| 3646 | static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) |
| 3647 | { |
| 3648 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | status = decode_op_hdr(xdr, OP_LINK); |
| 3651 | if (status) |
| 3652 | return status; |
| 3653 | return decode_change_info(xdr, cinfo); |
| 3654 | } |
| 3655 | |
| 3656 | /* |
| 3657 | * We create the owner, so we know a proper owner.id length is 4. |
| 3658 | */ |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3659 | static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3661 | uint64_t offset, length, clientid; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3662 | __be32 *p; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3663 | uint32_t namelen, type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | |
| 3665 | READ_BUF(32); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3666 | READ64(offset); |
| 3667 | READ64(length); |
| 3668 | READ32(type); |
| 3669 | if (fl != NULL) { |
| 3670 | fl->fl_start = (loff_t)offset; |
| 3671 | fl->fl_end = fl->fl_start + (loff_t)length - 1; |
| 3672 | if (length == ~(uint64_t)0) |
| 3673 | fl->fl_end = OFFSET_MAX; |
| 3674 | fl->fl_type = F_WRLCK; |
| 3675 | if (type & 1) |
| 3676 | fl->fl_type = F_RDLCK; |
| 3677 | fl->fl_pid = 0; |
| 3678 | } |
| 3679 | READ64(clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | READ32(namelen); |
| 3681 | READ_BUF(namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | return -NFS4ERR_DENIED; |
| 3683 | } |
| 3684 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3685 | static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3687 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | int status; |
| 3689 | |
| 3690 | status = decode_op_hdr(xdr, OP_LOCK); |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3691 | if (status == -EIO) |
| 3692 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | if (status == 0) { |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 3694 | READ_BUF(NFS4_STATEID_SIZE); |
| 3695 | COPYMEM(res->stateid.data, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | } else if (status == -NFS4ERR_DENIED) |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3697 | status = decode_lock_denied(xdr, NULL); |
| 3698 | if (res->open_seqid != NULL) |
| 3699 | nfs_increment_open_seqid(status, res->open_seqid); |
| 3700 | nfs_increment_lock_seqid(status, res->lock_seqid); |
| 3701 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | return status; |
| 3703 | } |
| 3704 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3705 | static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | { |
| 3707 | int status; |
| 3708 | status = decode_op_hdr(xdr, OP_LOCKT); |
| 3709 | if (status == -NFS4ERR_DENIED) |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3710 | return decode_lock_denied(xdr, res->denied); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | return status; |
| 3712 | } |
| 3713 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3714 | static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3716 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | int status; |
| 3718 | |
| 3719 | status = decode_op_hdr(xdr, OP_LOCKU); |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3720 | if (status != -EIO) |
| 3721 | nfs_increment_lock_seqid(status, res->seqid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | if (status == 0) { |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 3723 | READ_BUF(NFS4_STATEID_SIZE); |
| 3724 | COPYMEM(res->stateid.data, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | } |
| 3726 | return status; |
| 3727 | } |
| 3728 | |
| 3729 | static int decode_lookup(struct xdr_stream *xdr) |
| 3730 | { |
| 3731 | return decode_op_hdr(xdr, OP_LOOKUP); |
| 3732 | } |
| 3733 | |
| 3734 | /* This is too sick! */ |
| 3735 | static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) |
| 3736 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3737 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | uint32_t limit_type, nblocks, blocksize; |
| 3739 | |
| 3740 | READ_BUF(12); |
| 3741 | READ32(limit_type); |
| 3742 | switch (limit_type) { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3743 | case 1: |
| 3744 | READ64(*maxsize); |
| 3745 | break; |
| 3746 | case 2: |
| 3747 | READ32(nblocks); |
| 3748 | READ32(blocksize); |
| 3749 | *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | } |
| 3751 | return 0; |
| 3752 | } |
| 3753 | |
| 3754 | static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) |
| 3755 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3756 | __be32 *p; |
| 3757 | uint32_t delegation_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | |
| 3759 | READ_BUF(4); |
| 3760 | READ32(delegation_type); |
| 3761 | if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { |
| 3762 | res->delegation_type = 0; |
| 3763 | return 0; |
| 3764 | } |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 3765 | READ_BUF(NFS4_STATEID_SIZE+4); |
| 3766 | COPYMEM(res->delegation.data, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | READ32(res->do_recall); |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | switch (delegation_type) { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3770 | case NFS4_OPEN_DELEGATE_READ: |
| 3771 | res->delegation_type = FMODE_READ; |
| 3772 | break; |
| 3773 | case NFS4_OPEN_DELEGATE_WRITE: |
| 3774 | res->delegation_type = FMODE_WRITE|FMODE_READ; |
| 3775 | if (decode_space_limit(xdr, &res->maxsize) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | return -EIO; |
| 3777 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3778 | return decode_ace(xdr, NULL, res->server->nfs_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
| 3781 | static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) |
| 3782 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3783 | __be32 *p; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3784 | uint32_t savewords, bmlen, i; |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3785 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3787 | status = decode_op_hdr(xdr, OP_OPEN); |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3788 | if (status != -EIO) |
| 3789 | nfs_increment_open_seqid(status, res->seqid); |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3790 | if (status) |
| 3791 | return status; |
| 3792 | READ_BUF(NFS4_STATEID_SIZE); |
| 3793 | COPYMEM(res->stateid.data, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3795 | decode_change_info(xdr, &res->cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3797 | READ_BUF(8); |
| 3798 | READ32(res->rflags); |
| 3799 | READ32(bmlen); |
| 3800 | if (bmlen > 10) |
| 3801 | goto xdr_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3803 | READ_BUF(bmlen << 2); |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3804 | savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); |
| 3805 | for (i = 0; i < savewords; ++i) |
| 3806 | READ32(res->attrset[i]); |
| 3807 | for (; i < NFS4_BITMAP_SIZE; i++) |
| 3808 | res->attrset[i] = 0; |
| 3809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | return decode_delegation(xdr, res); |
| 3811 | xdr_error: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3812 | dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | return -EIO; |
| 3814 | } |
| 3815 | |
| 3816 | static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) |
| 3817 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3818 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | int status; |
| 3820 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3821 | status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3822 | if (status != -EIO) |
| 3823 | nfs_increment_open_seqid(status, res->seqid); |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3824 | if (status) |
| 3825 | return status; |
| 3826 | READ_BUF(NFS4_STATEID_SIZE); |
| 3827 | COPYMEM(res->stateid.data, NFS4_STATEID_SIZE); |
| 3828 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
| 3831 | static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) |
| 3832 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3833 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | int status; |
| 3835 | |
| 3836 | status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3837 | if (status != -EIO) |
| 3838 | nfs_increment_open_seqid(status, res->seqid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | if (status) |
| 3840 | return status; |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 3841 | READ_BUF(NFS4_STATEID_SIZE); |
| 3842 | COPYMEM(res->stateid.data, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | return 0; |
| 3844 | } |
| 3845 | |
| 3846 | static int decode_putfh(struct xdr_stream *xdr) |
| 3847 | { |
| 3848 | return decode_op_hdr(xdr, OP_PUTFH); |
| 3849 | } |
| 3850 | |
| 3851 | static int decode_putrootfh(struct xdr_stream *xdr) |
| 3852 | { |
| 3853 | return decode_op_hdr(xdr, OP_PUTROOTFH); |
| 3854 | } |
| 3855 | |
| 3856 | static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) |
| 3857 | { |
| 3858 | struct kvec *iov = req->rq_rcv_buf.head; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3859 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | uint32_t count, eof, recvd, hdrlen; |
| 3861 | int status; |
| 3862 | |
| 3863 | status = decode_op_hdr(xdr, OP_READ); |
| 3864 | if (status) |
| 3865 | return status; |
| 3866 | READ_BUF(8); |
| 3867 | READ32(eof); |
| 3868 | READ32(count); |
| 3869 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; |
| 3870 | recvd = req->rq_rcv_buf.len - hdrlen; |
| 3871 | if (count > recvd) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 3872 | dprintk("NFS: server cheating in read reply: " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | "count %u > recvd %u\n", count, recvd); |
| 3874 | count = recvd; |
| 3875 | eof = 0; |
| 3876 | } |
| 3877 | xdr_read_pages(xdr, count); |
| 3878 | res->eof = eof; |
| 3879 | res->count = count; |
| 3880 | return 0; |
| 3881 | } |
| 3882 | |
| 3883 | static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) |
| 3884 | { |
| 3885 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; |
| 3886 | struct page *page = *rcvbuf->pages; |
| 3887 | struct kvec *iov = rcvbuf->head; |
Chuck Lever | bcecff7 | 2007-10-26 13:32:03 -0400 | [diff] [blame] | 3888 | size_t hdrlen; |
| 3889 | u32 recvd, pglen = rcvbuf->page_len; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3890 | __be32 *end, *entry, *p, *kaddr; |
Jeff Layton | 7bda2cd | 2008-02-22 14:50:01 -0500 | [diff] [blame] | 3891 | unsigned int nr = 0; |
Chuck Lever | bcecff7 | 2007-10-26 13:32:03 -0400 | [diff] [blame] | 3892 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | |
| 3894 | status = decode_op_hdr(xdr, OP_READDIR); |
| 3895 | if (status) |
| 3896 | return status; |
| 3897 | READ_BUF(8); |
| 3898 | COPYMEM(readdir->verifier.data, 8); |
Fred Isaman | 4410924 | 2008-04-02 15:21:15 +0300 | [diff] [blame] | 3899 | dprintk("%s: verifier = %08x:%08x\n", |
| 3900 | __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3901 | ((u32 *)readdir->verifier.data)[0], |
| 3902 | ((u32 *)readdir->verifier.data)[1]); |
| 3903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | |
| 3905 | hdrlen = (char *) p - (char *) iov->iov_base; |
| 3906 | recvd = rcvbuf->len - hdrlen; |
| 3907 | if (pglen > recvd) |
| 3908 | pglen = recvd; |
| 3909 | xdr_read_pages(xdr, pglen); |
| 3910 | |
| 3911 | BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE); |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3912 | kaddr = p = kmap_atomic(page, KM_USER0); |
David Howells | e889649 | 2006-08-24 15:44:19 -0400 | [diff] [blame] | 3913 | end = p + ((pglen + readdir->pgbase) >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | entry = p; |
Jeff Layton | 7bda2cd | 2008-02-22 14:50:01 -0500 | [diff] [blame] | 3915 | |
| 3916 | /* Make sure the packet actually has a value_follows and EOF entry */ |
| 3917 | if ((entry + 1) > end) |
| 3918 | goto short_pkt; |
| 3919 | |
| 3920 | for (; *p++; nr++) { |
Chuck Lever | bcecff7 | 2007-10-26 13:32:03 -0400 | [diff] [blame] | 3921 | u32 len, attrlen, xlen; |
David Howells | e889649 | 2006-08-24 15:44:19 -0400 | [diff] [blame] | 3922 | if (end - p < 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | goto short_pkt; |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3924 | dprintk("cookie = %Lu, ", *((unsigned long long *)p)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | p += 2; /* cookie */ |
| 3926 | len = ntohl(*p++); /* filename length */ |
| 3927 | if (len > NFS4_MAXNAMLEN) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 3928 | dprintk("NFS: giant filename in readdir (len 0x%x)\n", |
| 3929 | len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | goto err_unmap; |
| 3931 | } |
David Howells | e889649 | 2006-08-24 15:44:19 -0400 | [diff] [blame] | 3932 | xlen = XDR_QUADLEN(len); |
| 3933 | if (end - p < xlen + 1) |
| 3934 | goto short_pkt; |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3935 | dprintk("filename = %*s\n", len, (char *)p); |
David Howells | e889649 | 2006-08-24 15:44:19 -0400 | [diff] [blame] | 3936 | p += xlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | len = ntohl(*p++); /* bitmap length */ |
David Howells | e889649 | 2006-08-24 15:44:19 -0400 | [diff] [blame] | 3938 | if (end - p < len + 1) |
| 3939 | goto short_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | p += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | attrlen = XDR_QUADLEN(ntohl(*p++)); |
David Howells | e889649 | 2006-08-24 15:44:19 -0400 | [diff] [blame] | 3942 | if (end - p < attrlen + 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | goto short_pkt; |
David Howells | e889649 | 2006-08-24 15:44:19 -0400 | [diff] [blame] | 3944 | p += attrlen; /* attributes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | entry = p; |
| 3946 | } |
Jeff Layton | 7bda2cd | 2008-02-22 14:50:01 -0500 | [diff] [blame] | 3947 | /* |
| 3948 | * Apparently some server sends responses that are a valid size, but |
| 3949 | * contain no entries, and have value_follows==0 and EOF==0. For |
| 3950 | * those, just set the EOF marker. |
| 3951 | */ |
| 3952 | if (!nr && entry[1] == 0) { |
| 3953 | dprintk("NFS: readdir reply truncated!\n"); |
| 3954 | entry[1] = 1; |
| 3955 | } |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 3956 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | kunmap_atomic(kaddr, KM_USER0); |
| 3958 | return 0; |
| 3959 | short_pkt: |
Jeff Layton | 7bda2cd | 2008-02-22 14:50:01 -0500 | [diff] [blame] | 3960 | /* |
| 3961 | * When we get a short packet there are 2 possibilities. We can |
| 3962 | * return an error, or fix up the response to look like a valid |
| 3963 | * response and return what we have so far. If there are no |
| 3964 | * entries and the packet was short, then return -EIO. If there |
| 3965 | * are valid entries in the response, return them and pretend that |
| 3966 | * the call was successful, but incomplete. The caller can retry the |
| 3967 | * readdir starting at the last cookie. |
| 3968 | */ |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3969 | dprintk("%s: short packet at entry %d\n", __func__, nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | entry[0] = entry[1] = 0; |
Jeff Layton | 7bda2cd | 2008-02-22 14:50:01 -0500 | [diff] [blame] | 3971 | if (nr) |
| 3972 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | err_unmap: |
| 3974 | kunmap_atomic(kaddr, KM_USER0); |
| 3975 | return -errno_NFSERR_IO; |
| 3976 | } |
| 3977 | |
| 3978 | static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) |
| 3979 | { |
| 3980 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; |
| 3981 | struct kvec *iov = rcvbuf->head; |
Chuck Lever | bcecff7 | 2007-10-26 13:32:03 -0400 | [diff] [blame] | 3982 | size_t hdrlen; |
| 3983 | u32 len, recvd; |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 3984 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | char *kaddr; |
| 3986 | int status; |
| 3987 | |
| 3988 | status = decode_op_hdr(xdr, OP_READLINK); |
| 3989 | if (status) |
| 3990 | return status; |
| 3991 | |
| 3992 | /* Convert length of symlink */ |
| 3993 | READ_BUF(4); |
| 3994 | READ32(len); |
| 3995 | if (len >= rcvbuf->page_len || len <= 0) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 3996 | dprintk("nfs: server returned giant symlink!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | return -ENAMETOOLONG; |
| 3998 | } |
| 3999 | hdrlen = (char *) xdr->p - (char *) iov->iov_base; |
| 4000 | recvd = req->rq_rcv_buf.len - hdrlen; |
| 4001 | if (recvd < len) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 4002 | dprintk("NFS: server cheating in readlink reply: " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | "count %u > recvd %u\n", len, recvd); |
| 4004 | return -EIO; |
| 4005 | } |
| 4006 | xdr_read_pages(xdr, len); |
| 4007 | /* |
| 4008 | * The XDR encode routine has set things up so that |
| 4009 | * the link text will be copied directly into the |
| 4010 | * buffer. We just have to do overflow-checking, |
| 4011 | * and and null-terminate the text (the VFS expects |
| 4012 | * null-termination). |
| 4013 | */ |
| 4014 | kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0); |
| 4015 | kaddr[len+rcvbuf->page_base] = '\0'; |
| 4016 | kunmap_atomic(kaddr, KM_USER0); |
| 4017 | return 0; |
| 4018 | } |
| 4019 | |
| 4020 | static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) |
| 4021 | { |
| 4022 | int status; |
| 4023 | |
| 4024 | status = decode_op_hdr(xdr, OP_REMOVE); |
| 4025 | if (status) |
| 4026 | goto out; |
| 4027 | status = decode_change_info(xdr, cinfo); |
| 4028 | out: |
| 4029 | return status; |
| 4030 | } |
| 4031 | |
| 4032 | static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, |
| 4033 | struct nfs4_change_info *new_cinfo) |
| 4034 | { |
| 4035 | int status; |
| 4036 | |
| 4037 | status = decode_op_hdr(xdr, OP_RENAME); |
| 4038 | if (status) |
| 4039 | goto out; |
| 4040 | if ((status = decode_change_info(xdr, old_cinfo))) |
| 4041 | goto out; |
| 4042 | status = decode_change_info(xdr, new_cinfo); |
| 4043 | out: |
| 4044 | return status; |
| 4045 | } |
| 4046 | |
| 4047 | static int decode_renew(struct xdr_stream *xdr) |
| 4048 | { |
| 4049 | return decode_op_hdr(xdr, OP_RENEW); |
| 4050 | } |
| 4051 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 4052 | static int |
| 4053 | decode_restorefh(struct xdr_stream *xdr) |
| 4054 | { |
| 4055 | return decode_op_hdr(xdr, OP_RESTOREFH); |
| 4056 | } |
| 4057 | |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4058 | static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, |
| 4059 | size_t *acl_len) |
| 4060 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4061 | __be32 *savep; |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4062 | uint32_t attrlen, |
| 4063 | bitmap[2] = {0}; |
| 4064 | struct kvec *iov = req->rq_rcv_buf.head; |
| 4065 | int status; |
| 4066 | |
| 4067 | *acl_len = 0; |
| 4068 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 4069 | goto out; |
| 4070 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 4071 | goto out; |
| 4072 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 4073 | goto out; |
| 4074 | |
| 4075 | if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) |
| 4076 | return -EIO; |
| 4077 | if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { |
Chuck Lever | bcecff7 | 2007-10-26 13:32:03 -0400 | [diff] [blame] | 4078 | size_t hdrlen; |
| 4079 | u32 recvd; |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4080 | |
| 4081 | /* We ignore &savep and don't do consistency checks on |
| 4082 | * the attr length. Let userspace figure it out.... */ |
| 4083 | hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; |
| 4084 | recvd = req->rq_rcv_buf.len - hdrlen; |
| 4085 | if (attrlen > recvd) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 4086 | dprintk("NFS: server cheating in getattr" |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4087 | " acl reply: attrlen %u > recvd %u\n", |
| 4088 | attrlen, recvd); |
| 4089 | return -EINVAL; |
| 4090 | } |
J. Bruce Fields | c04871e | 2006-05-30 16:28:58 -0400 | [diff] [blame] | 4091 | xdr_read_pages(xdr, attrlen); |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4092 | *acl_len = attrlen; |
J. Bruce Fields | 8c233cf | 2005-10-13 16:54:27 -0400 | [diff] [blame] | 4093 | } else |
| 4094 | status = -EOPNOTSUPP; |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4095 | |
| 4096 | out: |
| 4097 | return status; |
| 4098 | } |
| 4099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | static int |
| 4101 | decode_savefh(struct xdr_stream *xdr) |
| 4102 | { |
| 4103 | return decode_op_hdr(xdr, OP_SAVEFH); |
| 4104 | } |
| 4105 | |
Benny Halevy | 9e9ecc0 | 2009-04-01 09:22:00 -0400 | [diff] [blame] | 4106 | static int decode_setattr(struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4108 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | uint32_t bmlen; |
| 4110 | int status; |
| 4111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4112 | status = decode_op_hdr(xdr, OP_SETATTR); |
| 4113 | if (status) |
| 4114 | return status; |
| 4115 | READ_BUF(4); |
| 4116 | READ32(bmlen); |
| 4117 | READ_BUF(bmlen << 2); |
| 4118 | return 0; |
| 4119 | } |
| 4120 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 4121 | static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4123 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | uint32_t opnum; |
| 4125 | int32_t nfserr; |
| 4126 | |
| 4127 | READ_BUF(8); |
| 4128 | READ32(opnum); |
| 4129 | if (opnum != OP_SETCLIENTID) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 4130 | dprintk("nfs: decode_setclientid: Server returned operation" |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4131 | " %d\n", opnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | return -EIO; |
| 4133 | } |
| 4134 | READ32(nfserr); |
| 4135 | if (nfserr == NFS_OK) { |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 4136 | READ_BUF(8 + NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | READ64(clp->cl_clientid); |
Trond Myklebust | 8ae20ab | 2007-05-14 16:50:45 -0400 | [diff] [blame] | 4138 | COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | } else if (nfserr == NFSERR_CLID_INUSE) { |
| 4140 | uint32_t len; |
| 4141 | |
| 4142 | /* skip netid string */ |
| 4143 | READ_BUF(4); |
| 4144 | READ32(len); |
| 4145 | READ_BUF(len); |
| 4146 | |
| 4147 | /* skip uaddr string */ |
| 4148 | READ_BUF(4); |
| 4149 | READ32(len); |
| 4150 | READ_BUF(len); |
| 4151 | return -NFSERR_CLID_INUSE; |
| 4152 | } else |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 4153 | return nfs4_stat_to_errno(nfserr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | |
| 4155 | return 0; |
| 4156 | } |
| 4157 | |
| 4158 | static int decode_setclientid_confirm(struct xdr_stream *xdr) |
| 4159 | { |
| 4160 | return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); |
| 4161 | } |
| 4162 | |
| 4163 | static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) |
| 4164 | { |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4165 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | int status; |
| 4167 | |
| 4168 | status = decode_op_hdr(xdr, OP_WRITE); |
| 4169 | if (status) |
| 4170 | return status; |
| 4171 | |
| 4172 | READ_BUF(16); |
| 4173 | READ32(res->count); |
| 4174 | READ32(res->verf->committed); |
| 4175 | COPYMEM(res->verf->verifier, 8); |
| 4176 | return 0; |
| 4177 | } |
| 4178 | |
| 4179 | static int decode_delegreturn(struct xdr_stream *xdr) |
| 4180 | { |
| 4181 | return decode_op_hdr(xdr, OP_DELEGRETURN); |
| 4182 | } |
| 4183 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4184 | #if defined(CONFIG_NFS_V4_1) |
| 4185 | static int decode_exchange_id(struct xdr_stream *xdr, |
| 4186 | struct nfs41_exchange_id_res *res) |
| 4187 | { |
| 4188 | __be32 *p; |
| 4189 | uint32_t dummy; |
| 4190 | int status; |
| 4191 | struct nfs_client *clp = res->client; |
| 4192 | |
| 4193 | status = decode_op_hdr(xdr, OP_EXCHANGE_ID); |
| 4194 | if (status) |
| 4195 | return status; |
| 4196 | |
| 4197 | READ_BUF(8); |
| 4198 | READ64(clp->cl_ex_clid); |
| 4199 | READ_BUF(12); |
| 4200 | READ32(clp->cl_seqid); |
| 4201 | READ32(clp->cl_exchange_flags); |
| 4202 | |
| 4203 | /* We ask for SP4_NONE */ |
| 4204 | READ32(dummy); |
| 4205 | if (dummy != SP4_NONE) |
| 4206 | return -EIO; |
| 4207 | |
| 4208 | /* Throw away minor_id */ |
| 4209 | READ_BUF(8); |
| 4210 | |
| 4211 | /* Throw away Major id */ |
| 4212 | READ_BUF(4); |
| 4213 | READ32(dummy); |
| 4214 | READ_BUF(dummy); |
| 4215 | |
| 4216 | /* Throw away server_scope */ |
| 4217 | READ_BUF(4); |
| 4218 | READ32(dummy); |
| 4219 | READ_BUF(dummy); |
| 4220 | |
| 4221 | /* Throw away Implementation id array */ |
| 4222 | READ_BUF(4); |
| 4223 | READ32(dummy); |
| 4224 | READ_BUF(dummy); |
| 4225 | |
| 4226 | return 0; |
| 4227 | } |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4228 | |
| 4229 | static int decode_chan_attrs(struct xdr_stream *xdr, |
| 4230 | struct nfs4_channel_attrs *attrs) |
| 4231 | { |
| 4232 | __be32 *p; |
| 4233 | u32 nr_attrs; |
| 4234 | |
| 4235 | READ_BUF(28); |
| 4236 | READ32(attrs->headerpadsz); |
| 4237 | READ32(attrs->max_rqst_sz); |
| 4238 | READ32(attrs->max_resp_sz); |
| 4239 | READ32(attrs->max_resp_sz_cached); |
| 4240 | READ32(attrs->max_ops); |
| 4241 | READ32(attrs->max_reqs); |
| 4242 | READ32(nr_attrs); |
| 4243 | if (unlikely(nr_attrs > 1)) { |
| 4244 | printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n", |
| 4245 | __func__, nr_attrs); |
| 4246 | return -EINVAL; |
| 4247 | } |
| 4248 | if (nr_attrs == 1) |
| 4249 | READ_BUF(4); /* skip rdma_attrs */ |
| 4250 | return 0; |
| 4251 | } |
| 4252 | |
| 4253 | static int decode_create_session(struct xdr_stream *xdr, |
| 4254 | struct nfs41_create_session_res *res) |
| 4255 | { |
| 4256 | __be32 *p; |
| 4257 | int status; |
| 4258 | struct nfs_client *clp = res->client; |
| 4259 | struct nfs4_session *session = clp->cl_session; |
| 4260 | |
| 4261 | status = decode_op_hdr(xdr, OP_CREATE_SESSION); |
| 4262 | |
| 4263 | if (status) |
| 4264 | return status; |
| 4265 | |
| 4266 | /* sessionid */ |
| 4267 | READ_BUF(NFS4_MAX_SESSIONID_LEN); |
| 4268 | COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN); |
| 4269 | |
| 4270 | /* seqid, flags */ |
| 4271 | READ_BUF(8); |
| 4272 | READ32(clp->cl_seqid); |
| 4273 | READ32(session->flags); |
| 4274 | |
| 4275 | /* Channel attributes */ |
| 4276 | status = decode_chan_attrs(xdr, &session->fc_attrs); |
| 4277 | if (!status) |
| 4278 | status = decode_chan_attrs(xdr, &session->bc_attrs); |
| 4279 | return status; |
| 4280 | } |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 4281 | |
| 4282 | static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) |
| 4283 | { |
| 4284 | return decode_op_hdr(xdr, OP_DESTROY_SESSION); |
| 4285 | } |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4286 | #endif /* CONFIG_NFS_V4_1 */ |
| 4287 | |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4288 | static int decode_sequence(struct xdr_stream *xdr, |
| 4289 | struct nfs4_sequence_res *res, |
| 4290 | struct rpc_rqst *rqstp) |
| 4291 | { |
| 4292 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 4293 | struct nfs4_slot *slot; |
| 4294 | struct nfs4_sessionid id; |
| 4295 | u32 dummy; |
| 4296 | int status; |
| 4297 | __be32 *p; |
| 4298 | |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4299 | if (!res->sr_session) |
| 4300 | return 0; |
| 4301 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 4302 | status = decode_op_hdr(xdr, OP_SEQUENCE); |
| 4303 | if (status) |
| 4304 | goto out_err; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4305 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 4306 | /* |
| 4307 | * If the server returns different values for sessionID, slotID or |
| 4308 | * sequence number, the server is looney tunes. |
| 4309 | */ |
| 4310 | status = -ESERVERFAULT; |
| 4311 | |
| 4312 | slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid]; |
| 4313 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 20); |
| 4314 | COPYMEM(id.data, NFS4_MAX_SESSIONID_LEN); |
| 4315 | if (memcmp(id.data, res->sr_session->sess_id.data, |
| 4316 | NFS4_MAX_SESSIONID_LEN)) { |
| 4317 | dprintk("%s Invalid session id\n", __func__); |
| 4318 | goto out_err; |
| 4319 | } |
| 4320 | /* seqid */ |
| 4321 | READ32(dummy); |
| 4322 | if (dummy != slot->seq_nr) { |
| 4323 | dprintk("%s Invalid sequence number\n", __func__); |
| 4324 | goto out_err; |
| 4325 | } |
| 4326 | /* slot id */ |
| 4327 | READ32(dummy); |
| 4328 | if (dummy != res->sr_slotid) { |
| 4329 | dprintk("%s Invalid slot id\n", __func__); |
| 4330 | goto out_err; |
| 4331 | } |
| 4332 | /* highest slot id - currently not processed */ |
| 4333 | READ32(dummy); |
| 4334 | /* target highest slot id - currently not processed */ |
| 4335 | READ32(dummy); |
| 4336 | /* result flags - currently not processed */ |
| 4337 | READ32(dummy); |
| 4338 | status = 0; |
| 4339 | out_err: |
| 4340 | res->sr_status = status; |
| 4341 | return status; |
| 4342 | #else /* CONFIG_NFS_V4_1 */ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4343 | return 0; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 4344 | #endif /* CONFIG_NFS_V4_1 */ |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4345 | } |
| 4346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | /* |
Benny Halevy | 49c2559 | 2008-12-23 16:06:16 -0500 | [diff] [blame] | 4348 | * END OF "GENERIC" DECODE ROUTINES. |
| 4349 | */ |
| 4350 | |
| 4351 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | * Decode OPEN_DOWNGRADE response |
| 4353 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4354 | static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4356 | struct xdr_stream xdr; |
| 4357 | struct compound_hdr hdr; |
| 4358 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4360 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4361 | status = decode_compound_hdr(&xdr, &hdr); |
| 4362 | if (status) |
| 4363 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4364 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4365 | if (status) |
| 4366 | goto out; |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4367 | status = decode_putfh(&xdr); |
| 4368 | if (status) |
| 4369 | goto out; |
| 4370 | status = decode_open_downgrade(&xdr, res); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 4371 | if (status != 0) |
| 4372 | goto out; |
| 4373 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | out: |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4375 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | } |
| 4377 | |
| 4378 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | * Decode ACCESS response |
| 4380 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4381 | static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | { |
| 4383 | struct xdr_stream xdr; |
| 4384 | struct compound_hdr hdr; |
| 4385 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4388 | status = decode_compound_hdr(&xdr, &hdr); |
| 4389 | if (status) |
| 4390 | goto out; |
| 4391 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4392 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | goto out; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4394 | status = decode_putfh(&xdr); |
| 4395 | if (status != 0) |
| 4396 | goto out; |
| 4397 | status = decode_access(&xdr, res); |
| 4398 | if (status != 0) |
| 4399 | goto out; |
| 4400 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | out: |
| 4402 | return status; |
| 4403 | } |
| 4404 | |
| 4405 | /* |
| 4406 | * Decode LOOKUP response |
| 4407 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4408 | static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | { |
| 4410 | struct xdr_stream xdr; |
| 4411 | struct compound_hdr hdr; |
| 4412 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4415 | status = decode_compound_hdr(&xdr, &hdr); |
| 4416 | if (status) |
| 4417 | goto out; |
| 4418 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4419 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | goto out; |
| 4421 | if ((status = decode_putfh(&xdr)) != 0) |
| 4422 | goto out; |
| 4423 | if ((status = decode_lookup(&xdr)) != 0) |
| 4424 | goto out; |
| 4425 | if ((status = decode_getfh(&xdr, res->fh)) != 0) |
| 4426 | goto out; |
| 4427 | status = decode_getfattr(&xdr, res->fattr, res->server); |
| 4428 | out: |
| 4429 | return status; |
| 4430 | } |
| 4431 | |
| 4432 | /* |
| 4433 | * Decode LOOKUP_ROOT response |
| 4434 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4435 | static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | { |
| 4437 | struct xdr_stream xdr; |
| 4438 | struct compound_hdr hdr; |
| 4439 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4442 | status = decode_compound_hdr(&xdr, &hdr); |
| 4443 | if (status) |
| 4444 | goto out; |
| 4445 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4446 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | goto out; |
| 4448 | if ((status = decode_putrootfh(&xdr)) != 0) |
| 4449 | goto out; |
| 4450 | if ((status = decode_getfh(&xdr, res->fh)) == 0) |
| 4451 | status = decode_getfattr(&xdr, res->fattr, res->server); |
| 4452 | out: |
| 4453 | return status; |
| 4454 | } |
| 4455 | |
| 4456 | /* |
| 4457 | * Decode REMOVE response |
| 4458 | */ |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4459 | static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | { |
| 4461 | struct xdr_stream xdr; |
| 4462 | struct compound_hdr hdr; |
| 4463 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4466 | status = decode_compound_hdr(&xdr, &hdr); |
| 4467 | if (status) |
| 4468 | goto out; |
| 4469 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4470 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | goto out; |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4472 | if ((status = decode_putfh(&xdr)) != 0) |
| 4473 | goto out; |
| 4474 | if ((status = decode_remove(&xdr, &res->cinfo)) != 0) |
| 4475 | goto out; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4476 | decode_getfattr(&xdr, &res->dir_attr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | out: |
| 4478 | return status; |
| 4479 | } |
| 4480 | |
| 4481 | /* |
| 4482 | * Decode RENAME response |
| 4483 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4484 | static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | { |
| 4486 | struct xdr_stream xdr; |
| 4487 | struct compound_hdr hdr; |
| 4488 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4491 | status = decode_compound_hdr(&xdr, &hdr); |
| 4492 | if (status) |
| 4493 | goto out; |
| 4494 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4495 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | goto out; |
| 4497 | if ((status = decode_putfh(&xdr)) != 0) |
| 4498 | goto out; |
| 4499 | if ((status = decode_savefh(&xdr)) != 0) |
| 4500 | goto out; |
| 4501 | if ((status = decode_putfh(&xdr)) != 0) |
| 4502 | goto out; |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 4503 | if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0) |
| 4504 | goto out; |
| 4505 | /* Current FH is target directory */ |
| 4506 | if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0) |
| 4507 | goto out; |
| 4508 | if ((status = decode_restorefh(&xdr)) != 0) |
| 4509 | goto out; |
| 4510 | decode_getfattr(&xdr, res->old_fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | out: |
| 4512 | return status; |
| 4513 | } |
| 4514 | |
| 4515 | /* |
| 4516 | * Decode LINK response |
| 4517 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4518 | static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | { |
| 4520 | struct xdr_stream xdr; |
| 4521 | struct compound_hdr hdr; |
| 4522 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4525 | status = decode_compound_hdr(&xdr, &hdr); |
| 4526 | if (status) |
| 4527 | goto out; |
| 4528 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4529 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | goto out; |
| 4531 | if ((status = decode_putfh(&xdr)) != 0) |
| 4532 | goto out; |
| 4533 | if ((status = decode_savefh(&xdr)) != 0) |
| 4534 | goto out; |
| 4535 | if ((status = decode_putfh(&xdr)) != 0) |
| 4536 | goto out; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4537 | if ((status = decode_link(&xdr, &res->cinfo)) != 0) |
| 4538 | goto out; |
| 4539 | /* |
| 4540 | * Note order: OP_LINK leaves the directory as the current |
| 4541 | * filehandle. |
| 4542 | */ |
| 4543 | if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0) |
| 4544 | goto out; |
| 4545 | if ((status = decode_restorefh(&xdr)) != 0) |
| 4546 | goto out; |
| 4547 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | out: |
| 4549 | return status; |
| 4550 | } |
| 4551 | |
| 4552 | /* |
| 4553 | * Decode CREATE response |
| 4554 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4555 | static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | { |
| 4557 | struct xdr_stream xdr; |
| 4558 | struct compound_hdr hdr; |
| 4559 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4562 | status = decode_compound_hdr(&xdr, &hdr); |
| 4563 | if (status) |
| 4564 | goto out; |
| 4565 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4566 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | goto out; |
| 4568 | if ((status = decode_putfh(&xdr)) != 0) |
| 4569 | goto out; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 4570 | if ((status = decode_savefh(&xdr)) != 0) |
| 4571 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0) |
| 4573 | goto out; |
| 4574 | if ((status = decode_getfh(&xdr, res->fh)) != 0) |
| 4575 | goto out; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 4576 | if (decode_getfattr(&xdr, res->fattr, res->server) != 0) |
| 4577 | goto out; |
| 4578 | if ((status = decode_restorefh(&xdr)) != 0) |
| 4579 | goto out; |
| 4580 | decode_getfattr(&xdr, res->dir_fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | out: |
| 4582 | return status; |
| 4583 | } |
| 4584 | |
| 4585 | /* |
| 4586 | * Decode SYMLINK response |
| 4587 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4588 | static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | { |
| 4590 | return nfs4_xdr_dec_create(rqstp, p, res); |
| 4591 | } |
| 4592 | |
| 4593 | /* |
| 4594 | * Decode GETATTR response |
| 4595 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4596 | static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | { |
| 4598 | struct xdr_stream xdr; |
| 4599 | struct compound_hdr hdr; |
| 4600 | int status; |
Andy Adamson | 6c0195a | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4603 | status = decode_compound_hdr(&xdr, &hdr); |
| 4604 | if (status) |
| 4605 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4606 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4607 | if (status) |
| 4608 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | status = decode_putfh(&xdr); |
| 4610 | if (status) |
| 4611 | goto out; |
| 4612 | status = decode_getfattr(&xdr, res->fattr, res->server); |
| 4613 | out: |
| 4614 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | } |
| 4616 | |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4617 | /* |
| 4618 | * Encode an SETACL request |
| 4619 | */ |
| 4620 | static int |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4621 | nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args) |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4622 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4623 | struct xdr_stream xdr; |
| 4624 | struct compound_hdr hdr = { |
Benny Halevy | 66cc042 | 2009-04-01 09:22:10 -0400 | [diff] [blame] | 4625 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4626 | }; |
| 4627 | int status; |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4628 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4629 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
Benny Halevy | 0c4e8c1 | 2009-04-01 09:22:07 -0400 | [diff] [blame] | 4630 | encode_compound_hdr(&xdr, req, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4631 | encode_sequence(&xdr, &args->seq_args, &hdr); |
Andy Adamson | cf8cdbe | 2008-12-23 16:06:18 -0500 | [diff] [blame] | 4632 | encode_putfh(&xdr, args->fh, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 4633 | status = encode_setacl(&xdr, args, &hdr); |
Andy Adamson | d017931 | 2008-12-23 16:06:17 -0500 | [diff] [blame] | 4634 | encode_nops(&hdr); |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4635 | return status; |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4636 | } |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4637 | |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4638 | /* |
| 4639 | * Decode SETACL response |
| 4640 | */ |
| 4641 | static int |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4642 | nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, |
| 4643 | struct nfs_setaclres *res) |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4644 | { |
| 4645 | struct xdr_stream xdr; |
| 4646 | struct compound_hdr hdr; |
| 4647 | int status; |
| 4648 | |
| 4649 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4650 | status = decode_compound_hdr(&xdr, &hdr); |
| 4651 | if (status) |
| 4652 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4653 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4654 | if (status) |
| 4655 | goto out; |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4656 | status = decode_putfh(&xdr); |
| 4657 | if (status) |
| 4658 | goto out; |
Benny Halevy | 9e9ecc0 | 2009-04-01 09:22:00 -0400 | [diff] [blame] | 4659 | status = decode_setattr(&xdr); |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4660 | out: |
| 4661 | return status; |
| 4662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | |
| 4664 | /* |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4665 | * Decode GETACL response |
| 4666 | */ |
| 4667 | static int |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4668 | nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, |
| 4669 | struct nfs_getaclres *res) |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4670 | { |
| 4671 | struct xdr_stream xdr; |
| 4672 | struct compound_hdr hdr; |
| 4673 | int status; |
| 4674 | |
| 4675 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4676 | status = decode_compound_hdr(&xdr, &hdr); |
| 4677 | if (status) |
| 4678 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4679 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4680 | if (status) |
| 4681 | goto out; |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4682 | status = decode_putfh(&xdr); |
| 4683 | if (status) |
| 4684 | goto out; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4685 | status = decode_getacl(&xdr, rqstp, &res->acl_len); |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4686 | |
| 4687 | out: |
| 4688 | return status; |
| 4689 | } |
| 4690 | |
| 4691 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4692 | * Decode CLOSE response |
| 4693 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4694 | static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4696 | struct xdr_stream xdr; |
| 4697 | struct compound_hdr hdr; |
| 4698 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4700 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4701 | status = decode_compound_hdr(&xdr, &hdr); |
| 4702 | if (status) |
| 4703 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4704 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4705 | if (status) |
| 4706 | goto out; |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4707 | status = decode_putfh(&xdr); |
| 4708 | if (status) |
| 4709 | goto out; |
| 4710 | status = decode_close(&xdr, res); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 4711 | if (status != 0) |
| 4712 | goto out; |
| 4713 | /* |
| 4714 | * Note: Server may do delete on close for this file |
| 4715 | * in which case the getattr call will fail with |
| 4716 | * an ESTALE error. Shouldn't be a problem, |
| 4717 | * though, since fattr->valid will remain unset. |
| 4718 | */ |
| 4719 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | out: |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4721 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | /* |
| 4725 | * Decode OPEN response |
| 4726 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4727 | static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4728 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4729 | struct xdr_stream xdr; |
| 4730 | struct compound_hdr hdr; |
| 4731 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4732 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4733 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4734 | status = decode_compound_hdr(&xdr, &hdr); |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 4735 | if (status) |
| 4736 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4737 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4738 | if (status) |
| 4739 | goto out; |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4740 | status = decode_putfh(&xdr); |
| 4741 | if (status) |
| 4742 | goto out; |
| 4743 | status = decode_savefh(&xdr); |
| 4744 | if (status) |
| 4745 | goto out; |
| 4746 | status = decode_open(&xdr, res); |
| 4747 | if (status) |
| 4748 | goto out; |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 4749 | if (decode_getfh(&xdr, &res->fh) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | goto out; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 4751 | if (decode_getfattr(&xdr, res->f_attr, res->server) != 0) |
| 4752 | goto out; |
Trond Myklebust | 365c8f5 | 2007-07-17 21:52:37 -0400 | [diff] [blame] | 4753 | if (decode_restorefh(&xdr) != 0) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 4754 | goto out; |
| 4755 | decode_getfattr(&xdr, res->dir_attr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | out: |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4757 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | /* |
| 4761 | * Decode OPEN_CONFIRM response |
| 4762 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4763 | static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4765 | struct xdr_stream xdr; |
| 4766 | struct compound_hdr hdr; |
| 4767 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4769 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4770 | status = decode_compound_hdr(&xdr, &hdr); |
| 4771 | if (status) |
| 4772 | goto out; |
| 4773 | status = decode_putfh(&xdr); |
| 4774 | if (status) |
| 4775 | goto out; |
| 4776 | status = decode_open_confirm(&xdr, res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | out: |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4778 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | } |
| 4780 | |
| 4781 | /* |
| 4782 | * Decode OPEN response |
| 4783 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4784 | static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4786 | struct xdr_stream xdr; |
| 4787 | struct compound_hdr hdr; |
| 4788 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4790 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4791 | status = decode_compound_hdr(&xdr, &hdr); |
| 4792 | if (status) |
| 4793 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4794 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4795 | if (status) |
| 4796 | goto out; |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4797 | status = decode_putfh(&xdr); |
| 4798 | if (status) |
| 4799 | goto out; |
| 4800 | status = decode_open(&xdr, res); |
| 4801 | if (status) |
| 4802 | goto out; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 4803 | decode_getfattr(&xdr, res->f_attr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 | out: |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4805 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | /* |
| 4809 | * Decode SETATTR response |
| 4810 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4811 | static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4812 | { |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4813 | struct xdr_stream xdr; |
| 4814 | struct compound_hdr hdr; |
| 4815 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4816 | |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4817 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4818 | status = decode_compound_hdr(&xdr, &hdr); |
| 4819 | if (status) |
| 4820 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4821 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4822 | if (status) |
| 4823 | goto out; |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4824 | status = decode_putfh(&xdr); |
| 4825 | if (status) |
| 4826 | goto out; |
Benny Halevy | 9e9ecc0 | 2009-04-01 09:22:00 -0400 | [diff] [blame] | 4827 | status = decode_setattr(&xdr); |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4828 | if (status) |
| 4829 | goto out; |
Trond Myklebust | 78f945f | 2009-03-11 14:10:23 -0400 | [diff] [blame] | 4830 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | out: |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 4832 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | /* |
| 4836 | * Decode LOCK response |
| 4837 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4838 | static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | { |
| 4840 | struct xdr_stream xdr; |
| 4841 | struct compound_hdr hdr; |
| 4842 | int status; |
| 4843 | |
| 4844 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4845 | status = decode_compound_hdr(&xdr, &hdr); |
| 4846 | if (status) |
| 4847 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4848 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4849 | if (status) |
| 4850 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | status = decode_putfh(&xdr); |
| 4852 | if (status) |
| 4853 | goto out; |
| 4854 | status = decode_lock(&xdr, res); |
| 4855 | out: |
| 4856 | return status; |
| 4857 | } |
| 4858 | |
| 4859 | /* |
| 4860 | * Decode LOCKT response |
| 4861 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4862 | static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | { |
| 4864 | struct xdr_stream xdr; |
| 4865 | struct compound_hdr hdr; |
| 4866 | int status; |
| 4867 | |
| 4868 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4869 | status = decode_compound_hdr(&xdr, &hdr); |
| 4870 | if (status) |
| 4871 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4872 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4873 | if (status) |
| 4874 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | status = decode_putfh(&xdr); |
| 4876 | if (status) |
| 4877 | goto out; |
| 4878 | status = decode_lockt(&xdr, res); |
| 4879 | out: |
| 4880 | return status; |
| 4881 | } |
| 4882 | |
| 4883 | /* |
| 4884 | * Decode LOCKU response |
| 4885 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4886 | static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | { |
| 4888 | struct xdr_stream xdr; |
| 4889 | struct compound_hdr hdr; |
| 4890 | int status; |
| 4891 | |
| 4892 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4893 | status = decode_compound_hdr(&xdr, &hdr); |
| 4894 | if (status) |
| 4895 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4896 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4897 | if (status) |
| 4898 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | status = decode_putfh(&xdr); |
| 4900 | if (status) |
| 4901 | goto out; |
| 4902 | status = decode_locku(&xdr, res); |
| 4903 | out: |
| 4904 | return status; |
| 4905 | } |
| 4906 | |
| 4907 | /* |
| 4908 | * Decode READLINK response |
| 4909 | */ |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4910 | static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, |
| 4911 | struct nfs4_readlink_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | { |
| 4913 | struct xdr_stream xdr; |
| 4914 | struct compound_hdr hdr; |
| 4915 | int status; |
| 4916 | |
| 4917 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4918 | status = decode_compound_hdr(&xdr, &hdr); |
| 4919 | if (status) |
| 4920 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4921 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4922 | if (status) |
| 4923 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | status = decode_putfh(&xdr); |
| 4925 | if (status) |
| 4926 | goto out; |
| 4927 | status = decode_readlink(&xdr, rqstp); |
| 4928 | out: |
| 4929 | return status; |
| 4930 | } |
| 4931 | |
| 4932 | /* |
| 4933 | * Decode READDIR response |
| 4934 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4935 | static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4936 | { |
| 4937 | struct xdr_stream xdr; |
| 4938 | struct compound_hdr hdr; |
| 4939 | int status; |
| 4940 | |
| 4941 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4942 | status = decode_compound_hdr(&xdr, &hdr); |
| 4943 | if (status) |
| 4944 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4945 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4946 | if (status) |
| 4947 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | status = decode_putfh(&xdr); |
| 4949 | if (status) |
| 4950 | goto out; |
| 4951 | status = decode_readdir(&xdr, rqstp, res); |
| 4952 | out: |
| 4953 | return status; |
| 4954 | } |
| 4955 | |
| 4956 | /* |
| 4957 | * Decode Read response |
| 4958 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4959 | static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | { |
| 4961 | struct xdr_stream xdr; |
| 4962 | struct compound_hdr hdr; |
| 4963 | int status; |
| 4964 | |
| 4965 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4966 | status = decode_compound_hdr(&xdr, &hdr); |
| 4967 | if (status) |
| 4968 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4969 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4970 | if (status) |
| 4971 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | status = decode_putfh(&xdr); |
| 4973 | if (status) |
| 4974 | goto out; |
| 4975 | status = decode_read(&xdr, rqstp, res); |
| 4976 | if (!status) |
| 4977 | status = res->count; |
| 4978 | out: |
| 4979 | return status; |
| 4980 | } |
| 4981 | |
| 4982 | /* |
| 4983 | * Decode WRITE response |
| 4984 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 4985 | static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4986 | { |
| 4987 | struct xdr_stream xdr; |
| 4988 | struct compound_hdr hdr; |
| 4989 | int status; |
| 4990 | |
| 4991 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4992 | status = decode_compound_hdr(&xdr, &hdr); |
| 4993 | if (status) |
| 4994 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 4995 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 4996 | if (status) |
| 4997 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | status = decode_putfh(&xdr); |
| 4999 | if (status) |
| 5000 | goto out; |
| 5001 | status = decode_write(&xdr, res); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5002 | if (status) |
| 5003 | goto out; |
| 5004 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | if (!status) |
| 5006 | status = res->count; |
| 5007 | out: |
| 5008 | return status; |
| 5009 | } |
| 5010 | |
| 5011 | /* |
| 5012 | * Decode COMMIT response |
| 5013 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 5014 | static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5015 | { |
| 5016 | struct xdr_stream xdr; |
| 5017 | struct compound_hdr hdr; |
| 5018 | int status; |
| 5019 | |
| 5020 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 5021 | status = decode_compound_hdr(&xdr, &hdr); |
| 5022 | if (status) |
| 5023 | goto out; |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 5024 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 5025 | if (status) |
| 5026 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5027 | status = decode_putfh(&xdr); |
| 5028 | if (status) |
| 5029 | goto out; |
| 5030 | status = decode_commit(&xdr, res); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5031 | if (status) |
| 5032 | goto out; |
| 5033 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5034 | out: |
| 5035 | return status; |
| 5036 | } |
| 5037 | |
| 5038 | /* |
| 5039 | * FSINFO request |
| 5040 | */ |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5041 | static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, |
| 5042 | struct nfs4_fsinfo_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | { |
| 5044 | struct xdr_stream xdr; |
| 5045 | struct compound_hdr hdr; |
| 5046 | int status; |
| 5047 | |
| 5048 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 5049 | status = decode_compound_hdr(&xdr, &hdr); |
| 5050 | if (!status) |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 5051 | status = decode_sequence(&xdr, &res->seq_res, req); |
| 5052 | if (!status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | status = decode_putfh(&xdr); |
| 5054 | if (!status) |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5055 | status = decode_fsinfo(&xdr, res->fsinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | return status; |
| 5057 | } |
| 5058 | |
| 5059 | /* |
| 5060 | * PATHCONF request |
| 5061 | */ |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5062 | static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, |
| 5063 | struct nfs4_pathconf_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | { |
| 5065 | struct xdr_stream xdr; |
| 5066 | struct compound_hdr hdr; |
| 5067 | int status; |
| 5068 | |
| 5069 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 5070 | status = decode_compound_hdr(&xdr, &hdr); |
| 5071 | if (!status) |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 5072 | status = decode_sequence(&xdr, &res->seq_res, req); |
| 5073 | if (!status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | status = decode_putfh(&xdr); |
| 5075 | if (!status) |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5076 | status = decode_pathconf(&xdr, res->pathconf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | return status; |
| 5078 | } |
| 5079 | |
| 5080 | /* |
| 5081 | * STATFS request |
| 5082 | */ |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5083 | static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, |
| 5084 | struct nfs4_statfs_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | { |
| 5086 | struct xdr_stream xdr; |
| 5087 | struct compound_hdr hdr; |
| 5088 | int status; |
| 5089 | |
| 5090 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 5091 | status = decode_compound_hdr(&xdr, &hdr); |
| 5092 | if (!status) |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 5093 | status = decode_sequence(&xdr, &res->seq_res, req); |
| 5094 | if (!status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | status = decode_putfh(&xdr); |
| 5096 | if (!status) |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5097 | status = decode_statfs(&xdr, res->fsstat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5098 | return status; |
| 5099 | } |
| 5100 | |
| 5101 | /* |
| 5102 | * GETATTR_BITMAP request |
| 5103 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 5104 | static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5105 | { |
| 5106 | struct xdr_stream xdr; |
| 5107 | struct compound_hdr hdr; |
| 5108 | int status; |
| 5109 | |
| 5110 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 5111 | status = decode_compound_hdr(&xdr, &hdr); |
| 5112 | if (status) |
| 5113 | goto out; |
| 5114 | status = decode_sequence(&xdr, &res->seq_res, req); |
| 5115 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5116 | goto out; |
| 5117 | if ((status = decode_putfh(&xdr)) != 0) |
| 5118 | goto out; |
| 5119 | status = decode_server_caps(&xdr, res); |
| 5120 | out: |
| 5121 | return status; |
| 5122 | } |
| 5123 | |
| 5124 | /* |
| 5125 | * Decode RENEW response |
| 5126 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 5127 | static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | { |
| 5129 | struct xdr_stream xdr; |
| 5130 | struct compound_hdr hdr; |
| 5131 | int status; |
| 5132 | |
| 5133 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 5134 | status = decode_compound_hdr(&xdr, &hdr); |
| 5135 | if (!status) |
| 5136 | status = decode_renew(&xdr); |
| 5137 | return status; |
| 5138 | } |
| 5139 | |
| 5140 | /* |
| 5141 | * a SETCLIENTID request |
| 5142 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 5143 | static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p, |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 5144 | struct nfs_client *clp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | { |
| 5146 | struct xdr_stream xdr; |
| 5147 | struct compound_hdr hdr; |
| 5148 | int status; |
| 5149 | |
| 5150 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 5151 | status = decode_compound_hdr(&xdr, &hdr); |
| 5152 | if (!status) |
| 5153 | status = decode_setclientid(&xdr, clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | return status; |
| 5155 | } |
| 5156 | |
| 5157 | /* |
| 5158 | * a SETCLIENTID_CONFIRM request |
| 5159 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 5160 | static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | { |
| 5162 | struct xdr_stream xdr; |
| 5163 | struct compound_hdr hdr; |
| 5164 | int status; |
| 5165 | |
| 5166 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 5167 | status = decode_compound_hdr(&xdr, &hdr); |
| 5168 | if (!status) |
| 5169 | status = decode_setclientid_confirm(&xdr); |
| 5170 | if (!status) |
| 5171 | status = decode_putrootfh(&xdr); |
| 5172 | if (!status) |
| 5173 | status = decode_fsinfo(&xdr, fsinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | return status; |
| 5175 | } |
| 5176 | |
| 5177 | /* |
| 5178 | * DELEGRETURN request |
| 5179 | */ |
Al Viro | 8687b63 | 2006-10-19 23:28:48 -0700 | [diff] [blame] | 5180 | static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5181 | { |
| 5182 | struct xdr_stream xdr; |
| 5183 | struct compound_hdr hdr; |
| 5184 | int status; |
| 5185 | |
| 5186 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 5187 | status = decode_compound_hdr(&xdr, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 5188 | if (status) |
| 5189 | goto out; |
| 5190 | status = decode_sequence(&xdr, &res->seq_res, rqstp); |
| 5191 | if (status) |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5192 | goto out; |
| 5193 | status = decode_putfh(&xdr); |
| 5194 | if (status != 0) |
| 5195 | goto out; |
| 5196 | status = decode_delegreturn(&xdr); |
| 5197 | decode_getfattr(&xdr, res->fattr, res->server); |
| 5198 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | return status; |
| 5200 | } |
| 5201 | |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5202 | /* |
| 5203 | * FS_LOCATIONS request |
| 5204 | */ |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5205 | static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, |
| 5206 | struct nfs4_fs_locations_res *res) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5207 | { |
| 5208 | struct xdr_stream xdr; |
| 5209 | struct compound_hdr hdr; |
| 5210 | int status; |
| 5211 | |
| 5212 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 5213 | status = decode_compound_hdr(&xdr, &hdr); |
Andy Adamson | 9b7b9fc | 2009-04-01 09:22:11 -0400 | [diff] [blame] | 5214 | if (status) |
| 5215 | goto out; |
| 5216 | status = decode_sequence(&xdr, &res->seq_res, req); |
| 5217 | if (status) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5218 | goto out; |
| 5219 | if ((status = decode_putfh(&xdr)) != 0) |
| 5220 | goto out; |
| 5221 | if ((status = decode_lookup(&xdr)) != 0) |
| 5222 | goto out; |
| 5223 | xdr_enter_page(&xdr, PAGE_SIZE); |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5224 | status = decode_getfattr(&xdr, &res->fs_locations->fattr, |
| 5225 | res->fs_locations->server); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5226 | out: |
| 5227 | return status; |
| 5228 | } |
| 5229 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5230 | #if defined(CONFIG_NFS_V4_1) |
| 5231 | /* |
| 5232 | * EXCHANGE_ID request |
| 5233 | */ |
| 5234 | static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p, |
| 5235 | void *res) |
| 5236 | { |
| 5237 | struct xdr_stream xdr; |
| 5238 | struct compound_hdr hdr; |
| 5239 | int status; |
| 5240 | |
| 5241 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 5242 | status = decode_compound_hdr(&xdr, &hdr); |
| 5243 | if (!status) |
| 5244 | status = decode_exchange_id(&xdr, res); |
| 5245 | return status; |
| 5246 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5247 | |
| 5248 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5249 | * a CREATE_SESSION request |
| 5250 | */ |
| 5251 | static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p, |
| 5252 | struct nfs41_create_session_res *res) |
| 5253 | { |
| 5254 | struct xdr_stream xdr; |
| 5255 | struct compound_hdr hdr; |
| 5256 | int status; |
| 5257 | |
| 5258 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 5259 | status = decode_compound_hdr(&xdr, &hdr); |
| 5260 | if (!status) |
| 5261 | status = decode_create_session(&xdr, res); |
| 5262 | return status; |
| 5263 | } |
| 5264 | |
| 5265 | /* |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5266 | * a DESTROY_SESSION request |
| 5267 | */ |
| 5268 | static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p, |
| 5269 | void *dummy) |
| 5270 | { |
| 5271 | struct xdr_stream xdr; |
| 5272 | struct compound_hdr hdr; |
| 5273 | int status; |
| 5274 | |
| 5275 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 5276 | status = decode_compound_hdr(&xdr, &hdr); |
| 5277 | if (!status) |
| 5278 | status = decode_destroy_session(&xdr, dummy); |
| 5279 | return status; |
| 5280 | } |
| 5281 | |
| 5282 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5283 | * a SEQUENCE request |
| 5284 | */ |
| 5285 | static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p, |
| 5286 | struct nfs4_sequence_res *res) |
| 5287 | { |
| 5288 | struct xdr_stream xdr; |
| 5289 | struct compound_hdr hdr; |
| 5290 | int status; |
| 5291 | |
| 5292 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 5293 | status = decode_compound_hdr(&xdr, &hdr); |
| 5294 | if (!status) |
| 5295 | status = decode_sequence(&xdr, res, rqstp); |
| 5296 | return status; |
| 5297 | } |
| 5298 | |
| 5299 | /* |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5300 | * a GET_LEASE_TIME request |
| 5301 | */ |
| 5302 | static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p, |
| 5303 | struct nfs4_get_lease_time_res *res) |
| 5304 | { |
| 5305 | struct xdr_stream xdr; |
| 5306 | struct compound_hdr hdr; |
| 5307 | int status; |
| 5308 | |
| 5309 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 5310 | status = decode_compound_hdr(&xdr, &hdr); |
| 5311 | if (!status) |
| 5312 | status = decode_sequence(&xdr, &res->lr_seq_res, rqstp); |
| 5313 | if (!status) |
| 5314 | status = decode_putrootfh(&xdr); |
| 5315 | if (!status) |
| 5316 | status = decode_fsinfo(&xdr, res->lr_fsinfo); |
| 5317 | return status; |
| 5318 | } |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5319 | #endif /* CONFIG_NFS_V4_1 */ |
| 5320 | |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 5321 | __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5322 | { |
| 5323 | uint32_t bitmap[2] = {0}; |
| 5324 | uint32_t len; |
| 5325 | |
| 5326 | if (!*p++) { |
| 5327 | if (!*p) |
| 5328 | return ERR_PTR(-EAGAIN); |
| 5329 | entry->eof = 1; |
| 5330 | return ERR_PTR(-EBADCOOKIE); |
| 5331 | } |
| 5332 | |
| 5333 | entry->prev_cookie = entry->cookie; |
| 5334 | p = xdr_decode_hyper(p, &entry->cookie); |
| 5335 | entry->len = ntohl(*p++); |
| 5336 | entry->name = (const char *) p; |
| 5337 | p += XDR_QUADLEN(entry->len); |
| 5338 | |
| 5339 | /* |
| 5340 | * In case the server doesn't return an inode number, |
| 5341 | * we fake one here. (We don't use inode number 0, |
| 5342 | * since glibc seems to choke on it...) |
| 5343 | */ |
| 5344 | entry->ino = 1; |
| 5345 | |
| 5346 | len = ntohl(*p++); /* bitmap length */ |
| 5347 | if (len-- > 0) { |
| 5348 | bitmap[0] = ntohl(*p++); |
| 5349 | if (len-- > 0) { |
| 5350 | bitmap[1] = ntohl(*p++); |
| 5351 | p += len; |
| 5352 | } |
| 5353 | } |
| 5354 | len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */ |
| 5355 | if (len > 0) { |
Manoj Naik | 97d312d | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 5356 | if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) { |
| 5357 | bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; |
| 5358 | /* Ignore the return value of rdattr_error for now */ |
| 5359 | p++; |
| 5360 | len--; |
| 5361 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5362 | if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5363 | xdr_decode_hyper(p, &entry->ino); |
| 5364 | else if (bitmap[0] == FATTR4_WORD0_FILEID) |
| 5365 | xdr_decode_hyper(p, &entry->ino); |
| 5366 | p += len; |
| 5367 | } |
| 5368 | |
| 5369 | entry->eof = !p[0] && p[1]; |
| 5370 | return p; |
| 5371 | } |
| 5372 | |
| 5373 | /* |
| 5374 | * We need to translate between nfs status return values and |
| 5375 | * the local errno values which may not be the same. |
| 5376 | */ |
| 5377 | static struct { |
| 5378 | int stat; |
| 5379 | int errno; |
| 5380 | } nfs_errtbl[] = { |
| 5381 | { NFS4_OK, 0 }, |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 5382 | { NFS4ERR_PERM, -EPERM }, |
| 5383 | { NFS4ERR_NOENT, -ENOENT }, |
| 5384 | { NFS4ERR_IO, -errno_NFSERR_IO}, |
| 5385 | { NFS4ERR_NXIO, -ENXIO }, |
| 5386 | { NFS4ERR_ACCESS, -EACCES }, |
| 5387 | { NFS4ERR_EXIST, -EEXIST }, |
| 5388 | { NFS4ERR_XDEV, -EXDEV }, |
| 5389 | { NFS4ERR_NOTDIR, -ENOTDIR }, |
| 5390 | { NFS4ERR_ISDIR, -EISDIR }, |
| 5391 | { NFS4ERR_INVAL, -EINVAL }, |
| 5392 | { NFS4ERR_FBIG, -EFBIG }, |
| 5393 | { NFS4ERR_NOSPC, -ENOSPC }, |
| 5394 | { NFS4ERR_ROFS, -EROFS }, |
| 5395 | { NFS4ERR_MLINK, -EMLINK }, |
| 5396 | { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, |
| 5397 | { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, |
| 5398 | { NFS4ERR_DQUOT, -EDQUOT }, |
| 5399 | { NFS4ERR_STALE, -ESTALE }, |
| 5400 | { NFS4ERR_BADHANDLE, -EBADHANDLE }, |
| 5401 | { NFS4ERR_BADOWNER, -EINVAL }, |
| 5402 | { NFS4ERR_BADNAME, -EINVAL }, |
| 5403 | { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, |
| 5404 | { NFS4ERR_NOTSUPP, -ENOTSUPP }, |
| 5405 | { NFS4ERR_TOOSMALL, -ETOOSMALL }, |
| 5406 | { NFS4ERR_SERVERFAULT, -ESERVERFAULT }, |
| 5407 | { NFS4ERR_BADTYPE, -EBADTYPE }, |
| 5408 | { NFS4ERR_LOCKED, -EAGAIN }, |
| 5409 | { NFS4ERR_RESOURCE, -EREMOTEIO }, |
| 5410 | { NFS4ERR_SYMLINK, -ELOOP }, |
| 5411 | { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, |
| 5412 | { NFS4ERR_DEADLOCK, -EDEADLK }, |
| 5413 | { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5414 | * to be handled by a |
| 5415 | * middle-layer. |
| 5416 | */ |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 5417 | { -1, -EIO } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5418 | }; |
| 5419 | |
| 5420 | /* |
| 5421 | * Convert an NFS error code to a local one. |
| 5422 | * This one is used jointly by NFSv2 and NFSv3. |
| 5423 | */ |
| 5424 | static int |
David Howells | 0a8ea43 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 5425 | nfs4_stat_to_errno(int stat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5426 | { |
| 5427 | int i; |
| 5428 | for (i = 0; nfs_errtbl[i].stat != -1; i++) { |
| 5429 | if (nfs_errtbl[i].stat == stat) |
| 5430 | return nfs_errtbl[i].errno; |
| 5431 | } |
| 5432 | if (stat <= 10000 || stat > 10100) { |
| 5433 | /* The server is looney tunes. */ |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 5434 | return -ESERVERFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5435 | } |
| 5436 | /* If we cannot translate the error, the recovery routines should |
| 5437 | * handle it. |
| 5438 | * Note: remaining NFSv4 error codes have values > 10000, so should |
| 5439 | * not conflict with native Linux error codes. |
| 5440 | */ |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 5441 | return -stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5442 | } |
| 5443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5444 | #define PROC(proc, argtype, restype) \ |
| 5445 | [NFSPROC4_CLNT_##proc] = { \ |
| 5446 | .p_proc = NFSPROC4_COMPOUND, \ |
| 5447 | .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \ |
| 5448 | .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \ |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 5449 | .p_arglen = NFS4_##argtype##_sz, \ |
| 5450 | .p_replen = NFS4_##restype##_sz, \ |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 5451 | .p_statidx = NFSPROC4_CLNT_##proc, \ |
| 5452 | .p_name = #proc, \ |
Andy Adamson | 05d564f | 2008-12-23 16:06:15 -0500 | [diff] [blame] | 5453 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5454 | |
| 5455 | struct rpc_procinfo nfs4_procedures[] = { |
| 5456 | PROC(READ, enc_read, dec_read), |
| 5457 | PROC(WRITE, enc_write, dec_write), |
| 5458 | PROC(COMMIT, enc_commit, dec_commit), |
| 5459 | PROC(OPEN, enc_open, dec_open), |
| 5460 | PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), |
| 5461 | PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), |
| 5462 | PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), |
| 5463 | PROC(CLOSE, enc_close, dec_close), |
| 5464 | PROC(SETATTR, enc_setattr, dec_setattr), |
| 5465 | PROC(FSINFO, enc_fsinfo, dec_fsinfo), |
| 5466 | PROC(RENEW, enc_renew, dec_renew), |
| 5467 | PROC(SETCLIENTID, enc_setclientid, dec_setclientid), |
| 5468 | PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), |
| 5469 | PROC(LOCK, enc_lock, dec_lock), |
| 5470 | PROC(LOCKT, enc_lockt, dec_lockt), |
| 5471 | PROC(LOCKU, enc_locku, dec_locku), |
| 5472 | PROC(ACCESS, enc_access, dec_access), |
| 5473 | PROC(GETATTR, enc_getattr, dec_getattr), |
| 5474 | PROC(LOOKUP, enc_lookup, dec_lookup), |
| 5475 | PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), |
| 5476 | PROC(REMOVE, enc_remove, dec_remove), |
| 5477 | PROC(RENAME, enc_rename, dec_rename), |
| 5478 | PROC(LINK, enc_link, dec_link), |
| 5479 | PROC(SYMLINK, enc_symlink, dec_symlink), |
| 5480 | PROC(CREATE, enc_create, dec_create), |
| 5481 | PROC(PATHCONF, enc_pathconf, dec_pathconf), |
| 5482 | PROC(STATFS, enc_statfs, dec_statfs), |
| 5483 | PROC(READLINK, enc_readlink, dec_readlink), |
| 5484 | PROC(READDIR, enc_readdir, dec_readdir), |
| 5485 | PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), |
| 5486 | PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5487 | PROC(GETACL, enc_getacl, dec_getacl), |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5488 | PROC(SETACL, enc_setacl, dec_setacl), |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5489 | PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5490 | #if defined(CONFIG_NFS_V4_1) |
| 5491 | PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5492 | PROC(CREATE_SESSION, enc_create_session, dec_create_session), |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5493 | PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5494 | PROC(SEQUENCE, enc_sequence, dec_sequence), |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5495 | PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5496 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5497 | }; |
| 5498 | |
| 5499 | struct rpc_version nfs_version4 = { |
| 5500 | .number = 4, |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 5501 | .nrprocs = ARRAY_SIZE(nfs4_procedures), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5502 | .procs = nfs4_procedures |
| 5503 | }; |
| 5504 | |
| 5505 | /* |
| 5506 | * Local variables: |
| 5507 | * c-basic-offset: 8 |
| 5508 | * End: |
| 5509 | */ |