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