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