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