Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/nfs/nfs2xdr.c |
| 4 | * |
| 5 | * XDR functions to encode/decode NFS RPC arguments and results. |
| 6 | * |
| 7 | * Copyright (C) 1992, 1993, 1994 Rick Sladkey |
| 8 | * Copyright (C) 1996 Olaf Kirch |
| 9 | * 04 Aug 1998 Ion Badulescu <ionut@cs.columbia.edu> |
| 10 | * FIFO's need special handling in NFSv2 |
| 11 | */ |
| 12 | |
| 13 | #include <linux/param.h> |
| 14 | #include <linux/time.h> |
| 15 | #include <linux/mm.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 | |
Bryan Schumaker | 5e7e5a0 | 2012-05-10 16:47:18 -0400 | [diff] [blame] | 65 | static int nfs_stat_to_errno(enum nfs_stat); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * While encoding arguments, set up the reply buffer in advance to |
| 69 | * receive reply data directly into the page cache. |
| 70 | */ |
| 71 | static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages, |
| 72 | unsigned int base, unsigned int len, |
| 73 | unsigned int bufsize) |
| 74 | { |
| 75 | struct rpc_auth *auth = req->rq_cred->cr_auth; |
| 76 | unsigned int replen; |
| 77 | |
| 78 | replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize; |
| 79 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len); |
| 80 | } |
| 81 | |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 82 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 83 | * Encode/decode NFSv2 basic data types |
| 84 | * |
| 85 | * Basic NFSv2 data types are defined in section 2.3 of RFC 1094: |
| 86 | * "NFS: Network File System Protocol Specification". |
| 87 | * |
| 88 | * Not all basic data types have their own encoding and decoding |
| 89 | * functions. For run-time efficiency, some data types are encoded |
| 90 | * or decoded inline. |
| 91 | */ |
| 92 | |
| 93 | /* |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 94 | * typedef opaque nfsdata<>; |
| 95 | */ |
Anna Schumaker | 9137bdf | 2014-05-06 09:12:25 -0400 | [diff] [blame] | 96 | static int decode_nfsdata(struct xdr_stream *xdr, struct nfs_pgio_res *result) |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 97 | { |
| 98 | u32 recvd, count; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 99 | __be32 *p; |
| 100 | |
| 101 | p = xdr_inline_decode(xdr, 4); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 102 | if (unlikely(!p)) |
| 103 | return -EIO; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 104 | count = be32_to_cpup(p); |
Trond Myklebust | 64bd577 | 2012-06-20 22:35:05 -0400 | [diff] [blame] | 105 | recvd = xdr_read_pages(xdr, count); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 106 | if (unlikely(count > recvd)) |
| 107 | goto out_cheating; |
| 108 | out: |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 109 | result->eof = 0; /* NFSv2 does not pass EOF flag on the wire. */ |
| 110 | result->count = count; |
| 111 | return count; |
| 112 | out_cheating: |
| 113 | dprintk("NFS: server cheating in read result: " |
| 114 | "count %u > recvd %u\n", count, recvd); |
| 115 | count = recvd; |
| 116 | goto out; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* |
| 120 | * enum stat { |
| 121 | * NFS_OK = 0, |
| 122 | * NFSERR_PERM = 1, |
| 123 | * NFSERR_NOENT = 2, |
| 124 | * NFSERR_IO = 5, |
| 125 | * NFSERR_NXIO = 6, |
| 126 | * NFSERR_ACCES = 13, |
| 127 | * NFSERR_EXIST = 17, |
| 128 | * NFSERR_NODEV = 19, |
| 129 | * NFSERR_NOTDIR = 20, |
| 130 | * NFSERR_ISDIR = 21, |
| 131 | * NFSERR_FBIG = 27, |
| 132 | * NFSERR_NOSPC = 28, |
| 133 | * NFSERR_ROFS = 30, |
| 134 | * NFSERR_NAMETOOLONG = 63, |
| 135 | * NFSERR_NOTEMPTY = 66, |
| 136 | * NFSERR_DQUOT = 69, |
| 137 | * NFSERR_STALE = 70, |
| 138 | * NFSERR_WFLUSH = 99 |
| 139 | * }; |
| 140 | */ |
| 141 | static int decode_stat(struct xdr_stream *xdr, enum nfs_stat *status) |
| 142 | { |
| 143 | __be32 *p; |
| 144 | |
| 145 | p = xdr_inline_decode(xdr, 4); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 146 | if (unlikely(!p)) |
| 147 | return -EIO; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 148 | *status = be32_to_cpup(p); |
| 149 | return 0; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* |
Chuck Lever | 5f96e5e | 2010-12-14 14:55:30 +0000 | [diff] [blame] | 153 | * 2.3.2. ftype |
| 154 | * |
| 155 | * enum ftype { |
| 156 | * NFNON = 0, |
| 157 | * NFREG = 1, |
| 158 | * NFDIR = 2, |
| 159 | * NFBLK = 3, |
| 160 | * NFCHR = 4, |
| 161 | * NFLNK = 5 |
| 162 | * }; |
| 163 | * |
| 164 | */ |
| 165 | static __be32 *xdr_decode_ftype(__be32 *p, u32 *type) |
| 166 | { |
| 167 | *type = be32_to_cpup(p++); |
| 168 | if (unlikely(*type > NF2FIFO)) |
| 169 | *type = NFBAD; |
| 170 | return p; |
| 171 | } |
| 172 | |
| 173 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 174 | * 2.3.3. fhandle |
| 175 | * |
| 176 | * typedef opaque fhandle[FHSIZE]; |
| 177 | */ |
| 178 | static void encode_fhandle(struct xdr_stream *xdr, const struct nfs_fh *fh) |
| 179 | { |
| 180 | __be32 *p; |
| 181 | |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 182 | p = xdr_reserve_space(xdr, NFS2_FHSIZE); |
| 183 | memcpy(p, fh->data, NFS2_FHSIZE); |
| 184 | } |
| 185 | |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 186 | static int decode_fhandle(struct xdr_stream *xdr, struct nfs_fh *fh) |
| 187 | { |
| 188 | __be32 *p; |
| 189 | |
| 190 | p = xdr_inline_decode(xdr, NFS2_FHSIZE); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 191 | if (unlikely(!p)) |
| 192 | return -EIO; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 193 | fh->size = NFS2_FHSIZE; |
| 194 | memcpy(fh->data, p, NFS2_FHSIZE); |
| 195 | return 0; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 198 | /* |
Chuck Lever | 282ac2a | 2010-12-14 14:54:50 +0000 | [diff] [blame] | 199 | * 2.3.4. timeval |
| 200 | * |
| 201 | * struct timeval { |
| 202 | * unsigned int seconds; |
| 203 | * unsigned int useconds; |
| 204 | * }; |
| 205 | */ |
| 206 | static __be32 *xdr_encode_time(__be32 *p, const struct timespec *timep) |
| 207 | { |
| 208 | *p++ = cpu_to_be32(timep->tv_sec); |
| 209 | if (timep->tv_nsec != 0) |
| 210 | *p++ = cpu_to_be32(timep->tv_nsec / NSEC_PER_USEC); |
| 211 | else |
| 212 | *p++ = cpu_to_be32(0); |
| 213 | return p; |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | * Passing the invalid value useconds=1000000 is a Sun convention for |
| 218 | * "set to current server time". It's needed to make permissions checks |
| 219 | * for the "touch" program across v2 mounts to Solaris and Irix servers |
| 220 | * work correctly. See description of sattr in section 6.1 of "NFS |
| 221 | * Illustrated" by Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5. |
| 222 | */ |
| 223 | static __be32 *xdr_encode_current_server_time(__be32 *p, |
| 224 | const struct timespec *timep) |
| 225 | { |
| 226 | *p++ = cpu_to_be32(timep->tv_sec); |
| 227 | *p++ = cpu_to_be32(1000000); |
| 228 | return p; |
| 229 | } |
| 230 | |
Chuck Lever | 5f96e5e | 2010-12-14 14:55:30 +0000 | [diff] [blame] | 231 | static __be32 *xdr_decode_time(__be32 *p, struct timespec *timep) |
| 232 | { |
| 233 | timep->tv_sec = be32_to_cpup(p++); |
| 234 | timep->tv_nsec = be32_to_cpup(p++) * NSEC_PER_USEC; |
| 235 | return p; |
| 236 | } |
| 237 | |
Chuck Lever | 282ac2a | 2010-12-14 14:54:50 +0000 | [diff] [blame] | 238 | /* |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 239 | * 2.3.5. fattr |
| 240 | * |
| 241 | * struct fattr { |
| 242 | * ftype type; |
| 243 | * unsigned int mode; |
| 244 | * unsigned int nlink; |
| 245 | * unsigned int uid; |
| 246 | * unsigned int gid; |
| 247 | * unsigned int size; |
| 248 | * unsigned int blocksize; |
| 249 | * unsigned int rdev; |
| 250 | * unsigned int blocks; |
| 251 | * unsigned int fsid; |
| 252 | * unsigned int fileid; |
| 253 | * timeval atime; |
| 254 | * timeval mtime; |
| 255 | * timeval ctime; |
| 256 | * }; |
| 257 | * |
| 258 | */ |
| 259 | static int decode_fattr(struct xdr_stream *xdr, struct nfs_fattr *fattr) |
| 260 | { |
Chuck Lever | 5f96e5e | 2010-12-14 14:55:30 +0000 | [diff] [blame] | 261 | u32 rdev, type; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 262 | __be32 *p; |
| 263 | |
| 264 | p = xdr_inline_decode(xdr, NFS_fattr_sz << 2); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 265 | if (unlikely(!p)) |
| 266 | return -EIO; |
Chuck Lever | 5f96e5e | 2010-12-14 14:55:30 +0000 | [diff] [blame] | 267 | |
| 268 | fattr->valid |= NFS_ATTR_FATTR_V2; |
| 269 | |
| 270 | p = xdr_decode_ftype(p, &type); |
| 271 | |
| 272 | fattr->mode = be32_to_cpup(p++); |
| 273 | fattr->nlink = be32_to_cpup(p++); |
Eric W. Biederman | cfa0898 | 2013-02-01 03:45:54 -0800 | [diff] [blame] | 274 | fattr->uid = make_kuid(&init_user_ns, be32_to_cpup(p++)); |
| 275 | if (!uid_valid(fattr->uid)) |
| 276 | goto out_uid; |
| 277 | fattr->gid = make_kgid(&init_user_ns, be32_to_cpup(p++)); |
| 278 | if (!gid_valid(fattr->gid)) |
| 279 | goto out_gid; |
| 280 | |
Chuck Lever | 5f96e5e | 2010-12-14 14:55:30 +0000 | [diff] [blame] | 281 | fattr->size = be32_to_cpup(p++); |
| 282 | fattr->du.nfs2.blocksize = be32_to_cpup(p++); |
| 283 | |
| 284 | rdev = be32_to_cpup(p++); |
| 285 | fattr->rdev = new_decode_dev(rdev); |
| 286 | if (type == (u32)NFCHR && rdev == (u32)NFS2_FIFO_DEV) { |
| 287 | fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO; |
| 288 | fattr->rdev = 0; |
| 289 | } |
| 290 | |
| 291 | fattr->du.nfs2.blocks = be32_to_cpup(p++); |
| 292 | fattr->fsid.major = be32_to_cpup(p++); |
| 293 | fattr->fsid.minor = 0; |
| 294 | fattr->fileid = be32_to_cpup(p++); |
| 295 | |
| 296 | p = xdr_decode_time(p, &fattr->atime); |
| 297 | p = xdr_decode_time(p, &fattr->mtime); |
| 298 | xdr_decode_time(p, &fattr->ctime); |
Trond Myklebust | 3a1556e | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 299 | fattr->change_attr = nfs_timespec_to_change_attr(&fattr->ctime); |
| 300 | |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 301 | return 0; |
Eric W. Biederman | cfa0898 | 2013-02-01 03:45:54 -0800 | [diff] [blame] | 302 | out_uid: |
| 303 | dprintk("NFS: returned invalid uid\n"); |
| 304 | return -EINVAL; |
| 305 | out_gid: |
| 306 | dprintk("NFS: returned invalid gid\n"); |
| 307 | return -EINVAL; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 311 | * 2.3.6. sattr |
| 312 | * |
| 313 | * struct sattr { |
| 314 | * unsigned int mode; |
| 315 | * unsigned int uid; |
| 316 | * unsigned int gid; |
| 317 | * unsigned int size; |
| 318 | * timeval atime; |
| 319 | * timeval mtime; |
| 320 | * }; |
| 321 | */ |
| 322 | |
| 323 | #define NFS2_SATTR_NOT_SET (0xffffffff) |
| 324 | |
| 325 | static __be32 *xdr_time_not_set(__be32 *p) |
| 326 | { |
| 327 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); |
| 328 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); |
| 329 | return p; |
| 330 | } |
| 331 | |
| 332 | static void encode_sattr(struct xdr_stream *xdr, const struct iattr *attr) |
| 333 | { |
Deepa Dinamani | 95582b0 | 2018-05-08 19:36:02 -0700 | [diff] [blame] | 334 | struct timespec ts; |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 335 | __be32 *p; |
| 336 | |
| 337 | p = xdr_reserve_space(xdr, NFS_sattr_sz << 2); |
| 338 | |
| 339 | if (attr->ia_valid & ATTR_MODE) |
| 340 | *p++ = cpu_to_be32(attr->ia_mode); |
| 341 | else |
| 342 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); |
| 343 | if (attr->ia_valid & ATTR_UID) |
Eric W. Biederman | cfa0898 | 2013-02-01 03:45:54 -0800 | [diff] [blame] | 344 | *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid)); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 345 | else |
| 346 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); |
| 347 | if (attr->ia_valid & ATTR_GID) |
Eric W. Biederman | cfa0898 | 2013-02-01 03:45:54 -0800 | [diff] [blame] | 348 | *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid)); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 349 | else |
| 350 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); |
| 351 | if (attr->ia_valid & ATTR_SIZE) |
| 352 | *p++ = cpu_to_be32((u32)attr->ia_size); |
| 353 | else |
| 354 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); |
| 355 | |
Deepa Dinamani | 95582b0 | 2018-05-08 19:36:02 -0700 | [diff] [blame] | 356 | if (attr->ia_valid & ATTR_ATIME_SET) { |
| 357 | ts = timespec64_to_timespec(attr->ia_atime); |
| 358 | p = xdr_encode_time(p, &ts); |
| 359 | } else if (attr->ia_valid & ATTR_ATIME) { |
| 360 | ts = timespec64_to_timespec(attr->ia_atime); |
| 361 | p = xdr_encode_current_server_time(p, &ts); |
| 362 | } else |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 363 | p = xdr_time_not_set(p); |
Deepa Dinamani | 95582b0 | 2018-05-08 19:36:02 -0700 | [diff] [blame] | 364 | if (attr->ia_valid & ATTR_MTIME_SET) { |
| 365 | ts = timespec64_to_timespec(attr->ia_atime); |
| 366 | xdr_encode_time(p, &ts); |
| 367 | } else if (attr->ia_valid & ATTR_MTIME) { |
| 368 | ts = timespec64_to_timespec(attr->ia_mtime); |
| 369 | xdr_encode_current_server_time(p, &ts); |
| 370 | } else |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 371 | xdr_time_not_set(p); |
| 372 | } |
| 373 | |
| 374 | /* |
| 375 | * 2.3.7. filename |
| 376 | * |
| 377 | * typedef string filename<MAXNAMLEN>; |
| 378 | */ |
| 379 | static void encode_filename(struct xdr_stream *xdr, |
| 380 | const char *name, u32 length) |
| 381 | { |
| 382 | __be32 *p; |
| 383 | |
Trond Myklebust | 7fc3884 | 2012-10-15 11:51:21 -0400 | [diff] [blame] | 384 | WARN_ON_ONCE(length > NFS2_MAXNAMLEN); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 385 | p = xdr_reserve_space(xdr, 4 + length); |
| 386 | xdr_encode_opaque(p, name, length); |
| 387 | } |
| 388 | |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 389 | static int decode_filename_inline(struct xdr_stream *xdr, |
| 390 | const char **name, u32 *length) |
| 391 | { |
| 392 | __be32 *p; |
| 393 | u32 count; |
| 394 | |
| 395 | p = xdr_inline_decode(xdr, 4); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 396 | if (unlikely(!p)) |
| 397 | return -EIO; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 398 | count = be32_to_cpup(p); |
| 399 | if (count > NFS3_MAXNAMLEN) |
| 400 | goto out_nametoolong; |
| 401 | p = xdr_inline_decode(xdr, count); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 402 | if (unlikely(!p)) |
| 403 | return -EIO; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 404 | *name = (const char *)p; |
| 405 | *length = count; |
| 406 | return 0; |
| 407 | out_nametoolong: |
| 408 | dprintk("NFS: returned filename too long: %u\n", count); |
| 409 | return -ENAMETOOLONG; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 412 | /* |
| 413 | * 2.3.8. path |
| 414 | * |
| 415 | * typedef string path<MAXPATHLEN>; |
| 416 | */ |
| 417 | static void encode_path(struct xdr_stream *xdr, struct page **pages, u32 length) |
| 418 | { |
| 419 | __be32 *p; |
| 420 | |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 421 | p = xdr_reserve_space(xdr, 4); |
| 422 | *p = cpu_to_be32(length); |
| 423 | xdr_write_pages(xdr, pages, 0, length); |
| 424 | } |
| 425 | |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 426 | static int decode_path(struct xdr_stream *xdr) |
| 427 | { |
| 428 | u32 length, recvd; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 429 | __be32 *p; |
| 430 | |
| 431 | p = xdr_inline_decode(xdr, 4); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 432 | if (unlikely(!p)) |
| 433 | return -EIO; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 434 | length = be32_to_cpup(p); |
| 435 | if (unlikely(length >= xdr->buf->page_len || length > NFS_MAXPATHLEN)) |
| 436 | goto out_size; |
Trond Myklebust | 64bd577 | 2012-06-20 22:35:05 -0400 | [diff] [blame] | 437 | recvd = xdr_read_pages(xdr, length); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 438 | if (unlikely(length > recvd)) |
| 439 | goto out_cheating; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 440 | xdr_terminate_string(xdr->buf, length); |
| 441 | return 0; |
| 442 | out_size: |
| 443 | dprintk("NFS: returned pathname too long: %u\n", length); |
| 444 | return -ENAMETOOLONG; |
| 445 | out_cheating: |
| 446 | dprintk("NFS: server cheating in pathname result: " |
| 447 | "length %u > received %u\n", length, recvd); |
| 448 | return -EIO; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | /* |
| 452 | * 2.3.9. attrstat |
| 453 | * |
| 454 | * union attrstat switch (stat status) { |
| 455 | * case NFS_OK: |
| 456 | * fattr attributes; |
| 457 | * default: |
| 458 | * void; |
| 459 | * }; |
| 460 | */ |
Peng Tao | aabff4d | 2014-08-27 10:47:14 +0800 | [diff] [blame] | 461 | static int decode_attrstat(struct xdr_stream *xdr, struct nfs_fattr *result, |
| 462 | __u32 *op_status) |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 463 | { |
| 464 | enum nfs_stat status; |
| 465 | int error; |
| 466 | |
| 467 | error = decode_stat(xdr, &status); |
| 468 | if (unlikely(error)) |
| 469 | goto out; |
Peng Tao | aabff4d | 2014-08-27 10:47:14 +0800 | [diff] [blame] | 470 | if (op_status) |
| 471 | *op_status = status; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 472 | if (status != NFS_OK) |
| 473 | goto out_default; |
| 474 | error = decode_fattr(xdr, result); |
| 475 | out: |
| 476 | return error; |
| 477 | out_default: |
| 478 | return nfs_stat_to_errno(status); |
| 479 | } |
| 480 | |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 481 | /* |
| 482 | * 2.3.10. diropargs |
| 483 | * |
| 484 | * struct diropargs { |
| 485 | * fhandle dir; |
| 486 | * filename name; |
| 487 | * }; |
| 488 | */ |
| 489 | static void encode_diropargs(struct xdr_stream *xdr, const struct nfs_fh *fh, |
| 490 | const char *name, u32 length) |
| 491 | { |
| 492 | encode_fhandle(xdr, fh); |
| 493 | encode_filename(xdr, name, length); |
| 494 | } |
| 495 | |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 496 | /* |
| 497 | * 2.3.11. diropres |
| 498 | * |
| 499 | * union diropres switch (stat status) { |
| 500 | * case NFS_OK: |
| 501 | * struct { |
| 502 | * fhandle file; |
| 503 | * fattr attributes; |
| 504 | * } diropok; |
| 505 | * default: |
| 506 | * void; |
| 507 | * }; |
| 508 | */ |
| 509 | static int decode_diropok(struct xdr_stream *xdr, struct nfs_diropok *result) |
| 510 | { |
| 511 | int error; |
| 512 | |
| 513 | error = decode_fhandle(xdr, result->fh); |
| 514 | if (unlikely(error)) |
| 515 | goto out; |
| 516 | error = decode_fattr(xdr, result->fattr); |
| 517 | out: |
| 518 | return error; |
| 519 | } |
| 520 | |
| 521 | static int decode_diropres(struct xdr_stream *xdr, struct nfs_diropok *result) |
| 522 | { |
| 523 | enum nfs_stat status; |
| 524 | int error; |
| 525 | |
| 526 | error = decode_stat(xdr, &status); |
| 527 | if (unlikely(error)) |
| 528 | goto out; |
| 529 | if (status != NFS_OK) |
| 530 | goto out_default; |
| 531 | error = decode_diropok(xdr, result); |
| 532 | out: |
| 533 | return error; |
| 534 | out_default: |
| 535 | return nfs_stat_to_errno(status); |
| 536 | } |
| 537 | |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 538 | |
| 539 | /* |
Chuck Lever | 2d70f53 | 2010-12-14 14:54:40 +0000 | [diff] [blame] | 540 | * NFSv2 XDR encode functions |
| 541 | * |
| 542 | * NFSv2 argument types are defined in section 2.2 of RFC 1094: |
| 543 | * "NFS: Network File System Protocol Specification". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 546 | static void nfs2_xdr_enc_fhandle(struct rpc_rqst *req, |
| 547 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 548 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 549 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 550 | const struct nfs_fh *fh = data; |
| 551 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 552 | encode_fhandle(xdr, fh); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 556 | * 2.2.3. sattrargs |
| 557 | * |
| 558 | * struct sattrargs { |
| 559 | * fhandle file; |
| 560 | * sattr attributes; |
| 561 | * }; |
| 562 | */ |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 563 | static void nfs2_xdr_enc_sattrargs(struct rpc_rqst *req, |
| 564 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 565 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 566 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 567 | const struct nfs_sattrargs *args = data; |
| 568 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 569 | encode_fhandle(xdr, args->fh); |
| 570 | encode_sattr(xdr, args->sattr); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 573 | static void nfs2_xdr_enc_diropargs(struct rpc_rqst *req, |
| 574 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 575 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 576 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 577 | const struct nfs_diropargs *args = data; |
| 578 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 579 | encode_diropargs(xdr, args->fh, args->name, args->len); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 582 | static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst *req, |
| 583 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 584 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 585 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 586 | const struct nfs_readlinkargs *args = data; |
| 587 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 588 | encode_fhandle(xdr, args->fh); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 589 | prepare_reply_buffer(req, args->pages, args->pgbase, |
| 590 | args->pglen, NFS_readlinkres_sz); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 593 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 594 | * 2.2.7. readargs |
| 595 | * |
| 596 | * struct readargs { |
| 597 | * fhandle file; |
| 598 | * unsigned offset; |
| 599 | * unsigned count; |
| 600 | * unsigned totalcount; |
| 601 | * }; |
| 602 | */ |
| 603 | static void encode_readargs(struct xdr_stream *xdr, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 604 | const struct nfs_pgio_args *args) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 605 | { |
| 606 | u32 offset = args->offset; |
| 607 | u32 count = args->count; |
| 608 | __be32 *p; |
| 609 | |
| 610 | encode_fhandle(xdr, args->fh); |
| 611 | |
| 612 | p = xdr_reserve_space(xdr, 4 + 4 + 4); |
| 613 | *p++ = cpu_to_be32(offset); |
| 614 | *p++ = cpu_to_be32(count); |
| 615 | *p = cpu_to_be32(count); |
| 616 | } |
| 617 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 618 | static void nfs2_xdr_enc_readargs(struct rpc_rqst *req, |
| 619 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 620 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 621 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 622 | const struct nfs_pgio_args *args = data; |
| 623 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 624 | encode_readargs(xdr, args); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 625 | prepare_reply_buffer(req, args->pages, args->pgbase, |
| 626 | args->count, NFS_readres_sz); |
| 627 | req->rq_rcv_buf.flags |= XDRBUF_READ; |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 631 | * 2.2.9. writeargs |
| 632 | * |
| 633 | * struct writeargs { |
| 634 | * fhandle file; |
| 635 | * unsigned beginoffset; |
| 636 | * unsigned offset; |
| 637 | * unsigned totalcount; |
| 638 | * nfsdata data; |
| 639 | * }; |
| 640 | */ |
| 641 | static void encode_writeargs(struct xdr_stream *xdr, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 642 | const struct nfs_pgio_args *args) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 643 | { |
| 644 | u32 offset = args->offset; |
| 645 | u32 count = args->count; |
| 646 | __be32 *p; |
| 647 | |
| 648 | encode_fhandle(xdr, args->fh); |
| 649 | |
| 650 | p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4); |
| 651 | *p++ = cpu_to_be32(offset); |
| 652 | *p++ = cpu_to_be32(offset); |
| 653 | *p++ = cpu_to_be32(count); |
| 654 | |
| 655 | /* nfsdata */ |
| 656 | *p = cpu_to_be32(count); |
| 657 | xdr_write_pages(xdr, args->pages, args->pgbase, count); |
| 658 | } |
| 659 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 660 | static void nfs2_xdr_enc_writeargs(struct rpc_rqst *req, |
| 661 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 662 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 663 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 664 | const struct nfs_pgio_args *args = data; |
| 665 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 666 | encode_writeargs(xdr, args); |
| 667 | xdr->buf->flags |= XDRBUF_WRITE; |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 671 | * 2.2.10. createargs |
| 672 | * |
| 673 | * struct createargs { |
| 674 | * diropargs where; |
| 675 | * sattr attributes; |
| 676 | * }; |
| 677 | */ |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 678 | static void nfs2_xdr_enc_createargs(struct rpc_rqst *req, |
| 679 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 680 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 681 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 682 | const struct nfs_createargs *args = data; |
| 683 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 684 | encode_diropargs(xdr, args->fh, args->name, args->len); |
| 685 | encode_sattr(xdr, args->sattr); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 688 | static void nfs2_xdr_enc_removeargs(struct rpc_rqst *req, |
| 689 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 690 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 691 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 692 | const struct nfs_removeargs *args = data; |
| 693 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 694 | encode_diropargs(xdr, args->fh, args->name.name, args->name.len); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 698 | * 2.2.12. renameargs |
| 699 | * |
| 700 | * struct renameargs { |
| 701 | * diropargs from; |
| 702 | * diropargs to; |
| 703 | * }; |
| 704 | */ |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 705 | static void nfs2_xdr_enc_renameargs(struct rpc_rqst *req, |
| 706 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 707 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 708 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 709 | const struct nfs_renameargs *args = data; |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 710 | const struct qstr *old = args->old_name; |
| 711 | const struct qstr *new = args->new_name; |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 712 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 713 | encode_diropargs(xdr, args->old_dir, old->name, old->len); |
| 714 | encode_diropargs(xdr, args->new_dir, new->name, new->len); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 718 | * 2.2.13. linkargs |
| 719 | * |
| 720 | * struct linkargs { |
| 721 | * fhandle from; |
| 722 | * diropargs to; |
| 723 | * }; |
| 724 | */ |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 725 | static void nfs2_xdr_enc_linkargs(struct rpc_rqst *req, |
| 726 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 727 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 728 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 729 | const struct nfs_linkargs *args = data; |
| 730 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 731 | encode_fhandle(xdr, args->fromfh); |
| 732 | encode_diropargs(xdr, args->tofh, args->toname, args->tolen); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 736 | * 2.2.14. symlinkargs |
| 737 | * |
| 738 | * struct symlinkargs { |
| 739 | * diropargs from; |
| 740 | * path to; |
| 741 | * sattr attributes; |
| 742 | * }; |
| 743 | */ |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 744 | static void nfs2_xdr_enc_symlinkargs(struct rpc_rqst *req, |
| 745 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 746 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 747 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 748 | const struct nfs_symlinkargs *args = data; |
| 749 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 750 | encode_diropargs(xdr, args->fromfh, args->fromname, args->fromlen); |
| 751 | encode_path(xdr, args->pages, args->pathlen); |
| 752 | encode_sattr(xdr, args->sattr); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | /* |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 756 | * 2.2.17. readdirargs |
| 757 | * |
| 758 | * struct readdirargs { |
| 759 | * fhandle dir; |
| 760 | * nfscookie cookie; |
| 761 | * unsigned count; |
| 762 | * }; |
| 763 | */ |
| 764 | static void encode_readdirargs(struct xdr_stream *xdr, |
| 765 | const struct nfs_readdirargs *args) |
| 766 | { |
| 767 | __be32 *p; |
| 768 | |
| 769 | encode_fhandle(xdr, args->fh); |
| 770 | |
| 771 | p = xdr_reserve_space(xdr, 4 + 4); |
| 772 | *p++ = cpu_to_be32(args->cookie); |
| 773 | *p = cpu_to_be32(args->count); |
| 774 | } |
| 775 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 776 | static void nfs2_xdr_enc_readdirargs(struct rpc_rqst *req, |
| 777 | struct xdr_stream *xdr, |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 778 | const void *data) |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 779 | { |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 780 | const struct nfs_readdirargs *args = data; |
| 781 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 782 | encode_readdirargs(xdr, args); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 783 | prepare_reply_buffer(req, args->pages, 0, |
| 784 | args->count, NFS_readdirres_sz); |
Chuck Lever | 25a0866 | 2010-12-14 14:54:30 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | /* |
Chuck Lever | 661ad42 | 2010-12-14 14:55:20 +0000 | [diff] [blame] | 788 | * NFSv2 XDR decode functions |
| 789 | * |
| 790 | * NFSv2 result types are defined in section 2.2 of RFC 1094: |
| 791 | * "NFS: Network File System Protocol Specification". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 794 | static int nfs2_xdr_dec_stat(struct rpc_rqst *req, struct xdr_stream *xdr, |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 795 | void *__unused) |
| 796 | { |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 797 | enum nfs_stat status; |
| 798 | int error; |
| 799 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 800 | error = decode_stat(xdr, &status); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 801 | if (unlikely(error)) |
| 802 | goto out; |
| 803 | if (status != NFS_OK) |
| 804 | goto out_default; |
| 805 | out: |
| 806 | return error; |
| 807 | out_default: |
| 808 | return nfs_stat_to_errno(status); |
| 809 | } |
| 810 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 811 | static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, struct xdr_stream *xdr, |
Christoph Hellwig | fc01648 | 2017-05-08 15:09:02 +0200 | [diff] [blame] | 812 | void *result) |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 813 | { |
Peng Tao | aabff4d | 2014-08-27 10:47:14 +0800 | [diff] [blame] | 814 | return decode_attrstat(xdr, result, NULL); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 817 | static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, struct xdr_stream *xdr, |
Christoph Hellwig | fc01648 | 2017-05-08 15:09:02 +0200 | [diff] [blame] | 818 | void *result) |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 819 | { |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 820 | return decode_diropres(xdr, result); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | /* |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 824 | * 2.2.6. readlinkres |
| 825 | * |
| 826 | * union readlinkres switch (stat status) { |
| 827 | * case NFS_OK: |
| 828 | * path data; |
| 829 | * default: |
| 830 | * void; |
| 831 | * }; |
| 832 | */ |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 833 | static int nfs2_xdr_dec_readlinkres(struct rpc_rqst *req, |
| 834 | struct xdr_stream *xdr, void *__unused) |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 835 | { |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 836 | enum nfs_stat status; |
| 837 | int error; |
| 838 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 839 | error = decode_stat(xdr, &status); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 840 | if (unlikely(error)) |
| 841 | goto out; |
| 842 | if (status != NFS_OK) |
| 843 | goto out_default; |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 844 | error = decode_path(xdr); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 845 | out: |
| 846 | return error; |
| 847 | out_default: |
| 848 | return nfs_stat_to_errno(status); |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | * 2.2.7. readres |
| 853 | * |
| 854 | * union readres switch (stat status) { |
| 855 | * case NFS_OK: |
| 856 | * fattr attributes; |
| 857 | * nfsdata data; |
| 858 | * default: |
| 859 | * void; |
| 860 | * }; |
| 861 | */ |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 862 | static int nfs2_xdr_dec_readres(struct rpc_rqst *req, struct xdr_stream *xdr, |
Christoph Hellwig | fc01648 | 2017-05-08 15:09:02 +0200 | [diff] [blame] | 863 | void *data) |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 864 | { |
Christoph Hellwig | fc01648 | 2017-05-08 15:09:02 +0200 | [diff] [blame] | 865 | struct nfs_pgio_res *result = data; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 866 | enum nfs_stat status; |
| 867 | int error; |
| 868 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 869 | error = decode_stat(xdr, &status); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 870 | if (unlikely(error)) |
| 871 | goto out; |
Peng Tao | aabff4d | 2014-08-27 10:47:14 +0800 | [diff] [blame] | 872 | result->op_status = status; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 873 | if (status != NFS_OK) |
| 874 | goto out_default; |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 875 | error = decode_fattr(xdr, result->fattr); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 876 | if (unlikely(error)) |
| 877 | goto out; |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 878 | error = decode_nfsdata(xdr, result); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 879 | out: |
| 880 | return error; |
| 881 | out_default: |
| 882 | return nfs_stat_to_errno(status); |
| 883 | } |
| 884 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 885 | static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, struct xdr_stream *xdr, |
Christoph Hellwig | fc01648 | 2017-05-08 15:09:02 +0200 | [diff] [blame] | 886 | void *data) |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 887 | { |
Christoph Hellwig | fc01648 | 2017-05-08 15:09:02 +0200 | [diff] [blame] | 888 | struct nfs_pgio_res *result = data; |
| 889 | |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 890 | /* All NFSv2 writes are "file sync" writes */ |
| 891 | result->verf->committed = NFS_FILE_SYNC; |
Peng Tao | aabff4d | 2014-08-27 10:47:14 +0800 | [diff] [blame] | 892 | return decode_attrstat(xdr, result->fattr, &result->op_status); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | /** |
| 896 | * nfs2_decode_dirent - Decode a single NFSv2 directory entry stored in |
| 897 | * the local page cache. |
| 898 | * @xdr: XDR stream where entry resides |
| 899 | * @entry: buffer to fill in with entry data |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 900 | * @plus: boolean indicating whether this should be a readdirplus entry |
| 901 | * |
Chuck Lever | 573c4e1 | 2010-12-14 14:58:11 +0000 | [diff] [blame] | 902 | * Returns zero if successful, otherwise a negative errno value is |
| 903 | * returned. |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 904 | * |
| 905 | * This function is not invoked during READDIR reply decoding, but |
| 906 | * rather whenever an application invokes the getdents(2) system call |
| 907 | * on a directory already in our cache. |
| 908 | * |
| 909 | * 2.2.17. entry |
| 910 | * |
| 911 | * struct entry { |
| 912 | * unsigned fileid; |
| 913 | * filename name; |
| 914 | * nfscookie cookie; |
| 915 | * entry *nextentry; |
| 916 | * }; |
| 917 | */ |
Chuck Lever | 573c4e1 | 2010-12-14 14:58:11 +0000 | [diff] [blame] | 918 | int nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 919 | bool plus) |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 920 | { |
| 921 | __be32 *p; |
| 922 | int error; |
| 923 | |
| 924 | p = xdr_inline_decode(xdr, 4); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 925 | if (unlikely(!p)) |
| 926 | return -EAGAIN; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 927 | if (*p++ == xdr_zero) { |
| 928 | p = xdr_inline_decode(xdr, 4); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 929 | if (unlikely(!p)) |
| 930 | return -EAGAIN; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 931 | if (*p++ == xdr_zero) |
Chuck Lever | 573c4e1 | 2010-12-14 14:58:11 +0000 | [diff] [blame] | 932 | return -EAGAIN; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 933 | entry->eof = 1; |
Chuck Lever | 573c4e1 | 2010-12-14 14:58:11 +0000 | [diff] [blame] | 934 | return -EBADCOOKIE; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | p = xdr_inline_decode(xdr, 4); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 938 | if (unlikely(!p)) |
| 939 | return -EAGAIN; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 940 | entry->ino = be32_to_cpup(p); |
| 941 | |
| 942 | error = decode_filename_inline(xdr, &entry->name, &entry->len); |
| 943 | if (unlikely(error)) |
Chuck Lever | 573c4e1 | 2010-12-14 14:58:11 +0000 | [diff] [blame] | 944 | return error; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 945 | |
| 946 | /* |
| 947 | * The type (size and byte order) of nfscookie isn't defined in |
| 948 | * RFC 1094. This implementation assumes that it's an XDR uint32. |
| 949 | */ |
| 950 | entry->prev_cookie = entry->cookie; |
| 951 | p = xdr_inline_decode(xdr, 4); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 952 | if (unlikely(!p)) |
| 953 | return -EAGAIN; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 954 | entry->cookie = be32_to_cpup(p); |
| 955 | |
| 956 | entry->d_type = DT_UNKNOWN; |
| 957 | |
Chuck Lever | 573c4e1 | 2010-12-14 14:58:11 +0000 | [diff] [blame] | 958 | return 0; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | /* |
| 962 | * 2.2.17. readdirres |
| 963 | * |
| 964 | * union readdirres switch (stat status) { |
| 965 | * case NFS_OK: |
| 966 | * struct { |
| 967 | * entry *entries; |
| 968 | * bool eof; |
| 969 | * } readdirok; |
| 970 | * default: |
| 971 | * void; |
| 972 | * }; |
| 973 | * |
| 974 | * Read the directory contents into the page cache, but don't |
| 975 | * touch them. The actual decoding is done by nfs2_decode_dirent() |
| 976 | * during subsequent nfs_readdir() calls. |
| 977 | */ |
| 978 | static int decode_readdirok(struct xdr_stream *xdr) |
| 979 | { |
Trond Myklebust | 64bd577 | 2012-06-20 22:35:05 -0400 | [diff] [blame] | 980 | return xdr_read_pages(xdr, xdr->buf->page_len); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 983 | static int nfs2_xdr_dec_readdirres(struct rpc_rqst *req, |
| 984 | struct xdr_stream *xdr, void *__unused) |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 985 | { |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 986 | enum nfs_stat status; |
| 987 | int error; |
| 988 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 989 | error = decode_stat(xdr, &status); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 990 | if (unlikely(error)) |
| 991 | goto out; |
| 992 | if (status != NFS_OK) |
| 993 | goto out_default; |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 994 | error = decode_readdirok(xdr); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 995 | out: |
| 996 | return error; |
| 997 | out_default: |
| 998 | return nfs_stat_to_errno(status); |
| 999 | } |
| 1000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | /* |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 1002 | * 2.2.18. statfsres |
| 1003 | * |
| 1004 | * union statfsres (stat status) { |
| 1005 | * case NFS_OK: |
| 1006 | * struct { |
| 1007 | * unsigned tsize; |
| 1008 | * unsigned bsize; |
| 1009 | * unsigned blocks; |
| 1010 | * unsigned bfree; |
| 1011 | * unsigned bavail; |
| 1012 | * } info; |
| 1013 | * default: |
| 1014 | * void; |
| 1015 | * }; |
| 1016 | */ |
| 1017 | static int decode_info(struct xdr_stream *xdr, struct nfs2_fsstat *result) |
| 1018 | { |
| 1019 | __be32 *p; |
| 1020 | |
| 1021 | p = xdr_inline_decode(xdr, NFS_info_sz << 2); |
Chuck Lever | eb72f48 | 2019-02-11 11:24:21 -0500 | [diff] [blame^] | 1022 | if (unlikely(!p)) |
| 1023 | return -EIO; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 1024 | result->tsize = be32_to_cpup(p++); |
| 1025 | result->bsize = be32_to_cpup(p++); |
| 1026 | result->blocks = be32_to_cpup(p++); |
| 1027 | result->bfree = be32_to_cpup(p++); |
| 1028 | result->bavail = be32_to_cpup(p); |
| 1029 | return 0; |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 1032 | static int nfs2_xdr_dec_statfsres(struct rpc_rqst *req, struct xdr_stream *xdr, |
Christoph Hellwig | fc01648 | 2017-05-08 15:09:02 +0200 | [diff] [blame] | 1033 | void *result) |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 1034 | { |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 1035 | enum nfs_stat status; |
| 1036 | int error; |
| 1037 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 1038 | error = decode_stat(xdr, &status); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 1039 | if (unlikely(error)) |
| 1040 | goto out; |
| 1041 | if (status != NFS_OK) |
| 1042 | goto out_default; |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 1043 | error = decode_info(xdr, result); |
Chuck Lever | f796f8b | 2010-12-14 14:55:10 +0000 | [diff] [blame] | 1044 | out: |
| 1045 | return error; |
| 1046 | out_default: |
| 1047 | return nfs_stat_to_errno(status); |
| 1048 | } |
| 1049 | |
| 1050 | |
| 1051 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | * We need to translate between nfs status return values and |
| 1053 | * the local errno values which may not be the same. |
| 1054 | */ |
Chuck Lever | 8582849 | 2010-12-14 14:55:00 +0000 | [diff] [blame] | 1055 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | int stat; |
| 1057 | int errno; |
| 1058 | } nfs_errtbl[] = { |
| 1059 | { NFS_OK, 0 }, |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 1060 | { NFSERR_PERM, -EPERM }, |
| 1061 | { NFSERR_NOENT, -ENOENT }, |
| 1062 | { NFSERR_IO, -errno_NFSERR_IO}, |
| 1063 | { NFSERR_NXIO, -ENXIO }, |
| 1064 | /* { NFSERR_EAGAIN, -EAGAIN }, */ |
| 1065 | { NFSERR_ACCES, -EACCES }, |
| 1066 | { NFSERR_EXIST, -EEXIST }, |
| 1067 | { NFSERR_XDEV, -EXDEV }, |
| 1068 | { NFSERR_NODEV, -ENODEV }, |
| 1069 | { NFSERR_NOTDIR, -ENOTDIR }, |
| 1070 | { NFSERR_ISDIR, -EISDIR }, |
| 1071 | { NFSERR_INVAL, -EINVAL }, |
| 1072 | { NFSERR_FBIG, -EFBIG }, |
| 1073 | { NFSERR_NOSPC, -ENOSPC }, |
| 1074 | { NFSERR_ROFS, -EROFS }, |
| 1075 | { NFSERR_MLINK, -EMLINK }, |
| 1076 | { NFSERR_NAMETOOLONG, -ENAMETOOLONG }, |
| 1077 | { NFSERR_NOTEMPTY, -ENOTEMPTY }, |
| 1078 | { NFSERR_DQUOT, -EDQUOT }, |
| 1079 | { NFSERR_STALE, -ESTALE }, |
| 1080 | { NFSERR_REMOTE, -EREMOTE }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | #ifdef EWFLUSH |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 1082 | { NFSERR_WFLUSH, -EWFLUSH }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | #endif |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 1084 | { NFSERR_BADHANDLE, -EBADHANDLE }, |
| 1085 | { NFSERR_NOT_SYNC, -ENOTSYNC }, |
| 1086 | { NFSERR_BAD_COOKIE, -EBADCOOKIE }, |
| 1087 | { NFSERR_NOTSUPP, -ENOTSUPP }, |
| 1088 | { NFSERR_TOOSMALL, -ETOOSMALL }, |
Trond Myklebust | fdcb457 | 2010-02-08 09:32:40 -0500 | [diff] [blame] | 1089 | { NFSERR_SERVERFAULT, -EREMOTEIO }, |
Benny Halevy | 856dff3 | 2008-03-31 17:39:06 +0300 | [diff] [blame] | 1090 | { NFSERR_BADTYPE, -EBADTYPE }, |
| 1091 | { NFSERR_JUKEBOX, -EJUKEBOX }, |
| 1092 | { -1, -EIO } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | }; |
| 1094 | |
Chuck Lever | 8582849 | 2010-12-14 14:55:00 +0000 | [diff] [blame] | 1095 | /** |
| 1096 | * nfs_stat_to_errno - convert an NFS status code to a local errno |
| 1097 | * @status: NFS status code to convert |
| 1098 | * |
| 1099 | * Returns a local errno value, or -EIO if the NFS status code is |
| 1100 | * not recognized. This function is used jointly by NFSv2 and NFSv3. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | */ |
Bryan Schumaker | 5e7e5a0 | 2012-05-10 16:47:18 -0400 | [diff] [blame] | 1102 | static int nfs_stat_to_errno(enum nfs_stat status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | { |
| 1104 | int i; |
| 1105 | |
| 1106 | for (i = 0; nfs_errtbl[i].stat != -1; i++) { |
Chuck Lever | 8582849 | 2010-12-14 14:55:00 +0000 | [diff] [blame] | 1107 | if (nfs_errtbl[i].stat == (int)status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | return nfs_errtbl[i].errno; |
| 1109 | } |
Chuck Lever | 8582849 | 2010-12-14 14:55:00 +0000 | [diff] [blame] | 1110 | dprintk("NFS: Unrecognized nfs status value: %u\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | return nfs_errtbl[i].errno; |
| 1112 | } |
| 1113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | #define PROC(proc, argtype, restype, timer) \ |
| 1115 | [NFSPROC_##proc] = { \ |
| 1116 | .p_proc = NFSPROC_##proc, \ |
Christoph Hellwig | fcc8581 | 2017-05-08 10:01:49 +0200 | [diff] [blame] | 1117 | .p_encode = nfs2_xdr_enc_##argtype, \ |
Christoph Hellwig | fc01648 | 2017-05-08 15:09:02 +0200 | [diff] [blame] | 1118 | .p_decode = nfs2_xdr_dec_##restype, \ |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1119 | .p_arglen = NFS_##argtype##_sz, \ |
| 1120 | .p_replen = NFS_##restype##_sz, \ |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 1121 | .p_timer = timer, \ |
| 1122 | .p_statidx = NFSPROC_##proc, \ |
| 1123 | .p_name = #proc, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | } |
Christoph Hellwig | 511e936 | 2017-05-12 15:36:49 +0200 | [diff] [blame] | 1125 | const struct rpc_procinfo nfs_procedures[] = { |
Chuck Lever | 7d93bd71 | 2010-12-14 14:57:42 +0000 | [diff] [blame] | 1126 | PROC(GETATTR, fhandle, attrstat, 1), |
| 1127 | PROC(SETATTR, sattrargs, attrstat, 0), |
| 1128 | PROC(LOOKUP, diropargs, diropres, 2), |
| 1129 | PROC(READLINK, readlinkargs, readlinkres, 3), |
| 1130 | PROC(READ, readargs, readres, 3), |
| 1131 | PROC(WRITE, writeargs, writeres, 4), |
| 1132 | PROC(CREATE, createargs, diropres, 0), |
| 1133 | PROC(REMOVE, removeargs, stat, 0), |
| 1134 | PROC(RENAME, renameargs, stat, 0), |
| 1135 | PROC(LINK, linkargs, stat, 0), |
| 1136 | PROC(SYMLINK, symlinkargs, stat, 0), |
| 1137 | PROC(MKDIR, createargs, diropres, 0), |
| 1138 | PROC(RMDIR, diropargs, stat, 0), |
| 1139 | PROC(READDIR, readdirargs, readdirres, 3), |
| 1140 | PROC(STATFS, fhandle, statfsres, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | }; |
| 1142 | |
Christoph Hellwig | c551858 | 2017-05-08 23:27:10 +0200 | [diff] [blame] | 1143 | static unsigned int nfs_version2_counts[ARRAY_SIZE(nfs_procedures)]; |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 1144 | const struct rpc_version nfs_version2 = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | .number = 2, |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 1146 | .nrprocs = ARRAY_SIZE(nfs_procedures), |
Christoph Hellwig | c551858 | 2017-05-08 23:27:10 +0200 | [diff] [blame] | 1147 | .procs = nfs_procedures, |
| 1148 | .counts = nfs_version2_counts, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | }; |