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