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> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/param.h> |
| 39 | #include <linux/time.h> |
| 40 | #include <linux/mm.h> |
| 41 | #include <linux/slab.h> |
| 42 | #include <linux/utsname.h> |
| 43 | #include <linux/errno.h> |
| 44 | #include <linux/string.h> |
| 45 | #include <linux/in.h> |
| 46 | #include <linux/pagemap.h> |
| 47 | #include <linux/proc_fs.h> |
| 48 | #include <linux/kdev_t.h> |
| 49 | #include <linux/sunrpc/clnt.h> |
| 50 | #include <linux/nfs.h> |
| 51 | #include <linux/nfs4.h> |
| 52 | #include <linux/nfs_fs.h> |
| 53 | #include <linux/nfs_idmap.h> |
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 | |
| 61 | static int nfs_stat_to_errno(int); |
| 62 | |
| 63 | /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ |
| 64 | #ifdef DEBUG |
| 65 | #define NFS4_MAXTAGLEN 20 |
| 66 | #else |
| 67 | #define NFS4_MAXTAGLEN 0 |
| 68 | #endif |
| 69 | |
| 70 | /* lock,open owner id: |
| 71 | * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2) |
| 72 | */ |
| 73 | #define owner_id_maxsz (1 + 1) |
| 74 | #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) |
| 75 | #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) |
| 76 | #define op_encode_hdr_maxsz (1) |
| 77 | #define op_decode_hdr_maxsz (2) |
| 78 | #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ |
| 79 | (NFS4_FHSIZE >> 2)) |
| 80 | #define decode_putfh_maxsz (op_decode_hdr_maxsz) |
| 81 | #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) |
| 82 | #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) |
| 83 | #define encode_getfh_maxsz (op_encode_hdr_maxsz) |
| 84 | #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ |
| 85 | ((3+NFS4_FHSIZE) >> 2)) |
J. Bruce Fields | 9692820 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 86 | #define nfs4_fattr_bitmap_maxsz 3 |
| 87 | #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) |
| 89 | #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) |
J. Bruce Fields | 9692820 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 90 | /* This is based on getfattr, which uses the most attributes: */ |
| 91 | #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ |
| 92 | 3 + 3 + 3 + 2 * nfs4_name_maxsz)) |
| 93 | #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ |
| 94 | nfs4_fattr_value_maxsz) |
| 95 | #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | #define encode_savefh_maxsz (op_encode_hdr_maxsz) |
| 97 | #define decode_savefh_maxsz (op_decode_hdr_maxsz) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 98 | #define encode_restorefh_maxsz (op_encode_hdr_maxsz) |
| 99 | #define decode_restorefh_maxsz (op_decode_hdr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2) |
| 101 | #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11) |
| 102 | #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) |
| 103 | #define decode_renew_maxsz (op_decode_hdr_maxsz) |
| 104 | #define encode_setclientid_maxsz \ |
| 105 | (op_encode_hdr_maxsz + \ |
| 106 | 4 /*server->ip_addr*/ + \ |
| 107 | 1 /*Netid*/ + \ |
| 108 | 6 /*uaddr*/ + \ |
| 109 | 6 + (NFS4_VERIFIER_SIZE >> 2)) |
| 110 | #define decode_setclientid_maxsz \ |
| 111 | (op_decode_hdr_maxsz + \ |
| 112 | 2 + \ |
| 113 | 1024) /* large value for CLID_INUSE */ |
| 114 | #define encode_setclientid_confirm_maxsz \ |
| 115 | (op_encode_hdr_maxsz + \ |
| 116 | 3 + (NFS4_VERIFIER_SIZE >> 2)) |
| 117 | #define decode_setclientid_confirm_maxsz \ |
| 118 | (op_decode_hdr_maxsz) |
| 119 | #define encode_lookup_maxsz (op_encode_hdr_maxsz + \ |
| 120 | 1 + ((3 + NFS4_FHSIZE) >> 2)) |
| 121 | #define encode_remove_maxsz (op_encode_hdr_maxsz + \ |
| 122 | nfs4_name_maxsz) |
| 123 | #define encode_rename_maxsz (op_encode_hdr_maxsz + \ |
| 124 | 2 * nfs4_name_maxsz) |
| 125 | #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5) |
| 126 | #define encode_link_maxsz (op_encode_hdr_maxsz + \ |
| 127 | nfs4_name_maxsz) |
| 128 | #define decode_link_maxsz (op_decode_hdr_maxsz + 5) |
| 129 | #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ |
| 130 | 1 + nfs4_name_maxsz + \ |
| 131 | nfs4_path_maxsz + \ |
J. Bruce Fields | 9692820 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 132 | nfs4_fattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) |
| 134 | #define encode_create_maxsz (op_encode_hdr_maxsz + \ |
| 135 | 2 + nfs4_name_maxsz + \ |
J. Bruce Fields | 9692820 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 136 | nfs4_fattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | #define decode_create_maxsz (op_decode_hdr_maxsz + 8) |
| 138 | #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) |
| 139 | #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) |
| 140 | #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ |
| 141 | #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ |
| 142 | #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ |
| 143 | encode_putfh_maxsz + \ |
| 144 | op_encode_hdr_maxsz + 7) |
| 145 | #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ |
| 146 | decode_putfh_maxsz + \ |
| 147 | op_decode_hdr_maxsz + 2) |
| 148 | #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ |
| 149 | encode_putfh_maxsz + \ |
| 150 | op_encode_hdr_maxsz) |
| 151 | #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ |
| 152 | decode_putfh_maxsz + \ |
| 153 | op_decode_hdr_maxsz) |
| 154 | #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ |
| 155 | encode_putfh_maxsz + \ |
| 156 | op_encode_hdr_maxsz + 9) |
| 157 | #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ |
| 158 | decode_putfh_maxsz + \ |
| 159 | op_decode_hdr_maxsz + 2) |
| 160 | #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ |
| 161 | encode_putfh_maxsz + \ |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 162 | op_encode_hdr_maxsz + 8 + \ |
| 163 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ |
| 165 | decode_putfh_maxsz + \ |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 166 | op_decode_hdr_maxsz + 4 + \ |
| 167 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ |
| 169 | encode_putfh_maxsz + \ |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 170 | op_encode_hdr_maxsz + 3 + \ |
| 171 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ |
| 173 | decode_putfh_maxsz + \ |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 174 | op_decode_hdr_maxsz + 2 + \ |
| 175 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ |
| 177 | encode_putfh_maxsz + \ |
| 178 | op_encode_hdr_maxsz + \ |
| 179 | 13 + 3 + 2 + 64 + \ |
| 180 | encode_getattr_maxsz + \ |
| 181 | encode_getfh_maxsz) |
| 182 | #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ |
| 183 | decode_putfh_maxsz + \ |
| 184 | op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \ |
| 185 | decode_getattr_maxsz + \ |
| 186 | decode_getfh_maxsz) |
| 187 | #define NFS4_enc_open_confirm_sz \ |
| 188 | (compound_encode_hdr_maxsz + \ |
| 189 | encode_putfh_maxsz + \ |
| 190 | op_encode_hdr_maxsz + 5) |
| 191 | #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \ |
| 192 | decode_putfh_maxsz + \ |
| 193 | op_decode_hdr_maxsz + 4) |
| 194 | #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ |
| 195 | encode_putfh_maxsz + \ |
| 196 | op_encode_hdr_maxsz + \ |
| 197 | 11) |
| 198 | #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ |
| 199 | decode_putfh_maxsz + \ |
| 200 | op_decode_hdr_maxsz + \ |
| 201 | 4 + 5 + 2 + 3) |
| 202 | #define NFS4_enc_open_downgrade_sz \ |
| 203 | (compound_encode_hdr_maxsz + \ |
| 204 | encode_putfh_maxsz + \ |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 205 | op_encode_hdr_maxsz + 7 + \ |
| 206 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | #define NFS4_dec_open_downgrade_sz \ |
| 208 | (compound_decode_hdr_maxsz + \ |
| 209 | decode_putfh_maxsz + \ |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 210 | op_decode_hdr_maxsz + 4 + \ |
| 211 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ |
| 213 | encode_putfh_maxsz + \ |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 214 | op_encode_hdr_maxsz + 5 + \ |
| 215 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ |
| 217 | decode_putfh_maxsz + \ |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 218 | op_decode_hdr_maxsz + 4 + \ |
| 219 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ |
| 221 | encode_putfh_maxsz + \ |
| 222 | op_encode_hdr_maxsz + 4 + \ |
J. Bruce Fields | 9692820 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 223 | nfs4_fattr_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | encode_getattr_maxsz) |
| 225 | #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ |
| 226 | decode_putfh_maxsz + \ |
| 227 | op_decode_hdr_maxsz + 3) |
| 228 | #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ |
| 229 | encode_putfh_maxsz + \ |
| 230 | encode_fsinfo_maxsz) |
| 231 | #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ |
| 232 | decode_putfh_maxsz + \ |
| 233 | decode_fsinfo_maxsz) |
| 234 | #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ |
| 235 | encode_renew_maxsz) |
| 236 | #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ |
| 237 | decode_renew_maxsz) |
| 238 | #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ |
| 239 | encode_setclientid_maxsz) |
| 240 | #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ |
| 241 | decode_setclientid_maxsz) |
| 242 | #define NFS4_enc_setclientid_confirm_sz \ |
| 243 | (compound_encode_hdr_maxsz + \ |
| 244 | encode_setclientid_confirm_maxsz + \ |
| 245 | encode_putrootfh_maxsz + \ |
| 246 | encode_fsinfo_maxsz) |
| 247 | #define NFS4_dec_setclientid_confirm_sz \ |
| 248 | (compound_decode_hdr_maxsz + \ |
| 249 | decode_setclientid_confirm_maxsz + \ |
| 250 | decode_putrootfh_maxsz + \ |
| 251 | decode_fsinfo_maxsz) |
| 252 | #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ |
| 253 | encode_putfh_maxsz + \ |
| 254 | encode_getattr_maxsz + \ |
| 255 | op_encode_hdr_maxsz + \ |
| 256 | 1 + 1 + 2 + 2 + \ |
| 257 | 1 + 4 + 1 + 2 + \ |
| 258 | owner_id_maxsz) |
| 259 | #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ |
| 260 | decode_putfh_maxsz + \ |
| 261 | decode_getattr_maxsz + \ |
| 262 | op_decode_hdr_maxsz + \ |
| 263 | 2 + 2 + 1 + 2 + \ |
| 264 | owner_id_maxsz) |
| 265 | #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ |
| 266 | encode_putfh_maxsz + \ |
| 267 | encode_getattr_maxsz + \ |
| 268 | op_encode_hdr_maxsz + \ |
| 269 | 1 + 2 + 2 + 2 + \ |
| 270 | owner_id_maxsz) |
| 271 | #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz) |
| 272 | #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ |
| 273 | encode_putfh_maxsz + \ |
| 274 | encode_getattr_maxsz + \ |
| 275 | op_encode_hdr_maxsz + \ |
| 276 | 1 + 1 + 4 + 2 + 2) |
| 277 | #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ |
| 278 | decode_putfh_maxsz + \ |
| 279 | decode_getattr_maxsz + \ |
| 280 | op_decode_hdr_maxsz + 4) |
| 281 | #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ |
| 282 | encode_putfh_maxsz + \ |
| 283 | op_encode_hdr_maxsz + 1) |
| 284 | #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ |
| 285 | decode_putfh_maxsz + \ |
| 286 | op_decode_hdr_maxsz + 2) |
| 287 | #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ |
| 288 | encode_putfh_maxsz + \ |
| 289 | encode_getattr_maxsz) |
| 290 | #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ |
| 291 | decode_putfh_maxsz + \ |
| 292 | decode_getattr_maxsz) |
| 293 | #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ |
| 294 | encode_putfh_maxsz + \ |
| 295 | encode_lookup_maxsz + \ |
| 296 | encode_getattr_maxsz + \ |
| 297 | encode_getfh_maxsz) |
| 298 | #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ |
| 299 | decode_putfh_maxsz + \ |
| 300 | op_decode_hdr_maxsz + \ |
| 301 | decode_getattr_maxsz + \ |
| 302 | decode_getfh_maxsz) |
| 303 | #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ |
| 304 | encode_putrootfh_maxsz + \ |
| 305 | encode_getattr_maxsz + \ |
| 306 | encode_getfh_maxsz) |
| 307 | #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ |
| 308 | decode_putrootfh_maxsz + \ |
| 309 | decode_getattr_maxsz + \ |
| 310 | decode_getfh_maxsz) |
| 311 | #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ |
| 312 | encode_putfh_maxsz + \ |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 313 | encode_remove_maxsz + \ |
| 314 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ |
| 316 | decode_putfh_maxsz + \ |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 317 | op_decode_hdr_maxsz + 5 + \ |
| 318 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ |
| 320 | encode_putfh_maxsz + \ |
| 321 | encode_savefh_maxsz + \ |
| 322 | encode_putfh_maxsz + \ |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 323 | encode_rename_maxsz + \ |
| 324 | encode_getattr_maxsz + \ |
| 325 | encode_restorefh_maxsz + \ |
| 326 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ |
| 328 | decode_putfh_maxsz + \ |
| 329 | decode_savefh_maxsz + \ |
| 330 | decode_putfh_maxsz + \ |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 331 | decode_rename_maxsz + \ |
| 332 | decode_getattr_maxsz + \ |
| 333 | decode_restorefh_maxsz + \ |
| 334 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ |
| 336 | encode_putfh_maxsz + \ |
| 337 | encode_savefh_maxsz + \ |
| 338 | encode_putfh_maxsz + \ |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 339 | encode_link_maxsz + \ |
| 340 | decode_getattr_maxsz + \ |
| 341 | encode_restorefh_maxsz + \ |
| 342 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ |
| 344 | decode_putfh_maxsz + \ |
| 345 | decode_savefh_maxsz + \ |
| 346 | decode_putfh_maxsz + \ |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 347 | decode_link_maxsz + \ |
| 348 | decode_getattr_maxsz + \ |
| 349 | decode_restorefh_maxsz + \ |
| 350 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ |
| 352 | encode_putfh_maxsz + \ |
| 353 | encode_symlink_maxsz + \ |
| 354 | encode_getattr_maxsz + \ |
| 355 | encode_getfh_maxsz) |
| 356 | #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ |
| 357 | decode_putfh_maxsz + \ |
| 358 | decode_symlink_maxsz + \ |
| 359 | decode_getattr_maxsz + \ |
| 360 | decode_getfh_maxsz) |
| 361 | #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ |
| 362 | encode_putfh_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 363 | encode_savefh_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | encode_create_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 365 | encode_getfh_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | encode_getattr_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 367 | encode_restorefh_maxsz + \ |
| 368 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ |
| 370 | decode_putfh_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 371 | decode_savefh_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | decode_create_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 373 | decode_getfh_maxsz + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | decode_getattr_maxsz + \ |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 375 | decode_restorefh_maxsz + \ |
| 376 | decode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ |
| 378 | encode_putfh_maxsz + \ |
| 379 | encode_getattr_maxsz) |
| 380 | #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ |
| 381 | decode_putfh_maxsz + \ |
| 382 | decode_getattr_maxsz) |
| 383 | #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ |
| 384 | encode_putfh_maxsz + \ |
| 385 | encode_getattr_maxsz) |
| 386 | #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ |
| 387 | decode_putfh_maxsz + \ |
| 388 | op_decode_hdr_maxsz + 12) |
| 389 | #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ |
| 390 | encode_getattr_maxsz) |
| 391 | #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ |
| 392 | decode_getattr_maxsz) |
| 393 | #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ |
| 394 | encode_putfh_maxsz + \ |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 395 | encode_delegreturn_maxsz + \ |
| 396 | encode_getattr_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 398 | decode_delegreturn_maxsz + \ |
| 399 | decode_getattr_maxsz) |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 400 | #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ |
| 401 | encode_putfh_maxsz + \ |
| 402 | encode_getattr_maxsz) |
| 403 | #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ |
| 404 | decode_putfh_maxsz + \ |
| 405 | op_decode_hdr_maxsz + \ |
| 406 | nfs4_fattr_bitmap_maxsz + 1) |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 407 | #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ |
| 408 | encode_putfh_maxsz + \ |
| 409 | op_encode_hdr_maxsz + 4 + \ |
| 410 | nfs4_fattr_bitmap_maxsz + 1) |
| 411 | #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ |
| 412 | decode_putfh_maxsz + \ |
| 413 | op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 414 | #define NFS4_enc_fs_locations_sz \ |
| 415 | (compound_encode_hdr_maxsz + \ |
| 416 | encode_putfh_maxsz + \ |
| 417 | encode_getattr_maxsz) |
| 418 | #define NFS4_dec_fs_locations_sz \ |
| 419 | (compound_decode_hdr_maxsz + \ |
| 420 | decode_putfh_maxsz + \ |
| 421 | op_decode_hdr_maxsz + \ |
| 422 | nfs4_fattr_bitmap_maxsz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | static struct { |
| 425 | unsigned int mode; |
| 426 | unsigned int nfs2type; |
| 427 | } nfs_type2fmt[] = { |
| 428 | { 0, NFNON }, |
| 429 | { S_IFREG, NFREG }, |
| 430 | { S_IFDIR, NFDIR }, |
| 431 | { S_IFBLK, NFBLK }, |
| 432 | { S_IFCHR, NFCHR }, |
| 433 | { S_IFLNK, NFLNK }, |
| 434 | { S_IFSOCK, NFSOCK }, |
| 435 | { S_IFIFO, NFFIFO }, |
| 436 | { 0, NFNON }, |
| 437 | { 0, NFNON }, |
| 438 | }; |
| 439 | |
| 440 | struct compound_hdr { |
| 441 | int32_t status; |
| 442 | uint32_t nops; |
| 443 | uint32_t taglen; |
| 444 | char * tag; |
| 445 | }; |
| 446 | |
| 447 | /* |
| 448 | * START OF "GENERIC" ENCODE ROUTINES. |
| 449 | * These may look a little ugly since they are imported from a "generic" |
| 450 | * set of XDR encode/decode routines which are intended to be shared by |
| 451 | * all of our NFSv4 implementations (OpenBSD, MacOS X...). |
| 452 | * |
| 453 | * If the pain of reading these is too great, it should be a straightforward |
| 454 | * task to translate them into Linux-specific versions which are more |
| 455 | * consistent with the style used in NFSv2/v3... |
| 456 | */ |
| 457 | #define WRITE32(n) *p++ = htonl(n) |
| 458 | #define WRITE64(n) do { \ |
| 459 | *p++ = htonl((uint32_t)((n) >> 32)); \ |
| 460 | *p++ = htonl((uint32_t)(n)); \ |
| 461 | } while (0) |
| 462 | #define WRITEMEM(ptr,nbytes) do { \ |
| 463 | p = xdr_encode_opaque_fixed(p, ptr, nbytes); \ |
| 464 | } while (0) |
| 465 | |
| 466 | #define RESERVE_SPACE(nbytes) do { \ |
| 467 | p = xdr_reserve_space(xdr, nbytes); \ |
| 468 | if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \ |
| 469 | BUG_ON(!p); \ |
| 470 | } while (0) |
| 471 | |
| 472 | static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) |
| 473 | { |
| 474 | uint32_t *p; |
| 475 | |
| 476 | p = xdr_reserve_space(xdr, 4 + len); |
| 477 | BUG_ON(p == NULL); |
| 478 | xdr_encode_opaque(p, str, len); |
| 479 | } |
| 480 | |
| 481 | static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) |
| 482 | { |
| 483 | uint32_t *p; |
| 484 | |
| 485 | dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag); |
| 486 | BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); |
| 487 | RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2)); |
| 488 | WRITE32(hdr->taglen); |
| 489 | WRITEMEM(hdr->tag, hdr->taglen); |
| 490 | WRITE32(NFS4_MINOR_VERSION); |
| 491 | WRITE32(hdr->nops); |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) |
| 496 | { |
| 497 | uint32_t *p; |
| 498 | |
| 499 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 500 | BUG_ON(p == NULL); |
| 501 | xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE); |
| 502 | } |
| 503 | |
| 504 | static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) |
| 505 | { |
| 506 | char owner_name[IDMAP_NAMESZ]; |
| 507 | char owner_group[IDMAP_NAMESZ]; |
| 508 | int owner_namelen = 0; |
| 509 | int owner_grouplen = 0; |
| 510 | uint32_t *p; |
| 511 | uint32_t *q; |
| 512 | int len; |
| 513 | uint32_t bmval0 = 0; |
| 514 | uint32_t bmval1 = 0; |
| 515 | int status; |
| 516 | |
| 517 | /* |
| 518 | * We reserve enough space to write the entire attribute buffer at once. |
| 519 | * In the worst-case, this would be |
| 520 | * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) |
| 521 | * = 36 bytes, plus any contribution from variable-length fields |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 522 | * such as owner/group. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | */ |
| 524 | len = 16; |
| 525 | |
| 526 | /* Sigh */ |
| 527 | if (iap->ia_valid & ATTR_SIZE) |
| 528 | len += 8; |
| 529 | if (iap->ia_valid & ATTR_MODE) |
| 530 | len += 4; |
| 531 | if (iap->ia_valid & ATTR_UID) { |
| 532 | owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name); |
| 533 | if (owner_namelen < 0) { |
| 534 | printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n", |
| 535 | iap->ia_uid); |
| 536 | /* XXX */ |
| 537 | strcpy(owner_name, "nobody"); |
| 538 | owner_namelen = sizeof("nobody") - 1; |
| 539 | /* goto out; */ |
| 540 | } |
| 541 | len += 4 + (XDR_QUADLEN(owner_namelen) << 2); |
| 542 | } |
| 543 | if (iap->ia_valid & ATTR_GID) { |
| 544 | owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group); |
| 545 | if (owner_grouplen < 0) { |
| 546 | printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n", |
| 547 | iap->ia_gid); |
| 548 | strcpy(owner_group, "nobody"); |
| 549 | owner_grouplen = sizeof("nobody") - 1; |
| 550 | /* goto out; */ |
| 551 | } |
| 552 | len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); |
| 553 | } |
| 554 | if (iap->ia_valid & ATTR_ATIME_SET) |
| 555 | len += 16; |
| 556 | else if (iap->ia_valid & ATTR_ATIME) |
| 557 | len += 4; |
| 558 | if (iap->ia_valid & ATTR_MTIME_SET) |
| 559 | len += 16; |
| 560 | else if (iap->ia_valid & ATTR_MTIME) |
| 561 | len += 4; |
| 562 | RESERVE_SPACE(len); |
| 563 | |
| 564 | /* |
| 565 | * We write the bitmap length now, but leave the bitmap and the attribute |
| 566 | * buffer length to be backfilled at the end of this routine. |
| 567 | */ |
| 568 | WRITE32(2); |
| 569 | q = p; |
| 570 | p += 3; |
| 571 | |
| 572 | if (iap->ia_valid & ATTR_SIZE) { |
| 573 | bmval0 |= FATTR4_WORD0_SIZE; |
| 574 | WRITE64(iap->ia_size); |
| 575 | } |
| 576 | if (iap->ia_valid & ATTR_MODE) { |
| 577 | bmval1 |= FATTR4_WORD1_MODE; |
Trond Myklebust | cf3fff5 | 2006-01-03 09:55:53 +0100 | [diff] [blame] | 578 | WRITE32(iap->ia_mode & S_IALLUGO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | } |
| 580 | if (iap->ia_valid & ATTR_UID) { |
| 581 | bmval1 |= FATTR4_WORD1_OWNER; |
| 582 | WRITE32(owner_namelen); |
| 583 | WRITEMEM(owner_name, owner_namelen); |
| 584 | } |
| 585 | if (iap->ia_valid & ATTR_GID) { |
| 586 | bmval1 |= FATTR4_WORD1_OWNER_GROUP; |
| 587 | WRITE32(owner_grouplen); |
| 588 | WRITEMEM(owner_group, owner_grouplen); |
| 589 | } |
| 590 | if (iap->ia_valid & ATTR_ATIME_SET) { |
| 591 | bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; |
| 592 | WRITE32(NFS4_SET_TO_CLIENT_TIME); |
| 593 | WRITE32(0); |
| 594 | WRITE32(iap->ia_mtime.tv_sec); |
| 595 | WRITE32(iap->ia_mtime.tv_nsec); |
| 596 | } |
| 597 | else if (iap->ia_valid & ATTR_ATIME) { |
| 598 | bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; |
| 599 | WRITE32(NFS4_SET_TO_SERVER_TIME); |
| 600 | } |
| 601 | if (iap->ia_valid & ATTR_MTIME_SET) { |
| 602 | bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; |
| 603 | WRITE32(NFS4_SET_TO_CLIENT_TIME); |
| 604 | WRITE32(0); |
| 605 | WRITE32(iap->ia_mtime.tv_sec); |
| 606 | WRITE32(iap->ia_mtime.tv_nsec); |
| 607 | } |
| 608 | else if (iap->ia_valid & ATTR_MTIME) { |
| 609 | bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; |
| 610 | WRITE32(NFS4_SET_TO_SERVER_TIME); |
| 611 | } |
| 612 | |
| 613 | /* |
| 614 | * Now we backfill the bitmap and the attribute buffer length. |
| 615 | */ |
| 616 | if (len != ((char *)p - (char *)q) + 4) { |
| 617 | printk ("encode_attr: Attr length calculation error! %u != %Zu\n", |
| 618 | len, ((char *)p - (char *)q) + 4); |
| 619 | BUG(); |
| 620 | } |
| 621 | len = (char *)p - (char *)q - 12; |
| 622 | *q++ = htonl(bmval0); |
| 623 | *q++ = htonl(bmval1); |
| 624 | *q++ = htonl(len); |
| 625 | |
| 626 | status = 0; |
| 627 | /* out: */ |
| 628 | return status; |
| 629 | } |
| 630 | |
| 631 | static int encode_access(struct xdr_stream *xdr, u32 access) |
| 632 | { |
| 633 | uint32_t *p; |
| 634 | |
| 635 | RESERVE_SPACE(8); |
| 636 | WRITE32(OP_ACCESS); |
| 637 | WRITE32(access); |
| 638 | |
| 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg) |
| 643 | { |
| 644 | uint32_t *p; |
| 645 | |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 646 | RESERVE_SPACE(8+sizeof(arg->stateid->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | WRITE32(OP_CLOSE); |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 648 | WRITE32(arg->seqid->sequence->counter); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 649 | WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args) |
| 655 | { |
| 656 | uint32_t *p; |
| 657 | |
| 658 | RESERVE_SPACE(16); |
| 659 | WRITE32(OP_COMMIT); |
| 660 | WRITE64(args->offset); |
| 661 | WRITE32(args->count); |
| 662 | |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create) |
| 667 | { |
| 668 | uint32_t *p; |
| 669 | |
| 670 | RESERVE_SPACE(8); |
| 671 | WRITE32(OP_CREATE); |
| 672 | WRITE32(create->ftype); |
| 673 | |
| 674 | switch (create->ftype) { |
| 675 | case NF4LNK: |
| 676 | RESERVE_SPACE(4 + create->u.symlink->len); |
| 677 | WRITE32(create->u.symlink->len); |
| 678 | WRITEMEM(create->u.symlink->name, create->u.symlink->len); |
| 679 | break; |
| 680 | |
| 681 | case NF4BLK: case NF4CHR: |
| 682 | RESERVE_SPACE(8); |
| 683 | WRITE32(create->u.device.specdata1); |
| 684 | WRITE32(create->u.device.specdata2); |
| 685 | break; |
| 686 | |
| 687 | default: |
| 688 | break; |
| 689 | } |
| 690 | |
| 691 | RESERVE_SPACE(4 + create->name->len); |
| 692 | WRITE32(create->name->len); |
| 693 | WRITEMEM(create->name->name, create->name->len); |
| 694 | |
| 695 | return encode_attrs(xdr, create->attrs, create->server); |
| 696 | } |
| 697 | |
| 698 | static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap) |
| 699 | { |
| 700 | uint32_t *p; |
| 701 | |
| 702 | RESERVE_SPACE(12); |
| 703 | WRITE32(OP_GETATTR); |
| 704 | WRITE32(1); |
| 705 | WRITE32(bitmap); |
| 706 | return 0; |
| 707 | } |
| 708 | |
| 709 | static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1) |
| 710 | { |
| 711 | uint32_t *p; |
| 712 | |
| 713 | RESERVE_SPACE(16); |
| 714 | WRITE32(OP_GETATTR); |
| 715 | WRITE32(2); |
| 716 | WRITE32(bm0); |
| 717 | WRITE32(bm1); |
| 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask) |
| 722 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | return encode_getattr_two(xdr, |
| 724 | bitmask[0] & nfs4_fattr_bitmap[0], |
| 725 | bitmask[1] & nfs4_fattr_bitmap[1]); |
| 726 | } |
| 727 | |
| 728 | static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask) |
| 729 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0], |
| 731 | bitmask[1] & nfs4_fsinfo_bitmap[1]); |
| 732 | } |
| 733 | |
| 734 | static int encode_getfh(struct xdr_stream *xdr) |
| 735 | { |
| 736 | uint32_t *p; |
| 737 | |
| 738 | RESERVE_SPACE(4); |
| 739 | WRITE32(OP_GETFH); |
| 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | static int encode_link(struct xdr_stream *xdr, const struct qstr *name) |
| 745 | { |
| 746 | uint32_t *p; |
| 747 | |
| 748 | RESERVE_SPACE(8 + name->len); |
| 749 | WRITE32(OP_LINK); |
| 750 | WRITE32(name->len); |
| 751 | WRITEMEM(name->name, name->len); |
| 752 | |
| 753 | return 0; |
| 754 | } |
| 755 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 756 | static inline int nfs4_lock_type(struct file_lock *fl, int block) |
| 757 | { |
| 758 | if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK) |
| 759 | return block ? NFS4_READW_LT : NFS4_READ_LT; |
| 760 | return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; |
| 761 | } |
| 762 | |
| 763 | static inline uint64_t nfs4_lock_length(struct file_lock *fl) |
| 764 | { |
| 765 | if (fl->fl_end == OFFSET_MAX) |
| 766 | return ~(uint64_t)0; |
| 767 | return fl->fl_end - fl->fl_start + 1; |
| 768 | } |
| 769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | /* |
| 771 | * opcode,type,reclaim,offset,length,new_lock_owner = 32 |
| 772 | * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 |
| 773 | */ |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 774 | static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | { |
| 776 | uint32_t *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | RESERVE_SPACE(32); |
| 779 | WRITE32(OP_LOCK); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 780 | WRITE32(nfs4_lock_type(args->fl, args->block)); |
| 781 | WRITE32(args->reclaim); |
| 782 | WRITE64(args->fl->fl_start); |
| 783 | WRITE64(nfs4_lock_length(args->fl)); |
| 784 | WRITE32(args->new_lock_owner); |
| 785 | if (args->new_lock_owner){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | RESERVE_SPACE(40); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 787 | WRITE32(args->open_seqid->sequence->counter); |
| 788 | WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data)); |
| 789 | WRITE32(args->lock_seqid->sequence->counter); |
| 790 | WRITE64(args->lock_owner.clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | WRITE32(4); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 792 | WRITE32(args->lock_owner.id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | } |
| 794 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | RESERVE_SPACE(20); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 796 | WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data)); |
| 797 | WRITE32(args->lock_seqid->sequence->counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 803 | static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
| 805 | uint32_t *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
| 807 | RESERVE_SPACE(40); |
| 808 | WRITE32(OP_LOCKT); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 809 | WRITE32(nfs4_lock_type(args->fl, 0)); |
| 810 | WRITE64(args->fl->fl_start); |
| 811 | WRITE64(nfs4_lock_length(args->fl)); |
| 812 | WRITE64(args->lock_owner.clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | WRITE32(4); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 814 | WRITE32(args->lock_owner.id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
| 816 | return 0; |
| 817 | } |
| 818 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 819 | static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
| 821 | uint32_t *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
| 823 | RESERVE_SPACE(44); |
| 824 | WRITE32(OP_LOCKU); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 825 | WRITE32(nfs4_lock_type(args->fl, 0)); |
| 826 | WRITE32(args->seqid->sequence->counter); |
| 827 | WRITEMEM(args->stateid->data, sizeof(args->stateid->data)); |
| 828 | WRITE64(args->fl->fl_start); |
| 829 | WRITE64(nfs4_lock_length(args->fl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
| 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name) |
| 835 | { |
| 836 | int len = name->len; |
| 837 | uint32_t *p; |
| 838 | |
| 839 | RESERVE_SPACE(8 + len); |
| 840 | WRITE32(OP_LOOKUP); |
| 841 | WRITE32(len); |
| 842 | WRITEMEM(name->name, len); |
| 843 | |
| 844 | return 0; |
| 845 | } |
| 846 | |
| 847 | static void encode_share_access(struct xdr_stream *xdr, int open_flags) |
| 848 | { |
| 849 | uint32_t *p; |
| 850 | |
| 851 | RESERVE_SPACE(8); |
| 852 | switch (open_flags & (FMODE_READ|FMODE_WRITE)) { |
| 853 | case FMODE_READ: |
| 854 | WRITE32(NFS4_SHARE_ACCESS_READ); |
| 855 | break; |
| 856 | case FMODE_WRITE: |
| 857 | WRITE32(NFS4_SHARE_ACCESS_WRITE); |
| 858 | break; |
| 859 | case FMODE_READ|FMODE_WRITE: |
| 860 | WRITE32(NFS4_SHARE_ACCESS_BOTH); |
| 861 | break; |
| 862 | default: |
| 863 | BUG(); |
| 864 | } |
| 865 | WRITE32(0); /* for linux, share_deny = 0 always */ |
| 866 | } |
| 867 | |
| 868 | static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) |
| 869 | { |
| 870 | uint32_t *p; |
| 871 | /* |
| 872 | * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, |
| 873 | * owner 4 = 32 |
| 874 | */ |
| 875 | RESERVE_SPACE(8); |
| 876 | WRITE32(OP_OPEN); |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 877 | WRITE32(arg->seqid->sequence->counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | encode_share_access(xdr, arg->open_flags); |
| 879 | RESERVE_SPACE(16); |
| 880 | WRITE64(arg->clientid); |
| 881 | WRITE32(4); |
| 882 | WRITE32(arg->id); |
| 883 | } |
| 884 | |
| 885 | static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) |
| 886 | { |
| 887 | uint32_t *p; |
| 888 | |
| 889 | RESERVE_SPACE(4); |
| 890 | switch(arg->open_flags & O_EXCL) { |
| 891 | case 0: |
| 892 | WRITE32(NFS4_CREATE_UNCHECKED); |
| 893 | encode_attrs(xdr, arg->u.attrs, arg->server); |
| 894 | break; |
| 895 | default: |
| 896 | WRITE32(NFS4_CREATE_EXCLUSIVE); |
| 897 | encode_nfs4_verifier(xdr, &arg->u.verifier); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) |
| 902 | { |
| 903 | uint32_t *p; |
| 904 | |
| 905 | RESERVE_SPACE(4); |
| 906 | switch (arg->open_flags & O_CREAT) { |
| 907 | case 0: |
| 908 | WRITE32(NFS4_OPEN_NOCREATE); |
| 909 | break; |
| 910 | default: |
| 911 | BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); |
| 912 | WRITE32(NFS4_OPEN_CREATE); |
| 913 | encode_createmode(xdr, arg); |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type) |
| 918 | { |
| 919 | uint32_t *p; |
| 920 | |
| 921 | RESERVE_SPACE(4); |
| 922 | switch (delegation_type) { |
| 923 | case 0: |
| 924 | WRITE32(NFS4_OPEN_DELEGATE_NONE); |
| 925 | break; |
| 926 | case FMODE_READ: |
| 927 | WRITE32(NFS4_OPEN_DELEGATE_READ); |
| 928 | break; |
| 929 | case FMODE_WRITE|FMODE_READ: |
| 930 | WRITE32(NFS4_OPEN_DELEGATE_WRITE); |
| 931 | break; |
| 932 | default: |
| 933 | BUG(); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) |
| 938 | { |
| 939 | uint32_t *p; |
| 940 | |
| 941 | RESERVE_SPACE(4); |
| 942 | WRITE32(NFS4_OPEN_CLAIM_NULL); |
| 943 | encode_string(xdr, name->len, name->name); |
| 944 | } |
| 945 | |
| 946 | static inline void encode_claim_previous(struct xdr_stream *xdr, int type) |
| 947 | { |
| 948 | uint32_t *p; |
| 949 | |
| 950 | RESERVE_SPACE(4); |
| 951 | WRITE32(NFS4_OPEN_CLAIM_PREVIOUS); |
| 952 | encode_delegation_type(xdr, type); |
| 953 | } |
| 954 | |
| 955 | static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) |
| 956 | { |
| 957 | uint32_t *p; |
| 958 | |
| 959 | RESERVE_SPACE(4+sizeof(stateid->data)); |
| 960 | WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR); |
| 961 | WRITEMEM(stateid->data, sizeof(stateid->data)); |
| 962 | encode_string(xdr, name->len, name->name); |
| 963 | } |
| 964 | |
| 965 | static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg) |
| 966 | { |
| 967 | encode_openhdr(xdr, arg); |
| 968 | encode_opentype(xdr, arg); |
| 969 | switch (arg->claim) { |
| 970 | case NFS4_OPEN_CLAIM_NULL: |
| 971 | encode_claim_null(xdr, arg->name); |
| 972 | break; |
| 973 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 974 | encode_claim_previous(xdr, arg->u.delegation_type); |
| 975 | break; |
| 976 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 977 | encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); |
| 978 | break; |
| 979 | default: |
| 980 | BUG(); |
| 981 | } |
| 982 | return 0; |
| 983 | } |
| 984 | |
| 985 | static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg) |
| 986 | { |
| 987 | uint32_t *p; |
| 988 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 989 | RESERVE_SPACE(8+sizeof(arg->stateid->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | WRITE32(OP_OPEN_CONFIRM); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 991 | WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 992 | WRITE32(arg->seqid->sequence->counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg) |
| 998 | { |
| 999 | uint32_t *p; |
| 1000 | |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1001 | RESERVE_SPACE(8+sizeof(arg->stateid->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | WRITE32(OP_OPEN_DOWNGRADE); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1003 | WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1004 | WRITE32(arg->seqid->sequence->counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | encode_share_access(xdr, arg->open_flags); |
| 1006 | return 0; |
| 1007 | } |
| 1008 | |
| 1009 | static int |
| 1010 | encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh) |
| 1011 | { |
| 1012 | int len = fh->size; |
| 1013 | uint32_t *p; |
| 1014 | |
| 1015 | RESERVE_SPACE(8 + len); |
| 1016 | WRITE32(OP_PUTFH); |
| 1017 | WRITE32(len); |
| 1018 | WRITEMEM(fh->data, len); |
| 1019 | |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | static int encode_putrootfh(struct xdr_stream *xdr) |
| 1024 | { |
| 1025 | uint32_t *p; |
| 1026 | |
| 1027 | RESERVE_SPACE(4); |
| 1028 | WRITE32(OP_PUTROOTFH); |
| 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx) |
| 1034 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | nfs4_stateid stateid; |
| 1036 | uint32_t *p; |
| 1037 | |
| 1038 | RESERVE_SPACE(16); |
| 1039 | if (ctx->state != NULL) { |
| 1040 | nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner); |
| 1041 | WRITEMEM(stateid.data, sizeof(stateid.data)); |
| 1042 | } else |
| 1043 | WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data)); |
| 1044 | } |
| 1045 | |
| 1046 | static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args) |
| 1047 | { |
| 1048 | uint32_t *p; |
| 1049 | |
| 1050 | RESERVE_SPACE(4); |
| 1051 | WRITE32(OP_READ); |
| 1052 | |
| 1053 | encode_stateid(xdr, args->context); |
| 1054 | |
| 1055 | RESERVE_SPACE(12); |
| 1056 | WRITE64(args->offset); |
| 1057 | WRITE32(args->count); |
| 1058 | |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req) |
| 1063 | { |
| 1064 | struct rpc_auth *auth = req->rq_task->tk_auth; |
Manoj Naik | 97d312d | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 1065 | uint32_t attrs[2] = { |
| 1066 | FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID, |
| 1067 | FATTR4_WORD1_MOUNTED_ON_FILEID, |
| 1068 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | int replen; |
| 1070 | uint32_t *p; |
| 1071 | |
| 1072 | RESERVE_SPACE(32+sizeof(nfs4_verifier)); |
| 1073 | WRITE32(OP_READDIR); |
| 1074 | WRITE64(readdir->cookie); |
| 1075 | WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data)); |
| 1076 | WRITE32(readdir->count >> 1); /* We're not doing readdirplus */ |
| 1077 | WRITE32(readdir->count); |
| 1078 | WRITE32(2); |
Manoj Naik | 97d312d | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 1079 | /* Switch to mounted_on_fileid if the server supports it */ |
| 1080 | if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 1081 | attrs[0] &= ~FATTR4_WORD0_FILEID; |
| 1082 | else |
| 1083 | attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 1084 | WRITE32(attrs[0] & readdir->bitmask[0]); |
| 1085 | WRITE32(attrs[1] & readdir->bitmask[1]); |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 1086 | dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n", |
| 1087 | __FUNCTION__, |
| 1088 | (unsigned long long)readdir->cookie, |
| 1089 | ((u32 *)readdir->verifier.data)[0], |
| 1090 | ((u32 *)readdir->verifier.data)[1], |
| 1091 | attrs[0] & readdir->bitmask[0], |
| 1092 | attrs[1] & readdir->bitmask[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | |
| 1094 | /* set up reply kvec |
| 1095 | * toplevel_status + taglen + rescount + OP_PUTFH + status |
| 1096 | * + OP_READDIR + status + verifer(2) = 9 |
| 1097 | */ |
| 1098 | replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2; |
| 1099 | xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages, |
| 1100 | readdir->pgbase, readdir->count); |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 1101 | dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", |
| 1102 | __FUNCTION__, replen, readdir->pages, |
| 1103 | readdir->pgbase, readdir->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
| 1108 | static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req) |
| 1109 | { |
| 1110 | struct rpc_auth *auth = req->rq_task->tk_auth; |
| 1111 | unsigned int replen; |
| 1112 | uint32_t *p; |
| 1113 | |
| 1114 | RESERVE_SPACE(4); |
| 1115 | WRITE32(OP_READLINK); |
| 1116 | |
| 1117 | /* set up reply kvec |
| 1118 | * toplevel_status + taglen + rescount + OP_PUTFH + status |
| 1119 | * + OP_READLINK + status + string length = 8 |
| 1120 | */ |
| 1121 | replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2; |
| 1122 | xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages, |
| 1123 | readlink->pgbase, readlink->pglen); |
| 1124 | |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | static int encode_remove(struct xdr_stream *xdr, const struct qstr *name) |
| 1129 | { |
| 1130 | uint32_t *p; |
| 1131 | |
| 1132 | RESERVE_SPACE(8 + name->len); |
| 1133 | WRITE32(OP_REMOVE); |
| 1134 | WRITE32(name->len); |
| 1135 | WRITEMEM(name->name, name->len); |
| 1136 | |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname) |
| 1141 | { |
| 1142 | uint32_t *p; |
| 1143 | |
| 1144 | RESERVE_SPACE(8 + oldname->len); |
| 1145 | WRITE32(OP_RENAME); |
| 1146 | WRITE32(oldname->len); |
| 1147 | WRITEMEM(oldname->name, oldname->len); |
| 1148 | |
| 1149 | RESERVE_SPACE(4 + newname->len); |
| 1150 | WRITE32(newname->len); |
| 1151 | WRITEMEM(newname->name, newname->len); |
| 1152 | |
| 1153 | return 0; |
| 1154 | } |
| 1155 | |
| 1156 | static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid) |
| 1157 | { |
| 1158 | uint32_t *p; |
| 1159 | |
| 1160 | RESERVE_SPACE(12); |
| 1161 | WRITE32(OP_RENEW); |
| 1162 | WRITE64(client_stateid->cl_clientid); |
| 1163 | |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | static int |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1168 | encode_restorefh(struct xdr_stream *xdr) |
| 1169 | { |
| 1170 | uint32_t *p; |
| 1171 | |
| 1172 | RESERVE_SPACE(4); |
| 1173 | WRITE32(OP_RESTOREFH); |
| 1174 | |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
| 1178 | static int |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 1179 | encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg) |
| 1180 | { |
| 1181 | uint32_t *p; |
| 1182 | |
| 1183 | RESERVE_SPACE(4+sizeof(zero_stateid.data)); |
| 1184 | WRITE32(OP_SETATTR); |
| 1185 | WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data)); |
| 1186 | RESERVE_SPACE(2*4); |
| 1187 | WRITE32(1); |
| 1188 | WRITE32(FATTR4_WORD0_ACL); |
| 1189 | if (arg->acl_len % 4) |
| 1190 | return -EINVAL; |
| 1191 | RESERVE_SPACE(4); |
| 1192 | WRITE32(arg->acl_len); |
| 1193 | xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
| 1197 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | encode_savefh(struct xdr_stream *xdr) |
| 1199 | { |
| 1200 | uint32_t *p; |
| 1201 | |
| 1202 | RESERVE_SPACE(4); |
| 1203 | WRITE32(OP_SAVEFH); |
| 1204 | |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server) |
| 1209 | { |
| 1210 | int status; |
| 1211 | uint32_t *p; |
| 1212 | |
| 1213 | RESERVE_SPACE(4+sizeof(arg->stateid.data)); |
| 1214 | WRITE32(OP_SETATTR); |
| 1215 | WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data)); |
| 1216 | |
| 1217 | if ((status = encode_attrs(xdr, arg->iap, server))) |
| 1218 | return status; |
| 1219 | |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
| 1223 | static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid) |
| 1224 | { |
| 1225 | uint32_t *p; |
| 1226 | |
| 1227 | RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data)); |
| 1228 | WRITE32(OP_SETCLIENTID); |
| 1229 | WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data)); |
| 1230 | |
| 1231 | encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); |
| 1232 | RESERVE_SPACE(4); |
| 1233 | WRITE32(setclientid->sc_prog); |
| 1234 | encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); |
| 1235 | encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); |
| 1236 | RESERVE_SPACE(4); |
| 1237 | WRITE32(setclientid->sc_cb_ident); |
| 1238 | |
| 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state) |
| 1243 | { |
| 1244 | uint32_t *p; |
| 1245 | |
| 1246 | RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data)); |
| 1247 | WRITE32(OP_SETCLIENTID_CONFIRM); |
| 1248 | WRITE64(client_state->cl_clientid); |
| 1249 | WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data)); |
| 1250 | |
| 1251 | return 0; |
| 1252 | } |
| 1253 | |
| 1254 | static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args) |
| 1255 | { |
| 1256 | uint32_t *p; |
| 1257 | |
| 1258 | RESERVE_SPACE(4); |
| 1259 | WRITE32(OP_WRITE); |
| 1260 | |
| 1261 | encode_stateid(xdr, args->context); |
| 1262 | |
| 1263 | RESERVE_SPACE(16); |
| 1264 | WRITE64(args->offset); |
| 1265 | WRITE32(args->stable); |
| 1266 | WRITE32(args->count); |
| 1267 | |
| 1268 | xdr_write_pages(xdr, args->pages, args->pgbase, args->count); |
| 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid) |
| 1274 | { |
| 1275 | uint32_t *p; |
| 1276 | |
| 1277 | RESERVE_SPACE(20); |
| 1278 | |
| 1279 | WRITE32(OP_DELEGRETURN); |
| 1280 | WRITEMEM(stateid->data, sizeof(stateid->data)); |
| 1281 | return 0; |
| 1282 | |
| 1283 | } |
| 1284 | /* |
| 1285 | * END OF "GENERIC" ENCODE ROUTINES. |
| 1286 | */ |
| 1287 | |
| 1288 | /* |
| 1289 | * Encode an ACCESS request |
| 1290 | */ |
| 1291 | static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args) |
| 1292 | { |
| 1293 | struct xdr_stream xdr; |
| 1294 | struct compound_hdr hdr = { |
| 1295 | .nops = 2, |
| 1296 | }; |
| 1297 | int status; |
| 1298 | |
| 1299 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1300 | encode_compound_hdr(&xdr, &hdr); |
| 1301 | if ((status = encode_putfh(&xdr, args->fh)) == 0) |
| 1302 | status = encode_access(&xdr, args->access); |
| 1303 | return status; |
| 1304 | } |
| 1305 | |
| 1306 | /* |
| 1307 | * Encode LOOKUP request |
| 1308 | */ |
| 1309 | static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args) |
| 1310 | { |
| 1311 | struct xdr_stream xdr; |
| 1312 | struct compound_hdr hdr = { |
| 1313 | .nops = 4, |
| 1314 | }; |
| 1315 | int status; |
| 1316 | |
| 1317 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1318 | encode_compound_hdr(&xdr, &hdr); |
| 1319 | if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) |
| 1320 | goto out; |
| 1321 | if ((status = encode_lookup(&xdr, args->name)) != 0) |
| 1322 | goto out; |
| 1323 | if ((status = encode_getfh(&xdr)) != 0) |
| 1324 | goto out; |
| 1325 | status = encode_getfattr(&xdr, args->bitmask); |
| 1326 | out: |
| 1327 | return status; |
| 1328 | } |
| 1329 | |
| 1330 | /* |
| 1331 | * Encode LOOKUP_ROOT request |
| 1332 | */ |
| 1333 | static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args) |
| 1334 | { |
| 1335 | struct xdr_stream xdr; |
| 1336 | struct compound_hdr hdr = { |
| 1337 | .nops = 3, |
| 1338 | }; |
| 1339 | int status; |
| 1340 | |
| 1341 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1342 | encode_compound_hdr(&xdr, &hdr); |
| 1343 | if ((status = encode_putrootfh(&xdr)) != 0) |
| 1344 | goto out; |
| 1345 | if ((status = encode_getfh(&xdr)) == 0) |
| 1346 | status = encode_getfattr(&xdr, args->bitmask); |
| 1347 | out: |
| 1348 | return status; |
| 1349 | } |
| 1350 | |
| 1351 | /* |
| 1352 | * Encode REMOVE request |
| 1353 | */ |
| 1354 | static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args) |
| 1355 | { |
| 1356 | struct xdr_stream xdr; |
| 1357 | struct compound_hdr hdr = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 1358 | .nops = 3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | }; |
| 1360 | int status; |
| 1361 | |
| 1362 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1363 | encode_compound_hdr(&xdr, &hdr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 1364 | if ((status = encode_putfh(&xdr, args->fh)) != 0) |
| 1365 | goto out; |
| 1366 | if ((status = encode_remove(&xdr, args->name)) != 0) |
| 1367 | goto out; |
| 1368 | status = encode_getfattr(&xdr, args->bitmask); |
| 1369 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | return status; |
| 1371 | } |
| 1372 | |
| 1373 | /* |
| 1374 | * Encode RENAME request |
| 1375 | */ |
| 1376 | static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args) |
| 1377 | { |
| 1378 | struct xdr_stream xdr; |
| 1379 | struct compound_hdr hdr = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 1380 | .nops = 7, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | }; |
| 1382 | int status; |
| 1383 | |
| 1384 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1385 | encode_compound_hdr(&xdr, &hdr); |
| 1386 | if ((status = encode_putfh(&xdr, args->old_dir)) != 0) |
| 1387 | goto out; |
| 1388 | if ((status = encode_savefh(&xdr)) != 0) |
| 1389 | goto out; |
| 1390 | if ((status = encode_putfh(&xdr, args->new_dir)) != 0) |
| 1391 | goto out; |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 1392 | if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0) |
| 1393 | goto out; |
| 1394 | if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) |
| 1395 | goto out; |
| 1396 | if ((status = encode_restorefh(&xdr)) != 0) |
| 1397 | goto out; |
| 1398 | status = encode_getfattr(&xdr, args->bitmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | out: |
| 1400 | return status; |
| 1401 | } |
| 1402 | |
| 1403 | /* |
| 1404 | * Encode LINK request |
| 1405 | */ |
| 1406 | static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args) |
| 1407 | { |
| 1408 | struct xdr_stream xdr; |
| 1409 | struct compound_hdr hdr = { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 1410 | .nops = 7, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | }; |
| 1412 | int status; |
| 1413 | |
| 1414 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1415 | encode_compound_hdr(&xdr, &hdr); |
| 1416 | if ((status = encode_putfh(&xdr, args->fh)) != 0) |
| 1417 | goto out; |
| 1418 | if ((status = encode_savefh(&xdr)) != 0) |
| 1419 | goto out; |
| 1420 | if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) |
| 1421 | goto out; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 1422 | if ((status = encode_link(&xdr, args->name)) != 0) |
| 1423 | goto out; |
| 1424 | if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) |
| 1425 | goto out; |
| 1426 | if ((status = encode_restorefh(&xdr)) != 0) |
| 1427 | goto out; |
| 1428 | status = encode_getfattr(&xdr, args->bitmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | out: |
| 1430 | return status; |
| 1431 | } |
| 1432 | |
| 1433 | /* |
| 1434 | * Encode CREATE request |
| 1435 | */ |
| 1436 | static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args) |
| 1437 | { |
| 1438 | struct xdr_stream xdr; |
| 1439 | struct compound_hdr hdr = { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1440 | .nops = 7, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | }; |
| 1442 | int status; |
| 1443 | |
| 1444 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1445 | encode_compound_hdr(&xdr, &hdr); |
| 1446 | if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) |
| 1447 | goto out; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1448 | if ((status = encode_savefh(&xdr)) != 0) |
| 1449 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | if ((status = encode_create(&xdr, args)) != 0) |
| 1451 | goto out; |
| 1452 | if ((status = encode_getfh(&xdr)) != 0) |
| 1453 | goto out; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1454 | if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) |
| 1455 | goto out; |
| 1456 | if ((status = encode_restorefh(&xdr)) != 0) |
| 1457 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | status = encode_getfattr(&xdr, args->bitmask); |
| 1459 | out: |
| 1460 | return status; |
| 1461 | } |
| 1462 | |
| 1463 | /* |
| 1464 | * Encode SYMLINK request |
| 1465 | */ |
| 1466 | static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args) |
| 1467 | { |
| 1468 | return nfs4_xdr_enc_create(req, p, args); |
| 1469 | } |
| 1470 | |
| 1471 | /* |
| 1472 | * Encode GETATTR request |
| 1473 | */ |
| 1474 | static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args) |
| 1475 | { |
| 1476 | struct xdr_stream xdr; |
| 1477 | struct compound_hdr hdr = { |
| 1478 | .nops = 2, |
| 1479 | }; |
| 1480 | int status; |
| 1481 | |
| 1482 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1483 | encode_compound_hdr(&xdr, &hdr); |
| 1484 | if ((status = encode_putfh(&xdr, args->fh)) == 0) |
| 1485 | status = encode_getfattr(&xdr, args->bitmask); |
| 1486 | return status; |
| 1487 | } |
| 1488 | |
| 1489 | /* |
| 1490 | * Encode a CLOSE request |
| 1491 | */ |
| 1492 | static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args) |
| 1493 | { |
| 1494 | struct xdr_stream xdr; |
| 1495 | struct compound_hdr hdr = { |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1496 | .nops = 3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | }; |
| 1498 | int status; |
| 1499 | |
| 1500 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1501 | encode_compound_hdr(&xdr, &hdr); |
| 1502 | status = encode_putfh(&xdr, args->fh); |
| 1503 | if(status) |
| 1504 | goto out; |
| 1505 | status = encode_close(&xdr, args); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1506 | if (status != 0) |
| 1507 | goto out; |
| 1508 | status = encode_getfattr(&xdr, args->bitmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | out: |
| 1510 | return status; |
| 1511 | } |
| 1512 | |
| 1513 | /* |
| 1514 | * Encode an OPEN request |
| 1515 | */ |
| 1516 | static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args) |
| 1517 | { |
| 1518 | struct xdr_stream xdr; |
| 1519 | struct compound_hdr hdr = { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1520 | .nops = 7, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | }; |
| 1522 | int status; |
| 1523 | |
| 1524 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1525 | encode_compound_hdr(&xdr, &hdr); |
| 1526 | status = encode_putfh(&xdr, args->fh); |
| 1527 | if (status) |
| 1528 | goto out; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1529 | status = encode_savefh(&xdr); |
| 1530 | if (status) |
| 1531 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | status = encode_open(&xdr, args); |
| 1533 | if (status) |
| 1534 | goto out; |
| 1535 | status = encode_getfh(&xdr); |
| 1536 | if (status) |
| 1537 | goto out; |
| 1538 | status = encode_getfattr(&xdr, args->bitmask); |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1539 | if (status) |
| 1540 | goto out; |
| 1541 | status = encode_restorefh(&xdr); |
| 1542 | if (status) |
| 1543 | goto out; |
| 1544 | status = encode_getfattr(&xdr, args->bitmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | out: |
| 1546 | return status; |
| 1547 | } |
| 1548 | |
| 1549 | /* |
| 1550 | * Encode an OPEN_CONFIRM request |
| 1551 | */ |
| 1552 | static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args) |
| 1553 | { |
| 1554 | struct xdr_stream xdr; |
| 1555 | struct compound_hdr hdr = { |
| 1556 | .nops = 2, |
| 1557 | }; |
| 1558 | int status; |
| 1559 | |
| 1560 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1561 | encode_compound_hdr(&xdr, &hdr); |
| 1562 | status = encode_putfh(&xdr, args->fh); |
| 1563 | if(status) |
| 1564 | goto out; |
| 1565 | status = encode_open_confirm(&xdr, args); |
| 1566 | out: |
| 1567 | return status; |
| 1568 | } |
| 1569 | |
| 1570 | /* |
| 1571 | * Encode an OPEN request with no attributes. |
| 1572 | */ |
| 1573 | static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args) |
| 1574 | { |
| 1575 | struct xdr_stream xdr; |
| 1576 | struct compound_hdr hdr = { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1577 | .nops = 3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | }; |
| 1579 | int status; |
| 1580 | |
| 1581 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1582 | encode_compound_hdr(&xdr, &hdr); |
| 1583 | status = encode_putfh(&xdr, args->fh); |
| 1584 | if (status) |
| 1585 | goto out; |
| 1586 | status = encode_open(&xdr, args); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1587 | if (status) |
| 1588 | goto out; |
| 1589 | status = encode_getfattr(&xdr, args->bitmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | out: |
| 1591 | return status; |
| 1592 | } |
| 1593 | |
| 1594 | /* |
| 1595 | * Encode an OPEN_DOWNGRADE request |
| 1596 | */ |
| 1597 | static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args) |
| 1598 | { |
| 1599 | struct xdr_stream xdr; |
| 1600 | struct compound_hdr hdr = { |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1601 | .nops = 3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | }; |
| 1603 | int status; |
| 1604 | |
| 1605 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1606 | encode_compound_hdr(&xdr, &hdr); |
| 1607 | status = encode_putfh(&xdr, args->fh); |
| 1608 | if (status) |
| 1609 | goto out; |
| 1610 | status = encode_open_downgrade(&xdr, args); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1611 | if (status != 0) |
| 1612 | goto out; |
| 1613 | status = encode_getfattr(&xdr, args->bitmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | out: |
| 1615 | return status; |
| 1616 | } |
| 1617 | |
| 1618 | /* |
| 1619 | * Encode a LOCK request |
| 1620 | */ |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1621 | static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lock_args *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | { |
| 1623 | struct xdr_stream xdr; |
| 1624 | struct compound_hdr hdr = { |
| 1625 | .nops = 2, |
| 1626 | }; |
| 1627 | int status; |
| 1628 | |
| 1629 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1630 | encode_compound_hdr(&xdr, &hdr); |
| 1631 | status = encode_putfh(&xdr, args->fh); |
| 1632 | if(status) |
| 1633 | goto out; |
| 1634 | status = encode_lock(&xdr, args); |
| 1635 | out: |
| 1636 | return status; |
| 1637 | } |
| 1638 | |
| 1639 | /* |
| 1640 | * Encode a LOCKT request |
| 1641 | */ |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1642 | static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockt_args *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | { |
| 1644 | struct xdr_stream xdr; |
| 1645 | struct compound_hdr hdr = { |
| 1646 | .nops = 2, |
| 1647 | }; |
| 1648 | int status; |
| 1649 | |
| 1650 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1651 | encode_compound_hdr(&xdr, &hdr); |
| 1652 | status = encode_putfh(&xdr, args->fh); |
| 1653 | if(status) |
| 1654 | goto out; |
| 1655 | status = encode_lockt(&xdr, args); |
| 1656 | out: |
| 1657 | return status; |
| 1658 | } |
| 1659 | |
| 1660 | /* |
| 1661 | * Encode a LOCKU request |
| 1662 | */ |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 1663 | static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_locku_args *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | { |
| 1665 | struct xdr_stream xdr; |
| 1666 | struct compound_hdr hdr = { |
| 1667 | .nops = 2, |
| 1668 | }; |
| 1669 | int status; |
| 1670 | |
| 1671 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1672 | encode_compound_hdr(&xdr, &hdr); |
| 1673 | status = encode_putfh(&xdr, args->fh); |
| 1674 | if(status) |
| 1675 | goto out; |
| 1676 | status = encode_locku(&xdr, args); |
| 1677 | out: |
| 1678 | return status; |
| 1679 | } |
| 1680 | |
| 1681 | /* |
| 1682 | * Encode a READLINK request |
| 1683 | */ |
| 1684 | static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args) |
| 1685 | { |
| 1686 | struct xdr_stream xdr; |
| 1687 | struct compound_hdr hdr = { |
| 1688 | .nops = 2, |
| 1689 | }; |
| 1690 | int status; |
| 1691 | |
| 1692 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1693 | encode_compound_hdr(&xdr, &hdr); |
| 1694 | status = encode_putfh(&xdr, args->fh); |
| 1695 | if(status) |
| 1696 | goto out; |
| 1697 | status = encode_readlink(&xdr, args, req); |
| 1698 | out: |
| 1699 | return status; |
| 1700 | } |
| 1701 | |
| 1702 | /* |
| 1703 | * Encode a READDIR request |
| 1704 | */ |
| 1705 | static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args) |
| 1706 | { |
| 1707 | struct xdr_stream xdr; |
| 1708 | struct compound_hdr hdr = { |
| 1709 | .nops = 2, |
| 1710 | }; |
| 1711 | int status; |
| 1712 | |
| 1713 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1714 | encode_compound_hdr(&xdr, &hdr); |
| 1715 | status = encode_putfh(&xdr, args->fh); |
| 1716 | if(status) |
| 1717 | goto out; |
| 1718 | status = encode_readdir(&xdr, args, req); |
| 1719 | out: |
| 1720 | return status; |
| 1721 | } |
| 1722 | |
| 1723 | /* |
| 1724 | * Encode a READ request |
| 1725 | */ |
| 1726 | static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args) |
| 1727 | { |
| 1728 | struct rpc_auth *auth = req->rq_task->tk_auth; |
| 1729 | struct xdr_stream xdr; |
| 1730 | struct compound_hdr hdr = { |
| 1731 | .nops = 2, |
| 1732 | }; |
| 1733 | int replen, status; |
| 1734 | |
| 1735 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1736 | encode_compound_hdr(&xdr, &hdr); |
| 1737 | status = encode_putfh(&xdr, args->fh); |
| 1738 | if (status) |
| 1739 | goto out; |
| 1740 | status = encode_read(&xdr, args); |
| 1741 | if (status) |
| 1742 | goto out; |
| 1743 | |
| 1744 | /* set up reply kvec |
| 1745 | * toplevel status + taglen=0 + rescount + OP_PUTFH + status |
| 1746 | * + OP_READ + status + eof + datalen = 9 |
| 1747 | */ |
| 1748 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2; |
| 1749 | xdr_inline_pages(&req->rq_rcv_buf, replen, |
| 1750 | args->pages, args->pgbase, args->count); |
| 1751 | out: |
| 1752 | return status; |
| 1753 | } |
| 1754 | |
| 1755 | /* |
| 1756 | * Encode an SETATTR request |
| 1757 | */ |
| 1758 | static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args) |
| 1759 | |
| 1760 | { |
| 1761 | struct xdr_stream xdr; |
| 1762 | struct compound_hdr hdr = { |
| 1763 | .nops = 3, |
| 1764 | }; |
| 1765 | int status; |
| 1766 | |
| 1767 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1768 | encode_compound_hdr(&xdr, &hdr); |
| 1769 | status = encode_putfh(&xdr, args->fh); |
| 1770 | if(status) |
| 1771 | goto out; |
| 1772 | status = encode_setattr(&xdr, args, args->server); |
| 1773 | if(status) |
| 1774 | goto out; |
| 1775 | status = encode_getfattr(&xdr, args->bitmask); |
| 1776 | out: |
| 1777 | return status; |
| 1778 | } |
| 1779 | |
| 1780 | /* |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 1781 | * Encode a GETACL request |
| 1782 | */ |
| 1783 | static int |
| 1784 | nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p, |
| 1785 | struct nfs_getaclargs *args) |
| 1786 | { |
| 1787 | struct xdr_stream xdr; |
| 1788 | struct rpc_auth *auth = req->rq_task->tk_auth; |
| 1789 | struct compound_hdr hdr = { |
| 1790 | .nops = 2, |
| 1791 | }; |
| 1792 | int replen, status; |
| 1793 | |
| 1794 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1795 | encode_compound_hdr(&xdr, &hdr); |
| 1796 | status = encode_putfh(&xdr, args->fh); |
| 1797 | if (status) |
| 1798 | goto out; |
| 1799 | status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0); |
| 1800 | /* set up reply buffer: */ |
| 1801 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2; |
| 1802 | xdr_inline_pages(&req->rq_rcv_buf, replen, |
| 1803 | args->acl_pages, args->acl_pgbase, args->acl_len); |
| 1804 | out: |
| 1805 | return status; |
| 1806 | } |
| 1807 | |
| 1808 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | * Encode a WRITE request |
| 1810 | */ |
| 1811 | static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args) |
| 1812 | { |
| 1813 | struct xdr_stream xdr; |
| 1814 | struct compound_hdr hdr = { |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 1815 | .nops = 3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | }; |
| 1817 | int status; |
| 1818 | |
| 1819 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1820 | encode_compound_hdr(&xdr, &hdr); |
| 1821 | status = encode_putfh(&xdr, args->fh); |
| 1822 | if (status) |
| 1823 | goto out; |
| 1824 | status = encode_write(&xdr, args); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 1825 | if (status) |
| 1826 | goto out; |
| 1827 | status = encode_getfattr(&xdr, args->bitmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | out: |
| 1829 | return status; |
| 1830 | } |
| 1831 | |
| 1832 | /* |
| 1833 | * a COMMIT request |
| 1834 | */ |
| 1835 | static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args) |
| 1836 | { |
| 1837 | struct xdr_stream xdr; |
| 1838 | struct compound_hdr hdr = { |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 1839 | .nops = 3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | }; |
| 1841 | int status; |
| 1842 | |
| 1843 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1844 | encode_compound_hdr(&xdr, &hdr); |
| 1845 | status = encode_putfh(&xdr, args->fh); |
| 1846 | if (status) |
| 1847 | goto out; |
| 1848 | status = encode_commit(&xdr, args); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 1849 | if (status) |
| 1850 | goto out; |
| 1851 | status = encode_getfattr(&xdr, args->bitmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | out: |
| 1853 | return status; |
| 1854 | } |
| 1855 | |
| 1856 | /* |
| 1857 | * FSINFO request |
| 1858 | */ |
| 1859 | static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args) |
| 1860 | { |
| 1861 | struct xdr_stream xdr; |
| 1862 | struct compound_hdr hdr = { |
| 1863 | .nops = 2, |
| 1864 | }; |
| 1865 | int status; |
| 1866 | |
| 1867 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1868 | encode_compound_hdr(&xdr, &hdr); |
| 1869 | status = encode_putfh(&xdr, args->fh); |
| 1870 | if (!status) |
| 1871 | status = encode_fsinfo(&xdr, args->bitmask); |
| 1872 | return status; |
| 1873 | } |
| 1874 | |
| 1875 | /* |
| 1876 | * a PATHCONF request |
| 1877 | */ |
| 1878 | static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args) |
| 1879 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | struct xdr_stream xdr; |
| 1881 | struct compound_hdr hdr = { |
| 1882 | .nops = 2, |
| 1883 | }; |
| 1884 | int status; |
| 1885 | |
| 1886 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1887 | encode_compound_hdr(&xdr, &hdr); |
| 1888 | status = encode_putfh(&xdr, args->fh); |
| 1889 | if (!status) |
| 1890 | status = encode_getattr_one(&xdr, |
| 1891 | args->bitmask[0] & nfs4_pathconf_bitmap[0]); |
| 1892 | return status; |
| 1893 | } |
| 1894 | |
| 1895 | /* |
| 1896 | * a STATFS request |
| 1897 | */ |
| 1898 | static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args) |
| 1899 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | struct xdr_stream xdr; |
| 1901 | struct compound_hdr hdr = { |
| 1902 | .nops = 2, |
| 1903 | }; |
| 1904 | int status; |
| 1905 | |
| 1906 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1907 | encode_compound_hdr(&xdr, &hdr); |
| 1908 | status = encode_putfh(&xdr, args->fh); |
| 1909 | if (status == 0) |
| 1910 | status = encode_getattr_two(&xdr, |
| 1911 | args->bitmask[0] & nfs4_statfs_bitmap[0], |
| 1912 | args->bitmask[1] & nfs4_statfs_bitmap[1]); |
| 1913 | return status; |
| 1914 | } |
| 1915 | |
| 1916 | /* |
| 1917 | * GETATTR_BITMAP request |
| 1918 | */ |
| 1919 | static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle) |
| 1920 | { |
| 1921 | struct xdr_stream xdr; |
| 1922 | struct compound_hdr hdr = { |
| 1923 | .nops = 2, |
| 1924 | }; |
| 1925 | int status; |
| 1926 | |
| 1927 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1928 | encode_compound_hdr(&xdr, &hdr); |
| 1929 | status = encode_putfh(&xdr, fhandle); |
| 1930 | if (status == 0) |
| 1931 | status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS| |
| 1932 | FATTR4_WORD0_LINK_SUPPORT| |
| 1933 | FATTR4_WORD0_SYMLINK_SUPPORT| |
| 1934 | FATTR4_WORD0_ACLSUPPORT); |
| 1935 | return status; |
| 1936 | } |
| 1937 | |
| 1938 | /* |
| 1939 | * a RENEW request |
| 1940 | */ |
| 1941 | static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp) |
| 1942 | { |
| 1943 | struct xdr_stream xdr; |
| 1944 | struct compound_hdr hdr = { |
| 1945 | .nops = 1, |
| 1946 | }; |
| 1947 | |
| 1948 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1949 | encode_compound_hdr(&xdr, &hdr); |
| 1950 | return encode_renew(&xdr, clp); |
| 1951 | } |
| 1952 | |
| 1953 | /* |
| 1954 | * a SETCLIENTID request |
| 1955 | */ |
| 1956 | static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc) |
| 1957 | { |
| 1958 | struct xdr_stream xdr; |
| 1959 | struct compound_hdr hdr = { |
| 1960 | .nops = 1, |
| 1961 | }; |
| 1962 | |
| 1963 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1964 | encode_compound_hdr(&xdr, &hdr); |
| 1965 | return encode_setclientid(&xdr, sc); |
| 1966 | } |
| 1967 | |
| 1968 | /* |
| 1969 | * a SETCLIENTID_CONFIRM request |
| 1970 | */ |
| 1971 | static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp) |
| 1972 | { |
| 1973 | struct xdr_stream xdr; |
| 1974 | struct compound_hdr hdr = { |
| 1975 | .nops = 3, |
| 1976 | }; |
| 1977 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; |
| 1978 | int status; |
| 1979 | |
| 1980 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 1981 | encode_compound_hdr(&xdr, &hdr); |
| 1982 | status = encode_setclientid_confirm(&xdr, clp); |
| 1983 | if (!status) |
| 1984 | status = encode_putrootfh(&xdr); |
| 1985 | if (!status) |
| 1986 | status = encode_fsinfo(&xdr, lease_bitmap); |
| 1987 | return status; |
| 1988 | } |
| 1989 | |
| 1990 | /* |
| 1991 | * DELEGRETURN request |
| 1992 | */ |
| 1993 | static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args) |
| 1994 | { |
| 1995 | struct xdr_stream xdr; |
| 1996 | struct compound_hdr hdr = { |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 1997 | .nops = 3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | }; |
| 1999 | int status; |
| 2000 | |
| 2001 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 2002 | encode_compound_hdr(&xdr, &hdr); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 2003 | status = encode_putfh(&xdr, args->fhandle); |
| 2004 | if (status != 0) |
| 2005 | goto out; |
| 2006 | status = encode_delegreturn(&xdr, args->stateid); |
| 2007 | if (status != 0) |
| 2008 | goto out; |
| 2009 | status = encode_getfattr(&xdr, args->bitmask); |
| 2010 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | return status; |
| 2012 | } |
| 2013 | |
| 2014 | /* |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2015 | * Encode FS_LOCATIONS request |
| 2016 | */ |
| 2017 | static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, uint32_t *p, struct nfs4_fs_locations_arg *args) |
| 2018 | { |
| 2019 | struct xdr_stream xdr; |
| 2020 | struct compound_hdr hdr = { |
| 2021 | .nops = 3, |
| 2022 | }; |
| 2023 | struct rpc_auth *auth = req->rq_task->tk_auth; |
| 2024 | int replen; |
| 2025 | int status; |
| 2026 | |
| 2027 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 2028 | encode_compound_hdr(&xdr, &hdr); |
| 2029 | if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) |
| 2030 | goto out; |
| 2031 | if ((status = encode_lookup(&xdr, args->name)) != 0) |
| 2032 | goto out; |
| 2033 | if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) |
| 2034 | goto out; |
| 2035 | /* set up reply |
| 2036 | * toplevel_status + taglen + rescount + OP_PUTFH + status |
| 2037 | * + OP_LOOKUP + status + OP_GETATTR + status = 7 |
| 2038 | */ |
| 2039 | replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2; |
| 2040 | xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page, |
| 2041 | 0, PAGE_SIZE); |
| 2042 | out: |
| 2043 | return status; |
| 2044 | } |
| 2045 | |
| 2046 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | * START OF "GENERIC" DECODE ROUTINES. |
| 2048 | * These may look a little ugly since they are imported from a "generic" |
| 2049 | * set of XDR encode/decode routines which are intended to be shared by |
| 2050 | * all of our NFSv4 implementations (OpenBSD, MacOS X...). |
| 2051 | * |
| 2052 | * If the pain of reading these is too great, it should be a straightforward |
| 2053 | * task to translate them into Linux-specific versions which are more |
| 2054 | * consistent with the style used in NFSv2/v3... |
| 2055 | */ |
| 2056 | #define READ32(x) (x) = ntohl(*p++) |
| 2057 | #define READ64(x) do { \ |
| 2058 | (x) = (u64)ntohl(*p++) << 32; \ |
| 2059 | (x) |= ntohl(*p++); \ |
| 2060 | } while (0) |
| 2061 | #define READTIME(x) do { \ |
| 2062 | p++; \ |
| 2063 | (x.tv_sec) = ntohl(*p++); \ |
| 2064 | (x.tv_nsec) = ntohl(*p++); \ |
| 2065 | } while (0) |
| 2066 | #define COPYMEM(x,nbytes) do { \ |
| 2067 | memcpy((x), p, nbytes); \ |
| 2068 | p += XDR_QUADLEN(nbytes); \ |
| 2069 | } while (0) |
| 2070 | |
| 2071 | #define READ_BUF(nbytes) do { \ |
| 2072 | p = xdr_inline_decode(xdr, nbytes); \ |
| 2073 | if (!p) { \ |
| 2074 | printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \ |
| 2075 | __FUNCTION__, __LINE__); \ |
| 2076 | return -EIO; \ |
| 2077 | } \ |
| 2078 | } while (0) |
| 2079 | |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2080 | 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] | 2081 | { |
| 2082 | uint32_t *p; |
| 2083 | |
| 2084 | READ_BUF(4); |
| 2085 | READ32(*len); |
| 2086 | READ_BUF(*len); |
| 2087 | *string = (char *)p; |
| 2088 | return 0; |
| 2089 | } |
| 2090 | |
| 2091 | static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) |
| 2092 | { |
| 2093 | uint32_t *p; |
| 2094 | |
| 2095 | READ_BUF(8); |
| 2096 | READ32(hdr->status); |
| 2097 | READ32(hdr->taglen); |
| 2098 | |
| 2099 | READ_BUF(hdr->taglen + 4); |
| 2100 | hdr->tag = (char *)p; |
| 2101 | p += XDR_QUADLEN(hdr->taglen); |
| 2102 | READ32(hdr->nops); |
| 2103 | return 0; |
| 2104 | } |
| 2105 | |
| 2106 | static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) |
| 2107 | { |
| 2108 | uint32_t *p; |
| 2109 | uint32_t opnum; |
| 2110 | int32_t nfserr; |
| 2111 | |
| 2112 | READ_BUF(8); |
| 2113 | READ32(opnum); |
| 2114 | if (opnum != expected) { |
| 2115 | printk(KERN_NOTICE |
| 2116 | "nfs4_decode_op_hdr: Server returned operation" |
| 2117 | " %d but we issued a request for %d\n", |
| 2118 | opnum, expected); |
| 2119 | return -EIO; |
| 2120 | } |
| 2121 | READ32(nfserr); |
| 2122 | if (nfserr != NFS_OK) |
| 2123 | return -nfs_stat_to_errno(nfserr); |
| 2124 | return 0; |
| 2125 | } |
| 2126 | |
| 2127 | /* Dummy routine */ |
| 2128 | static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp) |
| 2129 | { |
| 2130 | uint32_t *p; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2131 | unsigned int strlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | char *str; |
| 2133 | |
| 2134 | READ_BUF(12); |
| 2135 | return decode_opaque_inline(xdr, &strlen, &str); |
| 2136 | } |
| 2137 | |
| 2138 | static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) |
| 2139 | { |
| 2140 | uint32_t bmlen, *p; |
| 2141 | |
| 2142 | READ_BUF(4); |
| 2143 | READ32(bmlen); |
| 2144 | |
| 2145 | bitmap[0] = bitmap[1] = 0; |
| 2146 | READ_BUF((bmlen << 2)); |
| 2147 | if (bmlen > 0) { |
| 2148 | READ32(bitmap[0]); |
| 2149 | if (bmlen > 1) |
| 2150 | READ32(bitmap[1]); |
| 2151 | } |
| 2152 | return 0; |
| 2153 | } |
| 2154 | |
| 2155 | static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep) |
| 2156 | { |
| 2157 | uint32_t *p; |
| 2158 | |
| 2159 | READ_BUF(4); |
| 2160 | READ32(*attrlen); |
| 2161 | *savep = xdr->p; |
| 2162 | return 0; |
| 2163 | } |
| 2164 | |
| 2165 | static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) |
| 2166 | { |
| 2167 | if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { |
| 2168 | decode_attr_bitmap(xdr, bitmask); |
| 2169 | bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; |
| 2170 | } else |
| 2171 | bitmask[0] = bitmask[1] = 0; |
| 2172 | dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]); |
| 2173 | return 0; |
| 2174 | } |
| 2175 | |
| 2176 | static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) |
| 2177 | { |
| 2178 | uint32_t *p; |
| 2179 | |
| 2180 | *type = 0; |
| 2181 | if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) |
| 2182 | return -EIO; |
| 2183 | if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { |
| 2184 | READ_BUF(4); |
| 2185 | READ32(*type); |
| 2186 | if (*type < NF4REG || *type > NF4NAMEDATTR) { |
| 2187 | dprintk("%s: bad type %d\n", __FUNCTION__, *type); |
| 2188 | return -EIO; |
| 2189 | } |
| 2190 | bitmap[0] &= ~FATTR4_WORD0_TYPE; |
| 2191 | } |
| 2192 | dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type); |
| 2193 | return 0; |
| 2194 | } |
| 2195 | |
| 2196 | static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) |
| 2197 | { |
| 2198 | uint32_t *p; |
| 2199 | |
| 2200 | *change = 0; |
| 2201 | if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) |
| 2202 | return -EIO; |
| 2203 | if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { |
| 2204 | READ_BUF(8); |
| 2205 | READ64(*change); |
| 2206 | bitmap[0] &= ~FATTR4_WORD0_CHANGE; |
| 2207 | } |
| 2208 | dprintk("%s: change attribute=%Lu\n", __FUNCTION__, |
| 2209 | (unsigned long long)*change); |
| 2210 | return 0; |
| 2211 | } |
| 2212 | |
| 2213 | static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) |
| 2214 | { |
| 2215 | uint32_t *p; |
| 2216 | |
| 2217 | *size = 0; |
| 2218 | if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) |
| 2219 | return -EIO; |
| 2220 | if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { |
| 2221 | READ_BUF(8); |
| 2222 | READ64(*size); |
| 2223 | bitmap[0] &= ~FATTR4_WORD0_SIZE; |
| 2224 | } |
| 2225 | dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size); |
| 2226 | return 0; |
| 2227 | } |
| 2228 | |
| 2229 | static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2230 | { |
| 2231 | uint32_t *p; |
| 2232 | |
| 2233 | *res = 0; |
| 2234 | if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) |
| 2235 | return -EIO; |
| 2236 | if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { |
| 2237 | READ_BUF(4); |
| 2238 | READ32(*res); |
| 2239 | bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; |
| 2240 | } |
| 2241 | dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true"); |
| 2242 | return 0; |
| 2243 | } |
| 2244 | |
| 2245 | static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2246 | { |
| 2247 | uint32_t *p; |
| 2248 | |
| 2249 | *res = 0; |
| 2250 | if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) |
| 2251 | return -EIO; |
| 2252 | if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { |
| 2253 | READ_BUF(4); |
| 2254 | READ32(*res); |
| 2255 | bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; |
| 2256 | } |
| 2257 | dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true"); |
| 2258 | return 0; |
| 2259 | } |
| 2260 | |
Trond Myklebust | 8b4bdcf | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2261 | 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] | 2262 | { |
| 2263 | uint32_t *p; |
| 2264 | |
| 2265 | fsid->major = 0; |
| 2266 | fsid->minor = 0; |
| 2267 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) |
| 2268 | return -EIO; |
| 2269 | if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { |
| 2270 | READ_BUF(16); |
| 2271 | READ64(fsid->major); |
| 2272 | READ64(fsid->minor); |
| 2273 | bitmap[0] &= ~FATTR4_WORD0_FSID; |
| 2274 | } |
| 2275 | dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__, |
| 2276 | (unsigned long long)fsid->major, |
| 2277 | (unsigned long long)fsid->minor); |
| 2278 | return 0; |
| 2279 | } |
| 2280 | |
| 2281 | static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2282 | { |
| 2283 | uint32_t *p; |
| 2284 | |
| 2285 | *res = 60; |
| 2286 | if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) |
| 2287 | return -EIO; |
| 2288 | if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { |
| 2289 | READ_BUF(4); |
| 2290 | READ32(*res); |
| 2291 | bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; |
| 2292 | } |
| 2293 | dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res); |
| 2294 | return 0; |
| 2295 | } |
| 2296 | |
| 2297 | static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2298 | { |
| 2299 | uint32_t *p; |
| 2300 | |
| 2301 | *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; |
| 2302 | if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) |
| 2303 | return -EIO; |
| 2304 | if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { |
| 2305 | READ_BUF(4); |
| 2306 | READ32(*res); |
| 2307 | bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; |
| 2308 | } |
| 2309 | dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res); |
| 2310 | return 0; |
| 2311 | } |
| 2312 | |
| 2313 | static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) |
| 2314 | { |
| 2315 | uint32_t *p; |
| 2316 | |
| 2317 | *fileid = 0; |
| 2318 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) |
| 2319 | return -EIO; |
| 2320 | if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { |
| 2321 | READ_BUF(8); |
| 2322 | READ64(*fileid); |
| 2323 | bitmap[0] &= ~FATTR4_WORD0_FILEID; |
| 2324 | } |
| 2325 | dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid); |
| 2326 | return 0; |
| 2327 | } |
| 2328 | |
| 2329 | static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2330 | { |
| 2331 | uint32_t *p; |
| 2332 | int status = 0; |
| 2333 | |
| 2334 | *res = 0; |
| 2335 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) |
| 2336 | return -EIO; |
| 2337 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { |
| 2338 | READ_BUF(8); |
| 2339 | READ64(*res); |
| 2340 | bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; |
| 2341 | } |
| 2342 | dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res); |
| 2343 | return status; |
| 2344 | } |
| 2345 | |
| 2346 | static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2347 | { |
| 2348 | uint32_t *p; |
| 2349 | int status = 0; |
| 2350 | |
| 2351 | *res = 0; |
| 2352 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) |
| 2353 | return -EIO; |
| 2354 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { |
| 2355 | READ_BUF(8); |
| 2356 | READ64(*res); |
| 2357 | bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; |
| 2358 | } |
| 2359 | dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res); |
| 2360 | return status; |
| 2361 | } |
| 2362 | |
| 2363 | static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2364 | { |
| 2365 | uint32_t *p; |
| 2366 | int status = 0; |
| 2367 | |
| 2368 | *res = 0; |
| 2369 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) |
| 2370 | return -EIO; |
| 2371 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { |
| 2372 | READ_BUF(8); |
| 2373 | READ64(*res); |
| 2374 | bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; |
| 2375 | } |
| 2376 | dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res); |
| 2377 | return status; |
| 2378 | } |
| 2379 | |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame^] | 2380 | static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) |
| 2381 | { |
| 2382 | int n; |
| 2383 | uint32_t *p; |
| 2384 | int status = 0; |
| 2385 | |
| 2386 | READ_BUF(4); |
| 2387 | READ32(n); |
| 2388 | if (n <= 0) |
| 2389 | goto out_eio; |
| 2390 | dprintk("path "); |
| 2391 | path->ncomponents = 0; |
| 2392 | while (path->ncomponents < n) { |
| 2393 | struct nfs4_string *component = &path->components[path->ncomponents]; |
| 2394 | status = decode_opaque_inline(xdr, &component->len, &component->data); |
| 2395 | if (unlikely(status != 0)) |
| 2396 | goto out_eio; |
| 2397 | if (path->ncomponents != n) |
| 2398 | dprintk("/"); |
| 2399 | dprintk("%s", component->data); |
| 2400 | if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) |
| 2401 | path->ncomponents++; |
| 2402 | else { |
| 2403 | dprintk("cannot parse %d components in path\n", n); |
| 2404 | goto out_eio; |
| 2405 | } |
| 2406 | } |
| 2407 | out: |
| 2408 | dprintk("\n"); |
| 2409 | return status; |
| 2410 | out_eio: |
| 2411 | dprintk(" status %d", status); |
| 2412 | status = -EIO; |
| 2413 | goto out; |
| 2414 | } |
| 2415 | |
| 2416 | 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] | 2417 | { |
| 2418 | int n; |
| 2419 | uint32_t *p; |
| 2420 | int status = -EIO; |
| 2421 | |
| 2422 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) |
| 2423 | goto out; |
| 2424 | status = 0; |
| 2425 | if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) |
| 2426 | goto out; |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame^] | 2427 | dprintk("%s: fsroot ", __FUNCTION__); |
| 2428 | status = decode_pathname(xdr, &res->fs_path); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2429 | if (unlikely(status != 0)) |
| 2430 | goto out; |
| 2431 | READ_BUF(4); |
| 2432 | READ32(n); |
| 2433 | if (n <= 0) |
| 2434 | goto out_eio; |
| 2435 | res->nlocations = 0; |
| 2436 | while (res->nlocations < n) { |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame^] | 2437 | int m; |
| 2438 | struct nfs4_fs_location *loc = &res->locations[res->nlocations]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2439 | |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame^] | 2440 | READ_BUF(4); |
| 2441 | READ32(m); |
| 2442 | if (m <= 0) |
| 2443 | goto out_eio; |
| 2444 | |
| 2445 | loc->nservers = 0; |
| 2446 | dprintk("%s: servers ", __FUNCTION__); |
| 2447 | while (loc->nservers < m) { |
| 2448 | struct nfs4_string *server = &loc->servers[loc->nservers]; |
| 2449 | status = decode_opaque_inline(xdr, &server->len, &server->data); |
| 2450 | if (unlikely(status != 0)) |
| 2451 | goto out_eio; |
| 2452 | dprintk("%s ", server->data); |
| 2453 | if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) |
| 2454 | loc->nservers++; |
| 2455 | else { |
| 2456 | int i; |
| 2457 | dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations); |
| 2458 | for (i = loc->nservers; i < m; i++) { |
| 2459 | int len; |
| 2460 | char *data; |
| 2461 | status = decode_opaque_inline(xdr, &len, &data); |
| 2462 | if (unlikely(status != 0)) |
| 2463 | goto out_eio; |
| 2464 | } |
| 2465 | } |
| 2466 | } |
| 2467 | status = decode_pathname(xdr, &loc->rootpath); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2468 | if (unlikely(status != 0)) |
| 2469 | goto out_eio; |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame^] | 2470 | if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 2471 | res->nlocations++; |
| 2472 | } |
| 2473 | out: |
| 2474 | dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status); |
| 2475 | return status; |
| 2476 | out_eio: |
| 2477 | status = -EIO; |
| 2478 | goto out; |
| 2479 | } |
| 2480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2482 | { |
| 2483 | uint32_t *p; |
| 2484 | int status = 0; |
| 2485 | |
| 2486 | *res = 0; |
| 2487 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) |
| 2488 | return -EIO; |
| 2489 | if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { |
| 2490 | READ_BUF(8); |
| 2491 | READ64(*res); |
| 2492 | bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; |
| 2493 | } |
| 2494 | dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res); |
| 2495 | return status; |
| 2496 | } |
| 2497 | |
| 2498 | static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) |
| 2499 | { |
| 2500 | uint32_t *p; |
| 2501 | int status = 0; |
| 2502 | |
| 2503 | *maxlink = 1; |
| 2504 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) |
| 2505 | return -EIO; |
| 2506 | if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { |
| 2507 | READ_BUF(4); |
| 2508 | READ32(*maxlink); |
| 2509 | bitmap[0] &= ~FATTR4_WORD0_MAXLINK; |
| 2510 | } |
| 2511 | dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink); |
| 2512 | return status; |
| 2513 | } |
| 2514 | |
| 2515 | static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) |
| 2516 | { |
| 2517 | uint32_t *p; |
| 2518 | int status = 0; |
| 2519 | |
| 2520 | *maxname = 1024; |
| 2521 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) |
| 2522 | return -EIO; |
| 2523 | if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { |
| 2524 | READ_BUF(4); |
| 2525 | READ32(*maxname); |
| 2526 | bitmap[0] &= ~FATTR4_WORD0_MAXNAME; |
| 2527 | } |
| 2528 | dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname); |
| 2529 | return status; |
| 2530 | } |
| 2531 | |
| 2532 | static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2533 | { |
| 2534 | uint32_t *p; |
| 2535 | int status = 0; |
| 2536 | |
| 2537 | *res = 1024; |
| 2538 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) |
| 2539 | return -EIO; |
| 2540 | if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { |
| 2541 | uint64_t maxread; |
| 2542 | READ_BUF(8); |
| 2543 | READ64(maxread); |
| 2544 | if (maxread > 0x7FFFFFFF) |
| 2545 | maxread = 0x7FFFFFFF; |
| 2546 | *res = (uint32_t)maxread; |
| 2547 | bitmap[0] &= ~FATTR4_WORD0_MAXREAD; |
| 2548 | } |
| 2549 | dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res); |
| 2550 | return status; |
| 2551 | } |
| 2552 | |
| 2553 | static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) |
| 2554 | { |
| 2555 | uint32_t *p; |
| 2556 | int status = 0; |
| 2557 | |
| 2558 | *res = 1024; |
| 2559 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) |
| 2560 | return -EIO; |
| 2561 | if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { |
| 2562 | uint64_t maxwrite; |
| 2563 | READ_BUF(8); |
| 2564 | READ64(maxwrite); |
| 2565 | if (maxwrite > 0x7FFFFFFF) |
| 2566 | maxwrite = 0x7FFFFFFF; |
| 2567 | *res = (uint32_t)maxwrite; |
| 2568 | bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; |
| 2569 | } |
| 2570 | dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res); |
| 2571 | return status; |
| 2572 | } |
| 2573 | |
| 2574 | static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode) |
| 2575 | { |
| 2576 | uint32_t *p; |
| 2577 | |
| 2578 | *mode = 0; |
| 2579 | if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) |
| 2580 | return -EIO; |
| 2581 | if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { |
| 2582 | READ_BUF(4); |
| 2583 | READ32(*mode); |
| 2584 | *mode &= ~S_IFMT; |
| 2585 | bitmap[1] &= ~FATTR4_WORD1_MODE; |
| 2586 | } |
| 2587 | dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode); |
| 2588 | return 0; |
| 2589 | } |
| 2590 | |
| 2591 | static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) |
| 2592 | { |
| 2593 | uint32_t *p; |
| 2594 | |
| 2595 | *nlink = 1; |
| 2596 | if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) |
| 2597 | return -EIO; |
| 2598 | if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { |
| 2599 | READ_BUF(4); |
| 2600 | READ32(*nlink); |
| 2601 | bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; |
| 2602 | } |
| 2603 | dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink); |
| 2604 | return 0; |
| 2605 | } |
| 2606 | |
| 2607 | static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid) |
| 2608 | { |
| 2609 | uint32_t len, *p; |
| 2610 | |
| 2611 | *uid = -2; |
| 2612 | if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) |
| 2613 | return -EIO; |
| 2614 | if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { |
| 2615 | READ_BUF(4); |
| 2616 | READ32(len); |
| 2617 | READ_BUF(len); |
| 2618 | if (len < XDR_MAX_NETOBJ) { |
| 2619 | if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0) |
| 2620 | dprintk("%s: nfs_map_name_to_uid failed!\n", |
| 2621 | __FUNCTION__); |
| 2622 | } else |
| 2623 | printk(KERN_WARNING "%s: name too long (%u)!\n", |
| 2624 | __FUNCTION__, len); |
| 2625 | bitmap[1] &= ~FATTR4_WORD1_OWNER; |
| 2626 | } |
| 2627 | dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid); |
| 2628 | return 0; |
| 2629 | } |
| 2630 | |
| 2631 | static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid) |
| 2632 | { |
| 2633 | uint32_t len, *p; |
| 2634 | |
| 2635 | *gid = -2; |
| 2636 | if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) |
| 2637 | return -EIO; |
| 2638 | if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { |
| 2639 | READ_BUF(4); |
| 2640 | READ32(len); |
| 2641 | READ_BUF(len); |
| 2642 | if (len < XDR_MAX_NETOBJ) { |
| 2643 | if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0) |
| 2644 | dprintk("%s: nfs_map_group_to_gid failed!\n", |
| 2645 | __FUNCTION__); |
| 2646 | } else |
| 2647 | printk(KERN_WARNING "%s: name too long (%u)!\n", |
| 2648 | __FUNCTION__, len); |
| 2649 | bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; |
| 2650 | } |
| 2651 | dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid); |
| 2652 | return 0; |
| 2653 | } |
| 2654 | |
| 2655 | static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) |
| 2656 | { |
| 2657 | uint32_t major = 0, minor = 0, *p; |
| 2658 | |
| 2659 | *rdev = MKDEV(0,0); |
| 2660 | if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) |
| 2661 | return -EIO; |
| 2662 | if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { |
| 2663 | dev_t tmp; |
| 2664 | |
| 2665 | READ_BUF(8); |
| 2666 | READ32(major); |
| 2667 | READ32(minor); |
| 2668 | tmp = MKDEV(major, minor); |
| 2669 | if (MAJOR(tmp) == major && MINOR(tmp) == minor) |
| 2670 | *rdev = tmp; |
| 2671 | bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; |
| 2672 | } |
| 2673 | dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor); |
| 2674 | return 0; |
| 2675 | } |
| 2676 | |
| 2677 | static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2678 | { |
| 2679 | uint32_t *p; |
| 2680 | int status = 0; |
| 2681 | |
| 2682 | *res = 0; |
| 2683 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) |
| 2684 | return -EIO; |
| 2685 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { |
| 2686 | READ_BUF(8); |
| 2687 | READ64(*res); |
| 2688 | bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; |
| 2689 | } |
| 2690 | dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res); |
| 2691 | return status; |
| 2692 | } |
| 2693 | |
| 2694 | static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2695 | { |
| 2696 | uint32_t *p; |
| 2697 | int status = 0; |
| 2698 | |
| 2699 | *res = 0; |
| 2700 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) |
| 2701 | return -EIO; |
| 2702 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { |
| 2703 | READ_BUF(8); |
| 2704 | READ64(*res); |
| 2705 | bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; |
| 2706 | } |
| 2707 | dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res); |
| 2708 | return status; |
| 2709 | } |
| 2710 | |
| 2711 | static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
| 2712 | { |
| 2713 | uint32_t *p; |
| 2714 | int status = 0; |
| 2715 | |
| 2716 | *res = 0; |
| 2717 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) |
| 2718 | return -EIO; |
| 2719 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { |
| 2720 | READ_BUF(8); |
| 2721 | READ64(*res); |
| 2722 | bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; |
| 2723 | } |
| 2724 | dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res); |
| 2725 | return status; |
| 2726 | } |
| 2727 | |
| 2728 | static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) |
| 2729 | { |
| 2730 | uint32_t *p; |
| 2731 | |
| 2732 | *used = 0; |
| 2733 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) |
| 2734 | return -EIO; |
| 2735 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { |
| 2736 | READ_BUF(8); |
| 2737 | READ64(*used); |
| 2738 | bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; |
| 2739 | } |
| 2740 | dprintk("%s: space used=%Lu\n", __FUNCTION__, |
| 2741 | (unsigned long long)*used); |
| 2742 | return 0; |
| 2743 | } |
| 2744 | |
| 2745 | static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) |
| 2746 | { |
| 2747 | uint32_t *p; |
| 2748 | uint64_t sec; |
| 2749 | uint32_t nsec; |
| 2750 | |
| 2751 | READ_BUF(12); |
| 2752 | READ64(sec); |
| 2753 | READ32(nsec); |
| 2754 | time->tv_sec = (time_t)sec; |
| 2755 | time->tv_nsec = (long)nsec; |
| 2756 | return 0; |
| 2757 | } |
| 2758 | |
| 2759 | static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) |
| 2760 | { |
| 2761 | int status = 0; |
| 2762 | |
| 2763 | time->tv_sec = 0; |
| 2764 | time->tv_nsec = 0; |
| 2765 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) |
| 2766 | return -EIO; |
| 2767 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { |
| 2768 | status = decode_attr_time(xdr, time); |
| 2769 | bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; |
| 2770 | } |
| 2771 | dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec); |
| 2772 | return status; |
| 2773 | } |
| 2774 | |
| 2775 | static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) |
| 2776 | { |
| 2777 | int status = 0; |
| 2778 | |
| 2779 | time->tv_sec = 0; |
| 2780 | time->tv_nsec = 0; |
| 2781 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) |
| 2782 | return -EIO; |
| 2783 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { |
| 2784 | status = decode_attr_time(xdr, time); |
| 2785 | bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; |
| 2786 | } |
| 2787 | dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec); |
| 2788 | return status; |
| 2789 | } |
| 2790 | |
| 2791 | static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) |
| 2792 | { |
| 2793 | int status = 0; |
| 2794 | |
| 2795 | time->tv_sec = 0; |
| 2796 | time->tv_nsec = 0; |
| 2797 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) |
| 2798 | return -EIO; |
| 2799 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { |
| 2800 | status = decode_attr_time(xdr, time); |
| 2801 | bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; |
| 2802 | } |
| 2803 | dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec); |
| 2804 | return status; |
| 2805 | } |
| 2806 | |
| 2807 | static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen) |
| 2808 | { |
| 2809 | unsigned int attrwords = XDR_QUADLEN(attrlen); |
| 2810 | unsigned int nwords = xdr->p - savep; |
| 2811 | |
| 2812 | if (unlikely(attrwords != nwords)) { |
| 2813 | printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n", |
| 2814 | __FUNCTION__, |
| 2815 | attrwords << 2, |
| 2816 | (attrwords < nwords) ? '<' : '>', |
| 2817 | nwords << 2); |
| 2818 | return -EIO; |
| 2819 | } |
| 2820 | return 0; |
| 2821 | } |
| 2822 | |
| 2823 | static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) |
| 2824 | { |
| 2825 | uint32_t *p; |
| 2826 | |
| 2827 | READ_BUF(20); |
| 2828 | READ32(cinfo->atomic); |
| 2829 | READ64(cinfo->before); |
| 2830 | READ64(cinfo->after); |
| 2831 | return 0; |
| 2832 | } |
| 2833 | |
| 2834 | static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) |
| 2835 | { |
| 2836 | uint32_t *p; |
| 2837 | uint32_t supp, acc; |
| 2838 | int status; |
| 2839 | |
| 2840 | status = decode_op_hdr(xdr, OP_ACCESS); |
| 2841 | if (status) |
| 2842 | return status; |
| 2843 | READ_BUF(8); |
| 2844 | READ32(supp); |
| 2845 | READ32(acc); |
| 2846 | access->supported = supp; |
| 2847 | access->access = acc; |
| 2848 | return 0; |
| 2849 | } |
| 2850 | |
| 2851 | static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) |
| 2852 | { |
| 2853 | uint32_t *p; |
| 2854 | int status; |
| 2855 | |
| 2856 | status = decode_op_hdr(xdr, OP_CLOSE); |
| 2857 | if (status) |
| 2858 | return status; |
| 2859 | READ_BUF(sizeof(res->stateid.data)); |
| 2860 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); |
| 2861 | return 0; |
| 2862 | } |
| 2863 | |
| 2864 | static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) |
| 2865 | { |
| 2866 | uint32_t *p; |
| 2867 | int status; |
| 2868 | |
| 2869 | status = decode_op_hdr(xdr, OP_COMMIT); |
| 2870 | if (status) |
| 2871 | return status; |
| 2872 | READ_BUF(8); |
| 2873 | COPYMEM(res->verf->verifier, 8); |
| 2874 | return 0; |
| 2875 | } |
| 2876 | |
| 2877 | static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) |
| 2878 | { |
| 2879 | uint32_t *p; |
| 2880 | uint32_t bmlen; |
| 2881 | int status; |
| 2882 | |
| 2883 | status = decode_op_hdr(xdr, OP_CREATE); |
| 2884 | if (status) |
| 2885 | return status; |
| 2886 | if ((status = decode_change_info(xdr, cinfo))) |
| 2887 | return status; |
| 2888 | READ_BUF(4); |
| 2889 | READ32(bmlen); |
| 2890 | READ_BUF(bmlen << 2); |
| 2891 | return 0; |
| 2892 | } |
| 2893 | |
| 2894 | static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) |
| 2895 | { |
| 2896 | uint32_t *savep; |
| 2897 | uint32_t attrlen, |
| 2898 | bitmap[2] = {0}; |
| 2899 | int status; |
| 2900 | |
| 2901 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 2902 | goto xdr_error; |
| 2903 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 2904 | goto xdr_error; |
| 2905 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 2906 | goto xdr_error; |
| 2907 | if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) |
| 2908 | goto xdr_error; |
| 2909 | if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) |
| 2910 | goto xdr_error; |
| 2911 | if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) |
| 2912 | goto xdr_error; |
| 2913 | if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) |
| 2914 | goto xdr_error; |
| 2915 | status = verify_attr_len(xdr, savep, attrlen); |
| 2916 | xdr_error: |
Trond Myklebust | 16c32b7 | 2005-10-27 22:12:45 -0400 | [diff] [blame] | 2917 | dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | return status; |
| 2919 | } |
| 2920 | |
| 2921 | static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) |
| 2922 | { |
| 2923 | uint32_t *savep; |
| 2924 | uint32_t attrlen, |
| 2925 | bitmap[2] = {0}; |
| 2926 | int status; |
| 2927 | |
| 2928 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 2929 | goto xdr_error; |
| 2930 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 2931 | goto xdr_error; |
| 2932 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 2933 | goto xdr_error; |
| 2934 | |
| 2935 | if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) |
| 2936 | goto xdr_error; |
| 2937 | if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) |
| 2938 | goto xdr_error; |
| 2939 | if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) |
| 2940 | goto xdr_error; |
| 2941 | if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) |
| 2942 | goto xdr_error; |
| 2943 | if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) |
| 2944 | goto xdr_error; |
| 2945 | if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) |
| 2946 | goto xdr_error; |
| 2947 | |
| 2948 | status = verify_attr_len(xdr, savep, attrlen); |
| 2949 | xdr_error: |
Trond Myklebust | 16c32b7 | 2005-10-27 22:12:45 -0400 | [diff] [blame] | 2950 | dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | return status; |
| 2952 | } |
| 2953 | |
| 2954 | static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) |
| 2955 | { |
| 2956 | uint32_t *savep; |
| 2957 | uint32_t attrlen, |
| 2958 | bitmap[2] = {0}; |
| 2959 | int status; |
| 2960 | |
| 2961 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 2962 | goto xdr_error; |
| 2963 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 2964 | goto xdr_error; |
| 2965 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 2966 | goto xdr_error; |
| 2967 | |
| 2968 | if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) |
| 2969 | goto xdr_error; |
| 2970 | if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) |
| 2971 | goto xdr_error; |
| 2972 | |
| 2973 | status = verify_attr_len(xdr, savep, attrlen); |
| 2974 | xdr_error: |
Trond Myklebust | 16c32b7 | 2005-10-27 22:12:45 -0400 | [diff] [blame] | 2975 | dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | return status; |
| 2977 | } |
| 2978 | |
| 2979 | static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server) |
| 2980 | { |
| 2981 | uint32_t *savep; |
| 2982 | uint32_t attrlen, |
| 2983 | bitmap[2] = {0}, |
| 2984 | type; |
| 2985 | int status, fmode = 0; |
| 2986 | |
| 2987 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 2988 | goto xdr_error; |
| 2989 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 2990 | goto xdr_error; |
| 2991 | |
| 2992 | fattr->bitmap[0] = bitmap[0]; |
| 2993 | fattr->bitmap[1] = bitmap[1]; |
| 2994 | |
| 2995 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 2996 | goto xdr_error; |
| 2997 | |
| 2998 | |
| 2999 | if ((status = decode_attr_type(xdr, bitmap, &type)) != 0) |
| 3000 | goto xdr_error; |
| 3001 | fattr->type = nfs_type2fmt[type].nfs2type; |
| 3002 | fmode = nfs_type2fmt[type].mode; |
| 3003 | |
| 3004 | if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0) |
| 3005 | goto xdr_error; |
| 3006 | if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0) |
| 3007 | goto xdr_error; |
Trond Myklebust | 8b4bdcf | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3008 | if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | goto xdr_error; |
| 3010 | if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0) |
| 3011 | goto xdr_error; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 3012 | if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame^] | 3013 | struct nfs4_fs_locations, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 3014 | fattr))) != 0) |
| 3015 | goto xdr_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0) |
| 3017 | goto xdr_error; |
| 3018 | fattr->mode |= fmode; |
| 3019 | if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0) |
| 3020 | goto xdr_error; |
| 3021 | if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0) |
| 3022 | goto xdr_error; |
| 3023 | if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0) |
| 3024 | goto xdr_error; |
| 3025 | if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0) |
| 3026 | goto xdr_error; |
| 3027 | if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0) |
| 3028 | goto xdr_error; |
| 3029 | if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0) |
| 3030 | goto xdr_error; |
| 3031 | if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0) |
| 3032 | goto xdr_error; |
| 3033 | if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0) |
| 3034 | goto xdr_error; |
Trond Myklebust | 3380114 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 3035 | if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | xdr_error: |
Trond Myklebust | 16c32b7 | 2005-10-27 22:12:45 -0400 | [diff] [blame] | 3038 | dprintk("%s: xdr returned %d\n", __FUNCTION__, -status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | return status; |
| 3040 | } |
| 3041 | |
| 3042 | |
| 3043 | static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) |
| 3044 | { |
| 3045 | uint32_t *savep; |
| 3046 | uint32_t attrlen, bitmap[2]; |
| 3047 | int status; |
| 3048 | |
| 3049 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 3050 | goto xdr_error; |
| 3051 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 3052 | goto xdr_error; |
| 3053 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 3054 | goto xdr_error; |
| 3055 | |
| 3056 | fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ |
| 3057 | |
| 3058 | if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) |
| 3059 | goto xdr_error; |
| 3060 | if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) |
| 3061 | goto xdr_error; |
| 3062 | if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) |
| 3063 | goto xdr_error; |
| 3064 | fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; |
| 3065 | if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) |
| 3066 | goto xdr_error; |
| 3067 | fsinfo->wtpref = fsinfo->wtmax; |
| 3068 | |
| 3069 | status = verify_attr_len(xdr, savep, attrlen); |
| 3070 | xdr_error: |
Trond Myklebust | 16c32b7 | 2005-10-27 22:12:45 -0400 | [diff] [blame] | 3071 | dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | return status; |
| 3073 | } |
| 3074 | |
| 3075 | static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) |
| 3076 | { |
| 3077 | uint32_t *p; |
| 3078 | uint32_t len; |
| 3079 | int status; |
| 3080 | |
| 3081 | status = decode_op_hdr(xdr, OP_GETFH); |
| 3082 | if (status) |
| 3083 | return status; |
| 3084 | /* Zero handle first to allow comparisons */ |
| 3085 | memset(fh, 0, sizeof(*fh)); |
| 3086 | |
| 3087 | READ_BUF(4); |
| 3088 | READ32(len); |
| 3089 | if (len > NFS4_FHSIZE) |
| 3090 | return -EIO; |
| 3091 | fh->size = len; |
| 3092 | READ_BUF(len); |
| 3093 | COPYMEM(fh->data, len); |
| 3094 | return 0; |
| 3095 | } |
| 3096 | |
| 3097 | static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) |
| 3098 | { |
| 3099 | int status; |
| 3100 | |
| 3101 | status = decode_op_hdr(xdr, OP_LINK); |
| 3102 | if (status) |
| 3103 | return status; |
| 3104 | return decode_change_info(xdr, cinfo); |
| 3105 | } |
| 3106 | |
| 3107 | /* |
| 3108 | * We create the owner, so we know a proper owner.id length is 4. |
| 3109 | */ |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3110 | 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] | 3111 | { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3112 | uint64_t offset, length, clientid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | uint32_t *p; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3114 | uint32_t namelen, type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | |
| 3116 | READ_BUF(32); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3117 | READ64(offset); |
| 3118 | READ64(length); |
| 3119 | READ32(type); |
| 3120 | if (fl != NULL) { |
| 3121 | fl->fl_start = (loff_t)offset; |
| 3122 | fl->fl_end = fl->fl_start + (loff_t)length - 1; |
| 3123 | if (length == ~(uint64_t)0) |
| 3124 | fl->fl_end = OFFSET_MAX; |
| 3125 | fl->fl_type = F_WRLCK; |
| 3126 | if (type & 1) |
| 3127 | fl->fl_type = F_RDLCK; |
| 3128 | fl->fl_pid = 0; |
| 3129 | } |
| 3130 | READ64(clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | READ32(namelen); |
| 3132 | READ_BUF(namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | return -NFS4ERR_DENIED; |
| 3134 | } |
| 3135 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3136 | 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] | 3137 | { |
| 3138 | uint32_t *p; |
| 3139 | int status; |
| 3140 | |
| 3141 | status = decode_op_hdr(xdr, OP_LOCK); |
| 3142 | if (status == 0) { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3143 | READ_BUF(sizeof(res->stateid.data)); |
| 3144 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | } else if (status == -NFS4ERR_DENIED) |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3146 | return decode_lock_denied(xdr, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | return status; |
| 3148 | } |
| 3149 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3150 | 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] | 3151 | { |
| 3152 | int status; |
| 3153 | status = decode_op_hdr(xdr, OP_LOCKT); |
| 3154 | if (status == -NFS4ERR_DENIED) |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3155 | return decode_lock_denied(xdr, res->denied); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | return status; |
| 3157 | } |
| 3158 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3159 | 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] | 3160 | { |
| 3161 | uint32_t *p; |
| 3162 | int status; |
| 3163 | |
| 3164 | status = decode_op_hdr(xdr, OP_LOCKU); |
| 3165 | if (status == 0) { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3166 | READ_BUF(sizeof(res->stateid.data)); |
| 3167 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | } |
| 3169 | return status; |
| 3170 | } |
| 3171 | |
| 3172 | static int decode_lookup(struct xdr_stream *xdr) |
| 3173 | { |
| 3174 | return decode_op_hdr(xdr, OP_LOOKUP); |
| 3175 | } |
| 3176 | |
| 3177 | /* This is too sick! */ |
| 3178 | static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) |
| 3179 | { |
| 3180 | uint32_t *p; |
| 3181 | uint32_t limit_type, nblocks, blocksize; |
| 3182 | |
| 3183 | READ_BUF(12); |
| 3184 | READ32(limit_type); |
| 3185 | switch (limit_type) { |
| 3186 | case 1: |
| 3187 | READ64(*maxsize); |
| 3188 | break; |
| 3189 | case 2: |
| 3190 | READ32(nblocks); |
| 3191 | READ32(blocksize); |
| 3192 | *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; |
| 3193 | } |
| 3194 | return 0; |
| 3195 | } |
| 3196 | |
| 3197 | static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) |
| 3198 | { |
| 3199 | uint32_t *p; |
| 3200 | uint32_t delegation_type; |
| 3201 | |
| 3202 | READ_BUF(4); |
| 3203 | READ32(delegation_type); |
| 3204 | if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { |
| 3205 | res->delegation_type = 0; |
| 3206 | return 0; |
| 3207 | } |
| 3208 | READ_BUF(20); |
| 3209 | COPYMEM(res->delegation.data, sizeof(res->delegation.data)); |
| 3210 | READ32(res->do_recall); |
| 3211 | switch (delegation_type) { |
| 3212 | case NFS4_OPEN_DELEGATE_READ: |
| 3213 | res->delegation_type = FMODE_READ; |
| 3214 | break; |
| 3215 | case NFS4_OPEN_DELEGATE_WRITE: |
| 3216 | res->delegation_type = FMODE_WRITE|FMODE_READ; |
| 3217 | if (decode_space_limit(xdr, &res->maxsize) < 0) |
| 3218 | return -EIO; |
| 3219 | } |
| 3220 | return decode_ace(xdr, NULL, res->server->nfs4_state); |
| 3221 | } |
| 3222 | |
| 3223 | static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) |
| 3224 | { |
| 3225 | uint32_t *p; |
| 3226 | uint32_t bmlen; |
| 3227 | int status; |
| 3228 | |
| 3229 | status = decode_op_hdr(xdr, OP_OPEN); |
| 3230 | if (status) |
| 3231 | return status; |
| 3232 | READ_BUF(sizeof(res->stateid.data)); |
| 3233 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); |
| 3234 | |
| 3235 | decode_change_info(xdr, &res->cinfo); |
| 3236 | |
| 3237 | READ_BUF(8); |
| 3238 | READ32(res->rflags); |
| 3239 | READ32(bmlen); |
| 3240 | if (bmlen > 10) |
| 3241 | goto xdr_error; |
| 3242 | |
| 3243 | READ_BUF(bmlen << 2); |
| 3244 | p += bmlen; |
| 3245 | return decode_delegation(xdr, res); |
| 3246 | xdr_error: |
Trond Myklebust | 16c32b7 | 2005-10-27 22:12:45 -0400 | [diff] [blame] | 3247 | dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | return -EIO; |
| 3249 | } |
| 3250 | |
| 3251 | static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) |
| 3252 | { |
| 3253 | uint32_t *p; |
| 3254 | int status; |
| 3255 | |
| 3256 | status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); |
| 3257 | if (status) |
| 3258 | return status; |
| 3259 | READ_BUF(sizeof(res->stateid.data)); |
| 3260 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); |
| 3261 | return 0; |
| 3262 | } |
| 3263 | |
| 3264 | static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) |
| 3265 | { |
| 3266 | uint32_t *p; |
| 3267 | int status; |
| 3268 | |
| 3269 | status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); |
| 3270 | if (status) |
| 3271 | return status; |
| 3272 | READ_BUF(sizeof(res->stateid.data)); |
| 3273 | COPYMEM(res->stateid.data, sizeof(res->stateid.data)); |
| 3274 | return 0; |
| 3275 | } |
| 3276 | |
| 3277 | static int decode_putfh(struct xdr_stream *xdr) |
| 3278 | { |
| 3279 | return decode_op_hdr(xdr, OP_PUTFH); |
| 3280 | } |
| 3281 | |
| 3282 | static int decode_putrootfh(struct xdr_stream *xdr) |
| 3283 | { |
| 3284 | return decode_op_hdr(xdr, OP_PUTROOTFH); |
| 3285 | } |
| 3286 | |
| 3287 | static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) |
| 3288 | { |
| 3289 | struct kvec *iov = req->rq_rcv_buf.head; |
| 3290 | uint32_t *p; |
| 3291 | uint32_t count, eof, recvd, hdrlen; |
| 3292 | int status; |
| 3293 | |
| 3294 | status = decode_op_hdr(xdr, OP_READ); |
| 3295 | if (status) |
| 3296 | return status; |
| 3297 | READ_BUF(8); |
| 3298 | READ32(eof); |
| 3299 | READ32(count); |
| 3300 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; |
| 3301 | recvd = req->rq_rcv_buf.len - hdrlen; |
| 3302 | if (count > recvd) { |
| 3303 | printk(KERN_WARNING "NFS: server cheating in read reply: " |
| 3304 | "count %u > recvd %u\n", count, recvd); |
| 3305 | count = recvd; |
| 3306 | eof = 0; |
| 3307 | } |
| 3308 | xdr_read_pages(xdr, count); |
| 3309 | res->eof = eof; |
| 3310 | res->count = count; |
| 3311 | return 0; |
| 3312 | } |
| 3313 | |
| 3314 | static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) |
| 3315 | { |
| 3316 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; |
| 3317 | struct page *page = *rcvbuf->pages; |
| 3318 | struct kvec *iov = rcvbuf->head; |
| 3319 | unsigned int nr, pglen = rcvbuf->page_len; |
| 3320 | uint32_t *end, *entry, *p, *kaddr; |
| 3321 | uint32_t len, attrlen; |
| 3322 | int hdrlen, recvd, status; |
| 3323 | |
| 3324 | status = decode_op_hdr(xdr, OP_READDIR); |
| 3325 | if (status) |
| 3326 | return status; |
| 3327 | READ_BUF(8); |
| 3328 | COPYMEM(readdir->verifier.data, 8); |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3329 | dprintk("%s: verifier = 0x%x%x\n", |
| 3330 | __FUNCTION__, |
| 3331 | ((u32 *)readdir->verifier.data)[0], |
| 3332 | ((u32 *)readdir->verifier.data)[1]); |
| 3333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | |
| 3335 | hdrlen = (char *) p - (char *) iov->iov_base; |
| 3336 | recvd = rcvbuf->len - hdrlen; |
| 3337 | if (pglen > recvd) |
| 3338 | pglen = recvd; |
| 3339 | xdr_read_pages(xdr, pglen); |
| 3340 | |
| 3341 | BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE); |
| 3342 | kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0); |
| 3343 | end = (uint32_t *) ((char *)p + pglen + readdir->pgbase); |
| 3344 | entry = p; |
| 3345 | for (nr = 0; *p++; nr++) { |
| 3346 | if (p + 3 > end) |
| 3347 | goto short_pkt; |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3348 | dprintk("cookie = %Lu, ", *((unsigned long long *)p)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | p += 2; /* cookie */ |
| 3350 | len = ntohl(*p++); /* filename length */ |
| 3351 | if (len > NFS4_MAXNAMLEN) { |
| 3352 | printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len); |
| 3353 | goto err_unmap; |
| 3354 | } |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3355 | dprintk("filename = %*s\n", len, (char *)p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | p += XDR_QUADLEN(len); |
| 3357 | if (p + 1 > end) |
| 3358 | goto short_pkt; |
| 3359 | len = ntohl(*p++); /* bitmap length */ |
| 3360 | p += len; |
| 3361 | if (p + 1 > end) |
| 3362 | goto short_pkt; |
| 3363 | attrlen = XDR_QUADLEN(ntohl(*p++)); |
| 3364 | p += attrlen; /* attributes */ |
| 3365 | if (p + 2 > end) |
| 3366 | goto short_pkt; |
| 3367 | entry = p; |
| 3368 | } |
| 3369 | if (!nr && (entry[0] != 0 || entry[1] == 0)) |
| 3370 | goto short_pkt; |
| 3371 | out: |
| 3372 | kunmap_atomic(kaddr, KM_USER0); |
| 3373 | return 0; |
| 3374 | short_pkt: |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3375 | dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | entry[0] = entry[1] = 0; |
| 3377 | /* truncate listing ? */ |
| 3378 | if (!nr) { |
| 3379 | printk(KERN_NOTICE "NFS: readdir reply truncated!\n"); |
| 3380 | entry[1] = 1; |
| 3381 | } |
| 3382 | goto out; |
| 3383 | err_unmap: |
| 3384 | kunmap_atomic(kaddr, KM_USER0); |
| 3385 | return -errno_NFSERR_IO; |
| 3386 | } |
| 3387 | |
| 3388 | static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) |
| 3389 | { |
| 3390 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; |
| 3391 | struct kvec *iov = rcvbuf->head; |
| 3392 | int hdrlen, len, recvd; |
| 3393 | uint32_t *p; |
| 3394 | char *kaddr; |
| 3395 | int status; |
| 3396 | |
| 3397 | status = decode_op_hdr(xdr, OP_READLINK); |
| 3398 | if (status) |
| 3399 | return status; |
| 3400 | |
| 3401 | /* Convert length of symlink */ |
| 3402 | READ_BUF(4); |
| 3403 | READ32(len); |
| 3404 | if (len >= rcvbuf->page_len || len <= 0) { |
| 3405 | dprintk(KERN_WARNING "nfs: server returned giant symlink!\n"); |
| 3406 | return -ENAMETOOLONG; |
| 3407 | } |
| 3408 | hdrlen = (char *) xdr->p - (char *) iov->iov_base; |
| 3409 | recvd = req->rq_rcv_buf.len - hdrlen; |
| 3410 | if (recvd < len) { |
| 3411 | printk(KERN_WARNING "NFS: server cheating in readlink reply: " |
| 3412 | "count %u > recvd %u\n", len, recvd); |
| 3413 | return -EIO; |
| 3414 | } |
| 3415 | xdr_read_pages(xdr, len); |
| 3416 | /* |
| 3417 | * The XDR encode routine has set things up so that |
| 3418 | * the link text will be copied directly into the |
| 3419 | * buffer. We just have to do overflow-checking, |
| 3420 | * and and null-terminate the text (the VFS expects |
| 3421 | * null-termination). |
| 3422 | */ |
| 3423 | kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0); |
| 3424 | kaddr[len+rcvbuf->page_base] = '\0'; |
| 3425 | kunmap_atomic(kaddr, KM_USER0); |
| 3426 | return 0; |
| 3427 | } |
| 3428 | |
| 3429 | static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) |
| 3430 | { |
| 3431 | int status; |
| 3432 | |
| 3433 | status = decode_op_hdr(xdr, OP_REMOVE); |
| 3434 | if (status) |
| 3435 | goto out; |
| 3436 | status = decode_change_info(xdr, cinfo); |
| 3437 | out: |
| 3438 | return status; |
| 3439 | } |
| 3440 | |
| 3441 | static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, |
| 3442 | struct nfs4_change_info *new_cinfo) |
| 3443 | { |
| 3444 | int status; |
| 3445 | |
| 3446 | status = decode_op_hdr(xdr, OP_RENAME); |
| 3447 | if (status) |
| 3448 | goto out; |
| 3449 | if ((status = decode_change_info(xdr, old_cinfo))) |
| 3450 | goto out; |
| 3451 | status = decode_change_info(xdr, new_cinfo); |
| 3452 | out: |
| 3453 | return status; |
| 3454 | } |
| 3455 | |
| 3456 | static int decode_renew(struct xdr_stream *xdr) |
| 3457 | { |
| 3458 | return decode_op_hdr(xdr, OP_RENEW); |
| 3459 | } |
| 3460 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 3461 | static int |
| 3462 | decode_restorefh(struct xdr_stream *xdr) |
| 3463 | { |
| 3464 | return decode_op_hdr(xdr, OP_RESTOREFH); |
| 3465 | } |
| 3466 | |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3467 | static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, |
| 3468 | size_t *acl_len) |
| 3469 | { |
| 3470 | uint32_t *savep; |
| 3471 | uint32_t attrlen, |
| 3472 | bitmap[2] = {0}; |
| 3473 | struct kvec *iov = req->rq_rcv_buf.head; |
| 3474 | int status; |
| 3475 | |
| 3476 | *acl_len = 0; |
| 3477 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
| 3478 | goto out; |
| 3479 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) |
| 3480 | goto out; |
| 3481 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) |
| 3482 | goto out; |
| 3483 | |
| 3484 | if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) |
| 3485 | return -EIO; |
| 3486 | if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { |
| 3487 | int hdrlen, recvd; |
| 3488 | |
| 3489 | /* We ignore &savep and don't do consistency checks on |
| 3490 | * the attr length. Let userspace figure it out.... */ |
| 3491 | hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; |
| 3492 | recvd = req->rq_rcv_buf.len - hdrlen; |
| 3493 | if (attrlen > recvd) { |
| 3494 | printk(KERN_WARNING "NFS: server cheating in getattr" |
| 3495 | " acl reply: attrlen %u > recvd %u\n", |
| 3496 | attrlen, recvd); |
| 3497 | return -EINVAL; |
| 3498 | } |
J. Bruce Fields | c04871e | 2006-05-30 16:28:58 -0400 | [diff] [blame] | 3499 | xdr_read_pages(xdr, attrlen); |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3500 | *acl_len = attrlen; |
J. Bruce Fields | 8c233cf | 2005-10-13 16:54:27 -0400 | [diff] [blame] | 3501 | } else |
| 3502 | status = -EOPNOTSUPP; |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3503 | |
| 3504 | out: |
| 3505 | return status; |
| 3506 | } |
| 3507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | static int |
| 3509 | decode_savefh(struct xdr_stream *xdr) |
| 3510 | { |
| 3511 | return decode_op_hdr(xdr, OP_SAVEFH); |
| 3512 | } |
| 3513 | |
| 3514 | static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res) |
| 3515 | { |
| 3516 | uint32_t *p; |
| 3517 | uint32_t bmlen; |
| 3518 | int status; |
| 3519 | |
| 3520 | |
| 3521 | status = decode_op_hdr(xdr, OP_SETATTR); |
| 3522 | if (status) |
| 3523 | return status; |
| 3524 | READ_BUF(4); |
| 3525 | READ32(bmlen); |
| 3526 | READ_BUF(bmlen << 2); |
| 3527 | return 0; |
| 3528 | } |
| 3529 | |
| 3530 | static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp) |
| 3531 | { |
| 3532 | uint32_t *p; |
| 3533 | uint32_t opnum; |
| 3534 | int32_t nfserr; |
| 3535 | |
| 3536 | READ_BUF(8); |
| 3537 | READ32(opnum); |
| 3538 | if (opnum != OP_SETCLIENTID) { |
| 3539 | printk(KERN_NOTICE |
| 3540 | "nfs4_decode_setclientid: Server returned operation" |
| 3541 | " %d\n", opnum); |
| 3542 | return -EIO; |
| 3543 | } |
| 3544 | READ32(nfserr); |
| 3545 | if (nfserr == NFS_OK) { |
| 3546 | READ_BUF(8 + sizeof(clp->cl_confirm.data)); |
| 3547 | READ64(clp->cl_clientid); |
| 3548 | COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data)); |
| 3549 | } else if (nfserr == NFSERR_CLID_INUSE) { |
| 3550 | uint32_t len; |
| 3551 | |
| 3552 | /* skip netid string */ |
| 3553 | READ_BUF(4); |
| 3554 | READ32(len); |
| 3555 | READ_BUF(len); |
| 3556 | |
| 3557 | /* skip uaddr string */ |
| 3558 | READ_BUF(4); |
| 3559 | READ32(len); |
| 3560 | READ_BUF(len); |
| 3561 | return -NFSERR_CLID_INUSE; |
| 3562 | } else |
| 3563 | return -nfs_stat_to_errno(nfserr); |
| 3564 | |
| 3565 | return 0; |
| 3566 | } |
| 3567 | |
| 3568 | static int decode_setclientid_confirm(struct xdr_stream *xdr) |
| 3569 | { |
| 3570 | return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); |
| 3571 | } |
| 3572 | |
| 3573 | static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) |
| 3574 | { |
| 3575 | uint32_t *p; |
| 3576 | int status; |
| 3577 | |
| 3578 | status = decode_op_hdr(xdr, OP_WRITE); |
| 3579 | if (status) |
| 3580 | return status; |
| 3581 | |
| 3582 | READ_BUF(16); |
| 3583 | READ32(res->count); |
| 3584 | READ32(res->verf->committed); |
| 3585 | COPYMEM(res->verf->verifier, 8); |
| 3586 | return 0; |
| 3587 | } |
| 3588 | |
| 3589 | static int decode_delegreturn(struct xdr_stream *xdr) |
| 3590 | { |
| 3591 | return decode_op_hdr(xdr, OP_DELEGRETURN); |
| 3592 | } |
| 3593 | |
| 3594 | /* |
| 3595 | * Decode OPEN_DOWNGRADE response |
| 3596 | */ |
| 3597 | static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res) |
| 3598 | { |
| 3599 | struct xdr_stream xdr; |
| 3600 | struct compound_hdr hdr; |
| 3601 | int status; |
| 3602 | |
| 3603 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3604 | status = decode_compound_hdr(&xdr, &hdr); |
| 3605 | if (status) |
| 3606 | goto out; |
| 3607 | status = decode_putfh(&xdr); |
| 3608 | if (status) |
| 3609 | goto out; |
| 3610 | status = decode_open_downgrade(&xdr, res); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3611 | if (status != 0) |
| 3612 | goto out; |
| 3613 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | out: |
| 3615 | return status; |
| 3616 | } |
| 3617 | |
| 3618 | /* |
| 3619 | * END OF "GENERIC" DECODE ROUTINES. |
| 3620 | */ |
| 3621 | |
| 3622 | /* |
| 3623 | * Decode ACCESS response |
| 3624 | */ |
| 3625 | static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res) |
| 3626 | { |
| 3627 | struct xdr_stream xdr; |
| 3628 | struct compound_hdr hdr; |
| 3629 | int status; |
| 3630 | |
| 3631 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3632 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) |
| 3633 | goto out; |
| 3634 | if ((status = decode_putfh(&xdr)) == 0) |
| 3635 | status = decode_access(&xdr, res); |
| 3636 | out: |
| 3637 | return status; |
| 3638 | } |
| 3639 | |
| 3640 | /* |
| 3641 | * Decode LOOKUP response |
| 3642 | */ |
| 3643 | static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res) |
| 3644 | { |
| 3645 | struct xdr_stream xdr; |
| 3646 | struct compound_hdr hdr; |
| 3647 | int status; |
| 3648 | |
| 3649 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3650 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) |
| 3651 | goto out; |
| 3652 | if ((status = decode_putfh(&xdr)) != 0) |
| 3653 | goto out; |
| 3654 | if ((status = decode_lookup(&xdr)) != 0) |
| 3655 | goto out; |
| 3656 | if ((status = decode_getfh(&xdr, res->fh)) != 0) |
| 3657 | goto out; |
| 3658 | status = decode_getfattr(&xdr, res->fattr, res->server); |
| 3659 | out: |
| 3660 | return status; |
| 3661 | } |
| 3662 | |
| 3663 | /* |
| 3664 | * Decode LOOKUP_ROOT response |
| 3665 | */ |
| 3666 | static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res) |
| 3667 | { |
| 3668 | struct xdr_stream xdr; |
| 3669 | struct compound_hdr hdr; |
| 3670 | int status; |
| 3671 | |
| 3672 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3673 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) |
| 3674 | goto out; |
| 3675 | if ((status = decode_putrootfh(&xdr)) != 0) |
| 3676 | goto out; |
| 3677 | if ((status = decode_getfh(&xdr, res->fh)) == 0) |
| 3678 | status = decode_getfattr(&xdr, res->fattr, res->server); |
| 3679 | out: |
| 3680 | return status; |
| 3681 | } |
| 3682 | |
| 3683 | /* |
| 3684 | * Decode REMOVE response |
| 3685 | */ |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3686 | static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_remove_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | { |
| 3688 | struct xdr_stream xdr; |
| 3689 | struct compound_hdr hdr; |
| 3690 | int status; |
| 3691 | |
| 3692 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3693 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) |
| 3694 | goto out; |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3695 | if ((status = decode_putfh(&xdr)) != 0) |
| 3696 | goto out; |
| 3697 | if ((status = decode_remove(&xdr, &res->cinfo)) != 0) |
| 3698 | goto out; |
| 3699 | decode_getfattr(&xdr, res->dir_attr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 | out: |
| 3701 | return status; |
| 3702 | } |
| 3703 | |
| 3704 | /* |
| 3705 | * Decode RENAME response |
| 3706 | */ |
| 3707 | static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res) |
| 3708 | { |
| 3709 | struct xdr_stream xdr; |
| 3710 | struct compound_hdr hdr; |
| 3711 | int status; |
| 3712 | |
| 3713 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3714 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) |
| 3715 | goto out; |
| 3716 | if ((status = decode_putfh(&xdr)) != 0) |
| 3717 | goto out; |
| 3718 | if ((status = decode_savefh(&xdr)) != 0) |
| 3719 | goto out; |
| 3720 | if ((status = decode_putfh(&xdr)) != 0) |
| 3721 | goto out; |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3722 | if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0) |
| 3723 | goto out; |
| 3724 | /* Current FH is target directory */ |
| 3725 | if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0) |
| 3726 | goto out; |
| 3727 | if ((status = decode_restorefh(&xdr)) != 0) |
| 3728 | goto out; |
| 3729 | decode_getfattr(&xdr, res->old_fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | out: |
| 3731 | return status; |
| 3732 | } |
| 3733 | |
| 3734 | /* |
| 3735 | * Decode LINK response |
| 3736 | */ |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3737 | static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_link_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | { |
| 3739 | struct xdr_stream xdr; |
| 3740 | struct compound_hdr hdr; |
| 3741 | int status; |
| 3742 | |
| 3743 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3744 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) |
| 3745 | goto out; |
| 3746 | if ((status = decode_putfh(&xdr)) != 0) |
| 3747 | goto out; |
| 3748 | if ((status = decode_savefh(&xdr)) != 0) |
| 3749 | goto out; |
| 3750 | if ((status = decode_putfh(&xdr)) != 0) |
| 3751 | goto out; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3752 | if ((status = decode_link(&xdr, &res->cinfo)) != 0) |
| 3753 | goto out; |
| 3754 | /* |
| 3755 | * Note order: OP_LINK leaves the directory as the current |
| 3756 | * filehandle. |
| 3757 | */ |
| 3758 | if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0) |
| 3759 | goto out; |
| 3760 | if ((status = decode_restorefh(&xdr)) != 0) |
| 3761 | goto out; |
| 3762 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | out: |
| 3764 | return status; |
| 3765 | } |
| 3766 | |
| 3767 | /* |
| 3768 | * Decode CREATE response |
| 3769 | */ |
| 3770 | static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res) |
| 3771 | { |
| 3772 | struct xdr_stream xdr; |
| 3773 | struct compound_hdr hdr; |
| 3774 | int status; |
| 3775 | |
| 3776 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3777 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) |
| 3778 | goto out; |
| 3779 | if ((status = decode_putfh(&xdr)) != 0) |
| 3780 | goto out; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 3781 | if ((status = decode_savefh(&xdr)) != 0) |
| 3782 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0) |
| 3784 | goto out; |
| 3785 | if ((status = decode_getfh(&xdr, res->fh)) != 0) |
| 3786 | goto out; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 3787 | if (decode_getfattr(&xdr, res->fattr, res->server) != 0) |
| 3788 | goto out; |
| 3789 | if ((status = decode_restorefh(&xdr)) != 0) |
| 3790 | goto out; |
| 3791 | decode_getfattr(&xdr, res->dir_fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | out: |
| 3793 | return status; |
| 3794 | } |
| 3795 | |
| 3796 | /* |
| 3797 | * Decode SYMLINK response |
| 3798 | */ |
| 3799 | static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res) |
| 3800 | { |
| 3801 | return nfs4_xdr_dec_create(rqstp, p, res); |
| 3802 | } |
| 3803 | |
| 3804 | /* |
| 3805 | * Decode GETATTR response |
| 3806 | */ |
| 3807 | static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res) |
| 3808 | { |
| 3809 | struct xdr_stream xdr; |
| 3810 | struct compound_hdr hdr; |
| 3811 | int status; |
| 3812 | |
| 3813 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3814 | status = decode_compound_hdr(&xdr, &hdr); |
| 3815 | if (status) |
| 3816 | goto out; |
| 3817 | status = decode_putfh(&xdr); |
| 3818 | if (status) |
| 3819 | goto out; |
| 3820 | status = decode_getfattr(&xdr, res->fattr, res->server); |
| 3821 | out: |
| 3822 | return status; |
| 3823 | |
| 3824 | } |
| 3825 | |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3826 | /* |
| 3827 | * Encode an SETACL request |
| 3828 | */ |
| 3829 | static int |
| 3830 | nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args) |
| 3831 | { |
| 3832 | struct xdr_stream xdr; |
| 3833 | struct compound_hdr hdr = { |
| 3834 | .nops = 2, |
| 3835 | }; |
| 3836 | int status; |
| 3837 | |
| 3838 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 3839 | encode_compound_hdr(&xdr, &hdr); |
| 3840 | status = encode_putfh(&xdr, args->fh); |
| 3841 | if (status) |
| 3842 | goto out; |
| 3843 | status = encode_setacl(&xdr, args); |
| 3844 | out: |
| 3845 | return status; |
| 3846 | } |
| 3847 | /* |
| 3848 | * Decode SETACL response |
| 3849 | */ |
| 3850 | static int |
| 3851 | nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res) |
| 3852 | { |
| 3853 | struct xdr_stream xdr; |
| 3854 | struct compound_hdr hdr; |
| 3855 | int status; |
| 3856 | |
| 3857 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3858 | status = decode_compound_hdr(&xdr, &hdr); |
| 3859 | if (status) |
| 3860 | goto out; |
| 3861 | status = decode_putfh(&xdr); |
| 3862 | if (status) |
| 3863 | goto out; |
| 3864 | status = decode_setattr(&xdr, res); |
| 3865 | out: |
| 3866 | return status; |
| 3867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | |
| 3869 | /* |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3870 | * Decode GETACL response |
| 3871 | */ |
| 3872 | static int |
| 3873 | nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len) |
| 3874 | { |
| 3875 | struct xdr_stream xdr; |
| 3876 | struct compound_hdr hdr; |
| 3877 | int status; |
| 3878 | |
| 3879 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3880 | status = decode_compound_hdr(&xdr, &hdr); |
| 3881 | if (status) |
| 3882 | goto out; |
| 3883 | status = decode_putfh(&xdr); |
| 3884 | if (status) |
| 3885 | goto out; |
| 3886 | status = decode_getacl(&xdr, rqstp, acl_len); |
| 3887 | |
| 3888 | out: |
| 3889 | return status; |
| 3890 | } |
| 3891 | |
| 3892 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | * Decode CLOSE response |
| 3894 | */ |
| 3895 | static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res) |
| 3896 | { |
| 3897 | struct xdr_stream xdr; |
| 3898 | struct compound_hdr hdr; |
| 3899 | int status; |
| 3900 | |
| 3901 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3902 | status = decode_compound_hdr(&xdr, &hdr); |
| 3903 | if (status) |
| 3904 | goto out; |
| 3905 | status = decode_putfh(&xdr); |
| 3906 | if (status) |
| 3907 | goto out; |
| 3908 | status = decode_close(&xdr, res); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3909 | if (status != 0) |
| 3910 | goto out; |
| 3911 | /* |
| 3912 | * Note: Server may do delete on close for this file |
| 3913 | * in which case the getattr call will fail with |
| 3914 | * an ESTALE error. Shouldn't be a problem, |
| 3915 | * though, since fattr->valid will remain unset. |
| 3916 | */ |
| 3917 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | out: |
| 3919 | return status; |
| 3920 | } |
| 3921 | |
| 3922 | /* |
| 3923 | * Decode OPEN response |
| 3924 | */ |
| 3925 | static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res) |
| 3926 | { |
| 3927 | struct xdr_stream xdr; |
| 3928 | struct compound_hdr hdr; |
| 3929 | int status; |
| 3930 | |
| 3931 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3932 | status = decode_compound_hdr(&xdr, &hdr); |
| 3933 | if (status) |
| 3934 | goto out; |
| 3935 | status = decode_putfh(&xdr); |
| 3936 | if (status) |
| 3937 | goto out; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 3938 | status = decode_savefh(&xdr); |
| 3939 | if (status) |
| 3940 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | status = decode_open(&xdr, res); |
| 3942 | if (status) |
| 3943 | goto out; |
| 3944 | status = decode_getfh(&xdr, &res->fh); |
| 3945 | if (status) |
| 3946 | goto out; |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 3947 | if (decode_getfattr(&xdr, res->f_attr, res->server) != 0) |
| 3948 | goto out; |
| 3949 | if ((status = decode_restorefh(&xdr)) != 0) |
| 3950 | goto out; |
| 3951 | decode_getfattr(&xdr, res->dir_attr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | out: |
| 3953 | return status; |
| 3954 | } |
| 3955 | |
| 3956 | /* |
| 3957 | * Decode OPEN_CONFIRM response |
| 3958 | */ |
| 3959 | static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res) |
| 3960 | { |
| 3961 | struct xdr_stream xdr; |
| 3962 | struct compound_hdr hdr; |
| 3963 | int status; |
| 3964 | |
| 3965 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3966 | status = decode_compound_hdr(&xdr, &hdr); |
| 3967 | if (status) |
| 3968 | goto out; |
| 3969 | status = decode_putfh(&xdr); |
| 3970 | if (status) |
| 3971 | goto out; |
| 3972 | status = decode_open_confirm(&xdr, res); |
| 3973 | out: |
| 3974 | return status; |
| 3975 | } |
| 3976 | |
| 3977 | /* |
| 3978 | * Decode OPEN response |
| 3979 | */ |
| 3980 | static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res) |
| 3981 | { |
| 3982 | struct xdr_stream xdr; |
| 3983 | struct compound_hdr hdr; |
| 3984 | int status; |
| 3985 | |
| 3986 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 3987 | status = decode_compound_hdr(&xdr, &hdr); |
| 3988 | if (status) |
| 3989 | goto out; |
| 3990 | status = decode_putfh(&xdr); |
| 3991 | if (status) |
| 3992 | goto out; |
| 3993 | status = decode_open(&xdr, res); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 3994 | if (status) |
| 3995 | goto out; |
| 3996 | decode_getfattr(&xdr, res->f_attr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | out: |
| 3998 | return status; |
| 3999 | } |
| 4000 | |
| 4001 | /* |
| 4002 | * Decode SETATTR response |
| 4003 | */ |
| 4004 | static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res) |
| 4005 | { |
| 4006 | struct xdr_stream xdr; |
| 4007 | struct compound_hdr hdr; |
| 4008 | int status; |
| 4009 | |
| 4010 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4011 | status = decode_compound_hdr(&xdr, &hdr); |
| 4012 | if (status) |
| 4013 | goto out; |
| 4014 | status = decode_putfh(&xdr); |
| 4015 | if (status) |
| 4016 | goto out; |
| 4017 | status = decode_setattr(&xdr, res); |
| 4018 | if (status) |
| 4019 | goto out; |
| 4020 | status = decode_getfattr(&xdr, res->fattr, res->server); |
| 4021 | if (status == NFS4ERR_DELAY) |
| 4022 | status = 0; |
| 4023 | out: |
| 4024 | return status; |
| 4025 | } |
| 4026 | |
| 4027 | /* |
| 4028 | * Decode LOCK response |
| 4029 | */ |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4030 | static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lock_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | { |
| 4032 | struct xdr_stream xdr; |
| 4033 | struct compound_hdr hdr; |
| 4034 | int status; |
| 4035 | |
| 4036 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4037 | status = decode_compound_hdr(&xdr, &hdr); |
| 4038 | if (status) |
| 4039 | goto out; |
| 4040 | status = decode_putfh(&xdr); |
| 4041 | if (status) |
| 4042 | goto out; |
| 4043 | status = decode_lock(&xdr, res); |
| 4044 | out: |
| 4045 | return status; |
| 4046 | } |
| 4047 | |
| 4048 | /* |
| 4049 | * Decode LOCKT response |
| 4050 | */ |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4051 | static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockt_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | { |
| 4053 | struct xdr_stream xdr; |
| 4054 | struct compound_hdr hdr; |
| 4055 | int status; |
| 4056 | |
| 4057 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4058 | status = decode_compound_hdr(&xdr, &hdr); |
| 4059 | if (status) |
| 4060 | goto out; |
| 4061 | status = decode_putfh(&xdr); |
| 4062 | if (status) |
| 4063 | goto out; |
| 4064 | status = decode_lockt(&xdr, res); |
| 4065 | out: |
| 4066 | return status; |
| 4067 | } |
| 4068 | |
| 4069 | /* |
| 4070 | * Decode LOCKU response |
| 4071 | */ |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4072 | static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_locku_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4073 | { |
| 4074 | struct xdr_stream xdr; |
| 4075 | struct compound_hdr hdr; |
| 4076 | int status; |
| 4077 | |
| 4078 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4079 | status = decode_compound_hdr(&xdr, &hdr); |
| 4080 | if (status) |
| 4081 | goto out; |
| 4082 | status = decode_putfh(&xdr); |
| 4083 | if (status) |
| 4084 | goto out; |
| 4085 | status = decode_locku(&xdr, res); |
| 4086 | out: |
| 4087 | return status; |
| 4088 | } |
| 4089 | |
| 4090 | /* |
| 4091 | * Decode READLINK response |
| 4092 | */ |
| 4093 | static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res) |
| 4094 | { |
| 4095 | struct xdr_stream xdr; |
| 4096 | struct compound_hdr hdr; |
| 4097 | int status; |
| 4098 | |
| 4099 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4100 | status = decode_compound_hdr(&xdr, &hdr); |
| 4101 | if (status) |
| 4102 | goto out; |
| 4103 | status = decode_putfh(&xdr); |
| 4104 | if (status) |
| 4105 | goto out; |
| 4106 | status = decode_readlink(&xdr, rqstp); |
| 4107 | out: |
| 4108 | return status; |
| 4109 | } |
| 4110 | |
| 4111 | /* |
| 4112 | * Decode READDIR response |
| 4113 | */ |
| 4114 | static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res) |
| 4115 | { |
| 4116 | struct xdr_stream xdr; |
| 4117 | struct compound_hdr hdr; |
| 4118 | int status; |
| 4119 | |
| 4120 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4121 | status = decode_compound_hdr(&xdr, &hdr); |
| 4122 | if (status) |
| 4123 | goto out; |
| 4124 | status = decode_putfh(&xdr); |
| 4125 | if (status) |
| 4126 | goto out; |
| 4127 | status = decode_readdir(&xdr, rqstp, res); |
| 4128 | out: |
| 4129 | return status; |
| 4130 | } |
| 4131 | |
| 4132 | /* |
| 4133 | * Decode Read response |
| 4134 | */ |
| 4135 | static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res) |
| 4136 | { |
| 4137 | struct xdr_stream xdr; |
| 4138 | struct compound_hdr hdr; |
| 4139 | int status; |
| 4140 | |
| 4141 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4142 | status = decode_compound_hdr(&xdr, &hdr); |
| 4143 | if (status) |
| 4144 | goto out; |
| 4145 | status = decode_putfh(&xdr); |
| 4146 | if (status) |
| 4147 | goto out; |
| 4148 | status = decode_read(&xdr, rqstp, res); |
| 4149 | if (!status) |
| 4150 | status = res->count; |
| 4151 | out: |
| 4152 | return status; |
| 4153 | } |
| 4154 | |
| 4155 | /* |
| 4156 | * Decode WRITE response |
| 4157 | */ |
| 4158 | static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res) |
| 4159 | { |
| 4160 | struct xdr_stream xdr; |
| 4161 | struct compound_hdr hdr; |
| 4162 | int status; |
| 4163 | |
| 4164 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4165 | status = decode_compound_hdr(&xdr, &hdr); |
| 4166 | if (status) |
| 4167 | goto out; |
| 4168 | status = decode_putfh(&xdr); |
| 4169 | if (status) |
| 4170 | goto out; |
| 4171 | status = decode_write(&xdr, res); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4172 | if (status) |
| 4173 | goto out; |
| 4174 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | if (!status) |
| 4176 | status = res->count; |
| 4177 | out: |
| 4178 | return status; |
| 4179 | } |
| 4180 | |
| 4181 | /* |
| 4182 | * Decode COMMIT response |
| 4183 | */ |
| 4184 | static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res) |
| 4185 | { |
| 4186 | struct xdr_stream xdr; |
| 4187 | struct compound_hdr hdr; |
| 4188 | int status; |
| 4189 | |
| 4190 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4191 | status = decode_compound_hdr(&xdr, &hdr); |
| 4192 | if (status) |
| 4193 | goto out; |
| 4194 | status = decode_putfh(&xdr); |
| 4195 | if (status) |
| 4196 | goto out; |
| 4197 | status = decode_commit(&xdr, res); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4198 | if (status) |
| 4199 | goto out; |
| 4200 | decode_getfattr(&xdr, res->fattr, res->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | out: |
| 4202 | return status; |
| 4203 | } |
| 4204 | |
| 4205 | /* |
| 4206 | * FSINFO request |
| 4207 | */ |
| 4208 | static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo) |
| 4209 | { |
| 4210 | struct xdr_stream xdr; |
| 4211 | struct compound_hdr hdr; |
| 4212 | int status; |
| 4213 | |
| 4214 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 4215 | status = decode_compound_hdr(&xdr, &hdr); |
| 4216 | if (!status) |
| 4217 | status = decode_putfh(&xdr); |
| 4218 | if (!status) |
| 4219 | status = decode_fsinfo(&xdr, fsinfo); |
| 4220 | if (!status) |
| 4221 | status = -nfs_stat_to_errno(hdr.status); |
| 4222 | return status; |
| 4223 | } |
| 4224 | |
| 4225 | /* |
| 4226 | * PATHCONF request |
| 4227 | */ |
| 4228 | static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf) |
| 4229 | { |
| 4230 | struct xdr_stream xdr; |
| 4231 | struct compound_hdr hdr; |
| 4232 | int status; |
| 4233 | |
| 4234 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 4235 | status = decode_compound_hdr(&xdr, &hdr); |
| 4236 | if (!status) |
| 4237 | status = decode_putfh(&xdr); |
| 4238 | if (!status) |
| 4239 | status = decode_pathconf(&xdr, pathconf); |
| 4240 | return status; |
| 4241 | } |
| 4242 | |
| 4243 | /* |
| 4244 | * STATFS request |
| 4245 | */ |
| 4246 | static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat) |
| 4247 | { |
| 4248 | struct xdr_stream xdr; |
| 4249 | struct compound_hdr hdr; |
| 4250 | int status; |
| 4251 | |
| 4252 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 4253 | status = decode_compound_hdr(&xdr, &hdr); |
| 4254 | if (!status) |
| 4255 | status = decode_putfh(&xdr); |
| 4256 | if (!status) |
| 4257 | status = decode_statfs(&xdr, fsstat); |
| 4258 | return status; |
| 4259 | } |
| 4260 | |
| 4261 | /* |
| 4262 | * GETATTR_BITMAP request |
| 4263 | */ |
| 4264 | static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res) |
| 4265 | { |
| 4266 | struct xdr_stream xdr; |
| 4267 | struct compound_hdr hdr; |
| 4268 | int status; |
| 4269 | |
| 4270 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 4271 | if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) |
| 4272 | goto out; |
| 4273 | if ((status = decode_putfh(&xdr)) != 0) |
| 4274 | goto out; |
| 4275 | status = decode_server_caps(&xdr, res); |
| 4276 | out: |
| 4277 | return status; |
| 4278 | } |
| 4279 | |
| 4280 | /* |
| 4281 | * Decode RENEW response |
| 4282 | */ |
| 4283 | static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy) |
| 4284 | { |
| 4285 | struct xdr_stream xdr; |
| 4286 | struct compound_hdr hdr; |
| 4287 | int status; |
| 4288 | |
| 4289 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4290 | status = decode_compound_hdr(&xdr, &hdr); |
| 4291 | if (!status) |
| 4292 | status = decode_renew(&xdr); |
| 4293 | return status; |
| 4294 | } |
| 4295 | |
| 4296 | /* |
| 4297 | * a SETCLIENTID request |
| 4298 | */ |
| 4299 | static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p, |
| 4300 | struct nfs4_client *clp) |
| 4301 | { |
| 4302 | struct xdr_stream xdr; |
| 4303 | struct compound_hdr hdr; |
| 4304 | int status; |
| 4305 | |
| 4306 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 4307 | status = decode_compound_hdr(&xdr, &hdr); |
| 4308 | if (!status) |
| 4309 | status = decode_setclientid(&xdr, clp); |
| 4310 | if (!status) |
| 4311 | status = -nfs_stat_to_errno(hdr.status); |
| 4312 | return status; |
| 4313 | } |
| 4314 | |
| 4315 | /* |
| 4316 | * a SETCLIENTID_CONFIRM request |
| 4317 | */ |
| 4318 | static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo) |
| 4319 | { |
| 4320 | struct xdr_stream xdr; |
| 4321 | struct compound_hdr hdr; |
| 4322 | int status; |
| 4323 | |
| 4324 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 4325 | status = decode_compound_hdr(&xdr, &hdr); |
| 4326 | if (!status) |
| 4327 | status = decode_setclientid_confirm(&xdr); |
| 4328 | if (!status) |
| 4329 | status = decode_putrootfh(&xdr); |
| 4330 | if (!status) |
| 4331 | status = decode_fsinfo(&xdr, fsinfo); |
| 4332 | if (!status) |
| 4333 | status = -nfs_stat_to_errno(hdr.status); |
| 4334 | return status; |
| 4335 | } |
| 4336 | |
| 4337 | /* |
| 4338 | * DELEGRETURN request |
| 4339 | */ |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4340 | static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_delegreturnres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | { |
| 4342 | struct xdr_stream xdr; |
| 4343 | struct compound_hdr hdr; |
| 4344 | int status; |
| 4345 | |
| 4346 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 4347 | status = decode_compound_hdr(&xdr, &hdr); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4348 | if (status != 0) |
| 4349 | goto out; |
| 4350 | status = decode_putfh(&xdr); |
| 4351 | if (status != 0) |
| 4352 | goto out; |
| 4353 | status = decode_delegreturn(&xdr); |
| 4354 | decode_getfattr(&xdr, res->fattr, res->server); |
| 4355 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | return status; |
| 4357 | } |
| 4358 | |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4359 | /* |
| 4360 | * FS_LOCATIONS request |
| 4361 | */ |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame^] | 4362 | static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, uint32_t *p, struct nfs4_fs_locations *res) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4363 | { |
| 4364 | struct xdr_stream xdr; |
| 4365 | struct compound_hdr hdr; |
| 4366 | int status; |
| 4367 | |
| 4368 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 4369 | status = decode_compound_hdr(&xdr, &hdr); |
| 4370 | if (status != 0) |
| 4371 | goto out; |
| 4372 | if ((status = decode_putfh(&xdr)) != 0) |
| 4373 | goto out; |
| 4374 | if ((status = decode_lookup(&xdr)) != 0) |
| 4375 | goto out; |
| 4376 | xdr_enter_page(&xdr, PAGE_SIZE); |
| 4377 | status = decode_getfattr(&xdr, &res->fattr, res->server); |
| 4378 | out: |
| 4379 | return status; |
| 4380 | } |
| 4381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus) |
| 4383 | { |
| 4384 | uint32_t bitmap[2] = {0}; |
| 4385 | uint32_t len; |
| 4386 | |
| 4387 | if (!*p++) { |
| 4388 | if (!*p) |
| 4389 | return ERR_PTR(-EAGAIN); |
| 4390 | entry->eof = 1; |
| 4391 | return ERR_PTR(-EBADCOOKIE); |
| 4392 | } |
| 4393 | |
| 4394 | entry->prev_cookie = entry->cookie; |
| 4395 | p = xdr_decode_hyper(p, &entry->cookie); |
| 4396 | entry->len = ntohl(*p++); |
| 4397 | entry->name = (const char *) p; |
| 4398 | p += XDR_QUADLEN(entry->len); |
| 4399 | |
| 4400 | /* |
| 4401 | * In case the server doesn't return an inode number, |
| 4402 | * we fake one here. (We don't use inode number 0, |
| 4403 | * since glibc seems to choke on it...) |
| 4404 | */ |
| 4405 | entry->ino = 1; |
| 4406 | |
| 4407 | len = ntohl(*p++); /* bitmap length */ |
| 4408 | if (len-- > 0) { |
| 4409 | bitmap[0] = ntohl(*p++); |
| 4410 | if (len-- > 0) { |
| 4411 | bitmap[1] = ntohl(*p++); |
| 4412 | p += len; |
| 4413 | } |
| 4414 | } |
| 4415 | len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */ |
| 4416 | if (len > 0) { |
Manoj Naik | 97d312d | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4417 | if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) { |
| 4418 | bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; |
| 4419 | /* Ignore the return value of rdattr_error for now */ |
| 4420 | p++; |
| 4421 | len--; |
| 4422 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 4424 | xdr_decode_hyper(p, &entry->ino); |
| 4425 | else if (bitmap[0] == FATTR4_WORD0_FILEID) |
| 4426 | xdr_decode_hyper(p, &entry->ino); |
| 4427 | p += len; |
| 4428 | } |
| 4429 | |
| 4430 | entry->eof = !p[0] && p[1]; |
| 4431 | return p; |
| 4432 | } |
| 4433 | |
| 4434 | /* |
| 4435 | * We need to translate between nfs status return values and |
| 4436 | * the local errno values which may not be the same. |
| 4437 | */ |
| 4438 | static struct { |
| 4439 | int stat; |
| 4440 | int errno; |
| 4441 | } nfs_errtbl[] = { |
| 4442 | { NFS4_OK, 0 }, |
| 4443 | { NFS4ERR_PERM, EPERM }, |
| 4444 | { NFS4ERR_NOENT, ENOENT }, |
| 4445 | { NFS4ERR_IO, errno_NFSERR_IO }, |
| 4446 | { NFS4ERR_NXIO, ENXIO }, |
| 4447 | { NFS4ERR_ACCESS, EACCES }, |
| 4448 | { NFS4ERR_EXIST, EEXIST }, |
| 4449 | { NFS4ERR_XDEV, EXDEV }, |
| 4450 | { NFS4ERR_NOTDIR, ENOTDIR }, |
| 4451 | { NFS4ERR_ISDIR, EISDIR }, |
| 4452 | { NFS4ERR_INVAL, EINVAL }, |
| 4453 | { NFS4ERR_FBIG, EFBIG }, |
| 4454 | { NFS4ERR_NOSPC, ENOSPC }, |
| 4455 | { NFS4ERR_ROFS, EROFS }, |
| 4456 | { NFS4ERR_MLINK, EMLINK }, |
| 4457 | { NFS4ERR_NAMETOOLONG, ENAMETOOLONG }, |
| 4458 | { NFS4ERR_NOTEMPTY, ENOTEMPTY }, |
| 4459 | { NFS4ERR_DQUOT, EDQUOT }, |
| 4460 | { NFS4ERR_STALE, ESTALE }, |
| 4461 | { NFS4ERR_BADHANDLE, EBADHANDLE }, |
Manoj Naik | 6ebf365 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4462 | { NFS4ERR_BADOWNER, EINVAL }, |
| 4463 | { NFS4ERR_BADNAME, EINVAL }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | { NFS4ERR_BAD_COOKIE, EBADCOOKIE }, |
| 4465 | { NFS4ERR_NOTSUPP, ENOTSUPP }, |
| 4466 | { NFS4ERR_TOOSMALL, ETOOSMALL }, |
| 4467 | { NFS4ERR_SERVERFAULT, ESERVERFAULT }, |
| 4468 | { NFS4ERR_BADTYPE, EBADTYPE }, |
| 4469 | { NFS4ERR_LOCKED, EAGAIN }, |
| 4470 | { NFS4ERR_RESOURCE, EREMOTEIO }, |
| 4471 | { NFS4ERR_SYMLINK, ELOOP }, |
| 4472 | { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP }, |
| 4473 | { NFS4ERR_DEADLOCK, EDEADLK }, |
| 4474 | { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs |
| 4475 | * to be handled by a |
| 4476 | * middle-layer. |
| 4477 | */ |
| 4478 | { -1, EIO } |
| 4479 | }; |
| 4480 | |
| 4481 | /* |
| 4482 | * Convert an NFS error code to a local one. |
| 4483 | * This one is used jointly by NFSv2 and NFSv3. |
| 4484 | */ |
| 4485 | static int |
| 4486 | nfs_stat_to_errno(int stat) |
| 4487 | { |
| 4488 | int i; |
| 4489 | for (i = 0; nfs_errtbl[i].stat != -1; i++) { |
| 4490 | if (nfs_errtbl[i].stat == stat) |
| 4491 | return nfs_errtbl[i].errno; |
| 4492 | } |
| 4493 | if (stat <= 10000 || stat > 10100) { |
| 4494 | /* The server is looney tunes. */ |
| 4495 | return ESERVERFAULT; |
| 4496 | } |
| 4497 | /* If we cannot translate the error, the recovery routines should |
| 4498 | * handle it. |
| 4499 | * Note: remaining NFSv4 error codes have values > 10000, so should |
| 4500 | * not conflict with native Linux error codes. |
| 4501 | */ |
| 4502 | return stat; |
| 4503 | } |
| 4504 | |
| 4505 | #ifndef MAX |
| 4506 | # define MAX(a, b) (((a) > (b))? (a) : (b)) |
| 4507 | #endif |
| 4508 | |
| 4509 | #define PROC(proc, argtype, restype) \ |
| 4510 | [NFSPROC4_CLNT_##proc] = { \ |
| 4511 | .p_proc = NFSPROC4_COMPOUND, \ |
| 4512 | .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \ |
| 4513 | .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \ |
| 4514 | .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \ |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 4515 | .p_statidx = NFSPROC4_CLNT_##proc, \ |
| 4516 | .p_name = #proc, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | struct rpc_procinfo nfs4_procedures[] = { |
| 4520 | PROC(READ, enc_read, dec_read), |
| 4521 | PROC(WRITE, enc_write, dec_write), |
| 4522 | PROC(COMMIT, enc_commit, dec_commit), |
| 4523 | PROC(OPEN, enc_open, dec_open), |
| 4524 | PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), |
| 4525 | PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), |
| 4526 | PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), |
| 4527 | PROC(CLOSE, enc_close, dec_close), |
| 4528 | PROC(SETATTR, enc_setattr, dec_setattr), |
| 4529 | PROC(FSINFO, enc_fsinfo, dec_fsinfo), |
| 4530 | PROC(RENEW, enc_renew, dec_renew), |
| 4531 | PROC(SETCLIENTID, enc_setclientid, dec_setclientid), |
| 4532 | PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), |
| 4533 | PROC(LOCK, enc_lock, dec_lock), |
| 4534 | PROC(LOCKT, enc_lockt, dec_lockt), |
| 4535 | PROC(LOCKU, enc_locku, dec_locku), |
| 4536 | PROC(ACCESS, enc_access, dec_access), |
| 4537 | PROC(GETATTR, enc_getattr, dec_getattr), |
| 4538 | PROC(LOOKUP, enc_lookup, dec_lookup), |
| 4539 | PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), |
| 4540 | PROC(REMOVE, enc_remove, dec_remove), |
| 4541 | PROC(RENAME, enc_rename, dec_rename), |
| 4542 | PROC(LINK, enc_link, dec_link), |
| 4543 | PROC(SYMLINK, enc_symlink, dec_symlink), |
| 4544 | PROC(CREATE, enc_create, dec_create), |
| 4545 | PROC(PATHCONF, enc_pathconf, dec_pathconf), |
| 4546 | PROC(STATFS, enc_statfs, dec_statfs), |
| 4547 | PROC(READLINK, enc_readlink, dec_readlink), |
| 4548 | PROC(READDIR, enc_readdir, dec_readdir), |
| 4549 | PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), |
| 4550 | PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), |
J. Bruce Fields | 029d105 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4551 | PROC(GETACL, enc_getacl, dec_getacl), |
J. Bruce Fields | 23ec696 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4552 | PROC(SETACL, enc_setacl, dec_setacl), |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4553 | PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | }; |
| 4555 | |
| 4556 | struct rpc_version nfs_version4 = { |
| 4557 | .number = 4, |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 4558 | .nrprocs = ARRAY_SIZE(nfs4_procedures), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | .procs = nfs4_procedures |
| 4560 | }; |
| 4561 | |
| 4562 | /* |
| 4563 | * Local variables: |
| 4564 | * c-basic-offset: 8 |
| 4565 | * End: |
| 4566 | */ |