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 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * XDR support for nfsd/protocol version 3. |
| 4 | * |
| 5 | * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de> |
| 6 | * |
| 7 | * 2003-08-09 Jamie Lokier: Use htonl() for nanoseconds, not htons()! |
| 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/namei.h> |
Stanislav Kinsbursky | b9c0ef8 | 2012-12-06 14:23:19 +0300 | [diff] [blame] | 11 | #include <linux/sunrpc/svc_xprt.h> |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 12 | #include "xdr3.h" |
J. Bruce Fields | 2e8138a | 2007-11-15 17:05:43 -0500 | [diff] [blame] | 13 | #include "auth.h" |
Stanislav Kinsbursky | b9c0ef8 | 2012-12-06 14:23:19 +0300 | [diff] [blame] | 14 | #include "netns.h" |
Al Viro | 3dadecc | 2013-01-24 02:18:08 -0500 | [diff] [blame] | 15 | #include "vfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /* |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 18 | * Force construction of an empty post-op attr |
| 19 | */ |
| 20 | static const struct svc_fh nfs3svc_null_fh = { |
| 21 | .fh_no_wcc = true, |
| 22 | }; |
| 23 | |
| 24 | /* |
Chuck Lever | 0a139d1 | 2020-10-22 13:42:13 -0400 | [diff] [blame] | 25 | * time_delta. {1, 0} means the server is accurate only |
| 26 | * to the nearest second. |
| 27 | */ |
| 28 | static const struct timespec64 nfs3svc_time_delta = { |
| 29 | .tv_sec = 1, |
| 30 | .tv_nsec = 0, |
| 31 | }; |
| 32 | |
| 33 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | * Mapping of S_IF* types to NFS file types |
| 35 | */ |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 36 | static const u32 nfs3_ftypes[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | NF3NON, NF3FIFO, NF3CHR, NF3BAD, |
| 38 | NF3DIR, NF3BAD, NF3BLK, NF3BAD, |
| 39 | NF3REG, NF3BAD, NF3LNK, NF3BAD, |
| 40 | NF3SOCK, NF3BAD, NF3LNK, NF3BAD, |
| 41 | }; |
| 42 | |
Trond Myklebust | 27c438f | 2019-09-02 13:02:56 -0400 | [diff] [blame] | 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* |
Chuck Lever | 9575363 | 2020-10-20 14:30:02 -0400 | [diff] [blame] | 45 | * Basic NFSv3 data types (RFC 1813 Sections 2.5 and 2.6) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | */ |
Chuck Lever | 9575363 | 2020-10-20 14:30:02 -0400 | [diff] [blame] | 47 | |
Adrian Bunk | 3ee6f61 | 2006-12-06 20:40:23 -0800 | [diff] [blame] | 48 | static __be32 * |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 49 | encode_nfstime3(__be32 *p, const struct timespec64 *time) |
| 50 | { |
| 51 | *p++ = cpu_to_be32((u32)time->tv_sec); |
| 52 | *p++ = cpu_to_be32(time->tv_nsec); |
| 53 | |
| 54 | return p; |
| 55 | } |
| 56 | |
Chuck Lever | 9cde936 | 2020-10-20 15:48:22 -0400 | [diff] [blame] | 57 | static bool |
| 58 | svcxdr_decode_nfstime3(struct xdr_stream *xdr, struct timespec64 *timep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
Chuck Lever | 9cde936 | 2020-10-20 15:48:22 -0400 | [diff] [blame] | 60 | __be32 *p; |
| 61 | |
| 62 | p = xdr_inline_decode(xdr, XDR_UNIT * 2); |
| 63 | if (!p) |
| 64 | return false; |
| 65 | timep->tv_sec = be32_to_cpup(p++); |
| 66 | timep->tv_nsec = be32_to_cpup(p); |
| 67 | |
| 68 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Chuck Lever | 05027ea | 2020-11-17 11:52:04 -0500 | [diff] [blame] | 71 | /** |
| 72 | * svcxdr_decode_nfs_fh3 - Decode an NFSv3 file handle |
| 73 | * @xdr: XDR stream positioned at an undecoded NFSv3 FH |
| 74 | * @fhp: OUT: filled-in server file handle |
| 75 | * |
| 76 | * Return values: |
| 77 | * %false: The encoded file handle was not valid |
| 78 | * %true: @fhp has been initialized |
| 79 | */ |
| 80 | bool |
Chuck Lever | 9575363 | 2020-10-20 14:30:02 -0400 | [diff] [blame] | 81 | svcxdr_decode_nfs_fh3(struct xdr_stream *xdr, struct svc_fh *fhp) |
| 82 | { |
| 83 | __be32 *p; |
| 84 | u32 size; |
| 85 | |
| 86 | if (xdr_stream_decode_u32(xdr, &size) < 0) |
| 87 | return false; |
| 88 | if (size == 0 || size > NFS3_FHSIZE) |
| 89 | return false; |
| 90 | p = xdr_inline_decode(xdr, size); |
| 91 | if (!p) |
| 92 | return false; |
| 93 | fh_init(fhp, NFS3_FHSIZE); |
| 94 | fhp->fh_handle.fh_size = size; |
NeilBrown | d8b2607 | 2021-09-02 11:16:32 +1000 | [diff] [blame] | 95 | memcpy(&fhp->fh_handle.fh_raw, p, size); |
Chuck Lever | 9575363 | 2020-10-20 14:30:02 -0400 | [diff] [blame] | 96 | |
| 97 | return true; |
| 98 | } |
| 99 | |
Chuck Lever | 20798df | 2020-11-18 16:11:42 -0500 | [diff] [blame] | 100 | /** |
| 101 | * svcxdr_encode_nfsstat3 - Encode an NFSv3 status code |
| 102 | * @xdr: XDR stream |
| 103 | * @status: status value to encode |
| 104 | * |
| 105 | * Return values: |
| 106 | * %false: Send buffer space was exhausted |
| 107 | * %true: Success |
| 108 | */ |
| 109 | bool |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 110 | svcxdr_encode_nfsstat3(struct xdr_stream *xdr, __be32 status) |
| 111 | { |
| 112 | __be32 *p; |
| 113 | |
| 114 | p = xdr_reserve_space(xdr, sizeof(status)); |
| 115 | if (!p) |
| 116 | return false; |
| 117 | *p = status; |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 122 | static bool |
| 123 | svcxdr_encode_nfs_fh3(struct xdr_stream *xdr, const struct svc_fh *fhp) |
| 124 | { |
| 125 | u32 size = fhp->fh_handle.fh_size; |
| 126 | __be32 *p; |
| 127 | |
| 128 | p = xdr_reserve_space(xdr, XDR_UNIT + size); |
| 129 | if (!p) |
| 130 | return false; |
| 131 | *p++ = cpu_to_be32(size); |
| 132 | if (size) |
| 133 | p[XDR_QUADLEN(size) - 1] = 0; |
NeilBrown | d8b2607 | 2021-09-02 11:16:32 +1000 | [diff] [blame] | 134 | memcpy(p, &fhp->fh_handle.fh_raw, size); |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 135 | |
| 136 | return true; |
| 137 | } |
| 138 | |
Chuck Lever | 78315b3 | 2020-10-22 15:27:23 -0400 | [diff] [blame] | 139 | static bool |
| 140 | svcxdr_encode_post_op_fh3(struct xdr_stream *xdr, const struct svc_fh *fhp) |
| 141 | { |
| 142 | if (xdr_stream_encode_item_present(xdr) < 0) |
| 143 | return false; |
| 144 | if (!svcxdr_encode_nfs_fh3(xdr, fhp)) |
| 145 | return false; |
| 146 | |
| 147 | return true; |
| 148 | } |
| 149 | |
Chuck Lever | 54d1d43 | 2020-10-20 15:42:33 -0400 | [diff] [blame] | 150 | static bool |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 151 | svcxdr_encode_cookieverf3(struct xdr_stream *xdr, const __be32 *verf) |
| 152 | { |
| 153 | __be32 *p; |
| 154 | |
| 155 | p = xdr_reserve_space(xdr, NFS3_COOKIEVERFSIZE); |
| 156 | if (!p) |
| 157 | return false; |
| 158 | memcpy(p, verf, NFS3_COOKIEVERFSIZE); |
| 159 | |
| 160 | return true; |
| 161 | } |
| 162 | |
| 163 | static bool |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 164 | svcxdr_encode_writeverf3(struct xdr_stream *xdr, const __be32 *verf) |
| 165 | { |
| 166 | __be32 *p; |
| 167 | |
| 168 | p = xdr_reserve_space(xdr, NFS3_WRITEVERFSIZE); |
| 169 | if (!p) |
| 170 | return false; |
| 171 | memcpy(p, verf, NFS3_WRITEVERFSIZE); |
| 172 | |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | static bool |
Chuck Lever | 54d1d43 | 2020-10-20 15:42:33 -0400 | [diff] [blame] | 177 | svcxdr_decode_filename3(struct xdr_stream *xdr, char **name, unsigned int *len) |
| 178 | { |
| 179 | u32 size, i; |
| 180 | __be32 *p; |
| 181 | char *c; |
| 182 | |
| 183 | if (xdr_stream_decode_u32(xdr, &size) < 0) |
| 184 | return false; |
| 185 | if (size == 0 || size > NFS3_MAXNAMLEN) |
| 186 | return false; |
| 187 | p = xdr_inline_decode(xdr, size); |
| 188 | if (!p) |
| 189 | return false; |
| 190 | |
| 191 | *len = size; |
| 192 | *name = (char *)p; |
| 193 | for (i = 0, c = *name; i < size; i++, c++) { |
| 194 | if (*c == '\0' || *c == '/') |
| 195 | return false; |
| 196 | } |
| 197 | |
| 198 | return true; |
| 199 | } |
| 200 | |
| 201 | static bool |
| 202 | svcxdr_decode_diropargs3(struct xdr_stream *xdr, struct svc_fh *fhp, |
| 203 | char **name, unsigned int *len) |
| 204 | { |
| 205 | return svcxdr_decode_nfs_fh3(xdr, fhp) && |
| 206 | svcxdr_decode_filename3(xdr, name, len); |
| 207 | } |
| 208 | |
Chuck Lever | 9cde936 | 2020-10-20 15:48:22 -0400 | [diff] [blame] | 209 | static bool |
| 210 | svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr, |
| 211 | struct iattr *iap) |
| 212 | { |
| 213 | u32 set_it; |
| 214 | |
| 215 | iap->ia_valid = 0; |
| 216 | |
| 217 | if (xdr_stream_decode_bool(xdr, &set_it) < 0) |
| 218 | return false; |
| 219 | if (set_it) { |
| 220 | u32 mode; |
| 221 | |
| 222 | if (xdr_stream_decode_u32(xdr, &mode) < 0) |
| 223 | return false; |
| 224 | iap->ia_valid |= ATTR_MODE; |
| 225 | iap->ia_mode = mode; |
| 226 | } |
| 227 | if (xdr_stream_decode_bool(xdr, &set_it) < 0) |
| 228 | return false; |
| 229 | if (set_it) { |
| 230 | u32 uid; |
| 231 | |
| 232 | if (xdr_stream_decode_u32(xdr, &uid) < 0) |
| 233 | return false; |
| 234 | iap->ia_uid = make_kuid(nfsd_user_namespace(rqstp), uid); |
| 235 | if (uid_valid(iap->ia_uid)) |
| 236 | iap->ia_valid |= ATTR_UID; |
| 237 | } |
| 238 | if (xdr_stream_decode_bool(xdr, &set_it) < 0) |
| 239 | return false; |
| 240 | if (set_it) { |
| 241 | u32 gid; |
| 242 | |
| 243 | if (xdr_stream_decode_u32(xdr, &gid) < 0) |
| 244 | return false; |
| 245 | iap->ia_gid = make_kgid(nfsd_user_namespace(rqstp), gid); |
| 246 | if (gid_valid(iap->ia_gid)) |
| 247 | iap->ia_valid |= ATTR_GID; |
| 248 | } |
| 249 | if (xdr_stream_decode_bool(xdr, &set_it) < 0) |
| 250 | return false; |
| 251 | if (set_it) { |
| 252 | u64 newsize; |
| 253 | |
| 254 | if (xdr_stream_decode_u64(xdr, &newsize) < 0) |
| 255 | return false; |
| 256 | iap->ia_valid |= ATTR_SIZE; |
Chuck Lever | a648fde | 2022-01-25 15:59:57 -0500 | [diff] [blame] | 257 | iap->ia_size = newsize; |
Chuck Lever | 9cde936 | 2020-10-20 15:48:22 -0400 | [diff] [blame] | 258 | } |
| 259 | if (xdr_stream_decode_u32(xdr, &set_it) < 0) |
| 260 | return false; |
| 261 | switch (set_it) { |
| 262 | case DONT_CHANGE: |
| 263 | break; |
| 264 | case SET_TO_SERVER_TIME: |
| 265 | iap->ia_valid |= ATTR_ATIME; |
| 266 | break; |
| 267 | case SET_TO_CLIENT_TIME: |
| 268 | if (!svcxdr_decode_nfstime3(xdr, &iap->ia_atime)) |
| 269 | return false; |
| 270 | iap->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET; |
| 271 | break; |
| 272 | default: |
| 273 | return false; |
| 274 | } |
| 275 | if (xdr_stream_decode_u32(xdr, &set_it) < 0) |
| 276 | return false; |
| 277 | switch (set_it) { |
| 278 | case DONT_CHANGE: |
| 279 | break; |
| 280 | case SET_TO_SERVER_TIME: |
| 281 | iap->ia_valid |= ATTR_MTIME; |
| 282 | break; |
| 283 | case SET_TO_CLIENT_TIME: |
| 284 | if (!svcxdr_decode_nfstime3(xdr, &iap->ia_mtime)) |
| 285 | return false; |
| 286 | iap->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET; |
| 287 | break; |
| 288 | default: |
| 289 | return false; |
| 290 | } |
| 291 | |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | static bool |
| 296 | svcxdr_decode_sattrguard3(struct xdr_stream *xdr, struct nfsd3_sattrargs *args) |
| 297 | { |
| 298 | __be32 *p; |
| 299 | u32 check; |
| 300 | |
| 301 | if (xdr_stream_decode_bool(xdr, &check) < 0) |
| 302 | return false; |
| 303 | if (check) { |
| 304 | p = xdr_inline_decode(xdr, XDR_UNIT * 2); |
| 305 | if (!p) |
| 306 | return false; |
| 307 | args->check_guard = 1; |
| 308 | args->guardtime = be32_to_cpup(p); |
| 309 | } else |
| 310 | args->check_guard = 0; |
| 311 | |
| 312 | return true; |
| 313 | } |
| 314 | |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 315 | static bool |
| 316 | svcxdr_decode_specdata3(struct xdr_stream *xdr, struct nfsd3_mknodargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 318 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 320 | p = xdr_inline_decode(xdr, XDR_UNIT * 2); |
| 321 | if (!p) |
| 322 | return false; |
| 323 | args->major = be32_to_cpup(p++); |
| 324 | args->minor = be32_to_cpup(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 326 | return true; |
| 327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 329 | static bool |
| 330 | svcxdr_decode_devicedata3(struct svc_rqst *rqstp, struct xdr_stream *xdr, |
| 331 | struct nfsd3_mknodargs *args) |
| 332 | { |
| 333 | return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs) && |
| 334 | svcxdr_decode_specdata3(xdr, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 337 | static bool |
| 338 | svcxdr_encode_fattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr, |
| 339 | const struct svc_fh *fhp, const struct kstat *stat) |
| 340 | { |
| 341 | struct user_namespace *userns = nfsd_user_namespace(rqstp); |
| 342 | __be32 *p; |
| 343 | u64 fsid; |
| 344 | |
| 345 | p = xdr_reserve_space(xdr, XDR_UNIT * 21); |
| 346 | if (!p) |
| 347 | return false; |
| 348 | |
| 349 | *p++ = cpu_to_be32(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]); |
| 350 | *p++ = cpu_to_be32((u32)(stat->mode & S_IALLUGO)); |
| 351 | *p++ = cpu_to_be32((u32)stat->nlink); |
| 352 | *p++ = cpu_to_be32((u32)from_kuid_munged(userns, stat->uid)); |
| 353 | *p++ = cpu_to_be32((u32)from_kgid_munged(userns, stat->gid)); |
| 354 | if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) |
| 355 | p = xdr_encode_hyper(p, (u64)NFS3_MAXPATHLEN); |
| 356 | else |
| 357 | p = xdr_encode_hyper(p, (u64)stat->size); |
| 358 | |
| 359 | /* used */ |
| 360 | p = xdr_encode_hyper(p, ((u64)stat->blocks) << 9); |
| 361 | |
| 362 | /* rdev */ |
| 363 | *p++ = cpu_to_be32((u32)MAJOR(stat->rdev)); |
| 364 | *p++ = cpu_to_be32((u32)MINOR(stat->rdev)); |
| 365 | |
| 366 | switch(fsid_source(fhp)) { |
| 367 | case FSIDSOURCE_FSID: |
| 368 | fsid = (u64)fhp->fh_export->ex_fsid; |
| 369 | break; |
| 370 | case FSIDSOURCE_UUID: |
| 371 | fsid = ((u64 *)fhp->fh_export->ex_uuid)[0]; |
| 372 | fsid ^= ((u64 *)fhp->fh_export->ex_uuid)[1]; |
| 373 | break; |
| 374 | default: |
| 375 | fsid = (u64)huge_encode_dev(fhp->fh_dentry->d_sb->s_dev); |
| 376 | } |
| 377 | p = xdr_encode_hyper(p, fsid); |
| 378 | |
| 379 | /* fileid */ |
| 380 | p = xdr_encode_hyper(p, stat->ino); |
| 381 | |
| 382 | p = encode_nfstime3(p, &stat->atime); |
| 383 | p = encode_nfstime3(p, &stat->mtime); |
| 384 | encode_nfstime3(p, &stat->ctime); |
| 385 | |
| 386 | return true; |
| 387 | } |
| 388 | |
Chuck Lever | 907c382 | 2020-10-22 13:56:58 -0400 | [diff] [blame] | 389 | static bool |
Chuck Lever | 70f8e83 | 2020-10-22 15:12:38 -0400 | [diff] [blame] | 390 | svcxdr_encode_wcc_attr(struct xdr_stream *xdr, const struct svc_fh *fhp) |
| 391 | { |
| 392 | __be32 *p; |
| 393 | |
| 394 | p = xdr_reserve_space(xdr, XDR_UNIT * 6); |
| 395 | if (!p) |
| 396 | return false; |
| 397 | p = xdr_encode_hyper(p, (u64)fhp->fh_pre_size); |
| 398 | p = encode_nfstime3(p, &fhp->fh_pre_mtime); |
| 399 | encode_nfstime3(p, &fhp->fh_pre_ctime); |
| 400 | |
| 401 | return true; |
| 402 | } |
| 403 | |
| 404 | static bool |
| 405 | svcxdr_encode_pre_op_attr(struct xdr_stream *xdr, const struct svc_fh *fhp) |
| 406 | { |
| 407 | if (!fhp->fh_pre_saved) { |
| 408 | if (xdr_stream_encode_item_absent(xdr) < 0) |
| 409 | return false; |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | if (xdr_stream_encode_item_present(xdr) < 0) |
| 414 | return false; |
| 415 | return svcxdr_encode_wcc_attr(xdr, fhp); |
| 416 | } |
| 417 | |
Chuck Lever | 20798df | 2020-11-18 16:11:42 -0500 | [diff] [blame] | 418 | /** |
| 419 | * svcxdr_encode_post_op_attr - Encode NFSv3 post-op attributes |
| 420 | * @rqstp: Context of a completed RPC transaction |
| 421 | * @xdr: XDR stream |
| 422 | * @fhp: File handle to encode |
| 423 | * |
| 424 | * Return values: |
| 425 | * %false: Send buffer space was exhausted |
| 426 | * %true: Success |
| 427 | */ |
| 428 | bool |
Chuck Lever | 907c382 | 2020-10-22 13:56:58 -0400 | [diff] [blame] | 429 | svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr, |
| 430 | const struct svc_fh *fhp) |
| 431 | { |
| 432 | struct dentry *dentry = fhp->fh_dentry; |
| 433 | struct kstat stat; |
| 434 | |
| 435 | /* |
| 436 | * The inode may be NULL if the call failed because of a |
| 437 | * stale file handle. In this case, no attributes are |
| 438 | * returned. |
| 439 | */ |
| 440 | if (fhp->fh_no_wcc || !dentry || !d_really_is_positive(dentry)) |
| 441 | goto no_post_op_attrs; |
| 442 | if (fh_getattr(fhp, &stat) != nfs_ok) |
| 443 | goto no_post_op_attrs; |
| 444 | |
| 445 | if (xdr_stream_encode_item_present(xdr) < 0) |
| 446 | return false; |
| 447 | lease_get_mtime(d_inode(dentry), &stat.mtime); |
| 448 | if (!svcxdr_encode_fattr3(rqstp, xdr, fhp, &stat)) |
| 449 | return false; |
| 450 | |
| 451 | return true; |
| 452 | |
| 453 | no_post_op_attrs: |
| 454 | return xdr_stream_encode_item_absent(xdr) > 0; |
| 455 | } |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | /* |
Chuck Lever | 70f8e83 | 2020-10-22 15:12:38 -0400 | [diff] [blame] | 458 | * Encode weak cache consistency data |
| 459 | */ |
| 460 | static bool |
| 461 | svcxdr_encode_wcc_data(struct svc_rqst *rqstp, struct xdr_stream *xdr, |
| 462 | const struct svc_fh *fhp) |
| 463 | { |
| 464 | struct dentry *dentry = fhp->fh_dentry; |
| 465 | |
| 466 | if (!dentry || !d_really_is_positive(dentry) || !fhp->fh_post_saved) |
| 467 | goto neither; |
| 468 | |
| 469 | /* before */ |
| 470 | if (!svcxdr_encode_pre_op_attr(xdr, fhp)) |
| 471 | return false; |
| 472 | |
| 473 | /* after */ |
| 474 | if (xdr_stream_encode_item_present(xdr) < 0) |
| 475 | return false; |
| 476 | if (!svcxdr_encode_fattr3(rqstp, xdr, fhp, &fhp->fh_post_attr)) |
| 477 | return false; |
| 478 | |
| 479 | return true; |
| 480 | |
| 481 | neither: |
| 482 | if (xdr_stream_encode_item_absent(xdr) < 0) |
| 483 | return false; |
| 484 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, fhp)) |
| 485 | return false; |
| 486 | |
| 487 | return true; |
| 488 | } |
| 489 | |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 490 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | * XDR decode functions |
| 492 | */ |
Chuck Lever | dcc4699 | 2020-10-01 18:59:12 -0400 | [diff] [blame] | 493 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 494 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 495 | nfs3svc_decode_fhandleargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 497 | struct nfsd_fhandle *args = rqstp->rq_argp; |
| 498 | |
Chuck Lever | 9575363 | 2020-10-20 14:30:02 -0400 | [diff] [blame] | 499 | return svcxdr_decode_nfs_fh3(xdr, &args->fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 502 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 503 | nfs3svc_decode_sattrargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 505 | struct nfsd3_sattrargs *args = rqstp->rq_argp; |
| 506 | |
Chuck Lever | 9cde936 | 2020-10-20 15:48:22 -0400 | [diff] [blame] | 507 | return svcxdr_decode_nfs_fh3(xdr, &args->fh) && |
| 508 | svcxdr_decode_sattr3(rqstp, xdr, &args->attrs) && |
| 509 | svcxdr_decode_sattrguard3(xdr, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 512 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 513 | nfs3svc_decode_diropargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 515 | struct nfsd3_diropargs *args = rqstp->rq_argp; |
| 516 | |
Chuck Lever | 54d1d43 | 2020-10-20 15:42:33 -0400 | [diff] [blame] | 517 | return svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 520 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 521 | nfs3svc_decode_accessargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 523 | struct nfsd3_accessargs *args = rqstp->rq_argp; |
| 524 | |
Chuck Lever | 3b921a2 | 2020-10-20 14:32:04 -0400 | [diff] [blame] | 525 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 526 | return false; |
Chuck Lever | 3b921a2 | 2020-10-20 14:32:04 -0400 | [diff] [blame] | 527 | if (xdr_stream_decode_u32(xdr, &args->access) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 528 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 530 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 533 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 534 | nfs3svc_decode_readargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 536 | struct nfsd3_readargs *args = rqstp->rq_argp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
Chuck Lever | be63bd2 | 2020-10-20 14:34:40 -0400 | [diff] [blame] | 538 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 539 | return false; |
Chuck Lever | be63bd2 | 2020-10-20 14:34:40 -0400 | [diff] [blame] | 540 | if (xdr_stream_decode_u64(xdr, &args->offset) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 541 | return false; |
Chuck Lever | be63bd2 | 2020-10-20 14:34:40 -0400 | [diff] [blame] | 542 | if (xdr_stream_decode_u32(xdr, &args->count) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 543 | return false; |
J. Bruce Fields | 9512a16 | 2017-05-16 15:57:42 -0400 | [diff] [blame] | 544 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 545 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 548 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 549 | nfs3svc_decode_writeargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 551 | struct nfsd3_writeargs *args = rqstp->rq_argp; |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 552 | u32 max_blocksize = svc_max_payload(rqstp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 554 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 555 | return false; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 556 | if (xdr_stream_decode_u64(xdr, &args->offset) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 557 | return false; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 558 | if (xdr_stream_decode_u32(xdr, &args->count) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 559 | return false; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 560 | if (xdr_stream_decode_u32(xdr, &args->stable) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 561 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 563 | /* opaque data */ |
| 564 | if (xdr_stream_decode_u32(xdr, &args->len) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 565 | return false; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 566 | |
| 567 | /* request sanity */ |
Peter Staubach | f34b9568 | 2007-05-09 02:34:48 -0700 | [diff] [blame] | 568 | if (args->count != args->len) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 569 | return false; |
Peter Staubach | f34b9568 | 2007-05-09 02:34:48 -0700 | [diff] [blame] | 570 | if (args->count > max_blocksize) { |
| 571 | args->count = max_blocksize; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 572 | args->len = max_blocksize; |
Peter Staubach | f34b9568 | 2007-05-09 02:34:48 -0700 | [diff] [blame] | 573 | } |
Chuck Lever | dae9a6c | 2021-09-30 17:06:21 -0400 | [diff] [blame] | 574 | if (!xdr_stream_subsegment(xdr, &args->payload, args->count)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 575 | return false; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 576 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 577 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 580 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 581 | nfs3svc_decode_createargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 583 | struct nfsd3_createargs *args = rqstp->rq_argp; |
| 584 | |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 585 | if (!svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 586 | return false; |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 587 | if (xdr_stream_decode_u32(xdr, &args->createmode) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 588 | return false; |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 589 | switch (args->createmode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | case NFS3_CREATE_UNCHECKED: |
| 591 | case NFS3_CREATE_GUARDED: |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 592 | return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | case NFS3_CREATE_EXCLUSIVE: |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 594 | args->verf = xdr_inline_decode(xdr, NFS3_CREATEVERFSIZE); |
| 595 | if (!args->verf) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 596 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | break; |
| 598 | default: |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 599 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 601 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 603 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 604 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 605 | nfs3svc_decode_mkdirargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 607 | struct nfsd3_createargs *args = rqstp->rq_argp; |
| 608 | |
Chuck Lever | 83374c2 | 2020-10-20 17:02:16 -0400 | [diff] [blame] | 609 | return svcxdr_decode_diropargs3(xdr, &args->fh, |
| 610 | &args->name, &args->len) && |
| 611 | svcxdr_decode_sattr3(rqstp, xdr, &args->attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 614 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 615 | nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 617 | struct nfsd3_symlinkargs *args = rqstp->rq_argp; |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 618 | struct kvec *head = rqstp->rq_arg.head; |
| 619 | struct kvec *tail = rqstp->rq_arg.tail; |
| 620 | size_t remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 622 | if (!svcxdr_decode_diropargs3(xdr, &args->ffh, &args->fname, &args->flen)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 623 | return false; |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 624 | if (!svcxdr_decode_sattr3(rqstp, xdr, &args->attrs)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 625 | return false; |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 626 | if (xdr_stream_decode_u32(xdr, &args->tlen) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 627 | return false; |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 628 | |
| 629 | /* request sanity */ |
| 630 | remaining = head->iov_len + rqstp->rq_arg.page_len + tail->iov_len; |
| 631 | remaining -= xdr_stream_pos(xdr); |
| 632 | if (remaining < xdr_align_size(args->tlen)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 633 | return false; |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 634 | |
| 635 | args->first.iov_base = xdr->p; |
| 636 | args->first.iov_len = head->iov_len - xdr_stream_pos(xdr); |
| 637 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 638 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 641 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 642 | nfs3svc_decode_mknodargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 644 | struct nfsd3_mknodargs *args = rqstp->rq_argp; |
| 645 | |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 646 | if (!svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 647 | return false; |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 648 | if (xdr_stream_decode_u32(xdr, &args->ftype) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 649 | return false; |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 650 | switch (args->ftype) { |
| 651 | case NF3CHR: |
| 652 | case NF3BLK: |
| 653 | return svcxdr_decode_devicedata3(rqstp, xdr, args); |
| 654 | case NF3SOCK: |
| 655 | case NF3FIFO: |
| 656 | return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs); |
| 657 | case NF3REG: |
| 658 | case NF3DIR: |
| 659 | case NF3LNK: |
| 660 | /* Valid XDR but illegal file types */ |
| 661 | break; |
| 662 | default: |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 663 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 666 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 669 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 670 | nfs3svc_decode_renameargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 672 | struct nfsd3_renameargs *args = rqstp->rq_argp; |
| 673 | |
Chuck Lever | d181e0a | 2020-10-20 15:44:12 -0400 | [diff] [blame] | 674 | return svcxdr_decode_diropargs3(xdr, &args->ffh, |
| 675 | &args->fname, &args->flen) && |
| 676 | svcxdr_decode_diropargs3(xdr, &args->tfh, |
| 677 | &args->tname, &args->tlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 680 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 681 | nfs3svc_decode_linkargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 683 | struct nfsd3_linkargs *args = rqstp->rq_argp; |
| 684 | |
Chuck Lever | efaa1e7 | 2020-10-19 13:26:32 -0400 | [diff] [blame] | 685 | return svcxdr_decode_nfs_fh3(xdr, &args->ffh) && |
| 686 | svcxdr_decode_diropargs3(xdr, &args->tfh, |
| 687 | &args->tname, &args->tlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 690 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 691 | nfs3svc_decode_readdirargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 693 | struct nfsd3_readdirargs *args = rqstp->rq_argp; |
NeilBrown | f875a79 | 2019-03-07 09:49:46 +1100 | [diff] [blame] | 694 | |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 695 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 696 | return false; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 697 | if (xdr_stream_decode_u64(xdr, &args->cookie) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 698 | return false; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 699 | args->verf = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE); |
| 700 | if (!args->verf) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 701 | return false; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 702 | if (xdr_stream_decode_u32(xdr, &args->count) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 703 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 705 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 708 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 709 | nfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 711 | struct nfsd3_readdirargs *args = rqstp->rq_argp; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 712 | u32 dircount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 714 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 715 | return false; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 716 | if (xdr_stream_decode_u64(xdr, &args->cookie) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 717 | return false; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 718 | args->verf = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE); |
| 719 | if (!args->verf) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 720 | return false; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 721 | /* dircount is ignored */ |
| 722 | if (xdr_stream_decode_u32(xdr, &dircount) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 723 | return false; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 724 | if (xdr_stream_decode_u32(xdr, &args->count) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 725 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 727 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 730 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 731 | nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 733 | struct nfsd3_commitargs *args = rqstp->rq_argp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
Chuck Lever | c8d26a0 | 2020-10-20 14:41:56 -0400 | [diff] [blame] | 735 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 736 | return false; |
Chuck Lever | c8d26a0 | 2020-10-20 14:41:56 -0400 | [diff] [blame] | 737 | if (xdr_stream_decode_u64(xdr, &args->offset) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 738 | return false; |
Chuck Lever | c8d26a0 | 2020-10-20 14:41:56 -0400 | [diff] [blame] | 739 | if (xdr_stream_decode_u32(xdr, &args->count) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 740 | return false; |
Chuck Lever | c8d26a0 | 2020-10-20 14:41:56 -0400 | [diff] [blame] | 741 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 742 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /* |
| 746 | * XDR encode functions |
| 747 | */ |
Chuck Lever | cc028a1 | 2020-10-02 15:52:44 -0400 | [diff] [blame] | 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | /* GETATTR */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 750 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 751 | nfs3svc_encode_getattrres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 753 | struct nfsd3_attrstat *resp = rqstp->rq_resp; |
| 754 | |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 755 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 756 | return false; |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 757 | switch (resp->status) { |
| 758 | case nfs_ok: |
| 759 | lease_get_mtime(d_inode(resp->fh.fh_dentry), &resp->stat.mtime); |
| 760 | if (!svcxdr_encode_fattr3(rqstp, xdr, &resp->fh, &resp->stat)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 761 | return false; |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 762 | break; |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 763 | } |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 764 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 765 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /* SETATTR, REMOVE, RMDIR */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 769 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 770 | nfs3svc_encode_wccstat(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 772 | struct nfsd3_attrstat *resp = rqstp->rq_resp; |
| 773 | |
Chuck Lever | 70f8e83 | 2020-10-22 15:12:38 -0400 | [diff] [blame] | 774 | return svcxdr_encode_nfsstat3(xdr, resp->status) && |
| 775 | svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | /* LOOKUP */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 779 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 780 | nfs3svc_encode_lookupres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 782 | struct nfsd3_diropres *resp = rqstp->rq_resp; |
| 783 | |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 784 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 785 | return false; |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 786 | switch (resp->status) { |
| 787 | case nfs_ok: |
| 788 | if (!svcxdr_encode_nfs_fh3(xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 789 | return false; |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 790 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 791 | return false; |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 792 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->dirfh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 793 | return false; |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 794 | break; |
| 795 | default: |
| 796 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->dirfh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 797 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 799 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 800 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | /* ACCESS */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 804 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 805 | nfs3svc_encode_accessres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 807 | struct nfsd3_accessres *resp = rqstp->rq_resp; |
| 808 | |
Chuck Lever | 907c382 | 2020-10-22 13:56:58 -0400 | [diff] [blame] | 809 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 810 | return false; |
Chuck Lever | 907c382 | 2020-10-22 13:56:58 -0400 | [diff] [blame] | 811 | switch (resp->status) { |
| 812 | case nfs_ok: |
| 813 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 814 | return false; |
Chuck Lever | 907c382 | 2020-10-22 13:56:58 -0400 | [diff] [blame] | 815 | if (xdr_stream_encode_u32(xdr, resp->access) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 816 | return false; |
Chuck Lever | 907c382 | 2020-10-22 13:56:58 -0400 | [diff] [blame] | 817 | break; |
| 818 | default: |
| 819 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 820 | return false; |
Chuck Lever | 907c382 | 2020-10-22 13:56:58 -0400 | [diff] [blame] | 821 | } |
| 822 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 823 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | /* READLINK */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 827 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 828 | nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 830 | struct nfsd3_readlinkres *resp = rqstp->rq_resp; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 831 | struct kvec *head = rqstp->rq_res.head; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 832 | |
Chuck Lever | 9a9c892 | 2020-10-22 15:18:40 -0400 | [diff] [blame] | 833 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 834 | return false; |
Chuck Lever | 9a9c892 | 2020-10-22 15:18:40 -0400 | [diff] [blame] | 835 | switch (resp->status) { |
| 836 | case nfs_ok: |
| 837 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 838 | return false; |
Chuck Lever | 9a9c892 | 2020-10-22 15:18:40 -0400 | [diff] [blame] | 839 | if (xdr_stream_encode_u32(xdr, resp->len) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 840 | return false; |
Chuck Lever | 9a9c892 | 2020-10-22 15:18:40 -0400 | [diff] [blame] | 841 | xdr_write_pages(xdr, resp->pages, 0, resp->len); |
| 842 | if (svc_encode_result_payload(rqstp, head->iov_len, resp->len) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 843 | return false; |
Chuck Lever | 9a9c892 | 2020-10-22 15:18:40 -0400 | [diff] [blame] | 844 | break; |
| 845 | default: |
| 846 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 847 | return false; |
Chuck Lever | 9a9c892 | 2020-10-22 15:18:40 -0400 | [diff] [blame] | 848 | } |
| 849 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 850 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | /* READ */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 854 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 855 | nfs3svc_encode_readres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 857 | struct nfsd3_readres *resp = rqstp->rq_resp; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 858 | struct kvec *head = rqstp->rq_res.head; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 859 | |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 860 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 861 | return false; |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 862 | switch (resp->status) { |
| 863 | case nfs_ok: |
| 864 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 865 | return false; |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 866 | if (xdr_stream_encode_u32(xdr, resp->count) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 867 | return false; |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 868 | if (xdr_stream_encode_bool(xdr, resp->eof) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 869 | return false; |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 870 | if (xdr_stream_encode_u32(xdr, resp->count) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 871 | return false; |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 872 | xdr_write_pages(xdr, resp->pages, rqstp->rq_res.page_base, |
| 873 | resp->count); |
| 874 | if (svc_encode_result_payload(rqstp, head->iov_len, resp->count) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 875 | return false; |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 876 | break; |
| 877 | default: |
| 878 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 879 | return false; |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 880 | } |
| 881 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 882 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | /* WRITE */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 886 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 887 | nfs3svc_encode_writeres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 889 | struct nfsd3_writeres *resp = rqstp->rq_resp; |
Stanislav Kinsbursky | b9c0ef8 | 2012-12-06 14:23:19 +0300 | [diff] [blame] | 890 | |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 891 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 892 | return false; |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 893 | switch (resp->status) { |
| 894 | case nfs_ok: |
| 895 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 896 | return false; |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 897 | if (xdr_stream_encode_u32(xdr, resp->count) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 898 | return false; |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 899 | if (xdr_stream_encode_u32(xdr, resp->committed) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 900 | return false; |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 901 | if (!svcxdr_encode_writeverf3(xdr, resp->verf)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 902 | return false; |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 903 | break; |
| 904 | default: |
| 905 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 906 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 908 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 909 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | /* CREATE, MKDIR, SYMLINK, MKNOD */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 913 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 914 | nfs3svc_encode_createres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 916 | struct nfsd3_diropres *resp = rqstp->rq_resp; |
| 917 | |
Chuck Lever | 78315b3 | 2020-10-22 15:27:23 -0400 | [diff] [blame] | 918 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 919 | return false; |
Chuck Lever | 78315b3 | 2020-10-22 15:27:23 -0400 | [diff] [blame] | 920 | switch (resp->status) { |
| 921 | case nfs_ok: |
| 922 | if (!svcxdr_encode_post_op_fh3(xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 923 | return false; |
Chuck Lever | 78315b3 | 2020-10-22 15:27:23 -0400 | [diff] [blame] | 924 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 925 | return false; |
Chuck Lever | 78315b3 | 2020-10-22 15:27:23 -0400 | [diff] [blame] | 926 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->dirfh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 927 | return false; |
Chuck Lever | 78315b3 | 2020-10-22 15:27:23 -0400 | [diff] [blame] | 928 | break; |
| 929 | default: |
| 930 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->dirfh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 931 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } |
Chuck Lever | 78315b3 | 2020-10-22 15:27:23 -0400 | [diff] [blame] | 933 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 934 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | /* RENAME */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 938 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 939 | nfs3svc_encode_renameres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 941 | struct nfsd3_renameres *resp = rqstp->rq_resp; |
| 942 | |
Chuck Lever | 89d79e9 | 2020-10-22 15:33:05 -0400 | [diff] [blame] | 943 | return svcxdr_encode_nfsstat3(xdr, resp->status) && |
| 944 | svcxdr_encode_wcc_data(rqstp, xdr, &resp->ffh) && |
| 945 | svcxdr_encode_wcc_data(rqstp, xdr, &resp->tfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | /* LINK */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 949 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 950 | nfs3svc_encode_linkres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 952 | struct nfsd3_linkres *resp = rqstp->rq_resp; |
| 953 | |
Chuck Lever | 4d74380 | 2020-10-22 15:08:29 -0400 | [diff] [blame] | 954 | return svcxdr_encode_nfsstat3(xdr, resp->status) && |
| 955 | svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh) && |
| 956 | svcxdr_encode_wcc_data(rqstp, xdr, &resp->tfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | /* READDIR */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 960 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 961 | nfs3svc_encode_readdirres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 963 | struct nfsd3_readdirres *resp = rqstp->rq_resp; |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 964 | struct xdr_buf *dirlist = &resp->dirlist; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 965 | |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 966 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 967 | return false; |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 968 | switch (resp->status) { |
| 969 | case nfs_ok: |
| 970 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 971 | return false; |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 972 | if (!svcxdr_encode_cookieverf3(xdr, resp->verf)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 973 | return false; |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 974 | xdr_write_pages(xdr, dirlist->pages, 0, dirlist->len); |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 975 | /* no more entries */ |
| 976 | if (xdr_stream_encode_item_absent(xdr) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 977 | return false; |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 978 | if (xdr_stream_encode_bool(xdr, resp->common.err == nfserr_eof) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 979 | return false; |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 980 | break; |
| 981 | default: |
| 982 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 983 | return false; |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 984 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 986 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Al Viro | efe3965 | 2012-04-13 00:32:14 -0400 | [diff] [blame] | 989 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp, |
NeilBrown | 43b0e7e | 2015-05-03 09:16:53 +1000 | [diff] [blame] | 991 | const char *name, int namlen, u64 ino) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | { |
| 993 | struct svc_export *exp; |
| 994 | struct dentry *dparent, *dchild; |
Al Viro | efe3965 | 2012-04-13 00:32:14 -0400 | [diff] [blame] | 995 | __be32 rv = nfserr_noent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | |
| 997 | dparent = cd->fh.fh_dentry; |
| 998 | exp = cd->fh.fh_export; |
| 999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | if (isdotent(name, namlen)) { |
| 1001 | if (namlen == 2) { |
| 1002 | dchild = dget_parent(dparent); |
J. Bruce Fields | 51b2ee7 | 2021-01-11 16:01:29 -0500 | [diff] [blame] | 1003 | /* |
| 1004 | * Don't return filehandle for ".." if we're at |
| 1005 | * the filesystem or export root: |
| 1006 | */ |
Al Viro | efe3965 | 2012-04-13 00:32:14 -0400 | [diff] [blame] | 1007 | if (dchild == dparent) |
| 1008 | goto out; |
J. Bruce Fields | 51b2ee7 | 2021-01-11 16:01:29 -0500 | [diff] [blame] | 1009 | if (dparent == exp->ex_path.dentry) |
| 1010 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } else |
| 1012 | dchild = dget(dparent); |
| 1013 | } else |
Al Viro | 6c2d4798 | 2019-10-31 01:21:58 -0400 | [diff] [blame] | 1014 | dchild = lookup_positive_unlocked(name, dparent, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | if (IS_ERR(dchild)) |
Al Viro | efe3965 | 2012-04-13 00:32:14 -0400 | [diff] [blame] | 1016 | return rv; |
J. Bruce Fields | 8177e6d | 2009-09-04 14:13:09 -0400 | [diff] [blame] | 1017 | if (d_mountpoint(dchild)) |
| 1018 | goto out; |
NeilBrown | 43b0e7e | 2015-05-03 09:16:53 +1000 | [diff] [blame] | 1019 | if (dchild->d_inode->i_ino != ino) |
| 1020 | goto out; |
Al Viro | efe3965 | 2012-04-13 00:32:14 -0400 | [diff] [blame] | 1021 | rv = fh_compose(fhp, exp, dchild, &cd->fh); |
J. Bruce Fields | 8177e6d | 2009-09-04 14:13:09 -0400 | [diff] [blame] | 1022 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | dput(dchild); |
| 1024 | return rv; |
| 1025 | } |
| 1026 | |
Chuck Lever | a161e6c | 2020-11-10 09:57:14 -0500 | [diff] [blame] | 1027 | /** |
| 1028 | * nfs3svc_encode_cookie3 - Encode a directory offset cookie |
| 1029 | * @resp: readdir result context |
| 1030 | * @offset: offset cookie to encode |
| 1031 | * |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1032 | * The buffer space for the offset cookie has already been reserved |
| 1033 | * by svcxdr_encode_entry3_common(). |
Chuck Lever | a161e6c | 2020-11-10 09:57:14 -0500 | [diff] [blame] | 1034 | */ |
| 1035 | void nfs3svc_encode_cookie3(struct nfsd3_readdirres *resp, u64 offset) |
| 1036 | { |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1037 | __be64 cookie = cpu_to_be64(offset); |
Chuck Lever | a161e6c | 2020-11-10 09:57:14 -0500 | [diff] [blame] | 1038 | |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1039 | if (!resp->cookie_offset) |
| 1040 | return; |
| 1041 | write_bytes_to_xdr_buf(&resp->dirlist, resp->cookie_offset, &cookie, |
| 1042 | sizeof(cookie)); |
| 1043 | resp->cookie_offset = 0; |
Chuck Lever | a161e6c | 2020-11-10 09:57:14 -0500 | [diff] [blame] | 1044 | } |
| 1045 | |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1046 | static bool |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1047 | svcxdr_encode_entry3_common(struct nfsd3_readdirres *resp, const char *name, |
| 1048 | int namlen, loff_t offset, u64 ino) |
| 1049 | { |
| 1050 | struct xdr_buf *dirlist = &resp->dirlist; |
| 1051 | struct xdr_stream *xdr = &resp->xdr; |
| 1052 | |
| 1053 | if (xdr_stream_encode_item_present(xdr) < 0) |
| 1054 | return false; |
| 1055 | /* fileid */ |
| 1056 | if (xdr_stream_encode_u64(xdr, ino) < 0) |
| 1057 | return false; |
| 1058 | /* name */ |
| 1059 | if (xdr_stream_encode_opaque(xdr, name, min(namlen, NFS3_MAXNAMLEN)) < 0) |
| 1060 | return false; |
| 1061 | /* cookie */ |
| 1062 | resp->cookie_offset = dirlist->len; |
Chuck Lever | c306d73 | 2022-01-25 15:57:45 -0500 | [diff] [blame] | 1063 | if (xdr_stream_encode_u64(xdr, OFFSET_MAX) < 0) |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1064 | return false; |
| 1065 | |
| 1066 | return true; |
| 1067 | } |
| 1068 | |
| 1069 | /** |
| 1070 | * nfs3svc_encode_entry3 - encode one NFSv3 READDIR entry |
| 1071 | * @data: directory context |
| 1072 | * @name: name of the object to be encoded |
| 1073 | * @namlen: length of that name, in bytes |
| 1074 | * @offset: the offset of the previous entry |
| 1075 | * @ino: the fileid of this entry |
| 1076 | * @d_type: unused |
| 1077 | * |
| 1078 | * Return values: |
| 1079 | * %0: Entry was successfully encoded. |
| 1080 | * %-EINVAL: An encoding problem occured, secondary status code in resp->common.err |
| 1081 | * |
| 1082 | * On exit, the following fields are updated: |
| 1083 | * - resp->xdr |
| 1084 | * - resp->common.err |
| 1085 | * - resp->cookie_offset |
| 1086 | */ |
| 1087 | int nfs3svc_encode_entry3(void *data, const char *name, int namlen, |
| 1088 | loff_t offset, u64 ino, unsigned int d_type) |
| 1089 | { |
| 1090 | struct readdir_cd *ccd = data; |
| 1091 | struct nfsd3_readdirres *resp = container_of(ccd, |
| 1092 | struct nfsd3_readdirres, |
| 1093 | common); |
| 1094 | unsigned int starting_length = resp->dirlist.len; |
| 1095 | |
| 1096 | /* The offset cookie for the previous entry */ |
| 1097 | nfs3svc_encode_cookie3(resp, offset); |
| 1098 | |
| 1099 | if (!svcxdr_encode_entry3_common(resp, name, namlen, offset, ino)) |
| 1100 | goto out_toosmall; |
| 1101 | |
| 1102 | xdr_commit_encode(&resp->xdr); |
| 1103 | resp->common.err = nfs_ok; |
| 1104 | return 0; |
| 1105 | |
| 1106 | out_toosmall: |
| 1107 | resp->cookie_offset = 0; |
| 1108 | resp->common.err = nfserr_toosmall; |
| 1109 | resp->dirlist.len = starting_length; |
| 1110 | return -EINVAL; |
| 1111 | } |
| 1112 | |
| 1113 | static bool |
| 1114 | svcxdr_encode_entry3_plus(struct nfsd3_readdirres *resp, const char *name, |
| 1115 | int namlen, u64 ino) |
| 1116 | { |
| 1117 | struct xdr_stream *xdr = &resp->xdr; |
| 1118 | struct svc_fh *fhp = &resp->scratch; |
| 1119 | bool result; |
| 1120 | |
| 1121 | result = false; |
| 1122 | fh_init(fhp, NFS3_FHSIZE); |
| 1123 | if (compose_entry_fh(resp, fhp, name, namlen, ino) != nfs_ok) |
| 1124 | goto out_noattrs; |
| 1125 | |
| 1126 | if (!svcxdr_encode_post_op_attr(resp->rqstp, xdr, fhp)) |
| 1127 | goto out; |
| 1128 | if (!svcxdr_encode_post_op_fh3(xdr, fhp)) |
| 1129 | goto out; |
| 1130 | result = true; |
| 1131 | |
| 1132 | out: |
| 1133 | fh_put(fhp); |
| 1134 | return result; |
| 1135 | |
| 1136 | out_noattrs: |
| 1137 | if (xdr_stream_encode_item_absent(xdr) < 0) |
| 1138 | return false; |
| 1139 | if (xdr_stream_encode_item_absent(xdr) < 0) |
| 1140 | return false; |
| 1141 | return true; |
| 1142 | } |
| 1143 | |
| 1144 | /** |
| 1145 | * nfs3svc_encode_entryplus3 - encode one NFSv3 READDIRPLUS entry |
| 1146 | * @data: directory context |
| 1147 | * @name: name of the object to be encoded |
| 1148 | * @namlen: length of that name, in bytes |
| 1149 | * @offset: the offset of the previous entry |
| 1150 | * @ino: the fileid of this entry |
| 1151 | * @d_type: unused |
| 1152 | * |
| 1153 | * Return values: |
| 1154 | * %0: Entry was successfully encoded. |
| 1155 | * %-EINVAL: An encoding problem occured, secondary status code in resp->common.err |
| 1156 | * |
| 1157 | * On exit, the following fields are updated: |
| 1158 | * - resp->xdr |
| 1159 | * - resp->common.err |
| 1160 | * - resp->cookie_offset |
| 1161 | */ |
| 1162 | int nfs3svc_encode_entryplus3(void *data, const char *name, int namlen, |
| 1163 | loff_t offset, u64 ino, unsigned int d_type) |
| 1164 | { |
| 1165 | struct readdir_cd *ccd = data; |
| 1166 | struct nfsd3_readdirres *resp = container_of(ccd, |
| 1167 | struct nfsd3_readdirres, |
| 1168 | common); |
| 1169 | unsigned int starting_length = resp->dirlist.len; |
| 1170 | |
| 1171 | /* The offset cookie for the previous entry */ |
| 1172 | nfs3svc_encode_cookie3(resp, offset); |
| 1173 | |
| 1174 | if (!svcxdr_encode_entry3_common(resp, name, namlen, offset, ino)) |
| 1175 | goto out_toosmall; |
| 1176 | if (!svcxdr_encode_entry3_plus(resp, name, namlen, ino)) |
| 1177 | goto out_toosmall; |
| 1178 | |
| 1179 | xdr_commit_encode(&resp->xdr); |
| 1180 | resp->common.err = nfs_ok; |
| 1181 | return 0; |
| 1182 | |
| 1183 | out_toosmall: |
| 1184 | resp->cookie_offset = 0; |
| 1185 | resp->common.err = nfserr_toosmall; |
| 1186 | resp->dirlist.len = starting_length; |
| 1187 | return -EINVAL; |
| 1188 | } |
| 1189 | |
| 1190 | static bool |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1191 | svcxdr_encode_fsstat3resok(struct xdr_stream *xdr, |
| 1192 | const struct nfsd3_fsstatres *resp) |
| 1193 | { |
| 1194 | const struct kstatfs *s = &resp->stats; |
| 1195 | u64 bs = s->f_bsize; |
| 1196 | __be32 *p; |
| 1197 | |
| 1198 | p = xdr_reserve_space(xdr, XDR_UNIT * 13); |
| 1199 | if (!p) |
| 1200 | return false; |
| 1201 | p = xdr_encode_hyper(p, bs * s->f_blocks); /* total bytes */ |
| 1202 | p = xdr_encode_hyper(p, bs * s->f_bfree); /* free bytes */ |
| 1203 | p = xdr_encode_hyper(p, bs * s->f_bavail); /* user available bytes */ |
| 1204 | p = xdr_encode_hyper(p, s->f_files); /* total inodes */ |
| 1205 | p = xdr_encode_hyper(p, s->f_ffree); /* free inodes */ |
| 1206 | p = xdr_encode_hyper(p, s->f_ffree); /* user available inodes */ |
| 1207 | *p = cpu_to_be32(resp->invarsec); /* mean unchanged time */ |
| 1208 | |
| 1209 | return true; |
| 1210 | } |
| 1211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | /* FSSTAT */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1213 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 1214 | nfs3svc_encode_fsstatres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1216 | struct nfsd3_fsstatres *resp = rqstp->rq_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1218 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1219 | return false; |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1220 | switch (resp->status) { |
| 1221 | case nfs_ok: |
| 1222 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1223 | return false; |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1224 | if (!svcxdr_encode_fsstat3resok(xdr, resp)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1225 | return false; |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1226 | break; |
| 1227 | default: |
| 1228 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1229 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | } |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1231 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1232 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
Chuck Lever | 0a139d1 | 2020-10-22 13:42:13 -0400 | [diff] [blame] | 1235 | static bool |
| 1236 | svcxdr_encode_fsinfo3resok(struct xdr_stream *xdr, |
| 1237 | const struct nfsd3_fsinfores *resp) |
| 1238 | { |
| 1239 | __be32 *p; |
| 1240 | |
| 1241 | p = xdr_reserve_space(xdr, XDR_UNIT * 12); |
| 1242 | if (!p) |
| 1243 | return false; |
| 1244 | *p++ = cpu_to_be32(resp->f_rtmax); |
| 1245 | *p++ = cpu_to_be32(resp->f_rtpref); |
| 1246 | *p++ = cpu_to_be32(resp->f_rtmult); |
| 1247 | *p++ = cpu_to_be32(resp->f_wtmax); |
| 1248 | *p++ = cpu_to_be32(resp->f_wtpref); |
| 1249 | *p++ = cpu_to_be32(resp->f_wtmult); |
| 1250 | *p++ = cpu_to_be32(resp->f_dtpref); |
| 1251 | p = xdr_encode_hyper(p, resp->f_maxfilesize); |
| 1252 | p = encode_nfstime3(p, &nfs3svc_time_delta); |
| 1253 | *p = cpu_to_be32(resp->f_properties); |
| 1254 | |
| 1255 | return true; |
| 1256 | } |
| 1257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | /* FSINFO */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1259 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 1260 | nfs3svc_encode_fsinfores(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1262 | struct nfsd3_fsinfores *resp = rqstp->rq_resp; |
| 1263 | |
Chuck Lever | 0a139d1 | 2020-10-22 13:42:13 -0400 | [diff] [blame] | 1264 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1265 | return false; |
Chuck Lever | 0a139d1 | 2020-10-22 13:42:13 -0400 | [diff] [blame] | 1266 | switch (resp->status) { |
| 1267 | case nfs_ok: |
| 1268 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1269 | return false; |
Chuck Lever | 0a139d1 | 2020-10-22 13:42:13 -0400 | [diff] [blame] | 1270 | if (!svcxdr_encode_fsinfo3resok(xdr, resp)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1271 | return false; |
Chuck Lever | 0a139d1 | 2020-10-22 13:42:13 -0400 | [diff] [blame] | 1272 | break; |
| 1273 | default: |
| 1274 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1275 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1278 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Chuck Lever | ded04a5 | 2020-11-06 13:15:09 -0500 | [diff] [blame] | 1281 | static bool |
| 1282 | svcxdr_encode_pathconf3resok(struct xdr_stream *xdr, |
| 1283 | const struct nfsd3_pathconfres *resp) |
| 1284 | { |
| 1285 | __be32 *p; |
| 1286 | |
| 1287 | p = xdr_reserve_space(xdr, XDR_UNIT * 6); |
| 1288 | if (!p) |
| 1289 | return false; |
| 1290 | *p++ = cpu_to_be32(resp->p_link_max); |
| 1291 | *p++ = cpu_to_be32(resp->p_name_max); |
| 1292 | p = xdr_encode_bool(p, resp->p_no_trunc); |
| 1293 | p = xdr_encode_bool(p, resp->p_chown_restricted); |
| 1294 | p = xdr_encode_bool(p, resp->p_case_insensitive); |
| 1295 | xdr_encode_bool(p, resp->p_case_preserving); |
| 1296 | |
| 1297 | return true; |
| 1298 | } |
| 1299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | /* PATHCONF */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1301 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 1302 | nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1304 | struct nfsd3_pathconfres *resp = rqstp->rq_resp; |
| 1305 | |
Chuck Lever | ded04a5 | 2020-11-06 13:15:09 -0500 | [diff] [blame] | 1306 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1307 | return false; |
Chuck Lever | ded04a5 | 2020-11-06 13:15:09 -0500 | [diff] [blame] | 1308 | switch (resp->status) { |
| 1309 | case nfs_ok: |
| 1310 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1311 | return false; |
Chuck Lever | ded04a5 | 2020-11-06 13:15:09 -0500 | [diff] [blame] | 1312 | if (!svcxdr_encode_pathconf3resok(xdr, resp)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1313 | return false; |
Chuck Lever | ded04a5 | 2020-11-06 13:15:09 -0500 | [diff] [blame] | 1314 | break; |
| 1315 | default: |
| 1316 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1317 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1320 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /* COMMIT */ |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1324 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 1325 | nfs3svc_encode_commitres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1327 | struct nfsd3_commitres *resp = rqstp->rq_resp; |
Stanislav Kinsbursky | b9c0ef8 | 2012-12-06 14:23:19 +0300 | [diff] [blame] | 1328 | |
Chuck Lever | 5ef2826 | 2020-10-22 15:35:46 -0400 | [diff] [blame] | 1329 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1330 | return false; |
Chuck Lever | 5ef2826 | 2020-10-22 15:35:46 -0400 | [diff] [blame] | 1331 | switch (resp->status) { |
| 1332 | case nfs_ok: |
| 1333 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1334 | return false; |
Chuck Lever | 5ef2826 | 2020-10-22 15:35:46 -0400 | [diff] [blame] | 1335 | if (!svcxdr_encode_writeverf3(xdr, resp->verf)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1336 | return false; |
Chuck Lever | 5ef2826 | 2020-10-22 15:35:46 -0400 | [diff] [blame] | 1337 | break; |
| 1338 | default: |
| 1339 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1340 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | } |
Chuck Lever | 5ef2826 | 2020-10-22 15:35:46 -0400 | [diff] [blame] | 1342 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 1343 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | /* |
| 1347 | * XDR release functions |
| 1348 | */ |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 1349 | void |
| 1350 | nfs3svc_release_fhandle(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | { |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 1352 | struct nfsd3_attrstat *resp = rqstp->rq_resp; |
| 1353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | fh_put(&resp->fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 1357 | void |
| 1358 | nfs3svc_release_fhandle2(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | { |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 1360 | struct nfsd3_fhandle_pair *resp = rqstp->rq_resp; |
| 1361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | fh_put(&resp->fh1); |
| 1363 | fh_put(&resp->fh2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | } |