Thomas Gleixner | b4d0d23 | 2019-05-20 19:08:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 2 | /* YFS File Server client stubs |
| 3 | * |
| 4 | * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/slab.h> |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/circ_buf.h> |
| 12 | #include <linux/iversion.h> |
| 13 | #include "internal.h" |
| 14 | #include "afs_fs.h" |
| 15 | #include "xdr_fs.h" |
| 16 | #include "protocol_yfs.h" |
| 17 | |
| 18 | static const struct afs_fid afs_zero_fid; |
| 19 | |
| 20 | static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi) |
| 21 | { |
| 22 | call->cbi = afs_get_cb_interest(cbi); |
| 23 | } |
| 24 | |
| 25 | #define xdr_size(x) (sizeof(*x) / sizeof(__be32)) |
| 26 | |
| 27 | static void xdr_decode_YFSFid(const __be32 **_bp, struct afs_fid *fid) |
| 28 | { |
| 29 | const struct yfs_xdr_YFSFid *x = (const void *)*_bp; |
| 30 | |
| 31 | fid->vid = xdr_to_u64(x->volume); |
| 32 | fid->vnode = xdr_to_u64(x->vnode.lo); |
| 33 | fid->vnode_hi = ntohl(x->vnode.hi); |
| 34 | fid->unique = ntohl(x->vnode.unique); |
| 35 | *_bp += xdr_size(x); |
| 36 | } |
| 37 | |
| 38 | static __be32 *xdr_encode_u32(__be32 *bp, u32 n) |
| 39 | { |
| 40 | *bp++ = htonl(n); |
| 41 | return bp; |
| 42 | } |
| 43 | |
| 44 | static __be32 *xdr_encode_u64(__be32 *bp, u64 n) |
| 45 | { |
| 46 | struct yfs_xdr_u64 *x = (void *)bp; |
| 47 | |
| 48 | *x = u64_to_xdr(n); |
| 49 | return bp + xdr_size(x); |
| 50 | } |
| 51 | |
| 52 | static __be32 *xdr_encode_YFSFid(__be32 *bp, struct afs_fid *fid) |
| 53 | { |
| 54 | struct yfs_xdr_YFSFid *x = (void *)bp; |
| 55 | |
| 56 | x->volume = u64_to_xdr(fid->vid); |
| 57 | x->vnode.lo = u64_to_xdr(fid->vnode); |
| 58 | x->vnode.hi = htonl(fid->vnode_hi); |
| 59 | x->vnode.unique = htonl(fid->unique); |
| 60 | return bp + xdr_size(x); |
| 61 | } |
| 62 | |
| 63 | static size_t xdr_strlen(unsigned int len) |
| 64 | { |
| 65 | return sizeof(__be32) + round_up(len, sizeof(__be32)); |
| 66 | } |
| 67 | |
| 68 | static __be32 *xdr_encode_string(__be32 *bp, const char *p, unsigned int len) |
| 69 | { |
| 70 | bp = xdr_encode_u32(bp, len); |
| 71 | bp = memcpy(bp, p, len); |
| 72 | if (len & 3) { |
| 73 | unsigned int pad = 4 - (len & 3); |
| 74 | |
| 75 | memset((u8 *)bp + len, 0, pad); |
| 76 | len += pad; |
| 77 | } |
| 78 | |
| 79 | return bp + len / sizeof(__be32); |
| 80 | } |
| 81 | |
| 82 | static s64 linux_to_yfs_time(const struct timespec64 *t) |
| 83 | { |
| 84 | /* Convert to 100ns intervals. */ |
| 85 | return (u64)t->tv_sec * 10000000 + t->tv_nsec/100; |
| 86 | } |
| 87 | |
| 88 | static __be32 *xdr_encode_YFSStoreStatus_mode(__be32 *bp, mode_t mode) |
| 89 | { |
| 90 | struct yfs_xdr_YFSStoreStatus *x = (void *)bp; |
| 91 | |
| 92 | x->mask = htonl(AFS_SET_MODE); |
| 93 | x->mode = htonl(mode & S_IALLUGO); |
| 94 | x->mtime_client = u64_to_xdr(0); |
| 95 | x->owner = u64_to_xdr(0); |
| 96 | x->group = u64_to_xdr(0); |
| 97 | return bp + xdr_size(x); |
| 98 | } |
| 99 | |
| 100 | static __be32 *xdr_encode_YFSStoreStatus_mtime(__be32 *bp, const struct timespec64 *t) |
| 101 | { |
| 102 | struct yfs_xdr_YFSStoreStatus *x = (void *)bp; |
| 103 | s64 mtime = linux_to_yfs_time(t); |
| 104 | |
| 105 | x->mask = htonl(AFS_SET_MTIME); |
| 106 | x->mode = htonl(0); |
| 107 | x->mtime_client = u64_to_xdr(mtime); |
| 108 | x->owner = u64_to_xdr(0); |
| 109 | x->group = u64_to_xdr(0); |
| 110 | return bp + xdr_size(x); |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * Convert a signed 100ns-resolution 64-bit time into a timespec. |
| 115 | */ |
| 116 | static struct timespec64 yfs_time_to_linux(s64 t) |
| 117 | { |
| 118 | struct timespec64 ts; |
| 119 | u64 abs_t; |
| 120 | |
| 121 | /* |
| 122 | * Unfortunately can not use normal 64 bit division on 32 bit arch, but |
| 123 | * the alternative, do_div, does not work with negative numbers so have |
| 124 | * to special case them |
| 125 | */ |
| 126 | if (t < 0) { |
| 127 | abs_t = -t; |
| 128 | ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100); |
| 129 | ts.tv_nsec = -ts.tv_nsec; |
| 130 | ts.tv_sec = -abs_t; |
| 131 | } else { |
| 132 | abs_t = t; |
| 133 | ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100; |
| 134 | ts.tv_sec = abs_t; |
| 135 | } |
| 136 | |
| 137 | return ts; |
| 138 | } |
| 139 | |
| 140 | static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr) |
| 141 | { |
| 142 | s64 t = xdr_to_u64(xdr); |
| 143 | |
| 144 | return yfs_time_to_linux(t); |
| 145 | } |
| 146 | |
| 147 | static void yfs_check_req(struct afs_call *call, __be32 *bp) |
| 148 | { |
| 149 | size_t len = (void *)bp - call->request; |
| 150 | |
| 151 | if (len > call->request_size) |
| 152 | pr_err("kAFS: %s: Request buffer overflow (%zu>%u)\n", |
| 153 | call->type->name, len, call->request_size); |
| 154 | else if (len < call->request_size) |
Kefeng Wang | a4e530a | 2019-10-18 11:18:40 +0800 | [diff] [blame^] | 155 | pr_warn("kAFS: %s: Request buffer underflow (%zu<%u)\n", |
| 156 | call->type->name, len, call->request_size); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /* |
| 160 | * Dump a bad file status record. |
| 161 | */ |
| 162 | static void xdr_dump_bad(const __be32 *bp) |
| 163 | { |
| 164 | __be32 x[4]; |
| 165 | int i; |
| 166 | |
| 167 | pr_notice("YFS XDR: Bad status record\n"); |
| 168 | for (i = 0; i < 5 * 4 * 4; i += 16) { |
| 169 | memcpy(x, bp, 16); |
| 170 | bp += 4; |
| 171 | pr_notice("%03x: %08x %08x %08x %08x\n", |
| 172 | i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3])); |
| 173 | } |
| 174 | |
| 175 | memcpy(x, bp, 4); |
| 176 | pr_notice("0x50: %08x\n", ntohl(x[0])); |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Decode a YFSFetchStatus block |
| 181 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 182 | static int xdr_decode_YFSFetchStatus(const __be32 **_bp, |
| 183 | struct afs_call *call, |
| 184 | struct afs_status_cb *scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 185 | { |
| 186 | const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 187 | struct afs_file_status *status = &scb->status; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 188 | u32 type; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 189 | |
| 190 | status->abort_code = ntohl(xdr->abort_code); |
| 191 | if (status->abort_code != 0) { |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 192 | if (status->abort_code == VNOVNODE) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 193 | status->nlink = 0; |
David Howells | a38a755 | 2019-05-14 12:29:11 +0100 | [diff] [blame] | 194 | scb->have_error = true; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | type = ntohl(xdr->type); |
| 199 | switch (type) { |
| 200 | case AFS_FTYPE_FILE: |
| 201 | case AFS_FTYPE_DIR: |
| 202 | case AFS_FTYPE_SYMLINK: |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 203 | status->type = type; |
| 204 | break; |
| 205 | default: |
| 206 | goto bad; |
| 207 | } |
| 208 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 209 | status->nlink = ntohl(xdr->nlink); |
| 210 | status->author = xdr_to_u64(xdr->author); |
| 211 | status->owner = xdr_to_u64(xdr->owner); |
| 212 | status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */ |
| 213 | status->anon_access = ntohl(xdr->anon_access); |
| 214 | status->mode = ntohl(xdr->mode) & S_IALLUGO; |
| 215 | status->group = xdr_to_u64(xdr->group); |
| 216 | status->lock_count = ntohl(xdr->lock_count); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 217 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 218 | status->mtime_client = xdr_to_time(xdr->mtime_client); |
| 219 | status->mtime_server = xdr_to_time(xdr->mtime_server); |
| 220 | status->size = xdr_to_u64(xdr->size); |
| 221 | status->data_version = xdr_to_u64(xdr->data_version); |
David Howells | a38a755 | 2019-05-14 12:29:11 +0100 | [diff] [blame] | 222 | scb->have_status = true; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 223 | |
| 224 | *_bp += xdr_size(xdr); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 225 | return 0; |
| 226 | |
| 227 | bad: |
| 228 | xdr_dump_bad(*_bp); |
| 229 | return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status); |
| 230 | } |
| 231 | |
| 232 | /* |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 233 | * Decode a YFSCallBack block |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 234 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 235 | static void xdr_decode_YFSCallBack(const __be32 **_bp, |
| 236 | struct afs_call *call, |
| 237 | struct afs_status_cb *scb) |
David Howells | 7810705 | 2019-05-09 17:56:53 +0100 | [diff] [blame] | 238 | { |
| 239 | struct yfs_xdr_YFSCallBack *x = (void *)*_bp; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 240 | struct afs_callback *cb = &scb->callback; |
David Howells | 7810705 | 2019-05-09 17:56:53 +0100 | [diff] [blame] | 241 | ktime_t cb_expiry; |
| 242 | |
| 243 | cb_expiry = call->reply_time; |
| 244 | cb_expiry = ktime_add(cb_expiry, xdr_to_u64(x->expiration_time) * 100); |
| 245 | cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC); |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 246 | scb->have_cb = true; |
David Howells | 7810705 | 2019-05-09 17:56:53 +0100 | [diff] [blame] | 247 | *_bp += xdr_size(x); |
| 248 | } |
| 249 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 250 | /* |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 251 | * Decode a YFSVolSync block |
| 252 | */ |
| 253 | static void xdr_decode_YFSVolSync(const __be32 **_bp, |
| 254 | struct afs_volsync *volsync) |
| 255 | { |
| 256 | struct yfs_xdr_YFSVolSync *x = (void *)*_bp; |
| 257 | u64 creation; |
| 258 | |
| 259 | if (volsync) { |
| 260 | creation = xdr_to_u64(x->vol_creation_date); |
| 261 | do_div(creation, 10 * 1000 * 1000); |
| 262 | volsync->creation = creation; |
| 263 | } |
| 264 | |
| 265 | *_bp += xdr_size(x); |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * Encode the requested attributes into a YFSStoreStatus block |
| 270 | */ |
| 271 | static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr) |
| 272 | { |
| 273 | struct yfs_xdr_YFSStoreStatus *x = (void *)bp; |
| 274 | s64 mtime = 0, owner = 0, group = 0; |
| 275 | u32 mask = 0, mode = 0; |
| 276 | |
| 277 | mask = 0; |
| 278 | if (attr->ia_valid & ATTR_MTIME) { |
| 279 | mask |= AFS_SET_MTIME; |
| 280 | mtime = linux_to_yfs_time(&attr->ia_mtime); |
| 281 | } |
| 282 | |
| 283 | if (attr->ia_valid & ATTR_UID) { |
| 284 | mask |= AFS_SET_OWNER; |
| 285 | owner = from_kuid(&init_user_ns, attr->ia_uid); |
| 286 | } |
| 287 | |
| 288 | if (attr->ia_valid & ATTR_GID) { |
| 289 | mask |= AFS_SET_GROUP; |
| 290 | group = from_kgid(&init_user_ns, attr->ia_gid); |
| 291 | } |
| 292 | |
| 293 | if (attr->ia_valid & ATTR_MODE) { |
| 294 | mask |= AFS_SET_MODE; |
| 295 | mode = attr->ia_mode & S_IALLUGO; |
| 296 | } |
| 297 | |
| 298 | x->mask = htonl(mask); |
| 299 | x->mode = htonl(mode); |
| 300 | x->mtime_client = u64_to_xdr(mtime); |
| 301 | x->owner = u64_to_xdr(owner); |
| 302 | x->group = u64_to_xdr(group); |
| 303 | return bp + xdr_size(x); |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | * Decode a YFSFetchVolumeStatus block. |
| 308 | */ |
| 309 | static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp, |
| 310 | struct afs_volume_status *vs) |
| 311 | { |
| 312 | const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp; |
| 313 | u32 flags; |
| 314 | |
| 315 | vs->vid = xdr_to_u64(x->vid); |
| 316 | vs->parent_id = xdr_to_u64(x->parent_id); |
| 317 | flags = ntohl(x->flags); |
| 318 | vs->online = flags & yfs_FVSOnline; |
| 319 | vs->in_service = flags & yfs_FVSInservice; |
| 320 | vs->blessed = flags & yfs_FVSBlessed; |
| 321 | vs->needs_salvage = flags & yfs_FVSNeedsSalvage; |
| 322 | vs->type = ntohl(x->type); |
| 323 | vs->min_quota = 0; |
| 324 | vs->max_quota = xdr_to_u64(x->max_quota); |
| 325 | vs->blocks_in_use = xdr_to_u64(x->blocks_in_use); |
| 326 | vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail); |
| 327 | vs->part_max_blocks = xdr_to_u64(x->part_max_blocks); |
| 328 | vs->vol_copy_date = xdr_to_u64(x->vol_copy_date); |
| 329 | vs->vol_backup_date = xdr_to_u64(x->vol_backup_date); |
| 330 | *_bp += sizeof(*x) / sizeof(__be32); |
| 331 | } |
| 332 | |
| 333 | /* |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 334 | * Deliver a reply that's a status, callback and volsync. |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 335 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 336 | static int yfs_deliver_fs_status_cb_and_volsync(struct afs_call *call) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 337 | { |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 338 | const __be32 *bp; |
| 339 | int ret; |
| 340 | |
| 341 | ret = afs_transfer_reply(call); |
| 342 | if (ret < 0) |
| 343 | return ret; |
| 344 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 345 | /* unmarshall the reply once we've received all of it */ |
| 346 | bp = call->buffer; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 347 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 348 | if (ret < 0) |
| 349 | return ret; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 350 | xdr_decode_YFSCallBack(&bp, call, call->out_scb); |
| 351 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
| 352 | |
| 353 | _leave(" = 0 [done]"); |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * Deliver reply data to operations that just return a file status and a volume |
| 359 | * sync record. |
| 360 | */ |
| 361 | static int yfs_deliver_status_and_volsync(struct afs_call *call) |
| 362 | { |
| 363 | const __be32 *bp; |
| 364 | int ret; |
| 365 | |
| 366 | ret = afs_transfer_reply(call); |
| 367 | if (ret < 0) |
| 368 | return ret; |
| 369 | |
| 370 | bp = call->buffer; |
| 371 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb); |
| 372 | if (ret < 0) |
| 373 | return ret; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 374 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 375 | |
| 376 | _leave(" = 0 [done]"); |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * YFS.FetchStatus operation type |
| 382 | */ |
| 383 | static const struct afs_call_type yfs_RXYFSFetchStatus_vnode = { |
| 384 | .name = "YFS.FetchStatus(vnode)", |
| 385 | .op = yfs_FS_FetchStatus, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 386 | .deliver = yfs_deliver_fs_status_cb_and_volsync, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 387 | .destructor = afs_flat_call_destructor, |
| 388 | }; |
| 389 | |
| 390 | /* |
| 391 | * Fetch the status information for a file. |
| 392 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 393 | int yfs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_status_cb *scb, |
| 394 | struct afs_volsync *volsync) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 395 | { |
| 396 | struct afs_vnode *vnode = fc->vnode; |
| 397 | struct afs_call *call; |
| 398 | struct afs_net *net = afs_v2net(vnode); |
| 399 | __be32 *bp; |
| 400 | |
| 401 | _enter(",%x,{%llx:%llu},,", |
| 402 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); |
| 403 | |
| 404 | call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus_vnode, |
| 405 | sizeof(__be32) * 2 + |
| 406 | sizeof(struct yfs_xdr_YFSFid), |
| 407 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 408 | sizeof(struct yfs_xdr_YFSCallBack) + |
| 409 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 410 | if (!call) { |
| 411 | fc->ac.error = -ENOMEM; |
| 412 | return -ENOMEM; |
| 413 | } |
| 414 | |
| 415 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 416 | call->out_scb = scb; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 417 | call->out_volsync = volsync; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 418 | |
| 419 | /* marshall the parameters */ |
| 420 | bp = call->request; |
| 421 | bp = xdr_encode_u32(bp, YFSFETCHSTATUS); |
| 422 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 423 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 424 | yfs_check_req(call, bp); |
| 425 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 426 | afs_use_fs_server(call, fc->cbi); |
| 427 | trace_afs_make_fs_call(call, &vnode->fid); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 428 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 429 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 430 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* |
| 434 | * Deliver reply data to an YFS.FetchData64. |
| 435 | */ |
| 436 | static int yfs_deliver_fs_fetch_data64(struct afs_call *call) |
| 437 | { |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 438 | struct afs_read *req = call->read_request; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 439 | const __be32 *bp; |
| 440 | unsigned int size; |
| 441 | int ret; |
| 442 | |
| 443 | _enter("{%u,%zu/%llu}", |
| 444 | call->unmarshall, iov_iter_count(&call->iter), req->actual_len); |
| 445 | |
| 446 | switch (call->unmarshall) { |
| 447 | case 0: |
| 448 | req->actual_len = 0; |
| 449 | req->index = 0; |
| 450 | req->offset = req->pos & (PAGE_SIZE - 1); |
| 451 | afs_extract_to_tmp64(call); |
| 452 | call->unmarshall++; |
| 453 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 454 | /* Fall through - and extract the returned data length */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 455 | case 1: |
| 456 | _debug("extract data length"); |
| 457 | ret = afs_extract_data(call, true); |
| 458 | if (ret < 0) |
| 459 | return ret; |
| 460 | |
| 461 | req->actual_len = be64_to_cpu(call->tmp64); |
| 462 | _debug("DATA length: %llu", req->actual_len); |
| 463 | req->remain = min(req->len, req->actual_len); |
| 464 | if (req->remain == 0) |
| 465 | goto no_more_data; |
| 466 | |
| 467 | call->unmarshall++; |
| 468 | |
| 469 | begin_page: |
| 470 | ASSERTCMP(req->index, <, req->nr_pages); |
| 471 | if (req->remain > PAGE_SIZE - req->offset) |
| 472 | size = PAGE_SIZE - req->offset; |
| 473 | else |
| 474 | size = req->remain; |
| 475 | call->bvec[0].bv_len = size; |
| 476 | call->bvec[0].bv_offset = req->offset; |
| 477 | call->bvec[0].bv_page = req->pages[req->index]; |
| 478 | iov_iter_bvec(&call->iter, READ, call->bvec, 1, size); |
| 479 | ASSERTCMP(size, <=, PAGE_SIZE); |
| 480 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 481 | /* Fall through - and extract the returned data */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 482 | case 2: |
| 483 | _debug("extract data %zu/%llu", |
| 484 | iov_iter_count(&call->iter), req->remain); |
| 485 | |
| 486 | ret = afs_extract_data(call, true); |
| 487 | if (ret < 0) |
| 488 | return ret; |
| 489 | req->remain -= call->bvec[0].bv_len; |
| 490 | req->offset += call->bvec[0].bv_len; |
| 491 | ASSERTCMP(req->offset, <=, PAGE_SIZE); |
| 492 | if (req->offset == PAGE_SIZE) { |
| 493 | req->offset = 0; |
| 494 | if (req->page_done) |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 495 | req->page_done(req); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 496 | req->index++; |
| 497 | if (req->remain > 0) |
| 498 | goto begin_page; |
| 499 | } |
| 500 | |
| 501 | ASSERTCMP(req->remain, ==, 0); |
| 502 | if (req->actual_len <= req->len) |
| 503 | goto no_more_data; |
| 504 | |
| 505 | /* Discard any excess data the server gave us */ |
| 506 | iov_iter_discard(&call->iter, READ, req->actual_len - req->len); |
| 507 | call->unmarshall = 3; |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 508 | |
| 509 | /* Fall through */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 510 | case 3: |
| 511 | _debug("extract discard %zu/%llu", |
| 512 | iov_iter_count(&call->iter), req->actual_len - req->len); |
| 513 | |
| 514 | ret = afs_extract_data(call, true); |
| 515 | if (ret < 0) |
| 516 | return ret; |
| 517 | |
| 518 | no_more_data: |
| 519 | call->unmarshall = 4; |
| 520 | afs_extract_to_buf(call, |
| 521 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 522 | sizeof(struct yfs_xdr_YFSCallBack) + |
| 523 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 524 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 525 | /* Fall through - and extract the metadata */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 526 | case 4: |
| 527 | ret = afs_extract_data(call, false); |
| 528 | if (ret < 0) |
| 529 | return ret; |
| 530 | |
| 531 | bp = call->buffer; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 532 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 533 | if (ret < 0) |
| 534 | return ret; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 535 | xdr_decode_YFSCallBack(&bp, call, call->out_scb); |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 536 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 537 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 538 | req->data_version = call->out_scb->status.data_version; |
| 539 | req->file_size = call->out_scb->status.size; |
| 540 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 541 | call->unmarshall++; |
| 542 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 543 | /* Fall through */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 544 | case 5: |
| 545 | break; |
| 546 | } |
| 547 | |
| 548 | for (; req->index < req->nr_pages; req->index++) { |
| 549 | if (req->offset < PAGE_SIZE) |
| 550 | zero_user_segment(req->pages[req->index], |
| 551 | req->offset, PAGE_SIZE); |
| 552 | if (req->page_done) |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 553 | req->page_done(req); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 554 | req->offset = 0; |
| 555 | } |
| 556 | |
| 557 | _leave(" = 0 [done]"); |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | static void yfs_fetch_data_destructor(struct afs_call *call) |
| 562 | { |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 563 | afs_put_read(call->read_request); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 564 | afs_flat_call_destructor(call); |
| 565 | } |
| 566 | |
| 567 | /* |
| 568 | * YFS.FetchData64 operation type |
| 569 | */ |
| 570 | static const struct afs_call_type yfs_RXYFSFetchData64 = { |
| 571 | .name = "YFS.FetchData64", |
| 572 | .op = yfs_FS_FetchData64, |
| 573 | .deliver = yfs_deliver_fs_fetch_data64, |
| 574 | .destructor = yfs_fetch_data_destructor, |
| 575 | }; |
| 576 | |
| 577 | /* |
| 578 | * Fetch data from a file. |
| 579 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 580 | int yfs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_status_cb *scb, |
| 581 | struct afs_read *req) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 582 | { |
| 583 | struct afs_vnode *vnode = fc->vnode; |
| 584 | struct afs_call *call; |
| 585 | struct afs_net *net = afs_v2net(vnode); |
| 586 | __be32 *bp; |
| 587 | |
| 588 | _enter(",%x,{%llx:%llu},%llx,%llx", |
| 589 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode, |
| 590 | req->pos, req->len); |
| 591 | |
| 592 | call = afs_alloc_flat_call(net, &yfs_RXYFSFetchData64, |
| 593 | sizeof(__be32) * 2 + |
| 594 | sizeof(struct yfs_xdr_YFSFid) + |
| 595 | sizeof(struct yfs_xdr_u64) * 2, |
| 596 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 597 | sizeof(struct yfs_xdr_YFSCallBack) + |
| 598 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 599 | if (!call) |
| 600 | return -ENOMEM; |
| 601 | |
| 602 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 603 | call->out_scb = scb; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 604 | call->out_volsync = NULL; |
| 605 | call->read_request = req; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 606 | |
| 607 | /* marshall the parameters */ |
| 608 | bp = call->request; |
| 609 | bp = xdr_encode_u32(bp, YFSFETCHDATA64); |
| 610 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 611 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 612 | bp = xdr_encode_u64(bp, req->pos); |
| 613 | bp = xdr_encode_u64(bp, req->len); |
| 614 | yfs_check_req(call, bp); |
| 615 | |
| 616 | refcount_inc(&req->usage); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 617 | afs_use_fs_server(call, fc->cbi); |
| 618 | trace_afs_make_fs_call(call, &vnode->fid); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 619 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 620 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 621 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /* |
| 625 | * Deliver reply data for YFS.CreateFile or YFS.MakeDir. |
| 626 | */ |
| 627 | static int yfs_deliver_fs_create_vnode(struct afs_call *call) |
| 628 | { |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 629 | const __be32 *bp; |
| 630 | int ret; |
| 631 | |
| 632 | _enter("{%u}", call->unmarshall); |
| 633 | |
| 634 | ret = afs_transfer_reply(call); |
| 635 | if (ret < 0) |
| 636 | return ret; |
| 637 | |
| 638 | /* unmarshall the reply once we've received all of it */ |
| 639 | bp = call->buffer; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 640 | xdr_decode_YFSFid(&bp, call->out_fid); |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 641 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 642 | if (ret < 0) |
| 643 | return ret; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 644 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 645 | if (ret < 0) |
| 646 | return ret; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 647 | xdr_decode_YFSCallBack(&bp, call, call->out_scb); |
| 648 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 649 | |
| 650 | _leave(" = 0 [done]"); |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | /* |
| 655 | * FS.CreateFile and FS.MakeDir operation type |
| 656 | */ |
| 657 | static const struct afs_call_type afs_RXFSCreateFile = { |
| 658 | .name = "YFS.CreateFile", |
| 659 | .op = yfs_FS_CreateFile, |
| 660 | .deliver = yfs_deliver_fs_create_vnode, |
| 661 | .destructor = afs_flat_call_destructor, |
| 662 | }; |
| 663 | |
| 664 | /* |
| 665 | * Create a file. |
| 666 | */ |
| 667 | int yfs_fs_create_file(struct afs_fs_cursor *fc, |
| 668 | const char *name, |
| 669 | umode_t mode, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 670 | struct afs_status_cb *dvnode_scb, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 671 | struct afs_fid *newfid, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 672 | struct afs_status_cb *new_scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 673 | { |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 674 | struct afs_vnode *dvnode = fc->vnode; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 675 | struct afs_call *call; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 676 | struct afs_net *net = afs_v2net(dvnode); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 677 | size_t namesz, reqsz, rplsz; |
| 678 | __be32 *bp; |
| 679 | |
| 680 | _enter(""); |
| 681 | |
| 682 | namesz = strlen(name); |
| 683 | reqsz = (sizeof(__be32) + |
| 684 | sizeof(__be32) + |
| 685 | sizeof(struct yfs_xdr_YFSFid) + |
| 686 | xdr_strlen(namesz) + |
| 687 | sizeof(struct yfs_xdr_YFSStoreStatus) + |
| 688 | sizeof(__be32)); |
| 689 | rplsz = (sizeof(struct yfs_xdr_YFSFid) + |
| 690 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 691 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 692 | sizeof(struct yfs_xdr_YFSCallBack) + |
| 693 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 694 | |
| 695 | call = afs_alloc_flat_call(net, &afs_RXFSCreateFile, reqsz, rplsz); |
| 696 | if (!call) |
| 697 | return -ENOMEM; |
| 698 | |
| 699 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 700 | call->out_dir_scb = dvnode_scb; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 701 | call->out_fid = newfid; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 702 | call->out_scb = new_scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 703 | |
| 704 | /* marshall the parameters */ |
| 705 | bp = call->request; |
| 706 | bp = xdr_encode_u32(bp, YFSCREATEFILE); |
| 707 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 708 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 709 | bp = xdr_encode_string(bp, name, namesz); |
| 710 | bp = xdr_encode_YFSStoreStatus_mode(bp, mode); |
Marc Dionne | 5edc22c | 2019-01-09 17:23:54 +0000 | [diff] [blame] | 711 | bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 712 | yfs_check_req(call, bp); |
| 713 | |
| 714 | afs_use_fs_server(call, fc->cbi); |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 715 | trace_afs_make_fs_call1(call, &dvnode->fid, name); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 716 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 717 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 718 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | static const struct afs_call_type yfs_RXFSMakeDir = { |
| 722 | .name = "YFS.MakeDir", |
| 723 | .op = yfs_FS_MakeDir, |
| 724 | .deliver = yfs_deliver_fs_create_vnode, |
| 725 | .destructor = afs_flat_call_destructor, |
| 726 | }; |
| 727 | |
| 728 | /* |
| 729 | * Make a directory. |
| 730 | */ |
| 731 | int yfs_fs_make_dir(struct afs_fs_cursor *fc, |
| 732 | const char *name, |
| 733 | umode_t mode, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 734 | struct afs_status_cb *dvnode_scb, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 735 | struct afs_fid *newfid, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 736 | struct afs_status_cb *new_scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 737 | { |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 738 | struct afs_vnode *dvnode = fc->vnode; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 739 | struct afs_call *call; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 740 | struct afs_net *net = afs_v2net(dvnode); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 741 | size_t namesz, reqsz, rplsz; |
| 742 | __be32 *bp; |
| 743 | |
| 744 | _enter(""); |
| 745 | |
| 746 | namesz = strlen(name); |
| 747 | reqsz = (sizeof(__be32) + |
| 748 | sizeof(struct yfs_xdr_RPCFlags) + |
| 749 | sizeof(struct yfs_xdr_YFSFid) + |
| 750 | xdr_strlen(namesz) + |
| 751 | sizeof(struct yfs_xdr_YFSStoreStatus)); |
| 752 | rplsz = (sizeof(struct yfs_xdr_YFSFid) + |
| 753 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 754 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 755 | sizeof(struct yfs_xdr_YFSCallBack) + |
| 756 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 757 | |
| 758 | call = afs_alloc_flat_call(net, &yfs_RXFSMakeDir, reqsz, rplsz); |
| 759 | if (!call) |
| 760 | return -ENOMEM; |
| 761 | |
| 762 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 763 | call->out_dir_scb = dvnode_scb; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 764 | call->out_fid = newfid; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 765 | call->out_scb = new_scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 766 | |
| 767 | /* marshall the parameters */ |
| 768 | bp = call->request; |
| 769 | bp = xdr_encode_u32(bp, YFSMAKEDIR); |
| 770 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 771 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 772 | bp = xdr_encode_string(bp, name, namesz); |
| 773 | bp = xdr_encode_YFSStoreStatus_mode(bp, mode); |
| 774 | yfs_check_req(call, bp); |
| 775 | |
| 776 | afs_use_fs_server(call, fc->cbi); |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 777 | trace_afs_make_fs_call1(call, &dvnode->fid, name); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 778 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 779 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 780 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | /* |
| 784 | * Deliver reply data to a YFS.RemoveFile2 operation. |
| 785 | */ |
| 786 | static int yfs_deliver_fs_remove_file2(struct afs_call *call) |
| 787 | { |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 788 | struct afs_fid fid; |
| 789 | const __be32 *bp; |
| 790 | int ret; |
| 791 | |
| 792 | _enter("{%u}", call->unmarshall); |
| 793 | |
| 794 | ret = afs_transfer_reply(call); |
| 795 | if (ret < 0) |
| 796 | return ret; |
| 797 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 798 | bp = call->buffer; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 799 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 800 | if (ret < 0) |
| 801 | return ret; |
| 802 | |
| 803 | xdr_decode_YFSFid(&bp, &fid); |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 804 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 805 | if (ret < 0) |
| 806 | return ret; |
| 807 | /* Was deleted if vnode->status.abort_code == VNOVNODE. */ |
| 808 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 809 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | /* |
| 814 | * YFS.RemoveFile2 operation type. |
| 815 | */ |
| 816 | static const struct afs_call_type yfs_RXYFSRemoveFile2 = { |
| 817 | .name = "YFS.RemoveFile2", |
| 818 | .op = yfs_FS_RemoveFile2, |
| 819 | .deliver = yfs_deliver_fs_remove_file2, |
| 820 | .destructor = afs_flat_call_destructor, |
| 821 | }; |
| 822 | |
| 823 | /* |
| 824 | * Remove a file and retrieve new file status. |
| 825 | */ |
| 826 | int yfs_fs_remove_file2(struct afs_fs_cursor *fc, struct afs_vnode *vnode, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 827 | const char *name, struct afs_status_cb *dvnode_scb, |
| 828 | struct afs_status_cb *vnode_scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 829 | { |
| 830 | struct afs_vnode *dvnode = fc->vnode; |
| 831 | struct afs_call *call; |
| 832 | struct afs_net *net = afs_v2net(dvnode); |
| 833 | size_t namesz; |
| 834 | __be32 *bp; |
| 835 | |
| 836 | _enter(""); |
| 837 | |
| 838 | namesz = strlen(name); |
| 839 | |
| 840 | call = afs_alloc_flat_call(net, &yfs_RXYFSRemoveFile2, |
| 841 | sizeof(__be32) + |
| 842 | sizeof(struct yfs_xdr_RPCFlags) + |
| 843 | sizeof(struct yfs_xdr_YFSFid) + |
| 844 | xdr_strlen(namesz), |
| 845 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 846 | sizeof(struct yfs_xdr_YFSFid) + |
| 847 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 848 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 849 | if (!call) |
| 850 | return -ENOMEM; |
| 851 | |
| 852 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 853 | call->out_dir_scb = dvnode_scb; |
| 854 | call->out_scb = vnode_scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 855 | |
| 856 | /* marshall the parameters */ |
| 857 | bp = call->request; |
| 858 | bp = xdr_encode_u32(bp, YFSREMOVEFILE2); |
| 859 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 860 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); |
| 861 | bp = xdr_encode_string(bp, name, namesz); |
| 862 | yfs_check_req(call, bp); |
| 863 | |
| 864 | afs_use_fs_server(call, fc->cbi); |
David Howells | 80548b0 | 2019-04-25 14:26:51 +0100 | [diff] [blame] | 865 | trace_afs_make_fs_call1(call, &dvnode->fid, name); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 866 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 867 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 868 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | /* |
| 872 | * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation. |
| 873 | */ |
| 874 | static int yfs_deliver_fs_remove(struct afs_call *call) |
| 875 | { |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 876 | const __be32 *bp; |
| 877 | int ret; |
| 878 | |
| 879 | _enter("{%u}", call->unmarshall); |
| 880 | |
| 881 | ret = afs_transfer_reply(call); |
| 882 | if (ret < 0) |
| 883 | return ret; |
| 884 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 885 | bp = call->buffer; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 886 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 887 | if (ret < 0) |
| 888 | return ret; |
| 889 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 890 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | /* |
| 895 | * FS.RemoveDir and FS.RemoveFile operation types. |
| 896 | */ |
| 897 | static const struct afs_call_type yfs_RXYFSRemoveFile = { |
| 898 | .name = "YFS.RemoveFile", |
| 899 | .op = yfs_FS_RemoveFile, |
| 900 | .deliver = yfs_deliver_fs_remove, |
| 901 | .destructor = afs_flat_call_destructor, |
| 902 | }; |
| 903 | |
| 904 | static const struct afs_call_type yfs_RXYFSRemoveDir = { |
| 905 | .name = "YFS.RemoveDir", |
| 906 | .op = yfs_FS_RemoveDir, |
| 907 | .deliver = yfs_deliver_fs_remove, |
| 908 | .destructor = afs_flat_call_destructor, |
| 909 | }; |
| 910 | |
| 911 | /* |
| 912 | * remove a file or directory |
| 913 | */ |
| 914 | int yfs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 915 | const char *name, bool isdir, |
| 916 | struct afs_status_cb *dvnode_scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 917 | { |
| 918 | struct afs_vnode *dvnode = fc->vnode; |
| 919 | struct afs_call *call; |
| 920 | struct afs_net *net = afs_v2net(dvnode); |
| 921 | size_t namesz; |
| 922 | __be32 *bp; |
| 923 | |
| 924 | _enter(""); |
| 925 | |
| 926 | namesz = strlen(name); |
| 927 | call = afs_alloc_flat_call( |
| 928 | net, isdir ? &yfs_RXYFSRemoveDir : &yfs_RXYFSRemoveFile, |
| 929 | sizeof(__be32) + |
| 930 | sizeof(struct yfs_xdr_RPCFlags) + |
| 931 | sizeof(struct yfs_xdr_YFSFid) + |
| 932 | xdr_strlen(namesz), |
| 933 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 934 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 935 | if (!call) |
| 936 | return -ENOMEM; |
| 937 | |
| 938 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 939 | call->out_dir_scb = dvnode_scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 940 | |
| 941 | /* marshall the parameters */ |
| 942 | bp = call->request; |
| 943 | bp = xdr_encode_u32(bp, isdir ? YFSREMOVEDIR : YFSREMOVEFILE); |
| 944 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 945 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); |
| 946 | bp = xdr_encode_string(bp, name, namesz); |
| 947 | yfs_check_req(call, bp); |
| 948 | |
| 949 | afs_use_fs_server(call, fc->cbi); |
David Howells | 80548b0 | 2019-04-25 14:26:51 +0100 | [diff] [blame] | 950 | trace_afs_make_fs_call1(call, &dvnode->fid, name); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 951 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 952 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 953 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | /* |
| 957 | * Deliver reply data to a YFS.Link operation. |
| 958 | */ |
| 959 | static int yfs_deliver_fs_link(struct afs_call *call) |
| 960 | { |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 961 | const __be32 *bp; |
| 962 | int ret; |
| 963 | |
| 964 | _enter("{%u}", call->unmarshall); |
| 965 | |
| 966 | ret = afs_transfer_reply(call); |
| 967 | if (ret < 0) |
| 968 | return ret; |
| 969 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 970 | bp = call->buffer; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 971 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 972 | if (ret < 0) |
| 973 | return ret; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 974 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 975 | if (ret < 0) |
| 976 | return ret; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 977 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 978 | _leave(" = 0 [done]"); |
| 979 | return 0; |
| 980 | } |
| 981 | |
| 982 | /* |
| 983 | * YFS.Link operation type. |
| 984 | */ |
| 985 | static const struct afs_call_type yfs_RXYFSLink = { |
| 986 | .name = "YFS.Link", |
| 987 | .op = yfs_FS_Link, |
| 988 | .deliver = yfs_deliver_fs_link, |
| 989 | .destructor = afs_flat_call_destructor, |
| 990 | }; |
| 991 | |
| 992 | /* |
| 993 | * Make a hard link. |
| 994 | */ |
| 995 | int yfs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 996 | const char *name, |
| 997 | struct afs_status_cb *dvnode_scb, |
| 998 | struct afs_status_cb *vnode_scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 999 | { |
| 1000 | struct afs_vnode *dvnode = fc->vnode; |
| 1001 | struct afs_call *call; |
| 1002 | struct afs_net *net = afs_v2net(vnode); |
| 1003 | size_t namesz; |
| 1004 | __be32 *bp; |
| 1005 | |
| 1006 | _enter(""); |
| 1007 | |
| 1008 | namesz = strlen(name); |
| 1009 | call = afs_alloc_flat_call(net, &yfs_RXYFSLink, |
| 1010 | sizeof(__be32) + |
| 1011 | sizeof(struct yfs_xdr_RPCFlags) + |
| 1012 | sizeof(struct yfs_xdr_YFSFid) + |
| 1013 | xdr_strlen(namesz) + |
| 1014 | sizeof(struct yfs_xdr_YFSFid), |
| 1015 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1016 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1017 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 1018 | if (!call) |
| 1019 | return -ENOMEM; |
| 1020 | |
| 1021 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1022 | call->out_dir_scb = dvnode_scb; |
| 1023 | call->out_scb = vnode_scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1024 | |
| 1025 | /* marshall the parameters */ |
| 1026 | bp = call->request; |
| 1027 | bp = xdr_encode_u32(bp, YFSLINK); |
| 1028 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1029 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); |
| 1030 | bp = xdr_encode_string(bp, name, namesz); |
| 1031 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 1032 | yfs_check_req(call, bp); |
| 1033 | |
| 1034 | afs_use_fs_server(call, fc->cbi); |
David Howells | 80548b0 | 2019-04-25 14:26:51 +0100 | [diff] [blame] | 1035 | trace_afs_make_fs_call1(call, &vnode->fid, name); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1036 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1037 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1038 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | /* |
| 1042 | * Deliver reply data to a YFS.Symlink operation. |
| 1043 | */ |
| 1044 | static int yfs_deliver_fs_symlink(struct afs_call *call) |
| 1045 | { |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1046 | const __be32 *bp; |
| 1047 | int ret; |
| 1048 | |
| 1049 | _enter("{%u}", call->unmarshall); |
| 1050 | |
| 1051 | ret = afs_transfer_reply(call); |
| 1052 | if (ret < 0) |
| 1053 | return ret; |
| 1054 | |
| 1055 | /* unmarshall the reply once we've received all of it */ |
| 1056 | bp = call->buffer; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1057 | xdr_decode_YFSFid(&bp, call->out_fid); |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1058 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1059 | if (ret < 0) |
| 1060 | return ret; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1061 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1062 | if (ret < 0) |
| 1063 | return ret; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1064 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1065 | |
| 1066 | _leave(" = 0 [done]"); |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | /* |
| 1071 | * YFS.Symlink operation type |
| 1072 | */ |
| 1073 | static const struct afs_call_type yfs_RXYFSSymlink = { |
| 1074 | .name = "YFS.Symlink", |
| 1075 | .op = yfs_FS_Symlink, |
| 1076 | .deliver = yfs_deliver_fs_symlink, |
| 1077 | .destructor = afs_flat_call_destructor, |
| 1078 | }; |
| 1079 | |
| 1080 | /* |
| 1081 | * Create a symbolic link. |
| 1082 | */ |
| 1083 | int yfs_fs_symlink(struct afs_fs_cursor *fc, |
| 1084 | const char *name, |
| 1085 | const char *contents, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1086 | struct afs_status_cb *dvnode_scb, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1087 | struct afs_fid *newfid, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1088 | struct afs_status_cb *vnode_scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1089 | { |
| 1090 | struct afs_vnode *dvnode = fc->vnode; |
| 1091 | struct afs_call *call; |
| 1092 | struct afs_net *net = afs_v2net(dvnode); |
| 1093 | size_t namesz, contents_sz; |
| 1094 | __be32 *bp; |
| 1095 | |
| 1096 | _enter(""); |
| 1097 | |
| 1098 | namesz = strlen(name); |
| 1099 | contents_sz = strlen(contents); |
| 1100 | call = afs_alloc_flat_call(net, &yfs_RXYFSSymlink, |
| 1101 | sizeof(__be32) + |
| 1102 | sizeof(struct yfs_xdr_RPCFlags) + |
| 1103 | sizeof(struct yfs_xdr_YFSFid) + |
| 1104 | xdr_strlen(namesz) + |
| 1105 | xdr_strlen(contents_sz) + |
| 1106 | sizeof(struct yfs_xdr_YFSStoreStatus), |
| 1107 | sizeof(struct yfs_xdr_YFSFid) + |
| 1108 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1109 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1110 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 1111 | if (!call) |
| 1112 | return -ENOMEM; |
| 1113 | |
| 1114 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1115 | call->out_dir_scb = dvnode_scb; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1116 | call->out_fid = newfid; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1117 | call->out_scb = vnode_scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1118 | |
| 1119 | /* marshall the parameters */ |
| 1120 | bp = call->request; |
| 1121 | bp = xdr_encode_u32(bp, YFSSYMLINK); |
| 1122 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1123 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); |
| 1124 | bp = xdr_encode_string(bp, name, namesz); |
| 1125 | bp = xdr_encode_string(bp, contents, contents_sz); |
| 1126 | bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO); |
| 1127 | yfs_check_req(call, bp); |
| 1128 | |
| 1129 | afs_use_fs_server(call, fc->cbi); |
David Howells | 80548b0 | 2019-04-25 14:26:51 +0100 | [diff] [blame] | 1130 | trace_afs_make_fs_call1(call, &dvnode->fid, name); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1131 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1132 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1133 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | /* |
| 1137 | * Deliver reply data to a YFS.Rename operation. |
| 1138 | */ |
| 1139 | static int yfs_deliver_fs_rename(struct afs_call *call) |
| 1140 | { |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1141 | const __be32 *bp; |
| 1142 | int ret; |
| 1143 | |
| 1144 | _enter("{%u}", call->unmarshall); |
| 1145 | |
| 1146 | ret = afs_transfer_reply(call); |
| 1147 | if (ret < 0) |
| 1148 | return ret; |
| 1149 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1150 | bp = call->buffer; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1151 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1152 | if (ret < 0) |
| 1153 | return ret; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1154 | if (call->out_dir_scb != call->out_scb) { |
| 1155 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1156 | if (ret < 0) |
| 1157 | return ret; |
| 1158 | } |
| 1159 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1160 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1161 | _leave(" = 0 [done]"); |
| 1162 | return 0; |
| 1163 | } |
| 1164 | |
| 1165 | /* |
| 1166 | * YFS.Rename operation type |
| 1167 | */ |
| 1168 | static const struct afs_call_type yfs_RXYFSRename = { |
| 1169 | .name = "FS.Rename", |
| 1170 | .op = yfs_FS_Rename, |
| 1171 | .deliver = yfs_deliver_fs_rename, |
| 1172 | .destructor = afs_flat_call_destructor, |
| 1173 | }; |
| 1174 | |
| 1175 | /* |
| 1176 | * Rename a file or directory. |
| 1177 | */ |
| 1178 | int yfs_fs_rename(struct afs_fs_cursor *fc, |
| 1179 | const char *orig_name, |
| 1180 | struct afs_vnode *new_dvnode, |
| 1181 | const char *new_name, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1182 | struct afs_status_cb *orig_dvnode_scb, |
| 1183 | struct afs_status_cb *new_dvnode_scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1184 | { |
| 1185 | struct afs_vnode *orig_dvnode = fc->vnode; |
| 1186 | struct afs_call *call; |
| 1187 | struct afs_net *net = afs_v2net(orig_dvnode); |
| 1188 | size_t o_namesz, n_namesz; |
| 1189 | __be32 *bp; |
| 1190 | |
| 1191 | _enter(""); |
| 1192 | |
| 1193 | o_namesz = strlen(orig_name); |
| 1194 | n_namesz = strlen(new_name); |
| 1195 | call = afs_alloc_flat_call(net, &yfs_RXYFSRename, |
| 1196 | sizeof(__be32) + |
| 1197 | sizeof(struct yfs_xdr_RPCFlags) + |
| 1198 | sizeof(struct yfs_xdr_YFSFid) + |
| 1199 | xdr_strlen(o_namesz) + |
| 1200 | sizeof(struct yfs_xdr_YFSFid) + |
| 1201 | xdr_strlen(n_namesz), |
| 1202 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1203 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1204 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 1205 | if (!call) |
| 1206 | return -ENOMEM; |
| 1207 | |
| 1208 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1209 | call->out_dir_scb = orig_dvnode_scb; |
| 1210 | call->out_scb = new_dvnode_scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1211 | |
| 1212 | /* marshall the parameters */ |
| 1213 | bp = call->request; |
| 1214 | bp = xdr_encode_u32(bp, YFSRENAME); |
| 1215 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1216 | bp = xdr_encode_YFSFid(bp, &orig_dvnode->fid); |
| 1217 | bp = xdr_encode_string(bp, orig_name, o_namesz); |
| 1218 | bp = xdr_encode_YFSFid(bp, &new_dvnode->fid); |
| 1219 | bp = xdr_encode_string(bp, new_name, n_namesz); |
| 1220 | yfs_check_req(call, bp); |
| 1221 | |
| 1222 | afs_use_fs_server(call, fc->cbi); |
David Howells | 80548b0 | 2019-04-25 14:26:51 +0100 | [diff] [blame] | 1223 | trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1224 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1225 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1226 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | /* |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1230 | * YFS.StoreData64 operation type. |
| 1231 | */ |
| 1232 | static const struct afs_call_type yfs_RXYFSStoreData64 = { |
| 1233 | .name = "YFS.StoreData64", |
| 1234 | .op = yfs_FS_StoreData64, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1235 | .deliver = yfs_deliver_status_and_volsync, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1236 | .destructor = afs_flat_call_destructor, |
| 1237 | }; |
| 1238 | |
| 1239 | /* |
| 1240 | * Store a set of pages to a large file. |
| 1241 | */ |
| 1242 | int yfs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping, |
| 1243 | pgoff_t first, pgoff_t last, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1244 | unsigned offset, unsigned to, |
| 1245 | struct afs_status_cb *scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1246 | { |
| 1247 | struct afs_vnode *vnode = fc->vnode; |
| 1248 | struct afs_call *call; |
| 1249 | struct afs_net *net = afs_v2net(vnode); |
| 1250 | loff_t size, pos, i_size; |
| 1251 | __be32 *bp; |
| 1252 | |
| 1253 | _enter(",%x,{%llx:%llu},,", |
| 1254 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); |
| 1255 | |
| 1256 | size = (loff_t)to - (loff_t)offset; |
| 1257 | if (first != last) |
| 1258 | size += (loff_t)(last - first) << PAGE_SHIFT; |
| 1259 | pos = (loff_t)first << PAGE_SHIFT; |
| 1260 | pos += offset; |
| 1261 | |
| 1262 | i_size = i_size_read(&vnode->vfs_inode); |
| 1263 | if (pos + size > i_size) |
| 1264 | i_size = size + pos; |
| 1265 | |
| 1266 | _debug("size %llx, at %llx, i_size %llx", |
| 1267 | (unsigned long long)size, (unsigned long long)pos, |
| 1268 | (unsigned long long)i_size); |
| 1269 | |
| 1270 | call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64, |
| 1271 | sizeof(__be32) + |
| 1272 | sizeof(__be32) + |
| 1273 | sizeof(struct yfs_xdr_YFSFid) + |
| 1274 | sizeof(struct yfs_xdr_YFSStoreStatus) + |
| 1275 | sizeof(struct yfs_xdr_u64) * 3, |
| 1276 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1277 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 1278 | if (!call) |
| 1279 | return -ENOMEM; |
| 1280 | |
| 1281 | call->key = fc->key; |
| 1282 | call->mapping = mapping; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1283 | call->first = first; |
| 1284 | call->last = last; |
| 1285 | call->first_offset = offset; |
| 1286 | call->last_to = to; |
| 1287 | call->send_pages = true; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1288 | call->out_scb = scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1289 | |
| 1290 | /* marshall the parameters */ |
| 1291 | bp = call->request; |
| 1292 | bp = xdr_encode_u32(bp, YFSSTOREDATA64); |
| 1293 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1294 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 1295 | bp = xdr_encode_YFSStoreStatus_mtime(bp, &vnode->vfs_inode.i_mtime); |
| 1296 | bp = xdr_encode_u64(bp, pos); |
| 1297 | bp = xdr_encode_u64(bp, size); |
| 1298 | bp = xdr_encode_u64(bp, i_size); |
| 1299 | yfs_check_req(call, bp); |
| 1300 | |
| 1301 | afs_use_fs_server(call, fc->cbi); |
| 1302 | trace_afs_make_fs_call(call, &vnode->fid); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1303 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1304 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1305 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | /* |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1309 | * YFS.StoreStatus operation type |
| 1310 | */ |
| 1311 | static const struct afs_call_type yfs_RXYFSStoreStatus = { |
| 1312 | .name = "YFS.StoreStatus", |
| 1313 | .op = yfs_FS_StoreStatus, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1314 | .deliver = yfs_deliver_status_and_volsync, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1315 | .destructor = afs_flat_call_destructor, |
| 1316 | }; |
| 1317 | |
| 1318 | static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = { |
| 1319 | .name = "YFS.StoreData64", |
| 1320 | .op = yfs_FS_StoreData64, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1321 | .deliver = yfs_deliver_status_and_volsync, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1322 | .destructor = afs_flat_call_destructor, |
| 1323 | }; |
| 1324 | |
| 1325 | /* |
| 1326 | * Set the attributes on a file, using YFS.StoreData64 rather than |
| 1327 | * YFS.StoreStatus so as to alter the file size also. |
| 1328 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1329 | static int yfs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr, |
| 1330 | struct afs_status_cb *scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1331 | { |
| 1332 | struct afs_vnode *vnode = fc->vnode; |
| 1333 | struct afs_call *call; |
| 1334 | struct afs_net *net = afs_v2net(vnode); |
| 1335 | __be32 *bp; |
| 1336 | |
| 1337 | _enter(",%x,{%llx:%llu},,", |
| 1338 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); |
| 1339 | |
| 1340 | call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64_as_Status, |
| 1341 | sizeof(__be32) * 2 + |
| 1342 | sizeof(struct yfs_xdr_YFSFid) + |
| 1343 | sizeof(struct yfs_xdr_YFSStoreStatus) + |
| 1344 | sizeof(struct yfs_xdr_u64) * 3, |
| 1345 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1346 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 1347 | if (!call) |
| 1348 | return -ENOMEM; |
| 1349 | |
| 1350 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1351 | call->out_scb = scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1352 | |
| 1353 | /* marshall the parameters */ |
| 1354 | bp = call->request; |
| 1355 | bp = xdr_encode_u32(bp, YFSSTOREDATA64); |
| 1356 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1357 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 1358 | bp = xdr_encode_YFS_StoreStatus(bp, attr); |
David Howells | 8c7ae38 | 2019-03-27 22:48:02 +0000 | [diff] [blame] | 1359 | bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1360 | bp = xdr_encode_u64(bp, 0); /* size of write */ |
| 1361 | bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */ |
| 1362 | yfs_check_req(call, bp); |
| 1363 | |
| 1364 | afs_use_fs_server(call, fc->cbi); |
| 1365 | trace_afs_make_fs_call(call, &vnode->fid); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1366 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1367 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1368 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | /* |
| 1372 | * Set the attributes on a file, using YFS.StoreData64 if there's a change in |
| 1373 | * file size, and YFS.StoreStatus otherwise. |
| 1374 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1375 | int yfs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr, |
| 1376 | struct afs_status_cb *scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1377 | { |
| 1378 | struct afs_vnode *vnode = fc->vnode; |
| 1379 | struct afs_call *call; |
| 1380 | struct afs_net *net = afs_v2net(vnode); |
| 1381 | __be32 *bp; |
| 1382 | |
| 1383 | if (attr->ia_valid & ATTR_SIZE) |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1384 | return yfs_fs_setattr_size(fc, attr, scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1385 | |
| 1386 | _enter(",%x,{%llx:%llu},,", |
| 1387 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); |
| 1388 | |
| 1389 | call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus, |
| 1390 | sizeof(__be32) * 2 + |
| 1391 | sizeof(struct yfs_xdr_YFSFid) + |
| 1392 | sizeof(struct yfs_xdr_YFSStoreStatus), |
| 1393 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1394 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 1395 | if (!call) |
| 1396 | return -ENOMEM; |
| 1397 | |
| 1398 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1399 | call->out_scb = scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1400 | |
| 1401 | /* marshall the parameters */ |
| 1402 | bp = call->request; |
| 1403 | bp = xdr_encode_u32(bp, YFSSTORESTATUS); |
| 1404 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1405 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 1406 | bp = xdr_encode_YFS_StoreStatus(bp, attr); |
| 1407 | yfs_check_req(call, bp); |
| 1408 | |
| 1409 | afs_use_fs_server(call, fc->cbi); |
| 1410 | trace_afs_make_fs_call(call, &vnode->fid); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1411 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1412 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1413 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | /* |
| 1417 | * Deliver reply data to a YFS.GetVolumeStatus operation. |
| 1418 | */ |
| 1419 | static int yfs_deliver_fs_get_volume_status(struct afs_call *call) |
| 1420 | { |
| 1421 | const __be32 *bp; |
| 1422 | char *p; |
| 1423 | u32 size; |
| 1424 | int ret; |
| 1425 | |
| 1426 | _enter("{%u}", call->unmarshall); |
| 1427 | |
| 1428 | switch (call->unmarshall) { |
| 1429 | case 0: |
| 1430 | call->unmarshall++; |
| 1431 | afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus)); |
| 1432 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1433 | /* Fall through - and extract the returned status record */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1434 | case 1: |
| 1435 | _debug("extract status"); |
| 1436 | ret = afs_extract_data(call, true); |
| 1437 | if (ret < 0) |
| 1438 | return ret; |
| 1439 | |
| 1440 | bp = call->buffer; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1441 | xdr_decode_YFSFetchVolumeStatus(&bp, call->out_volstatus); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1442 | call->unmarshall++; |
| 1443 | afs_extract_to_tmp(call); |
| 1444 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1445 | /* Fall through - and extract the volume name length */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1446 | case 2: |
| 1447 | ret = afs_extract_data(call, true); |
| 1448 | if (ret < 0) |
| 1449 | return ret; |
| 1450 | |
| 1451 | call->count = ntohl(call->tmp); |
| 1452 | _debug("volname length: %u", call->count); |
| 1453 | if (call->count >= AFSNAMEMAX) |
| 1454 | return afs_protocol_error(call, -EBADMSG, |
| 1455 | afs_eproto_volname_len); |
| 1456 | size = (call->count + 3) & ~3; /* It's padded */ |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1457 | afs_extract_to_buf(call, size); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1458 | call->unmarshall++; |
| 1459 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1460 | /* Fall through - and extract the volume name */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1461 | case 3: |
| 1462 | _debug("extract volname"); |
| 1463 | ret = afs_extract_data(call, true); |
| 1464 | if (ret < 0) |
| 1465 | return ret; |
| 1466 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1467 | p = call->buffer; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1468 | p[call->count] = 0; |
| 1469 | _debug("volname '%s'", p); |
| 1470 | afs_extract_to_tmp(call); |
| 1471 | call->unmarshall++; |
| 1472 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1473 | /* Fall through - and extract the offline message length */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1474 | case 4: |
| 1475 | ret = afs_extract_data(call, true); |
| 1476 | if (ret < 0) |
| 1477 | return ret; |
| 1478 | |
| 1479 | call->count = ntohl(call->tmp); |
| 1480 | _debug("offline msg length: %u", call->count); |
| 1481 | if (call->count >= AFSNAMEMAX) |
| 1482 | return afs_protocol_error(call, -EBADMSG, |
| 1483 | afs_eproto_offline_msg_len); |
| 1484 | size = (call->count + 3) & ~3; /* It's padded */ |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1485 | afs_extract_to_buf(call, size); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1486 | call->unmarshall++; |
| 1487 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1488 | /* Fall through - and extract the offline message */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1489 | case 5: |
| 1490 | _debug("extract offline"); |
| 1491 | ret = afs_extract_data(call, true); |
| 1492 | if (ret < 0) |
| 1493 | return ret; |
| 1494 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1495 | p = call->buffer; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1496 | p[call->count] = 0; |
| 1497 | _debug("offline '%s'", p); |
| 1498 | |
| 1499 | afs_extract_to_tmp(call); |
| 1500 | call->unmarshall++; |
| 1501 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1502 | /* Fall through - and extract the message of the day length */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1503 | case 6: |
| 1504 | ret = afs_extract_data(call, true); |
| 1505 | if (ret < 0) |
| 1506 | return ret; |
| 1507 | |
| 1508 | call->count = ntohl(call->tmp); |
| 1509 | _debug("motd length: %u", call->count); |
| 1510 | if (call->count >= AFSNAMEMAX) |
| 1511 | return afs_protocol_error(call, -EBADMSG, |
| 1512 | afs_eproto_motd_len); |
| 1513 | size = (call->count + 3) & ~3; /* It's padded */ |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1514 | afs_extract_to_buf(call, size); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1515 | call->unmarshall++; |
| 1516 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1517 | /* Fall through - and extract the message of the day */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1518 | case 7: |
| 1519 | _debug("extract motd"); |
| 1520 | ret = afs_extract_data(call, false); |
| 1521 | if (ret < 0) |
| 1522 | return ret; |
| 1523 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1524 | p = call->buffer; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1525 | p[call->count] = 0; |
| 1526 | _debug("motd '%s'", p); |
| 1527 | |
| 1528 | call->unmarshall++; |
| 1529 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1530 | /* Fall through */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1531 | case 8: |
| 1532 | break; |
| 1533 | } |
| 1534 | |
| 1535 | _leave(" = 0 [done]"); |
| 1536 | return 0; |
| 1537 | } |
| 1538 | |
| 1539 | /* |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1540 | * YFS.GetVolumeStatus operation type |
| 1541 | */ |
| 1542 | static const struct afs_call_type yfs_RXYFSGetVolumeStatus = { |
| 1543 | .name = "YFS.GetVolumeStatus", |
| 1544 | .op = yfs_FS_GetVolumeStatus, |
| 1545 | .deliver = yfs_deliver_fs_get_volume_status, |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1546 | .destructor = afs_flat_call_destructor, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1547 | }; |
| 1548 | |
| 1549 | /* |
| 1550 | * fetch the status of a volume |
| 1551 | */ |
| 1552 | int yfs_fs_get_volume_status(struct afs_fs_cursor *fc, |
| 1553 | struct afs_volume_status *vs) |
| 1554 | { |
| 1555 | struct afs_vnode *vnode = fc->vnode; |
| 1556 | struct afs_call *call; |
| 1557 | struct afs_net *net = afs_v2net(vnode); |
| 1558 | __be32 *bp; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1559 | |
| 1560 | _enter(""); |
| 1561 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1562 | call = afs_alloc_flat_call(net, &yfs_RXYFSGetVolumeStatus, |
| 1563 | sizeof(__be32) * 2 + |
| 1564 | sizeof(struct yfs_xdr_u64), |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1565 | max_t(size_t, |
| 1566 | sizeof(struct yfs_xdr_YFSFetchVolumeStatus) + |
| 1567 | sizeof(__be32), |
| 1568 | AFSOPAQUEMAX + 1)); |
| 1569 | if (!call) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1570 | return -ENOMEM; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1571 | |
| 1572 | call->key = fc->key; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1573 | call->out_volstatus = vs; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1574 | |
| 1575 | /* marshall the parameters */ |
| 1576 | bp = call->request; |
| 1577 | bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS); |
| 1578 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1579 | bp = xdr_encode_u64(bp, vnode->fid.vid); |
| 1580 | yfs_check_req(call, bp); |
| 1581 | |
| 1582 | afs_use_fs_server(call, fc->cbi); |
| 1583 | trace_afs_make_fs_call(call, &vnode->fid); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1584 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1585 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1586 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | /* |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1590 | * YFS.SetLock operation type |
| 1591 | */ |
| 1592 | static const struct afs_call_type yfs_RXYFSSetLock = { |
| 1593 | .name = "YFS.SetLock", |
| 1594 | .op = yfs_FS_SetLock, |
David Howells | f5e4546 | 2019-05-01 14:05:27 +0100 | [diff] [blame] | 1595 | .deliver = yfs_deliver_status_and_volsync, |
David Howells | a690f60 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1596 | .done = afs_lock_op_done, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1597 | .destructor = afs_flat_call_destructor, |
| 1598 | }; |
| 1599 | |
| 1600 | /* |
| 1601 | * YFS.ExtendLock operation type |
| 1602 | */ |
| 1603 | static const struct afs_call_type yfs_RXYFSExtendLock = { |
| 1604 | .name = "YFS.ExtendLock", |
| 1605 | .op = yfs_FS_ExtendLock, |
David Howells | f5e4546 | 2019-05-01 14:05:27 +0100 | [diff] [blame] | 1606 | .deliver = yfs_deliver_status_and_volsync, |
David Howells | a690f60 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1607 | .done = afs_lock_op_done, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1608 | .destructor = afs_flat_call_destructor, |
| 1609 | }; |
| 1610 | |
| 1611 | /* |
| 1612 | * YFS.ReleaseLock operation type |
| 1613 | */ |
| 1614 | static const struct afs_call_type yfs_RXYFSReleaseLock = { |
| 1615 | .name = "YFS.ReleaseLock", |
| 1616 | .op = yfs_FS_ReleaseLock, |
David Howells | f5e4546 | 2019-05-01 14:05:27 +0100 | [diff] [blame] | 1617 | .deliver = yfs_deliver_status_and_volsync, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1618 | .destructor = afs_flat_call_destructor, |
| 1619 | }; |
| 1620 | |
| 1621 | /* |
| 1622 | * Set a lock on a file |
| 1623 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1624 | int yfs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type, |
| 1625 | struct afs_status_cb *scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1626 | { |
| 1627 | struct afs_vnode *vnode = fc->vnode; |
| 1628 | struct afs_call *call; |
| 1629 | struct afs_net *net = afs_v2net(vnode); |
| 1630 | __be32 *bp; |
| 1631 | |
| 1632 | _enter(""); |
| 1633 | |
| 1634 | call = afs_alloc_flat_call(net, &yfs_RXYFSSetLock, |
| 1635 | sizeof(__be32) * 2 + |
| 1636 | sizeof(struct yfs_xdr_YFSFid) + |
| 1637 | sizeof(__be32), |
| 1638 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1639 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 1640 | if (!call) |
| 1641 | return -ENOMEM; |
| 1642 | |
| 1643 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1644 | call->lvnode = vnode; |
| 1645 | call->out_scb = scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1646 | |
| 1647 | /* marshall the parameters */ |
| 1648 | bp = call->request; |
| 1649 | bp = xdr_encode_u32(bp, YFSSETLOCK); |
| 1650 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1651 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 1652 | bp = xdr_encode_u32(bp, type); |
| 1653 | yfs_check_req(call, bp); |
| 1654 | |
| 1655 | afs_use_fs_server(call, fc->cbi); |
David Howells | 6c6c1d6 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 1656 | trace_afs_make_fs_calli(call, &vnode->fid, type); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1657 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1658 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1659 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | /* |
| 1663 | * extend a lock on a file |
| 1664 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1665 | int yfs_fs_extend_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1666 | { |
| 1667 | struct afs_vnode *vnode = fc->vnode; |
| 1668 | struct afs_call *call; |
| 1669 | struct afs_net *net = afs_v2net(vnode); |
| 1670 | __be32 *bp; |
| 1671 | |
| 1672 | _enter(""); |
| 1673 | |
| 1674 | call = afs_alloc_flat_call(net, &yfs_RXYFSExtendLock, |
| 1675 | sizeof(__be32) * 2 + |
| 1676 | sizeof(struct yfs_xdr_YFSFid), |
| 1677 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1678 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 1679 | if (!call) |
| 1680 | return -ENOMEM; |
| 1681 | |
| 1682 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1683 | call->lvnode = vnode; |
| 1684 | call->out_scb = scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1685 | |
| 1686 | /* marshall the parameters */ |
| 1687 | bp = call->request; |
| 1688 | bp = xdr_encode_u32(bp, YFSEXTENDLOCK); |
| 1689 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1690 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 1691 | yfs_check_req(call, bp); |
| 1692 | |
| 1693 | afs_use_fs_server(call, fc->cbi); |
| 1694 | trace_afs_make_fs_call(call, &vnode->fid); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1695 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1696 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1697 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | /* |
| 1701 | * release a lock on a file |
| 1702 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1703 | int yfs_fs_release_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb) |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1704 | { |
| 1705 | struct afs_vnode *vnode = fc->vnode; |
| 1706 | struct afs_call *call; |
| 1707 | struct afs_net *net = afs_v2net(vnode); |
| 1708 | __be32 *bp; |
| 1709 | |
| 1710 | _enter(""); |
| 1711 | |
| 1712 | call = afs_alloc_flat_call(net, &yfs_RXYFSReleaseLock, |
| 1713 | sizeof(__be32) * 2 + |
| 1714 | sizeof(struct yfs_xdr_YFSFid), |
| 1715 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1716 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 1717 | if (!call) |
| 1718 | return -ENOMEM; |
| 1719 | |
| 1720 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1721 | call->lvnode = vnode; |
| 1722 | call->out_scb = scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1723 | |
| 1724 | /* marshall the parameters */ |
| 1725 | bp = call->request; |
| 1726 | bp = xdr_encode_u32(bp, YFSRELEASELOCK); |
| 1727 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1728 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 1729 | yfs_check_req(call, bp); |
| 1730 | |
| 1731 | afs_use_fs_server(call, fc->cbi); |
| 1732 | trace_afs_make_fs_call(call, &vnode->fid); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1733 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1734 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1735 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | /* |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1739 | * YFS.FetchStatus operation type |
| 1740 | */ |
| 1741 | static const struct afs_call_type yfs_RXYFSFetchStatus = { |
| 1742 | .name = "YFS.FetchStatus", |
| 1743 | .op = yfs_FS_FetchStatus, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1744 | .deliver = yfs_deliver_fs_status_cb_and_volsync, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1745 | .destructor = afs_flat_call_destructor, |
| 1746 | }; |
| 1747 | |
| 1748 | /* |
| 1749 | * Fetch the status information for a fid without needing a vnode handle. |
| 1750 | */ |
| 1751 | int yfs_fs_fetch_status(struct afs_fs_cursor *fc, |
| 1752 | struct afs_net *net, |
| 1753 | struct afs_fid *fid, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1754 | struct afs_status_cb *scb, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1755 | struct afs_volsync *volsync) |
| 1756 | { |
| 1757 | struct afs_call *call; |
| 1758 | __be32 *bp; |
| 1759 | |
| 1760 | _enter(",%x,{%llx:%llu},,", |
| 1761 | key_serial(fc->key), fid->vid, fid->vnode); |
| 1762 | |
| 1763 | call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus, |
| 1764 | sizeof(__be32) * 2 + |
| 1765 | sizeof(struct yfs_xdr_YFSFid), |
| 1766 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 1767 | sizeof(struct yfs_xdr_YFSCallBack) + |
| 1768 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 1769 | if (!call) { |
| 1770 | fc->ac.error = -ENOMEM; |
| 1771 | return -ENOMEM; |
| 1772 | } |
| 1773 | |
| 1774 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1775 | call->out_scb = scb; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1776 | call->out_volsync = volsync; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1777 | |
| 1778 | /* marshall the parameters */ |
| 1779 | bp = call->request; |
| 1780 | bp = xdr_encode_u32(bp, YFSFETCHSTATUS); |
| 1781 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1782 | bp = xdr_encode_YFSFid(bp, fid); |
| 1783 | yfs_check_req(call, bp); |
| 1784 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1785 | afs_use_fs_server(call, fc->cbi); |
| 1786 | trace_afs_make_fs_call(call, fid); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1787 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1788 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1789 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | /* |
| 1793 | * Deliver reply data to an YFS.InlineBulkStatus call |
| 1794 | */ |
| 1795 | static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call) |
| 1796 | { |
David Howells | 8718275 | 2019-05-09 16:17:05 +0100 | [diff] [blame] | 1797 | struct afs_status_cb *scb; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1798 | const __be32 *bp; |
| 1799 | u32 tmp; |
| 1800 | int ret; |
| 1801 | |
| 1802 | _enter("{%u}", call->unmarshall); |
| 1803 | |
| 1804 | switch (call->unmarshall) { |
| 1805 | case 0: |
| 1806 | afs_extract_to_tmp(call); |
| 1807 | call->unmarshall++; |
| 1808 | |
| 1809 | /* Extract the file status count and array in two steps */ |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1810 | /* Fall through */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1811 | case 1: |
| 1812 | _debug("extract status count"); |
| 1813 | ret = afs_extract_data(call, true); |
| 1814 | if (ret < 0) |
| 1815 | return ret; |
| 1816 | |
| 1817 | tmp = ntohl(call->tmp); |
| 1818 | _debug("status count: %u/%u", tmp, call->count2); |
| 1819 | if (tmp != call->count2) |
| 1820 | return afs_protocol_error(call, -EBADMSG, |
| 1821 | afs_eproto_ibulkst_count); |
| 1822 | |
| 1823 | call->count = 0; |
| 1824 | call->unmarshall++; |
| 1825 | more_counts: |
| 1826 | afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus)); |
| 1827 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1828 | /* Fall through */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1829 | case 2: |
| 1830 | _debug("extract status array %u", call->count); |
| 1831 | ret = afs_extract_data(call, true); |
| 1832 | if (ret < 0) |
| 1833 | return ret; |
| 1834 | |
| 1835 | bp = call->buffer; |
David Howells | 8718275 | 2019-05-09 16:17:05 +0100 | [diff] [blame] | 1836 | scb = &call->out_scb[call->count]; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1837 | ret = xdr_decode_YFSFetchStatus(&bp, call, scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1838 | if (ret < 0) |
| 1839 | return ret; |
| 1840 | |
| 1841 | call->count++; |
| 1842 | if (call->count < call->count2) |
| 1843 | goto more_counts; |
| 1844 | |
| 1845 | call->count = 0; |
| 1846 | call->unmarshall++; |
| 1847 | afs_extract_to_tmp(call); |
| 1848 | |
| 1849 | /* Extract the callback count and array in two steps */ |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1850 | /* Fall through */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1851 | case 3: |
| 1852 | _debug("extract CB count"); |
| 1853 | ret = afs_extract_data(call, true); |
| 1854 | if (ret < 0) |
| 1855 | return ret; |
| 1856 | |
| 1857 | tmp = ntohl(call->tmp); |
| 1858 | _debug("CB count: %u", tmp); |
| 1859 | if (tmp != call->count2) |
| 1860 | return afs_protocol_error(call, -EBADMSG, |
| 1861 | afs_eproto_ibulkst_cb_count); |
| 1862 | call->count = 0; |
| 1863 | call->unmarshall++; |
| 1864 | more_cbs: |
| 1865 | afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack)); |
| 1866 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1867 | /* Fall through */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1868 | case 4: |
| 1869 | _debug("extract CB array"); |
| 1870 | ret = afs_extract_data(call, true); |
| 1871 | if (ret < 0) |
| 1872 | return ret; |
| 1873 | |
| 1874 | _debug("unmarshall CB array"); |
| 1875 | bp = call->buffer; |
David Howells | 8718275 | 2019-05-09 16:17:05 +0100 | [diff] [blame] | 1876 | scb = &call->out_scb[call->count]; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1877 | xdr_decode_YFSCallBack(&bp, call, scb); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1878 | call->count++; |
| 1879 | if (call->count < call->count2) |
| 1880 | goto more_cbs; |
| 1881 | |
| 1882 | afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync)); |
| 1883 | call->unmarshall++; |
| 1884 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1885 | /* Fall through */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1886 | case 5: |
| 1887 | ret = afs_extract_data(call, false); |
| 1888 | if (ret < 0) |
| 1889 | return ret; |
| 1890 | |
| 1891 | bp = call->buffer; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1892 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1893 | |
| 1894 | call->unmarshall++; |
| 1895 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 1896 | /* Fall through */ |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1897 | case 6: |
| 1898 | break; |
| 1899 | } |
| 1900 | |
| 1901 | _leave(" = 0 [done]"); |
| 1902 | return 0; |
| 1903 | } |
| 1904 | |
| 1905 | /* |
| 1906 | * FS.InlineBulkStatus operation type |
| 1907 | */ |
| 1908 | static const struct afs_call_type yfs_RXYFSInlineBulkStatus = { |
| 1909 | .name = "YFS.InlineBulkStatus", |
| 1910 | .op = yfs_FS_InlineBulkStatus, |
| 1911 | .deliver = yfs_deliver_fs_inline_bulk_status, |
| 1912 | .destructor = afs_flat_call_destructor, |
| 1913 | }; |
| 1914 | |
| 1915 | /* |
| 1916 | * Fetch the status information for up to 1024 files |
| 1917 | */ |
| 1918 | int yfs_fs_inline_bulk_status(struct afs_fs_cursor *fc, |
| 1919 | struct afs_net *net, |
| 1920 | struct afs_fid *fids, |
David Howells | 8718275 | 2019-05-09 16:17:05 +0100 | [diff] [blame] | 1921 | struct afs_status_cb *statuses, |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1922 | unsigned int nr_fids, |
| 1923 | struct afs_volsync *volsync) |
| 1924 | { |
| 1925 | struct afs_call *call; |
| 1926 | __be32 *bp; |
| 1927 | int i; |
| 1928 | |
| 1929 | _enter(",%x,{%llx:%llu},%u", |
| 1930 | key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids); |
| 1931 | |
| 1932 | call = afs_alloc_flat_call(net, &yfs_RXYFSInlineBulkStatus, |
| 1933 | sizeof(__be32) + |
| 1934 | sizeof(__be32) + |
| 1935 | sizeof(__be32) + |
| 1936 | sizeof(struct yfs_xdr_YFSFid) * nr_fids, |
| 1937 | sizeof(struct yfs_xdr_YFSFetchStatus)); |
| 1938 | if (!call) { |
| 1939 | fc->ac.error = -ENOMEM; |
| 1940 | return -ENOMEM; |
| 1941 | } |
| 1942 | |
| 1943 | call->key = fc->key; |
David Howells | 8718275 | 2019-05-09 16:17:05 +0100 | [diff] [blame] | 1944 | call->out_scb = statuses; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1945 | call->out_volsync = volsync; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1946 | call->count2 = nr_fids; |
| 1947 | |
| 1948 | /* marshall the parameters */ |
| 1949 | bp = call->request; |
| 1950 | bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS); |
| 1951 | bp = xdr_encode_u32(bp, 0); /* RPCFlags */ |
| 1952 | bp = xdr_encode_u32(bp, nr_fids); |
| 1953 | for (i = 0; i < nr_fids; i++) |
| 1954 | bp = xdr_encode_YFSFid(bp, &fids[i]); |
| 1955 | yfs_check_req(call, bp); |
| 1956 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1957 | afs_use_fs_server(call, fc->cbi); |
| 1958 | trace_afs_make_fs_call(call, &fids[0]); |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 1959 | afs_set_fc_call(call, fc); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1960 | afs_make_call(&fc->ac, call, GFP_NOFS); |
| 1961 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1962 | } |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 1963 | |
| 1964 | /* |
| 1965 | * Deliver reply data to an YFS.FetchOpaqueACL. |
| 1966 | */ |
| 1967 | static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call) |
| 1968 | { |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1969 | struct yfs_acl *yacl = call->out_yacl; |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 1970 | struct afs_acl *acl; |
| 1971 | const __be32 *bp; |
| 1972 | unsigned int size; |
| 1973 | int ret; |
| 1974 | |
| 1975 | _enter("{%u}", call->unmarshall); |
| 1976 | |
| 1977 | switch (call->unmarshall) { |
| 1978 | case 0: |
| 1979 | afs_extract_to_tmp(call); |
| 1980 | call->unmarshall++; |
| 1981 | |
| 1982 | /* Extract the file ACL length */ |
| 1983 | case 1: |
| 1984 | ret = afs_extract_data(call, true); |
| 1985 | if (ret < 0) |
| 1986 | return ret; |
| 1987 | |
| 1988 | size = call->count2 = ntohl(call->tmp); |
| 1989 | size = round_up(size, 4); |
| 1990 | |
| 1991 | if (yacl->flags & YFS_ACL_WANT_ACL) { |
| 1992 | acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL); |
| 1993 | if (!acl) |
| 1994 | return -ENOMEM; |
| 1995 | yacl->acl = acl; |
| 1996 | acl->size = call->count2; |
| 1997 | afs_extract_begin(call, acl->data, size); |
| 1998 | } else { |
| 1999 | iov_iter_discard(&call->iter, READ, size); |
| 2000 | } |
| 2001 | call->unmarshall++; |
| 2002 | |
| 2003 | /* Extract the file ACL */ |
| 2004 | case 2: |
| 2005 | ret = afs_extract_data(call, true); |
| 2006 | if (ret < 0) |
| 2007 | return ret; |
| 2008 | |
| 2009 | afs_extract_to_tmp(call); |
| 2010 | call->unmarshall++; |
| 2011 | |
| 2012 | /* Extract the volume ACL length */ |
| 2013 | case 3: |
| 2014 | ret = afs_extract_data(call, true); |
| 2015 | if (ret < 0) |
| 2016 | return ret; |
| 2017 | |
| 2018 | size = call->count2 = ntohl(call->tmp); |
| 2019 | size = round_up(size, 4); |
| 2020 | |
| 2021 | if (yacl->flags & YFS_ACL_WANT_VOL_ACL) { |
| 2022 | acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL); |
| 2023 | if (!acl) |
| 2024 | return -ENOMEM; |
| 2025 | yacl->vol_acl = acl; |
| 2026 | acl->size = call->count2; |
| 2027 | afs_extract_begin(call, acl->data, size); |
| 2028 | } else { |
| 2029 | iov_iter_discard(&call->iter, READ, size); |
| 2030 | } |
| 2031 | call->unmarshall++; |
| 2032 | |
| 2033 | /* Extract the volume ACL */ |
| 2034 | case 4: |
| 2035 | ret = afs_extract_data(call, true); |
| 2036 | if (ret < 0) |
| 2037 | return ret; |
| 2038 | |
| 2039 | afs_extract_to_buf(call, |
| 2040 | sizeof(__be32) * 2 + |
| 2041 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 2042 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 2043 | call->unmarshall++; |
| 2044 | |
| 2045 | /* extract the metadata */ |
| 2046 | case 5: |
| 2047 | ret = afs_extract_data(call, false); |
| 2048 | if (ret < 0) |
| 2049 | return ret; |
| 2050 | |
| 2051 | bp = call->buffer; |
| 2052 | yacl->inherit_flag = ntohl(*bp++); |
| 2053 | yacl->num_cleaned = ntohl(*bp++); |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 2054 | ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb); |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2055 | if (ret < 0) |
| 2056 | return ret; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 2057 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2058 | |
| 2059 | call->unmarshall++; |
| 2060 | |
| 2061 | case 6: |
| 2062 | break; |
| 2063 | } |
| 2064 | |
| 2065 | _leave(" = 0 [done]"); |
| 2066 | return 0; |
| 2067 | } |
| 2068 | |
| 2069 | void yfs_free_opaque_acl(struct yfs_acl *yacl) |
| 2070 | { |
| 2071 | if (yacl) { |
| 2072 | kfree(yacl->acl); |
| 2073 | kfree(yacl->vol_acl); |
| 2074 | kfree(yacl); |
| 2075 | } |
| 2076 | } |
| 2077 | |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2078 | /* |
| 2079 | * YFS.FetchOpaqueACL operation type |
| 2080 | */ |
| 2081 | static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = { |
| 2082 | .name = "YFS.FetchOpaqueACL", |
| 2083 | .op = yfs_FS_FetchOpaqueACL, |
| 2084 | .deliver = yfs_deliver_fs_fetch_opaque_acl, |
David Howells | 773e0c4 | 2019-05-12 08:31:23 +0100 | [diff] [blame] | 2085 | .destructor = afs_flat_call_destructor, |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2086 | }; |
| 2087 | |
| 2088 | /* |
| 2089 | * Fetch the YFS advanced ACLs for a file. |
| 2090 | */ |
| 2091 | struct yfs_acl *yfs_fs_fetch_opaque_acl(struct afs_fs_cursor *fc, |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 2092 | struct yfs_acl *yacl, |
| 2093 | struct afs_status_cb *scb) |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2094 | { |
| 2095 | struct afs_vnode *vnode = fc->vnode; |
| 2096 | struct afs_call *call; |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2097 | struct afs_net *net = afs_v2net(vnode); |
| 2098 | __be32 *bp; |
| 2099 | |
| 2100 | _enter(",%x,{%llx:%llu},,", |
| 2101 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); |
| 2102 | |
| 2103 | call = afs_alloc_flat_call(net, &yfs_RXYFSFetchOpaqueACL, |
| 2104 | sizeof(__be32) * 2 + |
| 2105 | sizeof(struct yfs_xdr_YFSFid), |
| 2106 | sizeof(__be32) * 2 + |
| 2107 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 2108 | sizeof(struct yfs_xdr_YFSVolSync)); |
David Howells | 773e0c4 | 2019-05-12 08:31:23 +0100 | [diff] [blame] | 2109 | if (!call) { |
| 2110 | fc->ac.error = -ENOMEM; |
| 2111 | return ERR_PTR(-ENOMEM); |
| 2112 | } |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2113 | |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2114 | call->key = fc->key; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 2115 | call->out_yacl = yacl; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 2116 | call->out_scb = scb; |
| 2117 | call->out_volsync = NULL; |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2118 | |
| 2119 | /* marshall the parameters */ |
| 2120 | bp = call->request; |
| 2121 | bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL); |
| 2122 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 2123 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 2124 | yfs_check_req(call, bp); |
| 2125 | |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2126 | afs_use_fs_server(call, fc->cbi); |
| 2127 | trace_afs_make_fs_call(call, &vnode->fid); |
| 2128 | afs_make_call(&fc->ac, call, GFP_KERNEL); |
| 2129 | return (struct yfs_acl *)afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | ae46578 | 2019-04-30 18:30:21 +0100 | [diff] [blame] | 2130 | } |
David Howells | f5e4546 | 2019-05-01 14:05:27 +0100 | [diff] [blame] | 2131 | |
| 2132 | /* |
| 2133 | * YFS.StoreOpaqueACL2 operation type |
| 2134 | */ |
| 2135 | static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = { |
| 2136 | .name = "YFS.StoreOpaqueACL2", |
| 2137 | .op = yfs_FS_StoreOpaqueACL2, |
| 2138 | .deliver = yfs_deliver_status_and_volsync, |
| 2139 | .destructor = afs_flat_call_destructor, |
| 2140 | }; |
| 2141 | |
| 2142 | /* |
| 2143 | * Fetch the YFS ACL for a file. |
| 2144 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 2145 | int yfs_fs_store_opaque_acl2(struct afs_fs_cursor *fc, const struct afs_acl *acl, |
| 2146 | struct afs_status_cb *scb) |
David Howells | f5e4546 | 2019-05-01 14:05:27 +0100 | [diff] [blame] | 2147 | { |
| 2148 | struct afs_vnode *vnode = fc->vnode; |
| 2149 | struct afs_call *call; |
| 2150 | struct afs_net *net = afs_v2net(vnode); |
| 2151 | size_t size; |
| 2152 | __be32 *bp; |
| 2153 | |
| 2154 | _enter(",%x,{%llx:%llu},,", |
| 2155 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); |
| 2156 | |
| 2157 | size = round_up(acl->size, 4); |
| 2158 | call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus, |
| 2159 | sizeof(__be32) * 2 + |
| 2160 | sizeof(struct yfs_xdr_YFSFid) + |
| 2161 | sizeof(__be32) + size, |
| 2162 | sizeof(struct yfs_xdr_YFSFetchStatus) + |
| 2163 | sizeof(struct yfs_xdr_YFSVolSync)); |
| 2164 | if (!call) { |
| 2165 | fc->ac.error = -ENOMEM; |
| 2166 | return -ENOMEM; |
| 2167 | } |
| 2168 | |
| 2169 | call->key = fc->key; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 2170 | call->out_scb = scb; |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 2171 | call->out_volsync = NULL; |
David Howells | f5e4546 | 2019-05-01 14:05:27 +0100 | [diff] [blame] | 2172 | |
| 2173 | /* marshall the parameters */ |
| 2174 | bp = call->request; |
| 2175 | bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2); |
| 2176 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 2177 | bp = xdr_encode_YFSFid(bp, &vnode->fid); |
| 2178 | bp = xdr_encode_u32(bp, acl->size); |
| 2179 | memcpy(bp, acl->data, acl->size); |
| 2180 | if (acl->size != size) |
| 2181 | memset((void *)bp + acl->size, 0, size - acl->size); |
| 2182 | yfs_check_req(call, bp); |
| 2183 | |
| 2184 | trace_afs_make_fs_call(call, &vnode->fid); |
| 2185 | afs_make_call(&fc->ac, call, GFP_KERNEL); |
| 2186 | return afs_wait_for_call_to_complete(call, &fc->ac); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 2187 | } |