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