Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/nfs2xdr.c |
| 3 | * |
| 4 | * XDR functions to encode/decode NFS RPC arguments and results. |
| 5 | * |
| 6 | * Copyright (C) 1992, 1993, 1994 Rick Sladkey |
| 7 | * Copyright (C) 1996 Olaf Kirch |
| 8 | * 04 Aug 1998 Ion Badulescu <ionut@cs.columbia.edu> |
| 9 | * FIFO's need special handling in NFSv2 |
| 10 | */ |
| 11 | |
| 12 | #include <linux/param.h> |
| 13 | #include <linux/time.h> |
| 14 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/errno.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/in.h> |
| 18 | #include <linux/pagemap.h> |
| 19 | #include <linux/proc_fs.h> |
| 20 | #include <linux/sunrpc/clnt.h> |
| 21 | #include <linux/nfs.h> |
| 22 | #include <linux/nfs2.h> |
| 23 | #include <linux/nfs_fs.h> |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 24 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #define NFSDBG_FACILITY NFSDBG_XDR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | /* Mapping from NFS error code to "errno" error code. */ |
| 29 | #define errno_NFSERR_IO EIO |
| 30 | |
| 31 | /* |
| 32 | * Declare the space requirements for NFS arguments and replies as |
| 33 | * number of 32bit-words |
| 34 | */ |
| 35 | #define NFS_fhandle_sz (8) |
| 36 | #define NFS_sattr_sz (8) |
| 37 | #define NFS_filename_sz (1+(NFS2_MAXNAMLEN>>2)) |
| 38 | #define NFS_path_sz (1+(NFS2_MAXPATHLEN>>2)) |
| 39 | #define NFS_fattr_sz (17) |
| 40 | #define NFS_info_sz (5) |
| 41 | #define NFS_entry_sz (NFS_filename_sz+3) |
| 42 | |
| 43 | #define NFS_diropargs_sz (NFS_fhandle_sz+NFS_filename_sz) |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 44 | #define NFS_removeargs_sz (NFS_fhandle_sz+NFS_filename_sz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define NFS_sattrargs_sz (NFS_fhandle_sz+NFS_sattr_sz) |
| 46 | #define NFS_readlinkargs_sz (NFS_fhandle_sz) |
| 47 | #define NFS_readargs_sz (NFS_fhandle_sz+3) |
| 48 | #define NFS_writeargs_sz (NFS_fhandle_sz+4) |
| 49 | #define NFS_createargs_sz (NFS_diropargs_sz+NFS_sattr_sz) |
| 50 | #define NFS_renameargs_sz (NFS_diropargs_sz+NFS_diropargs_sz) |
| 51 | #define NFS_linkargs_sz (NFS_fhandle_sz+NFS_diropargs_sz) |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 52 | #define NFS_symlinkargs_sz (NFS_diropargs_sz+1+NFS_sattr_sz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define NFS_readdirargs_sz (NFS_fhandle_sz+2) |
| 54 | |
| 55 | #define NFS_attrstat_sz (1+NFS_fattr_sz) |
| 56 | #define NFS_diropres_sz (1+NFS_fhandle_sz+NFS_fattr_sz) |
| 57 | #define NFS_readlinkres_sz (2) |
| 58 | #define NFS_readres_sz (1+NFS_fattr_sz+1) |
| 59 | #define NFS_writeres_sz (NFS_attrstat_sz) |
| 60 | #define NFS_stat_sz (1) |
| 61 | #define NFS_readdirres_sz (1) |
| 62 | #define NFS_statfsres_sz (1+NFS_info_sz) |
| 63 | |
| 64 | /* |
| 65 | * Common NFS XDR functions as inlines |
| 66 | */ |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 67 | static inline __be32 * |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 68 | xdr_encode_fhandle(__be32 *p, const struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
| 70 | memcpy(p, fhandle->data, NFS2_FHSIZE); |
| 71 | return p + XDR_QUADLEN(NFS2_FHSIZE); |
| 72 | } |
| 73 | |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 74 | static inline __be32 * |
| 75 | xdr_decode_fhandle(__be32 *p, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
| 77 | /* NFSv2 handles have a fixed length */ |
| 78 | fhandle->size = NFS2_FHSIZE; |
| 79 | memcpy(fhandle->data, p, NFS2_FHSIZE); |
| 80 | return p + XDR_QUADLEN(NFS2_FHSIZE); |
| 81 | } |
| 82 | |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 83 | static inline __be32* |
| 84 | xdr_encode_time(__be32 *p, struct timespec *timep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
| 86 | *p++ = htonl(timep->tv_sec); |
| 87 | /* Convert nanoseconds into microseconds */ |
| 88 | *p++ = htonl(timep->tv_nsec ? timep->tv_nsec / 1000 : 0); |
| 89 | return p; |
| 90 | } |
| 91 | |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 92 | static inline __be32* |
| 93 | xdr_encode_current_server_time(__be32 *p, struct timespec *timep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
| 95 | /* |
| 96 | * Passing the invalid value useconds=1000000 is a |
| 97 | * Sun convention for "set to current server time". |
| 98 | * It's needed to make permissions checks for the |
| 99 | * "touch" program across v2 mounts to Solaris and |
| 100 | * Irix boxes work correctly. See description of |
| 101 | * sattr in section 6.1 of "NFS Illustrated" by |
| 102 | * Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5 |
| 103 | */ |
| 104 | *p++ = htonl(timep->tv_sec); |
| 105 | *p++ = htonl(1000000); |
| 106 | return p; |
| 107 | } |
| 108 | |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 109 | static inline __be32* |
| 110 | xdr_decode_time(__be32 *p, struct timespec *timep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { |
| 112 | timep->tv_sec = ntohl(*p++); |
| 113 | /* Convert microseconds into nanoseconds */ |
| 114 | timep->tv_nsec = ntohl(*p++) * 1000; |
| 115 | return p; |
| 116 | } |
| 117 | |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 118 | static __be32 * |
| 119 | xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
Trond Myklebust | bca7947 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 121 | u32 rdev, type; |
| 122 | type = ntohl(*p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | fattr->mode = ntohl(*p++); |
| 124 | fattr->nlink = ntohl(*p++); |
| 125 | fattr->uid = ntohl(*p++); |
| 126 | fattr->gid = ntohl(*p++); |
| 127 | fattr->size = ntohl(*p++); |
| 128 | fattr->du.nfs2.blocksize = ntohl(*p++); |
| 129 | rdev = ntohl(*p++); |
| 130 | fattr->du.nfs2.blocks = ntohl(*p++); |
Trond Myklebust | 8b4bdcf | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 131 | fattr->fsid.major = ntohl(*p++); |
| 132 | fattr->fsid.minor = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | fattr->fileid = ntohl(*p++); |
| 134 | p = xdr_decode_time(p, &fattr->atime); |
| 135 | p = xdr_decode_time(p, &fattr->mtime); |
| 136 | p = xdr_decode_time(p, &fattr->ctime); |
Trond Myklebust | 9e6e70f | 2009-03-11 14:10:24 -0400 | [diff] [blame] | 137 | fattr->valid |= NFS_ATTR_FATTR_V2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | fattr->rdev = new_decode_dev(rdev); |
Trond Myklebust | bca7947 | 2009-03-11 14:10:26 -0400 | [diff] [blame] | 139 | if (type == NFCHR && rdev == NFS2_FIFO_DEV) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO; |
| 141 | fattr->rdev = 0; |
| 142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return p; |
| 144 | } |
| 145 | |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 146 | static inline __be32 * |
| 147 | xdr_encode_sattr(__be32 *p, struct iattr *attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 149 | const __be32 not_set = __constant_htonl(0xFFFFFFFF); |
Trond Myklebust | eadb8c1 | 2006-01-03 09:55:54 +0100 | [diff] [blame] | 150 | |
| 151 | *p++ = (attr->ia_valid & ATTR_MODE) ? htonl(attr->ia_mode) : not_set; |
| 152 | *p++ = (attr->ia_valid & ATTR_UID) ? htonl(attr->ia_uid) : not_set; |
| 153 | *p++ = (attr->ia_valid & ATTR_GID) ? htonl(attr->ia_gid) : not_set; |
| 154 | *p++ = (attr->ia_valid & ATTR_SIZE) ? htonl(attr->ia_size) : not_set; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | if (attr->ia_valid & ATTR_ATIME_SET) { |
| 157 | p = xdr_encode_time(p, &attr->ia_atime); |
| 158 | } else if (attr->ia_valid & ATTR_ATIME) { |
| 159 | p = xdr_encode_current_server_time(p, &attr->ia_atime); |
| 160 | } else { |
Trond Myklebust | eadb8c1 | 2006-01-03 09:55:54 +0100 | [diff] [blame] | 161 | *p++ = not_set; |
| 162 | *p++ = not_set; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | if (attr->ia_valid & ATTR_MTIME_SET) { |
| 166 | p = xdr_encode_time(p, &attr->ia_mtime); |
| 167 | } else if (attr->ia_valid & ATTR_MTIME) { |
| 168 | p = xdr_encode_current_server_time(p, &attr->ia_mtime); |
| 169 | } else { |
Trond Myklebust | eadb8c1 | 2006-01-03 09:55:54 +0100 | [diff] [blame] | 170 | *p++ = not_set; |
| 171 | *p++ = not_set; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | return p; |
| 174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * NFS encode functions |
| 178 | */ |
| 179 | /* |
| 180 | * Encode file handle argument |
| 181 | * GETATTR, READLINK, STATFS |
| 182 | */ |
| 183 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 184 | nfs_xdr_fhandle(struct rpc_rqst *req, __be32 *p, struct nfs_fh *fh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
| 186 | p = xdr_encode_fhandle(p, fh); |
| 187 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | * Encode SETATTR arguments |
| 193 | */ |
| 194 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 195 | nfs_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs_sattrargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | p = xdr_encode_fhandle(p, args->fh); |
| 198 | p = xdr_encode_sattr(p, args->sattr); |
| 199 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * Encode directory ops argument |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 205 | * LOOKUP, RMDIR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | */ |
| 207 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 208 | nfs_xdr_diropargs(struct rpc_rqst *req, __be32 *p, struct nfs_diropargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
| 210 | p = xdr_encode_fhandle(p, args->fh); |
| 211 | p = xdr_encode_array(p, args->name, args->len); |
| 212 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | /* |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 217 | * Encode REMOVE argument |
| 218 | */ |
| 219 | static int |
| 220 | nfs_xdr_removeargs(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args) |
| 221 | { |
| 222 | p = xdr_encode_fhandle(p, args->fh); |
| 223 | p = xdr_encode_array(p, args->name.name, args->name.len); |
| 224 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | * Arguments to a READ call. Since we read data directly into the page |
| 230 | * cache, we also set up the reply iovec here so that iov[1] points |
| 231 | * exactly to the page we want to fetch. |
| 232 | */ |
| 233 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 234 | nfs_xdr_readargs(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
Trond Myklebust | a17c215 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 236 | struct rpc_auth *auth = req->rq_cred->cr_auth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | unsigned int replen; |
| 238 | u32 offset = (u32)args->offset; |
| 239 | u32 count = args->count; |
| 240 | |
| 241 | p = xdr_encode_fhandle(p, args->fh); |
| 242 | *p++ = htonl(offset); |
| 243 | *p++ = htonl(count); |
| 244 | *p++ = htonl(count); |
| 245 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 246 | |
| 247 | /* Inline the page array */ |
| 248 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS_readres_sz) << 2; |
| 249 | xdr_inline_pages(&req->rq_rcv_buf, replen, |
| 250 | args->pages, args->pgbase, count); |
\"Talpey, Thomas\ | 4f22ccc | 2007-09-10 13:44:58 -0400 | [diff] [blame] | 251 | req->rq_rcv_buf.flags |= XDRBUF_READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Decode READ reply |
| 257 | */ |
| 258 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 259 | nfs_xdr_readres(struct rpc_rqst *req, __be32 *p, struct nfs_readres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
| 261 | struct kvec *iov = req->rq_rcv_buf.head; |
Chuck Lever | 6232dbb | 2007-10-26 13:31:52 -0400 | [diff] [blame] | 262 | size_t hdrlen; |
| 263 | u32 count, recvd; |
| 264 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
| 266 | if ((status = ntohl(*p++))) |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 267 | return nfs_stat_to_errno(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | p = xdr_decode_fattr(p, res->fattr); |
| 269 | |
| 270 | count = ntohl(*p++); |
| 271 | res->eof = 0; |
| 272 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; |
| 273 | if (iov->iov_len < hdrlen) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 274 | dprintk("NFS: READ reply header overflowed:" |
Chuck Lever | 6232dbb | 2007-10-26 13:31:52 -0400 | [diff] [blame] | 275 | "length %Zu > %Zu\n", hdrlen, iov->iov_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | return -errno_NFSERR_IO; |
| 277 | } else if (iov->iov_len != hdrlen) { |
| 278 | dprintk("NFS: READ header is short. iovec will be shifted.\n"); |
| 279 | xdr_shift_buf(&req->rq_rcv_buf, iov->iov_len - hdrlen); |
| 280 | } |
| 281 | |
| 282 | recvd = req->rq_rcv_buf.len - hdrlen; |
| 283 | if (count > recvd) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 284 | dprintk("NFS: server cheating in read reply: " |
Chuck Lever | 6232dbb | 2007-10-26 13:31:52 -0400 | [diff] [blame] | 285 | "count %u > recvd %u\n", count, recvd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | count = recvd; |
| 287 | } |
| 288 | |
Chuck Lever | 6232dbb | 2007-10-26 13:31:52 -0400 | [diff] [blame] | 289 | dprintk("RPC: readres OK count %u\n", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | if (count < res->count) |
| 291 | res->count = count; |
| 292 | |
| 293 | return count; |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /* |
| 298 | * Write arguments. Splice the buffer to be written into the iovec. |
| 299 | */ |
| 300 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 301 | nfs_xdr_writeargs(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
| 303 | struct xdr_buf *sndbuf = &req->rq_snd_buf; |
| 304 | u32 offset = (u32)args->offset; |
| 305 | u32 count = args->count; |
| 306 | |
| 307 | p = xdr_encode_fhandle(p, args->fh); |
| 308 | *p++ = htonl(offset); |
| 309 | *p++ = htonl(offset); |
| 310 | *p++ = htonl(count); |
| 311 | *p++ = htonl(count); |
| 312 | sndbuf->len = xdr_adjust_iovec(sndbuf->head, p); |
| 313 | |
| 314 | /* Copy the page array */ |
| 315 | xdr_encode_pages(sndbuf, args->pages, args->pgbase, count); |
\"Talpey, Thomas\ | 4f22ccc | 2007-09-10 13:44:58 -0400 | [diff] [blame] | 316 | sndbuf->flags |= XDRBUF_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * Encode create arguments |
| 322 | * CREATE, MKDIR |
| 323 | */ |
| 324 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 325 | nfs_xdr_createargs(struct rpc_rqst *req, __be32 *p, struct nfs_createargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
| 327 | p = xdr_encode_fhandle(p, args->fh); |
| 328 | p = xdr_encode_array(p, args->name, args->len); |
| 329 | p = xdr_encode_sattr(p, args->sattr); |
| 330 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | * Encode RENAME arguments |
| 336 | */ |
| 337 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 338 | nfs_xdr_renameargs(struct rpc_rqst *req, __be32 *p, struct nfs_renameargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 340 | p = xdr_encode_fhandle(p, args->old_dir); |
| 341 | p = xdr_encode_array(p, args->old_name->name, args->old_name->len); |
| 342 | p = xdr_encode_fhandle(p, args->new_dir); |
| 343 | p = xdr_encode_array(p, args->new_name->name, args->new_name->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | /* |
| 349 | * Encode LINK arguments |
| 350 | */ |
| 351 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 352 | nfs_xdr_linkargs(struct rpc_rqst *req, __be32 *p, struct nfs_linkargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
| 354 | p = xdr_encode_fhandle(p, args->fromfh); |
| 355 | p = xdr_encode_fhandle(p, args->tofh); |
| 356 | p = xdr_encode_array(p, args->toname, args->tolen); |
| 357 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * Encode SYMLINK arguments |
| 363 | */ |
| 364 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 365 | nfs_xdr_symlinkargs(struct rpc_rqst *req, __be32 *p, struct nfs_symlinkargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | { |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 367 | struct xdr_buf *sndbuf = &req->rq_snd_buf; |
| 368 | size_t pad; |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | p = xdr_encode_fhandle(p, args->fromfh); |
| 371 | p = xdr_encode_array(p, args->fromname, args->fromlen); |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 372 | *p++ = htonl(args->pathlen); |
| 373 | sndbuf->len = xdr_adjust_iovec(sndbuf->head, p); |
| 374 | |
| 375 | xdr_encode_pages(sndbuf, args->pages, 0, args->pathlen); |
| 376 | |
| 377 | /* |
| 378 | * xdr_encode_pages may have added a few bytes to ensure the |
| 379 | * pathname ends on a 4-byte boundary. Start encoding the |
| 380 | * attributes after the pad bytes. |
| 381 | */ |
| 382 | pad = sndbuf->tail->iov_len; |
| 383 | if (pad > 0) |
| 384 | p++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | p = xdr_encode_sattr(p, args->sattr); |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 386 | sndbuf->len += xdr_adjust_iovec(sndbuf->tail, p) - pad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * Encode arguments to readdir call |
| 392 | */ |
| 393 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 394 | nfs_xdr_readdirargs(struct rpc_rqst *req, __be32 *p, struct nfs_readdirargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
Trond Myklebust | a17c215 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 396 | struct rpc_auth *auth = req->rq_cred->cr_auth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | unsigned int replen; |
| 398 | u32 count = args->count; |
| 399 | |
| 400 | p = xdr_encode_fhandle(p, args->fh); |
| 401 | *p++ = htonl(args->cookie); |
| 402 | *p++ = htonl(count); /* see above */ |
| 403 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 404 | |
| 405 | /* Inline the page array */ |
| 406 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS_readdirres_sz) << 2; |
| 407 | xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, 0, count); |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * Decode the result of a readdir call. |
| 413 | * We're not really decoding anymore, we just leave the buffer untouched |
| 414 | * and only check that it is syntactically correct. |
| 415 | * The real decoding happens in nfs_decode_entry below, called directly |
| 416 | * from nfs_readdir for each entry. |
| 417 | */ |
| 418 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 419 | nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
| 421 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; |
| 422 | struct kvec *iov = rcvbuf->head; |
| 423 | struct page **page; |
Chuck Lever | 6232dbb | 2007-10-26 13:31:52 -0400 | [diff] [blame] | 424 | size_t hdrlen; |
| 425 | unsigned int pglen, recvd; |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 426 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
| 428 | if ((status = ntohl(*p++))) |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 429 | return nfs_stat_to_errno(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; |
| 432 | if (iov->iov_len < hdrlen) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 433 | dprintk("NFS: READDIR reply header overflowed:" |
Chuck Lever | 6232dbb | 2007-10-26 13:31:52 -0400 | [diff] [blame] | 434 | "length %Zu > %Zu\n", hdrlen, iov->iov_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | return -errno_NFSERR_IO; |
| 436 | } else if (iov->iov_len != hdrlen) { |
| 437 | dprintk("NFS: READDIR header is short. iovec will be shifted.\n"); |
| 438 | xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen); |
| 439 | } |
| 440 | |
| 441 | pglen = rcvbuf->page_len; |
| 442 | recvd = rcvbuf->len - hdrlen; |
| 443 | if (pglen > recvd) |
| 444 | pglen = recvd; |
| 445 | page = rcvbuf->pages; |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 446 | return pglen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Bryan Schumaker | babddc7 | 2010-10-20 15:44:29 -0400 | [diff] [blame] | 449 | static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | { |
Bryan Schumaker | babddc7 | 2010-10-20 15:44:29 -0400 | [diff] [blame] | 451 | dprintk("nfs: %s: prematurely hit end of receive buffer. " |
| 452 | "Remaining buffer length is %tu words.\n", |
| 453 | func, xdr->end - xdr->p); |
| 454 | } |
| 455 | |
| 456 | __be32 * |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 457 | nfs_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_server *server, int plus) |
Bryan Schumaker | babddc7 | 2010-10-20 15:44:29 -0400 | [diff] [blame] | 458 | { |
| 459 | __be32 *p; |
| 460 | p = xdr_inline_decode(xdr, 4); |
| 461 | if (unlikely(!p)) |
| 462 | goto out_overflow; |
| 463 | if (!ntohl(*p++)) { |
| 464 | p = xdr_inline_decode(xdr, 4); |
| 465 | if (unlikely(!p)) |
| 466 | goto out_overflow; |
| 467 | if (!ntohl(*p++)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return ERR_PTR(-EAGAIN); |
| 469 | entry->eof = 1; |
| 470 | return ERR_PTR(-EBADCOOKIE); |
| 471 | } |
| 472 | |
Bryan Schumaker | babddc7 | 2010-10-20 15:44:29 -0400 | [diff] [blame] | 473 | p = xdr_inline_decode(xdr, 8); |
| 474 | if (unlikely(!p)) |
| 475 | goto out_overflow; |
| 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | entry->ino = ntohl(*p++); |
| 478 | entry->len = ntohl(*p++); |
Bryan Schumaker | babddc7 | 2010-10-20 15:44:29 -0400 | [diff] [blame] | 479 | |
| 480 | p = xdr_inline_decode(xdr, entry->len + 4); |
| 481 | if (unlikely(!p)) |
| 482 | goto out_overflow; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | entry->name = (const char *) p; |
| 484 | p += XDR_QUADLEN(entry->len); |
| 485 | entry->prev_cookie = entry->cookie; |
| 486 | entry->cookie = ntohl(*p++); |
Bryan Schumaker | babddc7 | 2010-10-20 15:44:29 -0400 | [diff] [blame] | 487 | |
Trond Myklebust | 0b26a0b | 2010-11-20 14:26:44 -0500 | [diff] [blame^] | 488 | entry->d_type = DT_UNKNOWN; |
| 489 | |
Bryan Schumaker | babddc7 | 2010-10-20 15:44:29 -0400 | [diff] [blame] | 490 | p = xdr_inline_peek(xdr, 8); |
| 491 | if (p != NULL) |
| 492 | entry->eof = !p[0] && p[1]; |
| 493 | else |
| 494 | entry->eof = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | return p; |
Bryan Schumaker | babddc7 | 2010-10-20 15:44:29 -0400 | [diff] [blame] | 497 | |
| 498 | out_overflow: |
| 499 | print_overflow_msg(__func__, xdr); |
Trond Myklebust | 463a376 | 2010-11-20 12:22:20 -0500 | [diff] [blame] | 500 | return ERR_PTR(-EAGAIN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /* |
| 504 | * NFS XDR decode functions |
| 505 | */ |
| 506 | /* |
| 507 | * Decode simple status reply |
| 508 | */ |
| 509 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 510 | nfs_xdr_stat(struct rpc_rqst *req, __be32 *p, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | { |
| 512 | int status; |
| 513 | |
| 514 | if ((status = ntohl(*p++)) != 0) |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 515 | status = nfs_stat_to_errno(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | return status; |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * Decode attrstat reply |
| 521 | * GETATTR, SETATTR, WRITE |
| 522 | */ |
| 523 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 524 | nfs_xdr_attrstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | { |
| 526 | int status; |
| 527 | |
| 528 | if ((status = ntohl(*p++))) |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 529 | return nfs_stat_to_errno(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | xdr_decode_fattr(p, fattr); |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | /* |
| 535 | * Decode diropres reply |
| 536 | * LOOKUP, CREATE, MKDIR |
| 537 | */ |
| 538 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 539 | nfs_xdr_diropres(struct rpc_rqst *req, __be32 *p, struct nfs_diropok *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | { |
| 541 | int status; |
| 542 | |
| 543 | if ((status = ntohl(*p++))) |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 544 | return nfs_stat_to_errno(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | p = xdr_decode_fhandle(p, res->fh); |
| 546 | xdr_decode_fattr(p, res->fattr); |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | * Encode READLINK args |
| 552 | */ |
| 553 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 554 | nfs_xdr_readlinkargs(struct rpc_rqst *req, __be32 *p, struct nfs_readlinkargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
Trond Myklebust | a17c215 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 556 | struct rpc_auth *auth = req->rq_cred->cr_auth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | unsigned int replen; |
| 558 | |
| 559 | p = xdr_encode_fhandle(p, args->fh); |
| 560 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 561 | |
| 562 | /* Inline the page array */ |
| 563 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS_readlinkres_sz) << 2; |
| 564 | xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, args->pgbase, args->pglen); |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | /* |
| 569 | * Decode READLINK reply |
| 570 | */ |
| 571 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 572 | nfs_xdr_readlinkres(struct rpc_rqst *req, __be32 *p, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | { |
| 574 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; |
| 575 | struct kvec *iov = rcvbuf->head; |
Chuck Lever | 6232dbb | 2007-10-26 13:31:52 -0400 | [diff] [blame] | 576 | size_t hdrlen; |
| 577 | u32 len, recvd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | int status; |
| 579 | |
| 580 | if ((status = ntohl(*p++))) |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 581 | return nfs_stat_to_errno(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* Convert length of symlink */ |
| 583 | len = ntohl(*p++); |
Chuck Lever | 6232dbb | 2007-10-26 13:31:52 -0400 | [diff] [blame] | 584 | if (len >= rcvbuf->page_len) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 585 | dprintk("nfs: server returned giant symlink!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | return -ENAMETOOLONG; |
| 587 | } |
| 588 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; |
| 589 | if (iov->iov_len < hdrlen) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 590 | dprintk("NFS: READLINK reply header overflowed:" |
Chuck Lever | 6232dbb | 2007-10-26 13:31:52 -0400 | [diff] [blame] | 591 | "length %Zu > %Zu\n", hdrlen, iov->iov_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | return -errno_NFSERR_IO; |
| 593 | } else if (iov->iov_len != hdrlen) { |
| 594 | dprintk("NFS: READLINK header is short. iovec will be shifted.\n"); |
| 595 | xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen); |
| 596 | } |
| 597 | recvd = req->rq_rcv_buf.len - hdrlen; |
| 598 | if (recvd < len) { |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 599 | dprintk("NFS: server cheating in readlink reply: " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | "count %u > recvd %u\n", len, recvd); |
| 601 | return -EIO; |
| 602 | } |
| 603 | |
Chuck Lever | b4687da | 2010-09-21 16:55:48 -0400 | [diff] [blame] | 604 | xdr_terminate_string(rcvbuf, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | * Decode WRITE reply |
| 610 | */ |
| 611 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 612 | nfs_xdr_writeres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | { |
| 614 | res->verf->committed = NFS_FILE_SYNC; |
| 615 | return nfs_xdr_attrstat(req, p, res->fattr); |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * Decode STATFS reply |
| 620 | */ |
| 621 | static int |
Al Viro | 9d787a7 | 2006-10-19 23:28:47 -0700 | [diff] [blame] | 622 | nfs_xdr_statfsres(struct rpc_rqst *req, __be32 *p, struct nfs2_fsstat *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | { |
| 624 | int status; |
| 625 | |
| 626 | if ((status = ntohl(*p++))) |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 627 | return nfs_stat_to_errno(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
| 629 | res->tsize = ntohl(*p++); |
| 630 | res->bsize = ntohl(*p++); |
| 631 | res->blocks = ntohl(*p++); |
| 632 | res->bfree = ntohl(*p++); |
| 633 | res->bavail = ntohl(*p++); |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | * We need to translate between nfs status return values and |
| 639 | * the local errno values which may not be the same. |
| 640 | */ |
| 641 | static struct { |
| 642 | int stat; |
| 643 | int errno; |
| 644 | } nfs_errtbl[] = { |
| 645 | { NFS_OK, 0 }, |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 646 | { NFSERR_PERM, -EPERM }, |
| 647 | { NFSERR_NOENT, -ENOENT }, |
| 648 | { NFSERR_IO, -errno_NFSERR_IO}, |
| 649 | { NFSERR_NXIO, -ENXIO }, |
| 650 | /* { NFSERR_EAGAIN, -EAGAIN }, */ |
| 651 | { NFSERR_ACCES, -EACCES }, |
| 652 | { NFSERR_EXIST, -EEXIST }, |
| 653 | { NFSERR_XDEV, -EXDEV }, |
| 654 | { NFSERR_NODEV, -ENODEV }, |
| 655 | { NFSERR_NOTDIR, -ENOTDIR }, |
| 656 | { NFSERR_ISDIR, -EISDIR }, |
| 657 | { NFSERR_INVAL, -EINVAL }, |
| 658 | { NFSERR_FBIG, -EFBIG }, |
| 659 | { NFSERR_NOSPC, -ENOSPC }, |
| 660 | { NFSERR_ROFS, -EROFS }, |
| 661 | { NFSERR_MLINK, -EMLINK }, |
| 662 | { NFSERR_NAMETOOLONG, -ENAMETOOLONG }, |
| 663 | { NFSERR_NOTEMPTY, -ENOTEMPTY }, |
| 664 | { NFSERR_DQUOT, -EDQUOT }, |
| 665 | { NFSERR_STALE, -ESTALE }, |
| 666 | { NFSERR_REMOTE, -EREMOTE }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | #ifdef EWFLUSH |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 668 | { NFSERR_WFLUSH, -EWFLUSH }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | #endif |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 670 | { NFSERR_BADHANDLE, -EBADHANDLE }, |
| 671 | { NFSERR_NOT_SYNC, -ENOTSYNC }, |
| 672 | { NFSERR_BAD_COOKIE, -EBADCOOKIE }, |
| 673 | { NFSERR_NOTSUPP, -ENOTSUPP }, |
| 674 | { NFSERR_TOOSMALL, -ETOOSMALL }, |
Trond Myklebust | fdcb457 | 2010-02-08 09:32:40 -0500 | [diff] [blame] | 675 | { NFSERR_SERVERFAULT, -EREMOTEIO }, |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 676 | { NFSERR_BADTYPE, -EBADTYPE }, |
| 677 | { NFSERR_JUKEBOX, -EJUKEBOX }, |
| 678 | { -1, -EIO } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | }; |
| 680 | |
| 681 | /* |
| 682 | * Convert an NFS error code to a local one. |
| 683 | * This one is used jointly by NFSv2 and NFSv3. |
| 684 | */ |
| 685 | int |
| 686 | nfs_stat_to_errno(int stat) |
| 687 | { |
| 688 | int i; |
| 689 | |
| 690 | for (i = 0; nfs_errtbl[i].stat != -1; i++) { |
| 691 | if (nfs_errtbl[i].stat == stat) |
| 692 | return nfs_errtbl[i].errno; |
| 693 | } |
Chuck Lever | fe82a18 | 2007-09-11 18:01:10 -0400 | [diff] [blame] | 694 | dprintk("nfs_stat_to_errno: bad nfs status return value: %d\n", stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | return nfs_errtbl[i].errno; |
| 696 | } |
| 697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | #define PROC(proc, argtype, restype, timer) \ |
| 699 | [NFSPROC_##proc] = { \ |
| 700 | .p_proc = NFSPROC_##proc, \ |
| 701 | .p_encode = (kxdrproc_t) nfs_xdr_##argtype, \ |
| 702 | .p_decode = (kxdrproc_t) nfs_xdr_##restype, \ |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 703 | .p_arglen = NFS_##argtype##_sz, \ |
| 704 | .p_replen = NFS_##restype##_sz, \ |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 705 | .p_timer = timer, \ |
| 706 | .p_statidx = NFSPROC_##proc, \ |
| 707 | .p_name = #proc, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | struct rpc_procinfo nfs_procedures[] = { |
| 710 | PROC(GETATTR, fhandle, attrstat, 1), |
| 711 | PROC(SETATTR, sattrargs, attrstat, 0), |
| 712 | PROC(LOOKUP, diropargs, diropres, 2), |
| 713 | PROC(READLINK, readlinkargs, readlinkres, 3), |
| 714 | PROC(READ, readargs, readres, 3), |
| 715 | PROC(WRITE, writeargs, writeres, 4), |
| 716 | PROC(CREATE, createargs, diropres, 0), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 717 | PROC(REMOVE, removeargs, stat, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | PROC(RENAME, renameargs, stat, 0), |
| 719 | PROC(LINK, linkargs, stat, 0), |
| 720 | PROC(SYMLINK, symlinkargs, stat, 0), |
| 721 | PROC(MKDIR, createargs, diropres, 0), |
| 722 | PROC(RMDIR, diropargs, stat, 0), |
| 723 | PROC(READDIR, readdirargs, readdirres, 3), |
| 724 | PROC(STATFS, fhandle, statfsres, 0), |
| 725 | }; |
| 726 | |
| 727 | struct rpc_version nfs_version2 = { |
| 728 | .number = 2, |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 729 | .nrprocs = ARRAY_SIZE(nfs_procedures), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | .procs = nfs_procedures |
| 731 | }; |