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