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; |
| 95 | memcpy(&fhp->fh_handle.fh_base, p, size); |
| 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; |
| 134 | memcpy(p, &fhp->fh_handle.fh_base, size); |
| 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; |
| 257 | iap->ia_size = min_t(u64, newsize, NFS_OFFSET_MAX); |
| 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 | |
J. Bruce Fields | 428a23d | 2021-01-29 14:27:01 -0500 | [diff] [blame] | 490 | static bool fs_supports_change_attribute(struct super_block *sb) |
| 491 | { |
| 492 | return sb->s_flags & SB_I_VERSION || sb->s_export_op->fetch_iversion; |
| 493 | } |
| 494 | |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 495 | /* |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 496 | * Fill in the pre_op attr for the wcc data |
| 497 | */ |
| 498 | void fill_pre_wcc(struct svc_fh *fhp) |
| 499 | { |
| 500 | struct inode *inode; |
| 501 | struct kstat stat; |
J. Bruce Fields | 942b20dc | 2020-11-30 17:46:17 -0500 | [diff] [blame] | 502 | bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE); |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 503 | |
Jeff Layton | daab110 | 2020-11-30 17:03:14 -0500 | [diff] [blame] | 504 | if (fhp->fh_no_wcc || fhp->fh_pre_saved) |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 505 | return; |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 506 | inode = d_inode(fhp->fh_dentry); |
J. Bruce Fields | 428a23d | 2021-01-29 14:27:01 -0500 | [diff] [blame] | 507 | if (fs_supports_change_attribute(inode->i_sb) || !v4) { |
| 508 | __be32 err = fh_getattr(fhp, &stat); |
| 509 | |
| 510 | if (err) { |
| 511 | /* Grab the times from inode anyway */ |
| 512 | stat.mtime = inode->i_mtime; |
| 513 | stat.ctime = inode->i_ctime; |
| 514 | stat.size = inode->i_size; |
| 515 | } |
| 516 | fhp->fh_pre_mtime = stat.mtime; |
| 517 | fhp->fh_pre_ctime = stat.ctime; |
| 518 | fhp->fh_pre_size = stat.size; |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 519 | } |
J. Bruce Fields | 942b20dc | 2020-11-30 17:46:17 -0500 | [diff] [blame] | 520 | if (v4) |
| 521 | fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode); |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 522 | |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 523 | fhp->fh_pre_saved = true; |
| 524 | } |
| 525 | |
| 526 | /* |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 527 | * Fill in the post_op attr for the wcc data |
| 528 | */ |
| 529 | void fill_post_wcc(struct svc_fh *fhp) |
| 530 | { |
J. Bruce Fields | 942b20dc | 2020-11-30 17:46:17 -0500 | [diff] [blame] | 531 | bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE); |
| 532 | struct inode *inode = d_inode(fhp->fh_dentry); |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 533 | |
Jeff Layton | daab110 | 2020-11-30 17:03:14 -0500 | [diff] [blame] | 534 | if (fhp->fh_no_wcc) |
| 535 | return; |
| 536 | |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 537 | if (fhp->fh_post_saved) |
| 538 | printk("nfsd: inode locked twice during operation.\n"); |
| 539 | |
J. Bruce Fields | 428a23d | 2021-01-29 14:27:01 -0500 | [diff] [blame] | 540 | fhp->fh_post_saved = true; |
| 541 | |
| 542 | if (fs_supports_change_attribute(inode->i_sb) || !v4) { |
| 543 | __be32 err = fh_getattr(fhp, &fhp->fh_post_attr); |
| 544 | |
| 545 | if (err) { |
| 546 | fhp->fh_post_saved = false; |
| 547 | fhp->fh_post_attr.ctime = inode->i_ctime; |
| 548 | } |
| 549 | } |
J. Bruce Fields | 942b20dc | 2020-11-30 17:46:17 -0500 | [diff] [blame] | 550 | if (v4) |
| 551 | fhp->fh_post_change = |
| 552 | nfsd4_change_attribute(&fhp->fh_post_attr, inode); |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | /* |
| 556 | * XDR decode functions |
| 557 | */ |
Chuck Lever | dcc4699 | 2020-10-01 18:59:12 -0400 | [diff] [blame] | 558 | |
| 559 | int |
Chuck Lever | 9575363 | 2020-10-20 14:30:02 -0400 | [diff] [blame] | 560 | nfs3svc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
Chuck Lever | 9575363 | 2020-10-20 14:30:02 -0400 | [diff] [blame] | 562 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 563 | struct nfsd_fhandle *args = rqstp->rq_argp; |
| 564 | |
Chuck Lever | 9575363 | 2020-10-20 14:30:02 -0400 | [diff] [blame] | 565 | return svcxdr_decode_nfs_fh3(xdr, &args->fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 569 | nfs3svc_decode_sattrargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
Chuck Lever | 9cde936 | 2020-10-20 15:48:22 -0400 | [diff] [blame] | 571 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 572 | struct nfsd3_sattrargs *args = rqstp->rq_argp; |
| 573 | |
Chuck Lever | 9cde936 | 2020-10-20 15:48:22 -0400 | [diff] [blame] | 574 | return svcxdr_decode_nfs_fh3(xdr, &args->fh) && |
| 575 | svcxdr_decode_sattr3(rqstp, xdr, &args->attrs) && |
| 576 | svcxdr_decode_sattrguard3(xdr, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 580 | nfs3svc_decode_diropargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | { |
Chuck Lever | 54d1d43 | 2020-10-20 15:42:33 -0400 | [diff] [blame] | 582 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 583 | struct nfsd3_diropargs *args = rqstp->rq_argp; |
| 584 | |
Chuck Lever | 54d1d43 | 2020-10-20 15:42:33 -0400 | [diff] [blame] | 585 | return svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 589 | nfs3svc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | { |
Chuck Lever | 3b921a2 | 2020-10-20 14:32:04 -0400 | [diff] [blame] | 591 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 592 | struct nfsd3_accessargs *args = rqstp->rq_argp; |
| 593 | |
Chuck Lever | 3b921a2 | 2020-10-20 14:32:04 -0400 | [diff] [blame] | 594 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | return 0; |
Chuck Lever | 3b921a2 | 2020-10-20 14:32:04 -0400 | [diff] [blame] | 596 | if (xdr_stream_decode_u32(xdr, &args->access) < 0) |
| 597 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Chuck Lever | 3b921a2 | 2020-10-20 14:32:04 -0400 | [diff] [blame] | 599 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 603 | nfs3svc_decode_readargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | { |
Chuck Lever | be63bd2 | 2020-10-20 14:34:40 -0400 | [diff] [blame] | 605 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 606 | struct nfsd3_readargs *args = rqstp->rq_argp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Chuck Lever | be63bd2 | 2020-10-20 14:34:40 -0400 | [diff] [blame] | 608 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | return 0; |
Chuck Lever | be63bd2 | 2020-10-20 14:34:40 -0400 | [diff] [blame] | 610 | if (xdr_stream_decode_u64(xdr, &args->offset) < 0) |
| 611 | return 0; |
| 612 | if (xdr_stream_decode_u32(xdr, &args->count) < 0) |
| 613 | return 0; |
J. Bruce Fields | 9512a16 | 2017-05-16 15:57:42 -0400 | [diff] [blame] | 614 | |
Chuck Lever | be63bd2 | 2020-10-20 14:34:40 -0400 | [diff] [blame] | 615 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 619 | nfs3svc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | { |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 621 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 622 | struct nfsd3_writeargs *args = rqstp->rq_argp; |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 623 | u32 max_blocksize = svc_max_payload(rqstp); |
J. Bruce Fields | db44bac | 2017-04-25 16:21:34 -0400 | [diff] [blame] | 624 | struct kvec *head = rqstp->rq_arg.head; |
| 625 | struct kvec *tail = rqstp->rq_arg.tail; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 626 | size_t remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 628 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | return 0; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 630 | if (xdr_stream_decode_u64(xdr, &args->offset) < 0) |
| 631 | return 0; |
| 632 | if (xdr_stream_decode_u32(xdr, &args->count) < 0) |
| 633 | return 0; |
| 634 | if (xdr_stream_decode_u32(xdr, &args->stable) < 0) |
| 635 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 637 | /* opaque data */ |
| 638 | if (xdr_stream_decode_u32(xdr, &args->len) < 0) |
J. Bruce Fields | 13bf9fb | 2017-04-21 15:26:30 -0400 | [diff] [blame] | 639 | return 0; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 640 | |
| 641 | /* request sanity */ |
Peter Staubach | f34b9568 | 2007-05-09 02:34:48 -0700 | [diff] [blame] | 642 | if (args->count != args->len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | return 0; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 644 | remaining = head->iov_len + rqstp->rq_arg.page_len + tail->iov_len; |
| 645 | remaining -= xdr_stream_pos(xdr); |
| 646 | if (remaining < xdr_align_size(args->len)) |
Peter Staubach | f34b9568 | 2007-05-09 02:34:48 -0700 | [diff] [blame] | 647 | return 0; |
Peter Staubach | f34b9568 | 2007-05-09 02:34:48 -0700 | [diff] [blame] | 648 | if (args->count > max_blocksize) { |
| 649 | args->count = max_blocksize; |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 650 | args->len = max_blocksize; |
Peter Staubach | f34b9568 | 2007-05-09 02:34:48 -0700 | [diff] [blame] | 651 | } |
Chuck Lever | 8154ef2 | 2018-03-27 10:54:07 -0400 | [diff] [blame] | 652 | |
Chuck Lever | c43b2f2 | 2020-10-22 11:14:55 -0400 | [diff] [blame] | 653 | args->first.iov_base = xdr->p; |
| 654 | args->first.iov_len = head->iov_len - xdr_stream_pos(xdr); |
| 655 | |
Peter Staubach | f34b9568 | 2007-05-09 02:34:48 -0700 | [diff] [blame] | 656 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 660 | nfs3svc_decode_createargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | { |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 662 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 663 | struct nfsd3_createargs *args = rqstp->rq_argp; |
| 664 | |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 665 | if (!svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | return 0; |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 667 | if (xdr_stream_decode_u32(xdr, &args->createmode) < 0) |
| 668 | return 0; |
| 669 | switch (args->createmode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | case NFS3_CREATE_UNCHECKED: |
| 671 | case NFS3_CREATE_GUARDED: |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 672 | return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | case NFS3_CREATE_EXCLUSIVE: |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 674 | args->verf = xdr_inline_decode(xdr, NFS3_CREATEVERFSIZE); |
| 675 | if (!args->verf) |
| 676 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | break; |
| 678 | default: |
| 679 | return 0; |
| 680 | } |
Chuck Lever | 6b3a119 | 2020-10-20 15:56:11 -0400 | [diff] [blame] | 681 | return 1; |
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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 685 | nfs3svc_decode_mkdirargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
Chuck Lever | 83374c2 | 2020-10-20 17:02:16 -0400 | [diff] [blame] | 687 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 688 | struct nfsd3_createargs *args = rqstp->rq_argp; |
| 689 | |
Chuck Lever | 83374c2 | 2020-10-20 17:02:16 -0400 | [diff] [blame] | 690 | return svcxdr_decode_diropargs3(xdr, &args->fh, |
| 691 | &args->name, &args->len) && |
| 692 | svcxdr_decode_sattr3(rqstp, xdr, &args->attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 696 | nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | { |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 698 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 699 | struct nfsd3_symlinkargs *args = rqstp->rq_argp; |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 700 | struct kvec *head = rqstp->rq_arg.head; |
| 701 | struct kvec *tail = rqstp->rq_arg.tail; |
| 702 | size_t remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 704 | if (!svcxdr_decode_diropargs3(xdr, &args->ffh, &args->fname, &args->flen)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | return 0; |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 706 | if (!svcxdr_decode_sattr3(rqstp, xdr, &args->attrs)) |
Chuck Lever | 38a7031 | 2018-03-27 10:54:21 -0400 | [diff] [blame] | 707 | return 0; |
Chuck Lever | da39201 | 2020-10-20 16:01:16 -0400 | [diff] [blame] | 708 | if (xdr_stream_decode_u32(xdr, &args->tlen) < 0) |
| 709 | return 0; |
| 710 | |
| 711 | /* request sanity */ |
| 712 | remaining = head->iov_len + rqstp->rq_arg.page_len + tail->iov_len; |
| 713 | remaining -= xdr_stream_pos(xdr); |
| 714 | if (remaining < xdr_align_size(args->tlen)) |
| 715 | return 0; |
| 716 | |
| 717 | args->first.iov_base = xdr->p; |
| 718 | args->first.iov_len = head->iov_len - xdr_stream_pos(xdr); |
| 719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | return 1; |
| 721 | } |
| 722 | |
| 723 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 724 | nfs3svc_decode_mknodargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | { |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 726 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 727 | struct nfsd3_mknodargs *args = rqstp->rq_argp; |
| 728 | |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 729 | if (!svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | return 0; |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 731 | if (xdr_stream_decode_u32(xdr, &args->ftype) < 0) |
| 732 | return 0; |
| 733 | switch (args->ftype) { |
| 734 | case NF3CHR: |
| 735 | case NF3BLK: |
| 736 | return svcxdr_decode_devicedata3(rqstp, xdr, args); |
| 737 | case NF3SOCK: |
| 738 | case NF3FIFO: |
| 739 | return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs); |
| 740 | case NF3REG: |
| 741 | case NF3DIR: |
| 742 | case NF3LNK: |
| 743 | /* Valid XDR but illegal file types */ |
| 744 | break; |
| 745 | default: |
| 746 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Chuck Lever | f8a38e2 | 2020-10-20 17:04:03 -0400 | [diff] [blame] | 749 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 753 | nfs3svc_decode_renameargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { |
Chuck Lever | d181e0a | 2020-10-20 15:44:12 -0400 | [diff] [blame] | 755 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 756 | struct nfsd3_renameargs *args = rqstp->rq_argp; |
| 757 | |
Chuck Lever | d181e0a | 2020-10-20 15:44:12 -0400 | [diff] [blame] | 758 | return svcxdr_decode_diropargs3(xdr, &args->ffh, |
| 759 | &args->fname, &args->flen) && |
| 760 | svcxdr_decode_diropargs3(xdr, &args->tfh, |
| 761 | &args->tname, &args->tlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 765 | nfs3svc_decode_linkargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | { |
Chuck Lever | efaa1e7 | 2020-10-19 13:26:32 -0400 | [diff] [blame] | 767 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 768 | struct nfsd3_linkargs *args = rqstp->rq_argp; |
| 769 | |
Chuck Lever | efaa1e7 | 2020-10-19 13:26:32 -0400 | [diff] [blame] | 770 | return svcxdr_decode_nfs_fh3(xdr, &args->ffh) && |
| 771 | svcxdr_decode_diropargs3(xdr, &args->tfh, |
| 772 | &args->tname, &args->tlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 776 | nfs3svc_decode_readdirargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 778 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 779 | struct nfsd3_readdirargs *args = rqstp->rq_argp; |
NeilBrown | f875a79 | 2019-03-07 09:49:46 +1100 | [diff] [blame] | 780 | |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 781 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | return 0; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 783 | if (xdr_stream_decode_u64(xdr, &args->cookie) < 0) |
| 784 | return 0; |
| 785 | args->verf = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE); |
| 786 | if (!args->verf) |
| 787 | return 0; |
| 788 | if (xdr_stream_decode_u32(xdr, &args->count) < 0) |
| 789 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 791 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 795 | nfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | { |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 797 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 798 | struct nfsd3_readdirargs *args = rqstp->rq_argp; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 799 | u32 dircount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 801 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | return 0; |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 803 | if (xdr_stream_decode_u64(xdr, &args->cookie) < 0) |
| 804 | return 0; |
| 805 | args->verf = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE); |
| 806 | if (!args->verf) |
| 807 | return 0; |
| 808 | /* dircount is ignored */ |
| 809 | if (xdr_stream_decode_u32(xdr, &dircount) < 0) |
| 810 | return 0; |
| 811 | if (xdr_stream_decode_u32(xdr, &args->count) < 0) |
| 812 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | |
Chuck Lever | 9cedc2e | 2020-10-19 13:23:52 -0400 | [diff] [blame] | 814 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 818 | nfs3svc_decode_commitargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | { |
Chuck Lever | c8d26a0 | 2020-10-20 14:41:56 -0400 | [diff] [blame] | 820 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 821 | struct nfsd3_commitargs *args = rqstp->rq_argp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
Chuck Lever | c8d26a0 | 2020-10-20 14:41:56 -0400 | [diff] [blame] | 823 | if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) |
| 824 | return 0; |
| 825 | if (xdr_stream_decode_u64(xdr, &args->offset) < 0) |
| 826 | return 0; |
| 827 | if (xdr_stream_decode_u32(xdr, &args->count) < 0) |
| 828 | return 0; |
| 829 | |
| 830 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /* |
| 834 | * XDR encode functions |
| 835 | */ |
Chuck Lever | cc028a1 | 2020-10-02 15:52:44 -0400 | [diff] [blame] | 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | /* GETATTR */ |
| 838 | int |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 839 | nfs3svc_encode_getattrres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | { |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 841 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 842 | struct nfsd3_attrstat *resp = rqstp->rq_resp; |
| 843 | |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 844 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 845 | return 0; |
| 846 | switch (resp->status) { |
| 847 | case nfs_ok: |
| 848 | lease_get_mtime(d_inode(resp->fh.fh_dentry), &resp->stat.mtime); |
| 849 | if (!svcxdr_encode_fattr3(rqstp, xdr, &resp->fh, &resp->stat)) |
| 850 | return 0; |
| 851 | break; |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 852 | } |
Chuck Lever | 2c42f80 | 2020-10-21 11:58:41 -0400 | [diff] [blame] | 853 | |
| 854 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /* SETATTR, REMOVE, RMDIR */ |
| 858 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 859 | nfs3svc_encode_wccstat(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | { |
Chuck Lever | 70f8e83 | 2020-10-22 15:12:38 -0400 | [diff] [blame] | 861 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 862 | struct nfsd3_attrstat *resp = rqstp->rq_resp; |
| 863 | |
Chuck Lever | 70f8e83 | 2020-10-22 15:12:38 -0400 | [diff] [blame] | 864 | return svcxdr_encode_nfsstat3(xdr, resp->status) && |
| 865 | svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /* LOOKUP */ |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 869 | int nfs3svc_encode_lookupres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 871 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 872 | struct nfsd3_diropres *resp = rqstp->rq_resp; |
| 873 | |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 874 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 875 | return 0; |
| 876 | switch (resp->status) { |
| 877 | case nfs_ok: |
| 878 | if (!svcxdr_encode_nfs_fh3(xdr, &resp->fh)) |
| 879 | return 0; |
| 880 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
| 881 | return 0; |
| 882 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->dirfh)) |
| 883 | return 0; |
| 884 | break; |
| 885 | default: |
| 886 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->dirfh)) |
| 887 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | } |
Chuck Lever | 5cf3533 | 2020-10-22 14:46:58 -0400 | [diff] [blame] | 889 | |
| 890 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | /* ACCESS */ |
| 894 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 895 | nfs3svc_encode_accessres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Chuck Lever | 907c382 | 2020-10-22 13:56:58 -0400 | [diff] [blame] | 897 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 898 | struct nfsd3_accessres *resp = rqstp->rq_resp; |
| 899 | |
Chuck Lever | 907c382 | 2020-10-22 13:56:58 -0400 | [diff] [blame] | 900 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 901 | return 0; |
| 902 | switch (resp->status) { |
| 903 | case nfs_ok: |
| 904 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
| 905 | return 0; |
| 906 | if (xdr_stream_encode_u32(xdr, resp->access) < 0) |
| 907 | return 0; |
| 908 | break; |
| 909 | default: |
| 910 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
| 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | /* READLINK */ |
| 918 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 919 | nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | { |
Chuck Lever | 9a9c892 | 2020-10-22 15:18:40 -0400 | [diff] [blame] | 921 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 922 | struct nfsd3_readlinkres *resp = rqstp->rq_resp; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 923 | struct kvec *head = rqstp->rq_res.head; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 924 | |
Chuck Lever | 9a9c892 | 2020-10-22 15:18:40 -0400 | [diff] [blame] | 925 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 926 | return 0; |
| 927 | switch (resp->status) { |
| 928 | case nfs_ok: |
| 929 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 930 | return 0; |
Chuck Lever | 9a9c892 | 2020-10-22 15:18:40 -0400 | [diff] [blame] | 931 | if (xdr_stream_encode_u32(xdr, resp->len) < 0) |
| 932 | return 0; |
| 933 | xdr_write_pages(xdr, resp->pages, 0, resp->len); |
| 934 | if (svc_encode_result_payload(rqstp, head->iov_len, resp->len) < 0) |
| 935 | return 0; |
| 936 | break; |
| 937 | default: |
| 938 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | /* READ */ |
| 946 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 947 | nfs3svc_encode_readres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | { |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 949 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 950 | struct nfsd3_readres *resp = rqstp->rq_resp; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 951 | struct kvec *head = rqstp->rq_res.head; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 952 | |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 953 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 954 | return 0; |
| 955 | switch (resp->status) { |
| 956 | case nfs_ok: |
| 957 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 958 | return 0; |
Chuck Lever | cc9bcda | 2020-10-22 15:23:50 -0400 | [diff] [blame] | 959 | if (xdr_stream_encode_u32(xdr, resp->count) < 0) |
| 960 | return 0; |
| 961 | if (xdr_stream_encode_bool(xdr, resp->eof) < 0) |
| 962 | return 0; |
| 963 | if (xdr_stream_encode_u32(xdr, resp->count) < 0) |
| 964 | return 0; |
| 965 | xdr_write_pages(xdr, resp->pages, rqstp->rq_res.page_base, |
| 966 | resp->count); |
| 967 | if (svc_encode_result_payload(rqstp, head->iov_len, resp->count) < 0) |
| 968 | return 0; |
| 969 | break; |
| 970 | default: |
| 971 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
| 972 | return 0; |
| 973 | } |
| 974 | |
| 975 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | /* WRITE */ |
| 979 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 980 | nfs3svc_encode_writeres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | { |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 982 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 983 | struct nfsd3_writeres *resp = rqstp->rq_resp; |
Stanislav Kinsbursky | b9c0ef8 | 2012-12-06 14:23:19 +0300 | [diff] [blame] | 984 | |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 985 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 986 | return 0; |
| 987 | switch (resp->status) { |
| 988 | case nfs_ok: |
| 989 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) |
| 990 | return 0; |
| 991 | if (xdr_stream_encode_u32(xdr, resp->count) < 0) |
| 992 | return 0; |
| 993 | if (xdr_stream_encode_u32(xdr, resp->committed) < 0) |
| 994 | return 0; |
| 995 | if (!svcxdr_encode_writeverf3(xdr, resp->verf)) |
| 996 | return 0; |
| 997 | break; |
| 998 | default: |
| 999 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) |
| 1000 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | } |
Chuck Lever | ecb7a08 | 2020-10-22 15:26:31 -0400 | [diff] [blame] | 1002 | |
| 1003 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | /* CREATE, MKDIR, SYMLINK, MKNOD */ |
| 1007 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1008 | nfs3svc_encode_createres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | { |
Chuck Lever | 78315b3 | 2020-10-22 15:27:23 -0400 | [diff] [blame] | 1010 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1011 | struct nfsd3_diropres *resp = rqstp->rq_resp; |
| 1012 | |
Chuck Lever | 78315b3 | 2020-10-22 15:27:23 -0400 | [diff] [blame] | 1013 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 1014 | return 0; |
| 1015 | switch (resp->status) { |
| 1016 | case nfs_ok: |
| 1017 | if (!svcxdr_encode_post_op_fh3(xdr, &resp->fh)) |
| 1018 | return 0; |
| 1019 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
| 1020 | return 0; |
| 1021 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->dirfh)) |
| 1022 | return 0; |
| 1023 | break; |
| 1024 | default: |
| 1025 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->dirfh)) |
| 1026 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | } |
Chuck Lever | 78315b3 | 2020-10-22 15:27:23 -0400 | [diff] [blame] | 1028 | |
| 1029 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | /* RENAME */ |
| 1033 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1034 | nfs3svc_encode_renameres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | { |
Chuck Lever | 89d79e9 | 2020-10-22 15:33:05 -0400 | [diff] [blame] | 1036 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1037 | struct nfsd3_renameres *resp = rqstp->rq_resp; |
| 1038 | |
Chuck Lever | 89d79e9 | 2020-10-22 15:33:05 -0400 | [diff] [blame] | 1039 | return svcxdr_encode_nfsstat3(xdr, resp->status) && |
| 1040 | svcxdr_encode_wcc_data(rqstp, xdr, &resp->ffh) && |
| 1041 | svcxdr_encode_wcc_data(rqstp, xdr, &resp->tfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | /* LINK */ |
| 1045 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1046 | nfs3svc_encode_linkres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | { |
Chuck Lever | 4d74380 | 2020-10-22 15:08:29 -0400 | [diff] [blame] | 1048 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1049 | struct nfsd3_linkres *resp = rqstp->rq_resp; |
| 1050 | |
Chuck Lever | 4d74380 | 2020-10-22 15:08:29 -0400 | [diff] [blame] | 1051 | return svcxdr_encode_nfsstat3(xdr, resp->status) && |
| 1052 | svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh) && |
| 1053 | svcxdr_encode_wcc_data(rqstp, xdr, &resp->tfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | /* READDIR */ |
| 1057 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1058 | nfs3svc_encode_readdirres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | { |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 1060 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1061 | struct nfsd3_readdirres *resp = rqstp->rq_resp; |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1062 | struct xdr_buf *dirlist = &resp->dirlist; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1063 | |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 1064 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 1065 | return 0; |
| 1066 | switch (resp->status) { |
| 1067 | case nfs_ok: |
| 1068 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
| 1069 | return 0; |
| 1070 | if (!svcxdr_encode_cookieverf3(xdr, resp->verf)) |
| 1071 | return 0; |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1072 | xdr_write_pages(xdr, dirlist->pages, 0, dirlist->len); |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 1073 | /* no more entries */ |
| 1074 | if (xdr_stream_encode_item_absent(xdr) < 0) |
| 1075 | return 0; |
| 1076 | if (xdr_stream_encode_bool(xdr, resp->common.err == nfserr_eof) < 0) |
| 1077 | return 0; |
| 1078 | break; |
| 1079 | default: |
| 1080 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) |
| 1081 | return 0; |
| 1082 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
Chuck Lever | e4ccfe3 | 2020-10-22 19:31:48 -0400 | [diff] [blame] | 1084 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Al Viro | efe3965 | 2012-04-13 00:32:14 -0400 | [diff] [blame] | 1087 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp, |
NeilBrown | 43b0e7e | 2015-05-03 09:16:53 +1000 | [diff] [blame] | 1089 | const char *name, int namlen, u64 ino) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | { |
| 1091 | struct svc_export *exp; |
| 1092 | struct dentry *dparent, *dchild; |
Al Viro | efe3965 | 2012-04-13 00:32:14 -0400 | [diff] [blame] | 1093 | __be32 rv = nfserr_noent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
| 1095 | dparent = cd->fh.fh_dentry; |
| 1096 | exp = cd->fh.fh_export; |
| 1097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | if (isdotent(name, namlen)) { |
| 1099 | if (namlen == 2) { |
| 1100 | dchild = dget_parent(dparent); |
J. Bruce Fields | 51b2ee7 | 2021-01-11 16:01:29 -0500 | [diff] [blame] | 1101 | /* |
| 1102 | * Don't return filehandle for ".." if we're at |
| 1103 | * the filesystem or export root: |
| 1104 | */ |
Al Viro | efe3965 | 2012-04-13 00:32:14 -0400 | [diff] [blame] | 1105 | if (dchild == dparent) |
| 1106 | goto out; |
J. Bruce Fields | 51b2ee7 | 2021-01-11 16:01:29 -0500 | [diff] [blame] | 1107 | if (dparent == exp->ex_path.dentry) |
| 1108 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | } else |
| 1110 | dchild = dget(dparent); |
| 1111 | } else |
Al Viro | 6c2d4798 | 2019-10-31 01:21:58 -0400 | [diff] [blame] | 1112 | dchild = lookup_positive_unlocked(name, dparent, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | if (IS_ERR(dchild)) |
Al Viro | efe3965 | 2012-04-13 00:32:14 -0400 | [diff] [blame] | 1114 | return rv; |
J. Bruce Fields | 8177e6d | 2009-09-04 14:13:09 -0400 | [diff] [blame] | 1115 | if (d_mountpoint(dchild)) |
| 1116 | goto out; |
NeilBrown | 43b0e7e | 2015-05-03 09:16:53 +1000 | [diff] [blame] | 1117 | if (dchild->d_inode->i_ino != ino) |
| 1118 | goto out; |
Al Viro | efe3965 | 2012-04-13 00:32:14 -0400 | [diff] [blame] | 1119 | rv = fh_compose(fhp, exp, dchild, &cd->fh); |
J. Bruce Fields | 8177e6d | 2009-09-04 14:13:09 -0400 | [diff] [blame] | 1120 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | dput(dchild); |
| 1122 | return rv; |
| 1123 | } |
| 1124 | |
Chuck Lever | a161e6c | 2020-11-10 09:57:14 -0500 | [diff] [blame] | 1125 | /** |
| 1126 | * nfs3svc_encode_cookie3 - Encode a directory offset cookie |
| 1127 | * @resp: readdir result context |
| 1128 | * @offset: offset cookie to encode |
| 1129 | * |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1130 | * The buffer space for the offset cookie has already been reserved |
| 1131 | * by svcxdr_encode_entry3_common(). |
Chuck Lever | a161e6c | 2020-11-10 09:57:14 -0500 | [diff] [blame] | 1132 | */ |
| 1133 | void nfs3svc_encode_cookie3(struct nfsd3_readdirres *resp, u64 offset) |
| 1134 | { |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1135 | __be64 cookie = cpu_to_be64(offset); |
Chuck Lever | a161e6c | 2020-11-10 09:57:14 -0500 | [diff] [blame] | 1136 | |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1137 | if (!resp->cookie_offset) |
| 1138 | return; |
| 1139 | write_bytes_to_xdr_buf(&resp->dirlist, resp->cookie_offset, &cookie, |
| 1140 | sizeof(cookie)); |
| 1141 | resp->cookie_offset = 0; |
Chuck Lever | a161e6c | 2020-11-10 09:57:14 -0500 | [diff] [blame] | 1142 | } |
| 1143 | |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1144 | static bool |
Chuck Lever | 7f87fc2 | 2020-10-22 19:46:58 -0400 | [diff] [blame] | 1145 | svcxdr_encode_entry3_common(struct nfsd3_readdirres *resp, const char *name, |
| 1146 | int namlen, loff_t offset, u64 ino) |
| 1147 | { |
| 1148 | struct xdr_buf *dirlist = &resp->dirlist; |
| 1149 | struct xdr_stream *xdr = &resp->xdr; |
| 1150 | |
| 1151 | if (xdr_stream_encode_item_present(xdr) < 0) |
| 1152 | return false; |
| 1153 | /* fileid */ |
| 1154 | if (xdr_stream_encode_u64(xdr, ino) < 0) |
| 1155 | return false; |
| 1156 | /* name */ |
| 1157 | if (xdr_stream_encode_opaque(xdr, name, min(namlen, NFS3_MAXNAMLEN)) < 0) |
| 1158 | return false; |
| 1159 | /* cookie */ |
| 1160 | resp->cookie_offset = dirlist->len; |
| 1161 | if (xdr_stream_encode_u64(xdr, NFS_OFFSET_MAX) < 0) |
| 1162 | return false; |
| 1163 | |
| 1164 | return true; |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * nfs3svc_encode_entry3 - encode one NFSv3 READDIR entry |
| 1169 | * @data: directory context |
| 1170 | * @name: name of the object to be encoded |
| 1171 | * @namlen: length of that name, in bytes |
| 1172 | * @offset: the offset of the previous entry |
| 1173 | * @ino: the fileid of this entry |
| 1174 | * @d_type: unused |
| 1175 | * |
| 1176 | * Return values: |
| 1177 | * %0: Entry was successfully encoded. |
| 1178 | * %-EINVAL: An encoding problem occured, secondary status code in resp->common.err |
| 1179 | * |
| 1180 | * On exit, the following fields are updated: |
| 1181 | * - resp->xdr |
| 1182 | * - resp->common.err |
| 1183 | * - resp->cookie_offset |
| 1184 | */ |
| 1185 | int nfs3svc_encode_entry3(void *data, const char *name, int namlen, |
| 1186 | loff_t offset, u64 ino, unsigned int d_type) |
| 1187 | { |
| 1188 | struct readdir_cd *ccd = data; |
| 1189 | struct nfsd3_readdirres *resp = container_of(ccd, |
| 1190 | struct nfsd3_readdirres, |
| 1191 | common); |
| 1192 | unsigned int starting_length = resp->dirlist.len; |
| 1193 | |
| 1194 | /* The offset cookie for the previous entry */ |
| 1195 | nfs3svc_encode_cookie3(resp, offset); |
| 1196 | |
| 1197 | if (!svcxdr_encode_entry3_common(resp, name, namlen, offset, ino)) |
| 1198 | goto out_toosmall; |
| 1199 | |
| 1200 | xdr_commit_encode(&resp->xdr); |
| 1201 | resp->common.err = nfs_ok; |
| 1202 | return 0; |
| 1203 | |
| 1204 | out_toosmall: |
| 1205 | resp->cookie_offset = 0; |
| 1206 | resp->common.err = nfserr_toosmall; |
| 1207 | resp->dirlist.len = starting_length; |
| 1208 | return -EINVAL; |
| 1209 | } |
| 1210 | |
| 1211 | static bool |
| 1212 | svcxdr_encode_entry3_plus(struct nfsd3_readdirres *resp, const char *name, |
| 1213 | int namlen, u64 ino) |
| 1214 | { |
| 1215 | struct xdr_stream *xdr = &resp->xdr; |
| 1216 | struct svc_fh *fhp = &resp->scratch; |
| 1217 | bool result; |
| 1218 | |
| 1219 | result = false; |
| 1220 | fh_init(fhp, NFS3_FHSIZE); |
| 1221 | if (compose_entry_fh(resp, fhp, name, namlen, ino) != nfs_ok) |
| 1222 | goto out_noattrs; |
| 1223 | |
| 1224 | if (!svcxdr_encode_post_op_attr(resp->rqstp, xdr, fhp)) |
| 1225 | goto out; |
| 1226 | if (!svcxdr_encode_post_op_fh3(xdr, fhp)) |
| 1227 | goto out; |
| 1228 | result = true; |
| 1229 | |
| 1230 | out: |
| 1231 | fh_put(fhp); |
| 1232 | return result; |
| 1233 | |
| 1234 | out_noattrs: |
| 1235 | if (xdr_stream_encode_item_absent(xdr) < 0) |
| 1236 | return false; |
| 1237 | if (xdr_stream_encode_item_absent(xdr) < 0) |
| 1238 | return false; |
| 1239 | return true; |
| 1240 | } |
| 1241 | |
| 1242 | /** |
| 1243 | * nfs3svc_encode_entryplus3 - encode one NFSv3 READDIRPLUS entry |
| 1244 | * @data: directory context |
| 1245 | * @name: name of the object to be encoded |
| 1246 | * @namlen: length of that name, in bytes |
| 1247 | * @offset: the offset of the previous entry |
| 1248 | * @ino: the fileid of this entry |
| 1249 | * @d_type: unused |
| 1250 | * |
| 1251 | * Return values: |
| 1252 | * %0: Entry was successfully encoded. |
| 1253 | * %-EINVAL: An encoding problem occured, secondary status code in resp->common.err |
| 1254 | * |
| 1255 | * On exit, the following fields are updated: |
| 1256 | * - resp->xdr |
| 1257 | * - resp->common.err |
| 1258 | * - resp->cookie_offset |
| 1259 | */ |
| 1260 | int nfs3svc_encode_entryplus3(void *data, const char *name, int namlen, |
| 1261 | loff_t offset, u64 ino, unsigned int d_type) |
| 1262 | { |
| 1263 | struct readdir_cd *ccd = data; |
| 1264 | struct nfsd3_readdirres *resp = container_of(ccd, |
| 1265 | struct nfsd3_readdirres, |
| 1266 | common); |
| 1267 | unsigned int starting_length = resp->dirlist.len; |
| 1268 | |
| 1269 | /* The offset cookie for the previous entry */ |
| 1270 | nfs3svc_encode_cookie3(resp, offset); |
| 1271 | |
| 1272 | if (!svcxdr_encode_entry3_common(resp, name, namlen, offset, ino)) |
| 1273 | goto out_toosmall; |
| 1274 | if (!svcxdr_encode_entry3_plus(resp, name, namlen, ino)) |
| 1275 | goto out_toosmall; |
| 1276 | |
| 1277 | xdr_commit_encode(&resp->xdr); |
| 1278 | resp->common.err = nfs_ok; |
| 1279 | return 0; |
| 1280 | |
| 1281 | out_toosmall: |
| 1282 | resp->cookie_offset = 0; |
| 1283 | resp->common.err = nfserr_toosmall; |
| 1284 | resp->dirlist.len = starting_length; |
| 1285 | return -EINVAL; |
| 1286 | } |
| 1287 | |
| 1288 | static bool |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1289 | svcxdr_encode_fsstat3resok(struct xdr_stream *xdr, |
| 1290 | const struct nfsd3_fsstatres *resp) |
| 1291 | { |
| 1292 | const struct kstatfs *s = &resp->stats; |
| 1293 | u64 bs = s->f_bsize; |
| 1294 | __be32 *p; |
| 1295 | |
| 1296 | p = xdr_reserve_space(xdr, XDR_UNIT * 13); |
| 1297 | if (!p) |
| 1298 | return false; |
| 1299 | p = xdr_encode_hyper(p, bs * s->f_blocks); /* total bytes */ |
| 1300 | p = xdr_encode_hyper(p, bs * s->f_bfree); /* free bytes */ |
| 1301 | p = xdr_encode_hyper(p, bs * s->f_bavail); /* user available bytes */ |
| 1302 | p = xdr_encode_hyper(p, s->f_files); /* total inodes */ |
| 1303 | p = xdr_encode_hyper(p, s->f_ffree); /* free inodes */ |
| 1304 | p = xdr_encode_hyper(p, s->f_ffree); /* user available inodes */ |
| 1305 | *p = cpu_to_be32(resp->invarsec); /* mean unchanged time */ |
| 1306 | |
| 1307 | return true; |
| 1308 | } |
| 1309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | /* FSSTAT */ |
| 1311 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1312 | nfs3svc_encode_fsstatres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | { |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1314 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1315 | struct nfsd3_fsstatres *resp = rqstp->rq_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1317 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 1318 | return 0; |
| 1319 | switch (resp->status) { |
| 1320 | case nfs_ok: |
| 1321 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
| 1322 | return 0; |
| 1323 | if (!svcxdr_encode_fsstat3resok(xdr, resp)) |
| 1324 | return 0; |
| 1325 | break; |
| 1326 | default: |
| 1327 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
| 1328 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | } |
Chuck Lever | 8b70449 | 2020-11-06 13:08:45 -0500 | [diff] [blame] | 1330 | |
| 1331 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Chuck Lever | 0a139d1 | 2020-10-22 13:42:13 -0400 | [diff] [blame] | 1334 | static bool |
| 1335 | svcxdr_encode_fsinfo3resok(struct xdr_stream *xdr, |
| 1336 | const struct nfsd3_fsinfores *resp) |
| 1337 | { |
| 1338 | __be32 *p; |
| 1339 | |
| 1340 | p = xdr_reserve_space(xdr, XDR_UNIT * 12); |
| 1341 | if (!p) |
| 1342 | return false; |
| 1343 | *p++ = cpu_to_be32(resp->f_rtmax); |
| 1344 | *p++ = cpu_to_be32(resp->f_rtpref); |
| 1345 | *p++ = cpu_to_be32(resp->f_rtmult); |
| 1346 | *p++ = cpu_to_be32(resp->f_wtmax); |
| 1347 | *p++ = cpu_to_be32(resp->f_wtpref); |
| 1348 | *p++ = cpu_to_be32(resp->f_wtmult); |
| 1349 | *p++ = cpu_to_be32(resp->f_dtpref); |
| 1350 | p = xdr_encode_hyper(p, resp->f_maxfilesize); |
| 1351 | p = encode_nfstime3(p, &nfs3svc_time_delta); |
| 1352 | *p = cpu_to_be32(resp->f_properties); |
| 1353 | |
| 1354 | return true; |
| 1355 | } |
| 1356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | /* FSINFO */ |
| 1358 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1359 | nfs3svc_encode_fsinfores(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | { |
Chuck Lever | 0a139d1 | 2020-10-22 13:42:13 -0400 | [diff] [blame] | 1361 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1362 | struct nfsd3_fsinfores *resp = rqstp->rq_resp; |
| 1363 | |
Chuck Lever | 0a139d1 | 2020-10-22 13:42:13 -0400 | [diff] [blame] | 1364 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 1365 | return 0; |
| 1366 | switch (resp->status) { |
| 1367 | case nfs_ok: |
| 1368 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
| 1369 | return 0; |
| 1370 | if (!svcxdr_encode_fsinfo3resok(xdr, resp)) |
| 1371 | return 0; |
| 1372 | break; |
| 1373 | default: |
| 1374 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
| 1375 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
Chuck Lever | 0a139d1 | 2020-10-22 13:42:13 -0400 | [diff] [blame] | 1378 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
Chuck Lever | ded04a5 | 2020-11-06 13:15:09 -0500 | [diff] [blame] | 1381 | static bool |
| 1382 | svcxdr_encode_pathconf3resok(struct xdr_stream *xdr, |
| 1383 | const struct nfsd3_pathconfres *resp) |
| 1384 | { |
| 1385 | __be32 *p; |
| 1386 | |
| 1387 | p = xdr_reserve_space(xdr, XDR_UNIT * 6); |
| 1388 | if (!p) |
| 1389 | return false; |
| 1390 | *p++ = cpu_to_be32(resp->p_link_max); |
| 1391 | *p++ = cpu_to_be32(resp->p_name_max); |
| 1392 | p = xdr_encode_bool(p, resp->p_no_trunc); |
| 1393 | p = xdr_encode_bool(p, resp->p_chown_restricted); |
| 1394 | p = xdr_encode_bool(p, resp->p_case_insensitive); |
| 1395 | xdr_encode_bool(p, resp->p_case_preserving); |
| 1396 | |
| 1397 | return true; |
| 1398 | } |
| 1399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | /* PATHCONF */ |
| 1401 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1402 | nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | { |
Chuck Lever | ded04a5 | 2020-11-06 13:15:09 -0500 | [diff] [blame] | 1404 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1405 | struct nfsd3_pathconfres *resp = rqstp->rq_resp; |
| 1406 | |
Chuck Lever | ded04a5 | 2020-11-06 13:15:09 -0500 | [diff] [blame] | 1407 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 1408 | return 0; |
| 1409 | switch (resp->status) { |
| 1410 | case nfs_ok: |
| 1411 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
| 1412 | return 0; |
| 1413 | if (!svcxdr_encode_pathconf3resok(xdr, resp)) |
| 1414 | return 0; |
| 1415 | break; |
| 1416 | default: |
| 1417 | if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) |
| 1418 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
Chuck Lever | ded04a5 | 2020-11-06 13:15:09 -0500 | [diff] [blame] | 1421 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | /* COMMIT */ |
| 1425 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1426 | nfs3svc_encode_commitres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | { |
Chuck Lever | 5ef2826 | 2020-10-22 15:35:46 -0400 | [diff] [blame] | 1428 | struct xdr_stream *xdr = &rqstp->rq_res_stream; |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 1429 | struct nfsd3_commitres *resp = rqstp->rq_resp; |
Stanislav Kinsbursky | b9c0ef8 | 2012-12-06 14:23:19 +0300 | [diff] [blame] | 1430 | |
Chuck Lever | 5ef2826 | 2020-10-22 15:35:46 -0400 | [diff] [blame] | 1431 | if (!svcxdr_encode_nfsstat3(xdr, resp->status)) |
| 1432 | return 0; |
| 1433 | switch (resp->status) { |
| 1434 | case nfs_ok: |
| 1435 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) |
| 1436 | return 0; |
| 1437 | if (!svcxdr_encode_writeverf3(xdr, resp->verf)) |
| 1438 | return 0; |
| 1439 | break; |
| 1440 | default: |
| 1441 | if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) |
| 1442 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | } |
Chuck Lever | 5ef2826 | 2020-10-22 15:35:46 -0400 | [diff] [blame] | 1444 | |
| 1445 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | /* |
| 1449 | * XDR release functions |
| 1450 | */ |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 1451 | void |
| 1452 | nfs3svc_release_fhandle(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | { |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 1454 | struct nfsd3_attrstat *resp = rqstp->rq_resp; |
| 1455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | fh_put(&resp->fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 1459 | void |
| 1460 | nfs3svc_release_fhandle2(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | { |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 1462 | struct nfsd3_fhandle_pair *resp = rqstp->rq_resp; |
| 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | fh_put(&resp->fh1); |
| 1465 | fh_put(&resp->fh2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | } |