Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 2 | /* AFS File Server client stubs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 4 | * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Written by David Howells (dhowells@redhat.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/sched.h> |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 11 | #include <linux/circ_buf.h> |
Jeff Layton | a01179e | 2017-12-11 06:35:11 -0500 | [diff] [blame] | 12 | #include <linux/iversion.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "internal.h" |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 14 | #include "afs_fs.h" |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 15 | #include "xdr_fs.h" |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 16 | |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 17 | /* |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 18 | * decode an AFSFid block |
| 19 | */ |
| 20 | static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid) |
| 21 | { |
| 22 | const __be32 *bp = *_bp; |
| 23 | |
| 24 | fid->vid = ntohl(*bp++); |
| 25 | fid->vnode = ntohl(*bp++); |
| 26 | fid->unique = ntohl(*bp++); |
| 27 | *_bp = bp; |
| 28 | } |
| 29 | |
| 30 | /* |
David Howells | 888b338 | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 31 | * Dump a bad file status record. |
| 32 | */ |
| 33 | static void xdr_dump_bad(const __be32 *bp) |
| 34 | { |
| 35 | __be32 x[4]; |
| 36 | int i; |
| 37 | |
| 38 | pr_notice("AFS XDR: Bad status record\n"); |
| 39 | for (i = 0; i < 5 * 4 * 4; i += 16) { |
| 40 | memcpy(x, bp, 16); |
| 41 | bp += 4; |
| 42 | pr_notice("%03x: %08x %08x %08x %08x\n", |
| 43 | i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3])); |
| 44 | } |
| 45 | |
| 46 | memcpy(x, bp, 4); |
| 47 | pr_notice("0x50: %08x\n", ntohl(x[0])); |
| 48 | } |
| 49 | |
| 50 | /* |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 51 | * decode an AFSFetchStatus block |
| 52 | */ |
David Howells | 38355ee | 2020-04-08 16:13:20 +0100 | [diff] [blame] | 53 | static void xdr_decode_AFSFetchStatus(const __be32 **_bp, |
| 54 | struct afs_call *call, |
| 55 | struct afs_status_cb *scb) |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 56 | { |
| 57 | const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 58 | struct afs_file_status *status = &scb->status; |
David Howells | 684b0f6 | 2018-05-10 21:51:47 +0100 | [diff] [blame] | 59 | bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus); |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 60 | u64 data_version, size; |
| 61 | u32 type, abort_code; |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 62 | |
David Howells | 684b0f6 | 2018-05-10 21:51:47 +0100 | [diff] [blame] | 63 | abort_code = ntohl(xdr->abort_code); |
| 64 | |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 65 | if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) { |
David Howells | 684b0f6 | 2018-05-10 21:51:47 +0100 | [diff] [blame] | 66 | if (xdr->if_version == htonl(0) && |
| 67 | abort_code != 0 && |
| 68 | inline_error) { |
| 69 | /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus |
| 70 | * whereby it doesn't set the interface version in the error |
| 71 | * case. |
| 72 | */ |
| 73 | status->abort_code = abort_code; |
David Howells | a38a755 | 2019-05-14 12:29:11 +0100 | [diff] [blame] | 74 | scb->have_error = true; |
David Howells | 38355ee | 2020-04-08 16:13:20 +0100 | [diff] [blame] | 75 | goto advance; |
David Howells | 684b0f6 | 2018-05-10 21:51:47 +0100 | [diff] [blame] | 76 | } |
| 77 | |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 78 | pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version)); |
| 79 | goto bad; |
| 80 | } |
| 81 | |
David Howells | 684b0f6 | 2018-05-10 21:51:47 +0100 | [diff] [blame] | 82 | if (abort_code != 0 && inline_error) { |
| 83 | status->abort_code = abort_code; |
David Howells | 3e0d989 | 2020-04-08 17:32:10 +0100 | [diff] [blame] | 84 | scb->have_error = true; |
David Howells | 38355ee | 2020-04-08 16:13:20 +0100 | [diff] [blame] | 85 | goto advance; |
David Howells | 684b0f6 | 2018-05-10 21:51:47 +0100 | [diff] [blame] | 86 | } |
| 87 | |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 88 | type = ntohl(xdr->type); |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 89 | switch (type) { |
| 90 | case AFS_FTYPE_FILE: |
| 91 | case AFS_FTYPE_DIR: |
| 92 | case AFS_FTYPE_SYMLINK: |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 93 | status->type = type; |
| 94 | break; |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 95 | default: |
| 96 | goto bad; |
| 97 | } |
| 98 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 99 | status->nlink = ntohl(xdr->nlink); |
| 100 | status->author = ntohl(xdr->author); |
| 101 | status->owner = ntohl(xdr->owner); |
| 102 | status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */ |
| 103 | status->anon_access = ntohl(xdr->anon_access); |
| 104 | status->mode = ntohl(xdr->mode) & S_IALLUGO; |
| 105 | status->group = ntohl(xdr->group); |
| 106 | status->lock_count = ntohl(xdr->lock_count); |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 107 | |
David Howells | d493680 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 108 | status->mtime_client.tv_sec = ntohl(xdr->mtime_client); |
| 109 | status->mtime_client.tv_nsec = 0; |
| 110 | status->mtime_server.tv_sec = ntohl(xdr->mtime_server); |
| 111 | status->mtime_server.tv_nsec = 0; |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 112 | |
| 113 | size = (u64)ntohl(xdr->size_lo); |
| 114 | size |= (u64)ntohl(xdr->size_hi) << 32; |
David Howells | 63a4681 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 115 | status->size = size; |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 116 | |
| 117 | data_version = (u64)ntohl(xdr->data_version_lo); |
| 118 | data_version |= (u64)ntohl(xdr->data_version_hi) << 32; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 119 | status->data_version = data_version; |
David Howells | a38a755 | 2019-05-14 12:29:11 +0100 | [diff] [blame] | 120 | scb->have_status = true; |
David Howells | c72057b | 2020-04-08 16:13:20 +0100 | [diff] [blame] | 121 | advance: |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 122 | *_bp = (const void *)*_bp + sizeof(*xdr); |
David Howells | 38355ee | 2020-04-08 16:13:20 +0100 | [diff] [blame] | 123 | return; |
David Howells | dd9fbcb | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 124 | |
| 125 | bad: |
| 126 | xdr_dump_bad(*_bp); |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 127 | afs_protocol_error(call, afs_eproto_bad_status); |
David Howells | c72057b | 2020-04-08 16:13:20 +0100 | [diff] [blame] | 128 | goto advance; |
David Howells | c875c76 | 2018-05-23 11:32:06 +0100 | [diff] [blame] | 129 | } |
| 130 | |
David Howells | 7810705 | 2019-05-09 17:56:53 +0100 | [diff] [blame] | 131 | static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry) |
| 132 | { |
| 133 | return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry; |
| 134 | } |
| 135 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 136 | static void xdr_decode_AFSCallBack(const __be32 **_bp, |
| 137 | struct afs_call *call, |
| 138 | struct afs_status_cb *scb) |
David Howells | 7810705 | 2019-05-09 17:56:53 +0100 | [diff] [blame] | 139 | { |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 140 | struct afs_callback *cb = &scb->callback; |
David Howells | 7810705 | 2019-05-09 17:56:53 +0100 | [diff] [blame] | 141 | const __be32 *bp = *_bp; |
| 142 | |
David Howells | 7c71245 | 2019-05-14 15:35:44 +0100 | [diff] [blame] | 143 | bp++; /* version */ |
David Howells | 7810705 | 2019-05-09 17:56:53 +0100 | [diff] [blame] | 144 | cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++)); |
David Howells | 7c71245 | 2019-05-14 15:35:44 +0100 | [diff] [blame] | 145 | bp++; /* type */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 146 | scb->have_cb = true; |
David Howells | 7810705 | 2019-05-09 17:56:53 +0100 | [diff] [blame] | 147 | *_bp = bp; |
| 148 | } |
| 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 151 | * decode an AFSVolSync block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 153 | static void xdr_decode_AFSVolSync(const __be32 **_bp, |
| 154 | struct afs_volsync *volsync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 156 | const __be32 *bp = *_bp; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 157 | u32 creation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 159 | creation = ntohl(*bp++); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 160 | bp++; /* spare2 */ |
| 161 | bp++; /* spare3 */ |
| 162 | bp++; /* spare4 */ |
| 163 | bp++; /* spare5 */ |
| 164 | bp++; /* spare6 */ |
| 165 | *_bp = bp; |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 166 | |
| 167 | if (volsync) |
| 168 | volsync->creation = creation; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 169 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 170 | |
| 171 | /* |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 172 | * encode the requested attributes into an AFSStoreStatus block |
| 173 | */ |
| 174 | static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr) |
| 175 | { |
| 176 | __be32 *bp = *_bp; |
| 177 | u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0; |
| 178 | |
| 179 | mask = 0; |
| 180 | if (attr->ia_valid & ATTR_MTIME) { |
| 181 | mask |= AFS_SET_MTIME; |
| 182 | mtime = attr->ia_mtime.tv_sec; |
| 183 | } |
| 184 | |
| 185 | if (attr->ia_valid & ATTR_UID) { |
| 186 | mask |= AFS_SET_OWNER; |
Eric W. Biederman | a0a5386 | 2012-02-07 16:20:48 -0800 | [diff] [blame] | 187 | owner = from_kuid(&init_user_ns, attr->ia_uid); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | if (attr->ia_valid & ATTR_GID) { |
| 191 | mask |= AFS_SET_GROUP; |
Eric W. Biederman | a0a5386 | 2012-02-07 16:20:48 -0800 | [diff] [blame] | 192 | group = from_kgid(&init_user_ns, attr->ia_gid); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | if (attr->ia_valid & ATTR_MODE) { |
| 196 | mask |= AFS_SET_MODE; |
| 197 | mode = attr->ia_mode & S_IALLUGO; |
| 198 | } |
| 199 | |
| 200 | *bp++ = htonl(mask); |
| 201 | *bp++ = htonl(mtime); |
| 202 | *bp++ = htonl(owner); |
| 203 | *bp++ = htonl(group); |
| 204 | *bp++ = htonl(mode); |
| 205 | *bp++ = 0; /* segment size */ |
| 206 | *_bp = bp; |
| 207 | } |
| 208 | |
| 209 | /* |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 210 | * decode an AFSFetchVolumeStatus block |
| 211 | */ |
| 212 | static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp, |
| 213 | struct afs_volume_status *vs) |
| 214 | { |
| 215 | const __be32 *bp = *_bp; |
| 216 | |
| 217 | vs->vid = ntohl(*bp++); |
| 218 | vs->parent_id = ntohl(*bp++); |
| 219 | vs->online = ntohl(*bp++); |
| 220 | vs->in_service = ntohl(*bp++); |
| 221 | vs->blessed = ntohl(*bp++); |
| 222 | vs->needs_salvage = ntohl(*bp++); |
| 223 | vs->type = ntohl(*bp++); |
| 224 | vs->min_quota = ntohl(*bp++); |
| 225 | vs->max_quota = ntohl(*bp++); |
| 226 | vs->blocks_in_use = ntohl(*bp++); |
| 227 | vs->part_blocks_avail = ntohl(*bp++); |
| 228 | vs->part_max_blocks = ntohl(*bp++); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 229 | vs->vol_copy_date = 0; |
| 230 | vs->vol_backup_date = 0; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 231 | *_bp = bp; |
| 232 | } |
| 233 | |
| 234 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 235 | * deliver reply data to an FS.FetchStatus |
| 236 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 237 | static int afs_deliver_fs_fetch_status(struct afs_call *call) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 238 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 239 | struct afs_operation *op = call->op; |
| 240 | struct afs_vnode_param *vp = &op->file[op->fetch_status.which]; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 241 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 242 | int ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 243 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 244 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 245 | if (ret < 0) |
| 246 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 247 | |
| 248 | /* unmarshall the reply once we've received all of it */ |
| 249 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 250 | xdr_decode_AFSFetchStatus(&bp, call, &vp->scb); |
| 251 | xdr_decode_AFSCallBack(&bp, call, &vp->scb); |
| 252 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 253 | |
| 254 | _leave(" = 0 [done]"); |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * FS.FetchStatus operation type |
| 260 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 261 | static const struct afs_call_type afs_RXFSFetchStatus = { |
| 262 | .name = "FS.FetchStatus", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 263 | .op = afs_FS_FetchStatus, |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 264 | .deliver = afs_deliver_fs_fetch_status, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 265 | .destructor = afs_flat_call_destructor, |
| 266 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | /* |
| 269 | * fetch the status information for a file |
| 270 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 271 | void afs_fs_fetch_status(struct afs_operation *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 273 | struct afs_vnode_param *vp = &op->file[op->fetch_status.which]; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 274 | struct afs_call *call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | __be32 *bp; |
| 276 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 277 | _enter(",%x,{%llx:%llu},,", |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 278 | key_serial(op->key), vp->fid.vid, vp->fid.vnode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 280 | call = afs_alloc_flat_call(op->net, &afs_RXFSFetchStatus, |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 281 | 16, (21 + 3 + 6) * 4); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 282 | if (!call) |
| 283 | return afs_op_nomem(op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | /* marshall the parameters */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 286 | bp = call->request; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | bp[0] = htonl(FSFETCHSTATUS); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 288 | bp[1] = htonl(vp->fid.vid); |
| 289 | bp[2] = htonl(vp->fid.vnode); |
| 290 | bp[3] = htonl(vp->fid.unique); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 292 | trace_afs_make_fs_call(call, &vp->fid); |
| 293 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 297 | * deliver reply data to an FS.FetchData |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 299 | static int afs_deliver_fs_fetch_data(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 301 | struct afs_operation *op = call->op; |
| 302 | struct afs_vnode_param *vp = &op->file[0]; |
| 303 | struct afs_read *req = op->fetch.req; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 304 | const __be32 *bp; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 305 | unsigned int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | int ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 307 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 308 | _enter("{%u,%zu/%llu}", |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 309 | call->unmarshall, iov_iter_count(call->iter), req->actual_len); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 310 | |
| 311 | switch (call->unmarshall) { |
| 312 | case 0: |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 313 | req->actual_len = 0; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 314 | req->index = 0; |
| 315 | req->offset = req->pos & (PAGE_SIZE - 1); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 316 | call->unmarshall++; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 317 | if (call->operation_ID == FSFETCHDATA64) { |
| 318 | afs_extract_to_tmp64(call); |
| 319 | } else { |
| 320 | call->tmp_u = htonl(0); |
| 321 | afs_extract_to_tmp(call); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 322 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 323 | fallthrough; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 324 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 325 | /* extract the returned data length */ |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 326 | case 1: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 327 | _debug("extract data length"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 328 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 329 | if (ret < 0) |
| 330 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 331 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 332 | req->actual_len = be64_to_cpu(call->tmp64); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 333 | _debug("DATA length: %llu", req->actual_len); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 334 | req->remain = min(req->len, req->actual_len); |
| 335 | if (req->remain == 0) |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 336 | goto no_more_data; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 337 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 338 | call->unmarshall++; |
| 339 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 340 | begin_page: |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 341 | ASSERTCMP(req->index, <, req->nr_pages); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 342 | if (req->remain > PAGE_SIZE - req->offset) |
| 343 | size = PAGE_SIZE - req->offset; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 344 | else |
| 345 | size = req->remain; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 346 | call->bvec[0].bv_len = size; |
| 347 | call->bvec[0].bv_offset = req->offset; |
| 348 | call->bvec[0].bv_page = req->pages[req->index]; |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 349 | iov_iter_bvec(&call->def_iter, READ, call->bvec, 1, size); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 350 | ASSERTCMP(size, <=, PAGE_SIZE); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 351 | fallthrough; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 352 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 353 | /* extract the returned data */ |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 354 | case 2: |
| 355 | _debug("extract data %zu/%llu", |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 356 | iov_iter_count(call->iter), req->remain); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 357 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 358 | ret = afs_extract_data(call, true); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 359 | if (ret < 0) |
| 360 | return ret; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 361 | req->remain -= call->bvec[0].bv_len; |
| 362 | req->offset += call->bvec[0].bv_len; |
| 363 | ASSERTCMP(req->offset, <=, PAGE_SIZE); |
| 364 | if (req->offset == PAGE_SIZE) { |
| 365 | req->offset = 0; |
David Howells | 29f0698 | 2017-03-16 16:27:46 +0000 | [diff] [blame] | 366 | req->index++; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 367 | if (req->remain > 0) |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 368 | goto begin_page; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 369 | } |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 370 | |
| 371 | ASSERTCMP(req->remain, ==, 0); |
| 372 | if (req->actual_len <= req->len) |
| 373 | goto no_more_data; |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 374 | |
| 375 | /* Discard any excess data the server gave us */ |
David Howells | 23a2891 | 2019-08-20 09:22:38 +0100 | [diff] [blame] | 376 | afs_extract_discard(call, req->actual_len - req->len); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 377 | call->unmarshall = 3; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 378 | fallthrough; |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 379 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 380 | case 3: |
| 381 | _debug("extract discard %zu/%llu", |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 382 | iov_iter_count(call->iter), req->actual_len - req->len); |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 383 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 384 | ret = afs_extract_data(call, true); |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 385 | if (ret < 0) |
| 386 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 387 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 388 | no_more_data: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 389 | call->unmarshall = 4; |
| 390 | afs_extract_to_buf(call, (21 + 3 + 6) * 4); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 391 | fallthrough; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 392 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 393 | /* extract the metadata */ |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 394 | case 4: |
| 395 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 396 | if (ret < 0) |
| 397 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 398 | |
| 399 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 400 | xdr_decode_AFSFetchStatus(&bp, call, &vp->scb); |
| 401 | xdr_decode_AFSCallBack(&bp, call, &vp->scb); |
| 402 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 403 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 404 | req->data_version = vp->scb.status.data_version; |
| 405 | req->file_size = vp->scb.status.size; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 406 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 407 | call->unmarshall++; |
| 408 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 409 | case 5: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 410 | break; |
| 411 | } |
| 412 | |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 413 | for (; req->index < req->nr_pages; req->index++) { |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 414 | if (req->offset < PAGE_SIZE) |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 415 | zero_user_segment(req->pages[req->index], |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 416 | req->offset, PAGE_SIZE); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 417 | req->offset = 0; |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 418 | } |
| 419 | |
David Howells | 9d1be4f | 2020-05-17 21:21:05 +0100 | [diff] [blame] | 420 | if (req->page_done) |
| 421 | for (req->index = 0; req->index < req->nr_pages; req->index++) |
| 422 | req->page_done(req); |
| 423 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 424 | _leave(" = 0 [done]"); |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | * FS.FetchData operation type |
| 430 | */ |
| 431 | static const struct afs_call_type afs_RXFSFetchData = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 432 | .name = "FS.FetchData", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 433 | .op = afs_FS_FetchData, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 434 | .deliver = afs_deliver_fs_fetch_data, |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 435 | .destructor = afs_flat_call_destructor, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 436 | }; |
| 437 | |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 438 | static const struct afs_call_type afs_RXFSFetchData64 = { |
| 439 | .name = "FS.FetchData64", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 440 | .op = afs_FS_FetchData64, |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 441 | .deliver = afs_deliver_fs_fetch_data, |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 442 | .destructor = afs_flat_call_destructor, |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 443 | }; |
| 444 | |
| 445 | /* |
| 446 | * fetch data from a very large file |
| 447 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 448 | static void afs_fs_fetch_data64(struct afs_operation *op) |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 449 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 450 | struct afs_vnode_param *vp = &op->file[0]; |
| 451 | struct afs_read *req = op->fetch.req; |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 452 | struct afs_call *call; |
| 453 | __be32 *bp; |
| 454 | |
| 455 | _enter(""); |
| 456 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 457 | call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 458 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 459 | return afs_op_nomem(op); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 460 | |
| 461 | /* marshall the parameters */ |
| 462 | bp = call->request; |
| 463 | bp[0] = htonl(FSFETCHDATA64); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 464 | bp[1] = htonl(vp->fid.vid); |
| 465 | bp[2] = htonl(vp->fid.vnode); |
| 466 | bp[3] = htonl(vp->fid.unique); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 467 | bp[4] = htonl(upper_32_bits(req->pos)); |
| 468 | bp[5] = htonl(lower_32_bits(req->pos)); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 469 | bp[6] = 0; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 470 | bp[7] = htonl(lower_32_bits(req->len)); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 471 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 472 | trace_afs_make_fs_call(call, &vp->fid); |
| 473 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 474 | } |
| 475 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 476 | /* |
| 477 | * fetch data from a file |
| 478 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 479 | void afs_fs_fetch_data(struct afs_operation *op) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 480 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 481 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 482 | struct afs_call *call; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 483 | struct afs_read *req = op->fetch.req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | __be32 *bp; |
| 485 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 486 | if (upper_32_bits(req->pos) || |
| 487 | upper_32_bits(req->len) || |
| 488 | upper_32_bits(req->pos + req->len)) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 489 | return afs_fs_fetch_data64(op); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 490 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 491 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 493 | call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 494 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 495 | return afs_op_nomem(op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | /* marshall the parameters */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 498 | bp = call->request; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | bp[0] = htonl(FSFETCHDATA); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 500 | bp[1] = htonl(vp->fid.vid); |
| 501 | bp[2] = htonl(vp->fid.vnode); |
| 502 | bp[3] = htonl(vp->fid.unique); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 503 | bp[4] = htonl(lower_32_bits(req->pos)); |
| 504 | bp[5] = htonl(lower_32_bits(req->len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 506 | trace_afs_make_fs_call(call, &vp->fid); |
| 507 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 508 | } |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 509 | |
| 510 | /* |
| 511 | * deliver reply data to an FS.CreateFile or an FS.MakeDir |
| 512 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 513 | static int afs_deliver_fs_create_vnode(struct afs_call *call) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 514 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 515 | struct afs_operation *op = call->op; |
| 516 | struct afs_vnode_param *dvp = &op->file[0]; |
| 517 | struct afs_vnode_param *vp = &op->file[1]; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 518 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 519 | int ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 520 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 521 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 522 | if (ret < 0) |
| 523 | return ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 524 | |
| 525 | /* unmarshall the reply once we've received all of it */ |
| 526 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 527 | xdr_decode_AFSFid(&bp, &op->file[1].fid); |
| 528 | xdr_decode_AFSFetchStatus(&bp, call, &vp->scb); |
| 529 | xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb); |
| 530 | xdr_decode_AFSCallBack(&bp, call, &vp->scb); |
| 531 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 532 | |
| 533 | _leave(" = 0 [done]"); |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | * FS.CreateFile and FS.MakeDir operation type |
| 539 | */ |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 540 | static const struct afs_call_type afs_RXFSCreateFile = { |
| 541 | .name = "FS.CreateFile", |
| 542 | .op = afs_FS_CreateFile, |
| 543 | .deliver = afs_deliver_fs_create_vnode, |
| 544 | .destructor = afs_flat_call_destructor, |
| 545 | }; |
| 546 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 547 | /* |
| 548 | * Create a file. |
| 549 | */ |
| 550 | void afs_fs_create_file(struct afs_operation *op) |
| 551 | { |
| 552 | const struct qstr *name = &op->dentry->d_name; |
| 553 | struct afs_vnode_param *dvp = &op->file[0]; |
| 554 | struct afs_call *call; |
| 555 | size_t namesz, reqsz, padsz; |
| 556 | __be32 *bp; |
| 557 | |
| 558 | _enter(""); |
| 559 | |
| 560 | namesz = name->len; |
| 561 | padsz = (4 - (namesz & 3)) & 3; |
| 562 | reqsz = (5 * 4) + namesz + padsz + (6 * 4); |
| 563 | |
| 564 | call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, |
| 565 | reqsz, (3 + 21 + 21 + 3 + 6) * 4); |
| 566 | if (!call) |
| 567 | return afs_op_nomem(op); |
| 568 | |
| 569 | /* marshall the parameters */ |
| 570 | bp = call->request; |
| 571 | *bp++ = htonl(FSCREATEFILE); |
| 572 | *bp++ = htonl(dvp->fid.vid); |
| 573 | *bp++ = htonl(dvp->fid.vnode); |
| 574 | *bp++ = htonl(dvp->fid.unique); |
| 575 | *bp++ = htonl(namesz); |
| 576 | memcpy(bp, name->name, namesz); |
| 577 | bp = (void *) bp + namesz; |
| 578 | if (padsz > 0) { |
| 579 | memset(bp, 0, padsz); |
| 580 | bp = (void *) bp + padsz; |
| 581 | } |
| 582 | *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME); |
| 583 | *bp++ = htonl(op->mtime.tv_sec); /* mtime */ |
| 584 | *bp++ = 0; /* owner */ |
| 585 | *bp++ = 0; /* group */ |
| 586 | *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */ |
| 587 | *bp++ = 0; /* segment size */ |
| 588 | |
| 589 | trace_afs_make_fs_call1(call, &dvp->fid, name); |
| 590 | afs_make_op_call(op, call, GFP_NOFS); |
| 591 | } |
| 592 | |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 593 | static const struct afs_call_type afs_RXFSMakeDir = { |
| 594 | .name = "FS.MakeDir", |
| 595 | .op = afs_FS_MakeDir, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 596 | .deliver = afs_deliver_fs_create_vnode, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 597 | .destructor = afs_flat_call_destructor, |
| 598 | }; |
| 599 | |
| 600 | /* |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 601 | * Create a new directory |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 602 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 603 | void afs_fs_make_dir(struct afs_operation *op) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 604 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 605 | const struct qstr *name = &op->dentry->d_name; |
| 606 | struct afs_vnode_param *dvp = &op->file[0]; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 607 | struct afs_call *call; |
| 608 | size_t namesz, reqsz, padsz; |
| 609 | __be32 *bp; |
| 610 | |
| 611 | _enter(""); |
| 612 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 613 | namesz = name->len; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 614 | padsz = (4 - (namesz & 3)) & 3; |
| 615 | reqsz = (5 * 4) + namesz + padsz + (6 * 4); |
| 616 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 617 | call = afs_alloc_flat_call(op->net, &afs_RXFSMakeDir, |
| 618 | reqsz, (3 + 21 + 21 + 3 + 6) * 4); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 619 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 620 | return afs_op_nomem(op); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 621 | |
| 622 | /* marshall the parameters */ |
| 623 | bp = call->request; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 624 | *bp++ = htonl(FSMAKEDIR); |
| 625 | *bp++ = htonl(dvp->fid.vid); |
| 626 | *bp++ = htonl(dvp->fid.vnode); |
| 627 | *bp++ = htonl(dvp->fid.unique); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 628 | *bp++ = htonl(namesz); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 629 | memcpy(bp, name->name, namesz); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 630 | bp = (void *) bp + namesz; |
| 631 | if (padsz > 0) { |
| 632 | memset(bp, 0, padsz); |
| 633 | bp = (void *) bp + padsz; |
| 634 | } |
Marc Dionne | ab94f5d | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 635 | *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 636 | *bp++ = htonl(op->mtime.tv_sec); /* mtime */ |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 637 | *bp++ = 0; /* owner */ |
| 638 | *bp++ = 0; /* group */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 639 | *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */ |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 640 | *bp++ = 0; /* segment size */ |
| 641 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 642 | trace_afs_make_fs_call1(call, &dvp->fid, name); |
| 643 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | /* |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 647 | * Deliver reply data to any operation that returns status and volume sync. |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 648 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 649 | static int afs_deliver_fs_file_status_and_vol(struct afs_call *call) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 650 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 651 | struct afs_operation *op = call->op; |
| 652 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 653 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 654 | int ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 655 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 656 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 657 | if (ret < 0) |
| 658 | return ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 659 | |
| 660 | /* unmarshall the reply once we've received all of it */ |
| 661 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 662 | xdr_decode_AFSFetchStatus(&bp, call, &vp->scb); |
| 663 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 664 | |
| 665 | _leave(" = 0 [done]"); |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | /* |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 670 | * FS.RemoveFile operation type |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 671 | */ |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 672 | static const struct afs_call_type afs_RXFSRemoveFile = { |
| 673 | .name = "FS.RemoveFile", |
| 674 | .op = afs_FS_RemoveFile, |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 675 | .deliver = afs_deliver_fs_file_status_and_vol, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 676 | .destructor = afs_flat_call_destructor, |
| 677 | }; |
| 678 | |
| 679 | /* |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 680 | * Remove a file. |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 681 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 682 | void afs_fs_remove_file(struct afs_operation *op) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 683 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 684 | const struct qstr *name = &op->dentry->d_name; |
| 685 | struct afs_vnode_param *dvp = &op->file[0]; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 686 | struct afs_call *call; |
| 687 | size_t namesz, reqsz, padsz; |
| 688 | __be32 *bp; |
| 689 | |
| 690 | _enter(""); |
| 691 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 692 | namesz = name->len; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 693 | padsz = (4 - (namesz & 3)) & 3; |
| 694 | reqsz = (5 * 4) + namesz + padsz; |
| 695 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 696 | call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveFile, |
| 697 | reqsz, (21 + 6) * 4); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 698 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 699 | return afs_op_nomem(op); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 700 | |
| 701 | /* marshall the parameters */ |
| 702 | bp = call->request; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 703 | *bp++ = htonl(FSREMOVEFILE); |
| 704 | *bp++ = htonl(dvp->fid.vid); |
| 705 | *bp++ = htonl(dvp->fid.vnode); |
| 706 | *bp++ = htonl(dvp->fid.unique); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 707 | *bp++ = htonl(namesz); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 708 | memcpy(bp, name->name, namesz); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 709 | bp = (void *) bp + namesz; |
| 710 | if (padsz > 0) { |
| 711 | memset(bp, 0, padsz); |
| 712 | bp = (void *) bp + padsz; |
| 713 | } |
| 714 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 715 | trace_afs_make_fs_call1(call, &dvp->fid, name); |
| 716 | afs_make_op_call(op, call, GFP_NOFS); |
| 717 | } |
| 718 | |
| 719 | static const struct afs_call_type afs_RXFSRemoveDir = { |
| 720 | .name = "FS.RemoveDir", |
| 721 | .op = afs_FS_RemoveDir, |
| 722 | .deliver = afs_deliver_fs_file_status_and_vol, |
| 723 | .destructor = afs_flat_call_destructor, |
| 724 | }; |
| 725 | |
| 726 | /* |
| 727 | * Remove a directory. |
| 728 | */ |
| 729 | void afs_fs_remove_dir(struct afs_operation *op) |
| 730 | { |
| 731 | const struct qstr *name = &op->dentry->d_name; |
| 732 | struct afs_vnode_param *dvp = &op->file[0]; |
| 733 | struct afs_call *call; |
| 734 | size_t namesz, reqsz, padsz; |
| 735 | __be32 *bp; |
| 736 | |
| 737 | _enter(""); |
| 738 | |
| 739 | namesz = name->len; |
| 740 | padsz = (4 - (namesz & 3)) & 3; |
| 741 | reqsz = (5 * 4) + namesz + padsz; |
| 742 | |
| 743 | call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveDir, |
| 744 | reqsz, (21 + 6) * 4); |
| 745 | if (!call) |
| 746 | return afs_op_nomem(op); |
| 747 | |
| 748 | /* marshall the parameters */ |
| 749 | bp = call->request; |
| 750 | *bp++ = htonl(FSREMOVEDIR); |
| 751 | *bp++ = htonl(dvp->fid.vid); |
| 752 | *bp++ = htonl(dvp->fid.vnode); |
| 753 | *bp++ = htonl(dvp->fid.unique); |
| 754 | *bp++ = htonl(namesz); |
| 755 | memcpy(bp, name->name, namesz); |
| 756 | bp = (void *) bp + namesz; |
| 757 | if (padsz > 0) { |
| 758 | memset(bp, 0, padsz); |
| 759 | bp = (void *) bp + padsz; |
| 760 | } |
| 761 | |
| 762 | trace_afs_make_fs_call1(call, &dvp->fid, name); |
| 763 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /* |
| 767 | * deliver reply data to an FS.Link |
| 768 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 769 | static int afs_deliver_fs_link(struct afs_call *call) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 770 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 771 | struct afs_operation *op = call->op; |
| 772 | struct afs_vnode_param *dvp = &op->file[0]; |
| 773 | struct afs_vnode_param *vp = &op->file[1]; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 774 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 775 | int ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 776 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 777 | _enter("{%u}", call->unmarshall); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 778 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 779 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 780 | if (ret < 0) |
| 781 | return ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 782 | |
| 783 | /* unmarshall the reply once we've received all of it */ |
| 784 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 785 | xdr_decode_AFSFetchStatus(&bp, call, &vp->scb); |
| 786 | xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb); |
| 787 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 788 | |
| 789 | _leave(" = 0 [done]"); |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | /* |
| 794 | * FS.Link operation type |
| 795 | */ |
| 796 | static const struct afs_call_type afs_RXFSLink = { |
| 797 | .name = "FS.Link", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 798 | .op = afs_FS_Link, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 799 | .deliver = afs_deliver_fs_link, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 800 | .destructor = afs_flat_call_destructor, |
| 801 | }; |
| 802 | |
| 803 | /* |
| 804 | * make a hard link |
| 805 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 806 | void afs_fs_link(struct afs_operation *op) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 807 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 808 | const struct qstr *name = &op->dentry->d_name; |
| 809 | struct afs_vnode_param *dvp = &op->file[0]; |
| 810 | struct afs_vnode_param *vp = &op->file[1]; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 811 | struct afs_call *call; |
| 812 | size_t namesz, reqsz, padsz; |
| 813 | __be32 *bp; |
| 814 | |
| 815 | _enter(""); |
| 816 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 817 | namesz = name->len; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 818 | padsz = (4 - (namesz & 3)) & 3; |
| 819 | reqsz = (5 * 4) + namesz + padsz + (3 * 4); |
| 820 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 821 | call = afs_alloc_flat_call(op->net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 822 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 823 | return afs_op_nomem(op); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 824 | |
| 825 | /* marshall the parameters */ |
| 826 | bp = call->request; |
| 827 | *bp++ = htonl(FSLINK); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 828 | *bp++ = htonl(dvp->fid.vid); |
| 829 | *bp++ = htonl(dvp->fid.vnode); |
| 830 | *bp++ = htonl(dvp->fid.unique); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 831 | *bp++ = htonl(namesz); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 832 | memcpy(bp, name->name, namesz); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 833 | bp = (void *) bp + namesz; |
| 834 | if (padsz > 0) { |
| 835 | memset(bp, 0, padsz); |
| 836 | bp = (void *) bp + padsz; |
| 837 | } |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 838 | *bp++ = htonl(vp->fid.vid); |
| 839 | *bp++ = htonl(vp->fid.vnode); |
| 840 | *bp++ = htonl(vp->fid.unique); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 841 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 842 | trace_afs_make_fs_call1(call, &vp->fid, name); |
| 843 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | /* |
| 847 | * deliver reply data to an FS.Symlink |
| 848 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 849 | static int afs_deliver_fs_symlink(struct afs_call *call) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 850 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 851 | struct afs_operation *op = call->op; |
| 852 | struct afs_vnode_param *dvp = &op->file[0]; |
| 853 | struct afs_vnode_param *vp = &op->file[1]; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 854 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 855 | int ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 856 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 857 | _enter("{%u}", call->unmarshall); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 858 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 859 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 860 | if (ret < 0) |
| 861 | return ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 862 | |
| 863 | /* unmarshall the reply once we've received all of it */ |
| 864 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 865 | xdr_decode_AFSFid(&bp, &vp->fid); |
| 866 | xdr_decode_AFSFetchStatus(&bp, call, &vp->scb); |
| 867 | xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb); |
| 868 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 869 | |
| 870 | _leave(" = 0 [done]"); |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | /* |
| 875 | * FS.Symlink operation type |
| 876 | */ |
| 877 | static const struct afs_call_type afs_RXFSSymlink = { |
| 878 | .name = "FS.Symlink", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 879 | .op = afs_FS_Symlink, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 880 | .deliver = afs_deliver_fs_symlink, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 881 | .destructor = afs_flat_call_destructor, |
| 882 | }; |
| 883 | |
| 884 | /* |
| 885 | * create a symbolic link |
| 886 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 887 | void afs_fs_symlink(struct afs_operation *op) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 888 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 889 | const struct qstr *name = &op->dentry->d_name; |
| 890 | struct afs_vnode_param *dvp = &op->file[0]; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 891 | struct afs_call *call; |
| 892 | size_t namesz, reqsz, padsz, c_namesz, c_padsz; |
| 893 | __be32 *bp; |
| 894 | |
| 895 | _enter(""); |
| 896 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 897 | namesz = name->len; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 898 | padsz = (4 - (namesz & 3)) & 3; |
| 899 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 900 | c_namesz = strlen(op->create.symlink); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 901 | c_padsz = (4 - (c_namesz & 3)) & 3; |
| 902 | |
| 903 | reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4); |
| 904 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 905 | call = afs_alloc_flat_call(op->net, &afs_RXFSSymlink, reqsz, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 906 | (3 + 21 + 21 + 6) * 4); |
| 907 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 908 | return afs_op_nomem(op); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 909 | |
| 910 | /* marshall the parameters */ |
| 911 | bp = call->request; |
| 912 | *bp++ = htonl(FSSYMLINK); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 913 | *bp++ = htonl(dvp->fid.vid); |
| 914 | *bp++ = htonl(dvp->fid.vnode); |
| 915 | *bp++ = htonl(dvp->fid.unique); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 916 | *bp++ = htonl(namesz); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 917 | memcpy(bp, name->name, namesz); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 918 | bp = (void *) bp + namesz; |
| 919 | if (padsz > 0) { |
| 920 | memset(bp, 0, padsz); |
| 921 | bp = (void *) bp + padsz; |
| 922 | } |
| 923 | *bp++ = htonl(c_namesz); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 924 | memcpy(bp, op->create.symlink, c_namesz); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 925 | bp = (void *) bp + c_namesz; |
| 926 | if (c_padsz > 0) { |
| 927 | memset(bp, 0, c_padsz); |
| 928 | bp = (void *) bp + c_padsz; |
| 929 | } |
Marc Dionne | ab94f5d | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 930 | *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 931 | *bp++ = htonl(op->mtime.tv_sec); /* mtime */ |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 932 | *bp++ = 0; /* owner */ |
| 933 | *bp++ = 0; /* group */ |
| 934 | *bp++ = htonl(S_IRWXUGO); /* unix mode */ |
| 935 | *bp++ = 0; /* segment size */ |
| 936 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 937 | trace_afs_make_fs_call1(call, &dvp->fid, name); |
| 938 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | /* |
| 942 | * deliver reply data to an FS.Rename |
| 943 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 944 | static int afs_deliver_fs_rename(struct afs_call *call) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 945 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 946 | struct afs_operation *op = call->op; |
| 947 | struct afs_vnode_param *orig_dvp = &op->file[0]; |
| 948 | struct afs_vnode_param *new_dvp = &op->file[1]; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 949 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 950 | int ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 951 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 952 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 953 | if (ret < 0) |
| 954 | return ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 955 | |
David Howells | 38355ee | 2020-04-08 16:13:20 +0100 | [diff] [blame] | 956 | bp = call->buffer; |
David Howells | b98f0ec | 2020-04-08 20:56:20 +0100 | [diff] [blame] | 957 | /* If the two dirs are the same, we have two copies of the same status |
| 958 | * report, so we just decode it twice. |
| 959 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 960 | xdr_decode_AFSFetchStatus(&bp, call, &orig_dvp->scb); |
| 961 | xdr_decode_AFSFetchStatus(&bp, call, &new_dvp->scb); |
| 962 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 963 | |
| 964 | _leave(" = 0 [done]"); |
| 965 | return 0; |
| 966 | } |
| 967 | |
| 968 | /* |
| 969 | * FS.Rename operation type |
| 970 | */ |
| 971 | static const struct afs_call_type afs_RXFSRename = { |
| 972 | .name = "FS.Rename", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 973 | .op = afs_FS_Rename, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 974 | .deliver = afs_deliver_fs_rename, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 975 | .destructor = afs_flat_call_destructor, |
| 976 | }; |
| 977 | |
| 978 | /* |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 979 | * Rename/move a file or directory. |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 980 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 981 | void afs_fs_rename(struct afs_operation *op) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 982 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 983 | struct afs_vnode_param *orig_dvp = &op->file[0]; |
| 984 | struct afs_vnode_param *new_dvp = &op->file[1]; |
| 985 | const struct qstr *orig_name = &op->dentry->d_name; |
| 986 | const struct qstr *new_name = &op->dentry_2->d_name; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 987 | struct afs_call *call; |
| 988 | size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz; |
| 989 | __be32 *bp; |
| 990 | |
| 991 | _enter(""); |
| 992 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 993 | o_namesz = orig_name->len; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 994 | o_padsz = (4 - (o_namesz & 3)) & 3; |
| 995 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 996 | n_namesz = new_name->len; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 997 | n_padsz = (4 - (n_namesz & 3)) & 3; |
| 998 | |
| 999 | reqsz = (4 * 4) + |
| 1000 | 4 + o_namesz + o_padsz + |
| 1001 | (3 * 4) + |
| 1002 | 4 + n_namesz + n_padsz; |
| 1003 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1004 | call = afs_alloc_flat_call(op->net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1005 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1006 | return afs_op_nomem(op); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1007 | |
| 1008 | /* marshall the parameters */ |
| 1009 | bp = call->request; |
| 1010 | *bp++ = htonl(FSRENAME); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1011 | *bp++ = htonl(orig_dvp->fid.vid); |
| 1012 | *bp++ = htonl(orig_dvp->fid.vnode); |
| 1013 | *bp++ = htonl(orig_dvp->fid.unique); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1014 | *bp++ = htonl(o_namesz); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1015 | memcpy(bp, orig_name->name, o_namesz); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1016 | bp = (void *) bp + o_namesz; |
| 1017 | if (o_padsz > 0) { |
| 1018 | memset(bp, 0, o_padsz); |
| 1019 | bp = (void *) bp + o_padsz; |
| 1020 | } |
| 1021 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1022 | *bp++ = htonl(new_dvp->fid.vid); |
| 1023 | *bp++ = htonl(new_dvp->fid.vnode); |
| 1024 | *bp++ = htonl(new_dvp->fid.unique); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1025 | *bp++ = htonl(n_namesz); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1026 | memcpy(bp, new_name->name, n_namesz); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1027 | bp = (void *) bp + n_namesz; |
| 1028 | if (n_padsz > 0) { |
| 1029 | memset(bp, 0, n_padsz); |
| 1030 | bp = (void *) bp + n_padsz; |
| 1031 | } |
| 1032 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1033 | trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name); |
| 1034 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1035 | } |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1036 | |
| 1037 | /* |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1038 | * Deliver reply data to FS.StoreData or FS.StoreStatus |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1039 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1040 | static int afs_deliver_fs_store_data(struct afs_call *call) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1041 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1042 | struct afs_operation *op = call->op; |
| 1043 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1044 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1045 | int ret; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1046 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1047 | _enter(""); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1048 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1049 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1050 | if (ret < 0) |
| 1051 | return ret; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1052 | |
| 1053 | /* unmarshall the reply once we've received all of it */ |
| 1054 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1055 | xdr_decode_AFSFetchStatus(&bp, call, &vp->scb); |
| 1056 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1057 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1058 | _leave(" = 0 [done]"); |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | /* |
| 1063 | * FS.StoreData operation type |
| 1064 | */ |
| 1065 | static const struct afs_call_type afs_RXFSStoreData = { |
| 1066 | .name = "FS.StoreData", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1067 | .op = afs_FS_StoreData, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1068 | .deliver = afs_deliver_fs_store_data, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1069 | .destructor = afs_flat_call_destructor, |
| 1070 | }; |
| 1071 | |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1072 | static const struct afs_call_type afs_RXFSStoreData64 = { |
| 1073 | .name = "FS.StoreData64", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1074 | .op = afs_FS_StoreData64, |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1075 | .deliver = afs_deliver_fs_store_data, |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1076 | .destructor = afs_flat_call_destructor, |
| 1077 | }; |
| 1078 | |
| 1079 | /* |
| 1080 | * store a set of pages to a very large file |
| 1081 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1082 | static void afs_fs_store_data64(struct afs_operation *op, |
| 1083 | loff_t pos, loff_t size, loff_t i_size) |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1084 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1085 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1086 | struct afs_call *call; |
| 1087 | __be32 *bp; |
| 1088 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 1089 | _enter(",%x,{%llx:%llu},,", |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1090 | key_serial(op->key), vp->fid.vid, vp->fid.vnode); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1091 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1092 | call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64, |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1093 | (4 + 6 + 3 * 2) * 4, |
| 1094 | (21 + 6) * 4); |
| 1095 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1096 | return afs_op_nomem(op); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1097 | |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1098 | call->send_pages = true; |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1099 | |
| 1100 | /* marshall the parameters */ |
| 1101 | bp = call->request; |
| 1102 | *bp++ = htonl(FSSTOREDATA64); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1103 | *bp++ = htonl(vp->fid.vid); |
| 1104 | *bp++ = htonl(vp->fid.vnode); |
| 1105 | *bp++ = htonl(vp->fid.unique); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1106 | |
Marc Dionne | ab94f5d | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 1107 | *bp++ = htonl(AFS_SET_MTIME); /* mask */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1108 | *bp++ = htonl(op->mtime.tv_sec); /* mtime */ |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1109 | *bp++ = 0; /* owner */ |
| 1110 | *bp++ = 0; /* group */ |
| 1111 | *bp++ = 0; /* unix mode */ |
| 1112 | *bp++ = 0; /* segment size */ |
| 1113 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1114 | *bp++ = htonl(upper_32_bits(pos)); |
| 1115 | *bp++ = htonl(lower_32_bits(pos)); |
| 1116 | *bp++ = htonl(upper_32_bits(size)); |
| 1117 | *bp++ = htonl(lower_32_bits(size)); |
| 1118 | *bp++ = htonl(upper_32_bits(i_size)); |
| 1119 | *bp++ = htonl(lower_32_bits(i_size)); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1120 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1121 | trace_afs_make_fs_call(call, &vp->fid); |
| 1122 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1125 | /* |
| 1126 | * store a set of pages |
| 1127 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1128 | void afs_fs_store_data(struct afs_operation *op) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1129 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1130 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1131 | struct afs_call *call; |
| 1132 | loff_t size, pos, i_size; |
| 1133 | __be32 *bp; |
| 1134 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 1135 | _enter(",%x,{%llx:%llu},,", |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1136 | key_serial(op->key), vp->fid.vid, vp->fid.vnode); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1137 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1138 | size = (loff_t)op->store.last_to - (loff_t)op->store.first_offset; |
| 1139 | if (op->store.first != op->store.last) |
| 1140 | size += (loff_t)(op->store.last - op->store.first) << PAGE_SHIFT; |
| 1141 | pos = (loff_t)op->store.first << PAGE_SHIFT; |
| 1142 | pos += op->store.first_offset; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1143 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1144 | i_size = i_size_read(&vp->vnode->vfs_inode); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1145 | if (pos + size > i_size) |
| 1146 | i_size = size + pos; |
| 1147 | |
| 1148 | _debug("size %llx, at %llx, i_size %llx", |
| 1149 | (unsigned long long) size, (unsigned long long) pos, |
| 1150 | (unsigned long long) i_size); |
| 1151 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1152 | if (upper_32_bits(pos) || upper_32_bits(i_size) || upper_32_bits(size) || |
| 1153 | upper_32_bits(pos + size)) |
| 1154 | return afs_fs_store_data64(op, pos, size, i_size); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1155 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1156 | call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1157 | (4 + 6 + 3) * 4, |
| 1158 | (21 + 6) * 4); |
| 1159 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1160 | return afs_op_nomem(op); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1161 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1162 | call->send_pages = true; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1163 | |
| 1164 | /* marshall the parameters */ |
| 1165 | bp = call->request; |
| 1166 | *bp++ = htonl(FSSTOREDATA); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1167 | *bp++ = htonl(vp->fid.vid); |
| 1168 | *bp++ = htonl(vp->fid.vnode); |
| 1169 | *bp++ = htonl(vp->fid.unique); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1170 | |
Marc Dionne | ab94f5d | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 1171 | *bp++ = htonl(AFS_SET_MTIME); /* mask */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1172 | *bp++ = htonl(op->mtime.tv_sec); /* mtime */ |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1173 | *bp++ = 0; /* owner */ |
| 1174 | *bp++ = 0; /* group */ |
| 1175 | *bp++ = 0; /* unix mode */ |
| 1176 | *bp++ = 0; /* segment size */ |
| 1177 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1178 | *bp++ = htonl(lower_32_bits(pos)); |
| 1179 | *bp++ = htonl(lower_32_bits(size)); |
| 1180 | *bp++ = htonl(lower_32_bits(i_size)); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1181 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1182 | trace_afs_make_fs_call(call, &vp->fid); |
| 1183 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | /* |
| 1187 | * FS.StoreStatus operation type |
| 1188 | */ |
| 1189 | static const struct afs_call_type afs_RXFSStoreStatus = { |
| 1190 | .name = "FS.StoreStatus", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1191 | .op = afs_FS_StoreStatus, |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1192 | .deliver = afs_deliver_fs_store_data, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1193 | .destructor = afs_flat_call_destructor, |
| 1194 | }; |
| 1195 | |
| 1196 | static const struct afs_call_type afs_RXFSStoreData_as_Status = { |
| 1197 | .name = "FS.StoreData", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1198 | .op = afs_FS_StoreData, |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1199 | .deliver = afs_deliver_fs_store_data, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1200 | .destructor = afs_flat_call_destructor, |
| 1201 | }; |
| 1202 | |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1203 | static const struct afs_call_type afs_RXFSStoreData64_as_Status = { |
| 1204 | .name = "FS.StoreData64", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1205 | .op = afs_FS_StoreData64, |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1206 | .deliver = afs_deliver_fs_store_data, |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1207 | .destructor = afs_flat_call_destructor, |
| 1208 | }; |
| 1209 | |
| 1210 | /* |
| 1211 | * set the attributes on a very large file, using FS.StoreData rather than |
| 1212 | * FS.StoreStatus so as to alter the file size also |
| 1213 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1214 | static void afs_fs_setattr_size64(struct afs_operation *op) |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1215 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1216 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1217 | struct afs_call *call; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1218 | struct iattr *attr = op->setattr.attr; |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1219 | __be32 *bp; |
| 1220 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 1221 | _enter(",%x,{%llx:%llu},,", |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1222 | key_serial(op->key), vp->fid.vid, vp->fid.vnode); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1223 | |
| 1224 | ASSERT(attr->ia_valid & ATTR_SIZE); |
| 1225 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1226 | call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64_as_Status, |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1227 | (4 + 6 + 3 * 2) * 4, |
| 1228 | (21 + 6) * 4); |
| 1229 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1230 | return afs_op_nomem(op); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1231 | |
| 1232 | /* marshall the parameters */ |
| 1233 | bp = call->request; |
| 1234 | *bp++ = htonl(FSSTOREDATA64); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1235 | *bp++ = htonl(vp->fid.vid); |
| 1236 | *bp++ = htonl(vp->fid.vnode); |
| 1237 | *bp++ = htonl(vp->fid.unique); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1238 | |
| 1239 | xdr_encode_AFS_StoreStatus(&bp, attr); |
| 1240 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1241 | *bp++ = htonl(upper_32_bits(attr->ia_size)); /* position of start of write */ |
| 1242 | *bp++ = htonl(lower_32_bits(attr->ia_size)); |
| 1243 | *bp++ = 0; /* size of write */ |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1244 | *bp++ = 0; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1245 | *bp++ = htonl(upper_32_bits(attr->ia_size)); /* new file length */ |
| 1246 | *bp++ = htonl(lower_32_bits(attr->ia_size)); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1247 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1248 | trace_afs_make_fs_call(call, &vp->fid); |
| 1249 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1252 | /* |
| 1253 | * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus |
| 1254 | * so as to alter the file size also |
| 1255 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1256 | static void afs_fs_setattr_size(struct afs_operation *op) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1257 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1258 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1259 | struct afs_call *call; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1260 | struct iattr *attr = op->setattr.attr; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1261 | __be32 *bp; |
| 1262 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 1263 | _enter(",%x,{%llx:%llu},,", |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1264 | key_serial(op->key), vp->fid.vid, vp->fid.vnode); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1265 | |
| 1266 | ASSERT(attr->ia_valid & ATTR_SIZE); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1267 | if (upper_32_bits(attr->ia_size)) |
| 1268 | return afs_fs_setattr_size64(op); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1269 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1270 | call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData_as_Status, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1271 | (4 + 6 + 3) * 4, |
| 1272 | (21 + 6) * 4); |
| 1273 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1274 | return afs_op_nomem(op); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1275 | |
| 1276 | /* marshall the parameters */ |
| 1277 | bp = call->request; |
| 1278 | *bp++ = htonl(FSSTOREDATA); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1279 | *bp++ = htonl(vp->fid.vid); |
| 1280 | *bp++ = htonl(vp->fid.vnode); |
| 1281 | *bp++ = htonl(vp->fid.unique); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1282 | |
| 1283 | xdr_encode_AFS_StoreStatus(&bp, attr); |
| 1284 | |
David Howells | 8c7ae38 | 2019-03-27 22:48:02 +0000 | [diff] [blame] | 1285 | *bp++ = htonl(attr->ia_size); /* position of start of write */ |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1286 | *bp++ = 0; /* size of write */ |
| 1287 | *bp++ = htonl(attr->ia_size); /* new file length */ |
| 1288 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1289 | trace_afs_make_fs_call(call, &vp->fid); |
| 1290 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | /* |
| 1294 | * set the attributes on a file, using FS.StoreData if there's a change in file |
| 1295 | * size, and FS.StoreStatus otherwise |
| 1296 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1297 | void afs_fs_setattr(struct afs_operation *op) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1298 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1299 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1300 | struct afs_call *call; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1301 | struct iattr *attr = op->setattr.attr; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1302 | __be32 *bp; |
| 1303 | |
| 1304 | if (attr->ia_valid & ATTR_SIZE) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1305 | return afs_fs_setattr_size(op); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1306 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 1307 | _enter(",%x,{%llx:%llu},,", |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1308 | key_serial(op->key), vp->fid.vid, vp->fid.vnode); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1309 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1310 | call = afs_alloc_flat_call(op->net, &afs_RXFSStoreStatus, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1311 | (4 + 6) * 4, |
| 1312 | (21 + 6) * 4); |
| 1313 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1314 | return afs_op_nomem(op); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1315 | |
| 1316 | /* marshall the parameters */ |
| 1317 | bp = call->request; |
| 1318 | *bp++ = htonl(FSSTORESTATUS); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1319 | *bp++ = htonl(vp->fid.vid); |
| 1320 | *bp++ = htonl(vp->fid.vnode); |
| 1321 | *bp++ = htonl(vp->fid.unique); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1322 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1323 | xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1324 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1325 | trace_afs_make_fs_call(call, &vp->fid); |
| 1326 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1327 | } |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1328 | |
| 1329 | /* |
| 1330 | * deliver reply data to an FS.GetVolumeStatus |
| 1331 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1332 | static int afs_deliver_fs_get_volume_status(struct afs_call *call) |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1333 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1334 | struct afs_operation *op = call->op; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1335 | const __be32 *bp; |
| 1336 | char *p; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1337 | u32 size; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1338 | int ret; |
| 1339 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1340 | _enter("{%u}", call->unmarshall); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1341 | |
| 1342 | switch (call->unmarshall) { |
| 1343 | case 0: |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1344 | call->unmarshall++; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1345 | afs_extract_to_buf(call, 12 * 4); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1346 | fallthrough; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1347 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1348 | /* extract the returned status record */ |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1349 | case 1: |
| 1350 | _debug("extract status"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1351 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1352 | if (ret < 0) |
| 1353 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1354 | |
| 1355 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1356 | xdr_decode_AFSFetchVolumeStatus(&bp, &op->volstatus.vs); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1357 | call->unmarshall++; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1358 | afs_extract_to_tmp(call); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1359 | fallthrough; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1360 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1361 | /* extract the volume name length */ |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1362 | case 2: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1363 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1364 | if (ret < 0) |
| 1365 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1366 | |
| 1367 | call->count = ntohl(call->tmp); |
| 1368 | _debug("volname length: %u", call->count); |
| 1369 | if (call->count >= AFSNAMEMAX) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 1370 | return afs_protocol_error(call, afs_eproto_volname_len); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1371 | size = (call->count + 3) & ~3; /* It's padded */ |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1372 | afs_extract_to_buf(call, size); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1373 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1374 | fallthrough; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1375 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1376 | /* extract the volume name */ |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1377 | case 3: |
| 1378 | _debug("extract volname"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1379 | ret = afs_extract_data(call, true); |
| 1380 | if (ret < 0) |
| 1381 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1382 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1383 | p = call->buffer; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1384 | p[call->count] = 0; |
| 1385 | _debug("volname '%s'", p); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1386 | afs_extract_to_tmp(call); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1387 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1388 | fallthrough; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1389 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1390 | /* extract the offline message length */ |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1391 | case 4: |
| 1392 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1393 | if (ret < 0) |
| 1394 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1395 | |
| 1396 | call->count = ntohl(call->tmp); |
| 1397 | _debug("offline msg length: %u", call->count); |
| 1398 | if (call->count >= AFSNAMEMAX) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 1399 | return afs_protocol_error(call, afs_eproto_offline_msg_len); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1400 | size = (call->count + 3) & ~3; /* It's padded */ |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1401 | afs_extract_to_buf(call, size); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1402 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1403 | fallthrough; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1404 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1405 | /* extract the offline message */ |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1406 | case 5: |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1407 | _debug("extract offline"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1408 | ret = afs_extract_data(call, true); |
| 1409 | if (ret < 0) |
| 1410 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1411 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1412 | p = call->buffer; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1413 | p[call->count] = 0; |
| 1414 | _debug("offline '%s'", p); |
| 1415 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1416 | afs_extract_to_tmp(call); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1417 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1418 | fallthrough; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1419 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1420 | /* extract the message of the day length */ |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1421 | case 6: |
| 1422 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1423 | if (ret < 0) |
| 1424 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1425 | |
| 1426 | call->count = ntohl(call->tmp); |
| 1427 | _debug("motd length: %u", call->count); |
| 1428 | if (call->count >= AFSNAMEMAX) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 1429 | return afs_protocol_error(call, afs_eproto_motd_len); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1430 | size = (call->count + 3) & ~3; /* It's padded */ |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1431 | afs_extract_to_buf(call, size); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1432 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1433 | fallthrough; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1434 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1435 | /* extract the message of the day */ |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1436 | case 7: |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1437 | _debug("extract motd"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1438 | ret = afs_extract_data(call, false); |
| 1439 | if (ret < 0) |
| 1440 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1441 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1442 | p = call->buffer; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1443 | p[call->count] = 0; |
| 1444 | _debug("motd '%s'", p); |
| 1445 | |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1446 | call->unmarshall++; |
| 1447 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1448 | case 8: |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1449 | break; |
| 1450 | } |
| 1451 | |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1452 | _leave(" = 0 [done]"); |
| 1453 | return 0; |
| 1454 | } |
| 1455 | |
| 1456 | /* |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1457 | * FS.GetVolumeStatus operation type |
| 1458 | */ |
| 1459 | static const struct afs_call_type afs_RXFSGetVolumeStatus = { |
| 1460 | .name = "FS.GetVolumeStatus", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1461 | .op = afs_FS_GetVolumeStatus, |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1462 | .deliver = afs_deliver_fs_get_volume_status, |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1463 | .destructor = afs_flat_call_destructor, |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1464 | }; |
| 1465 | |
| 1466 | /* |
| 1467 | * fetch the status of a volume |
| 1468 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1469 | void afs_fs_get_volume_status(struct afs_operation *op) |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1470 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1471 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1472 | struct afs_call *call; |
| 1473 | __be32 *bp; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1474 | |
| 1475 | _enter(""); |
| 1476 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1477 | call = afs_alloc_flat_call(op->net, &afs_RXFSGetVolumeStatus, 2 * 4, |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1478 | max(12 * 4, AFSOPAQUEMAX + 1)); |
| 1479 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1480 | return afs_op_nomem(op); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1481 | |
| 1482 | /* marshall the parameters */ |
| 1483 | bp = call->request; |
| 1484 | bp[0] = htonl(FSGETVOLUMESTATUS); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1485 | bp[1] = htonl(vp->fid.vid); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1486 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1487 | trace_afs_make_fs_call(call, &vp->fid); |
| 1488 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1489 | } |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1490 | |
| 1491 | /* |
| 1492 | * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock |
| 1493 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1494 | static int afs_deliver_fs_xxxx_lock(struct afs_call *call) |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1495 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1496 | struct afs_operation *op = call->op; |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1497 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1498 | int ret; |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1499 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1500 | _enter("{%u}", call->unmarshall); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1501 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1502 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1503 | if (ret < 0) |
| 1504 | return ret; |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1505 | |
| 1506 | /* unmarshall the reply once we've received all of it */ |
| 1507 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1508 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1509 | |
| 1510 | _leave(" = 0 [done]"); |
| 1511 | return 0; |
| 1512 | } |
| 1513 | |
| 1514 | /* |
| 1515 | * FS.SetLock operation type |
| 1516 | */ |
| 1517 | static const struct afs_call_type afs_RXFSSetLock = { |
| 1518 | .name = "FS.SetLock", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1519 | .op = afs_FS_SetLock, |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1520 | .deliver = afs_deliver_fs_xxxx_lock, |
David Howells | a690f60 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1521 | .done = afs_lock_op_done, |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1522 | .destructor = afs_flat_call_destructor, |
| 1523 | }; |
| 1524 | |
| 1525 | /* |
| 1526 | * FS.ExtendLock operation type |
| 1527 | */ |
| 1528 | static const struct afs_call_type afs_RXFSExtendLock = { |
| 1529 | .name = "FS.ExtendLock", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1530 | .op = afs_FS_ExtendLock, |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1531 | .deliver = afs_deliver_fs_xxxx_lock, |
David Howells | a690f60 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1532 | .done = afs_lock_op_done, |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1533 | .destructor = afs_flat_call_destructor, |
| 1534 | }; |
| 1535 | |
| 1536 | /* |
| 1537 | * FS.ReleaseLock operation type |
| 1538 | */ |
| 1539 | static const struct afs_call_type afs_RXFSReleaseLock = { |
| 1540 | .name = "FS.ReleaseLock", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1541 | .op = afs_FS_ReleaseLock, |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1542 | .deliver = afs_deliver_fs_xxxx_lock, |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1543 | .destructor = afs_flat_call_destructor, |
| 1544 | }; |
| 1545 | |
| 1546 | /* |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1547 | * Set a lock on a file |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1548 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1549 | void afs_fs_set_lock(struct afs_operation *op) |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1550 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1551 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1552 | struct afs_call *call; |
| 1553 | __be32 *bp; |
| 1554 | |
| 1555 | _enter(""); |
| 1556 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1557 | call = afs_alloc_flat_call(op->net, &afs_RXFSSetLock, 5 * 4, 6 * 4); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1558 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1559 | return afs_op_nomem(op); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1560 | |
| 1561 | /* marshall the parameters */ |
| 1562 | bp = call->request; |
| 1563 | *bp++ = htonl(FSSETLOCK); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1564 | *bp++ = htonl(vp->fid.vid); |
| 1565 | *bp++ = htonl(vp->fid.vnode); |
| 1566 | *bp++ = htonl(vp->fid.unique); |
| 1567 | *bp++ = htonl(op->lock.type); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1568 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1569 | trace_afs_make_fs_calli(call, &vp->fid, op->lock.type); |
| 1570 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | /* |
| 1574 | * extend a lock on a file |
| 1575 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1576 | void afs_fs_extend_lock(struct afs_operation *op) |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1577 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1578 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1579 | struct afs_call *call; |
| 1580 | __be32 *bp; |
| 1581 | |
| 1582 | _enter(""); |
| 1583 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1584 | call = afs_alloc_flat_call(op->net, &afs_RXFSExtendLock, 4 * 4, 6 * 4); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1585 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1586 | return afs_op_nomem(op); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1587 | |
| 1588 | /* marshall the parameters */ |
| 1589 | bp = call->request; |
| 1590 | *bp++ = htonl(FSEXTENDLOCK); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1591 | *bp++ = htonl(vp->fid.vid); |
| 1592 | *bp++ = htonl(vp->fid.vnode); |
| 1593 | *bp++ = htonl(vp->fid.unique); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1594 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1595 | trace_afs_make_fs_call(call, &vp->fid); |
| 1596 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | /* |
| 1600 | * release a lock on a file |
| 1601 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1602 | void afs_fs_release_lock(struct afs_operation *op) |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1603 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1604 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1605 | struct afs_call *call; |
| 1606 | __be32 *bp; |
| 1607 | |
| 1608 | _enter(""); |
| 1609 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1610 | call = afs_alloc_flat_call(op->net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1611 | if (!call) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1612 | return afs_op_nomem(op); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1613 | |
| 1614 | /* marshall the parameters */ |
| 1615 | bp = call->request; |
| 1616 | *bp++ = htonl(FSRELEASELOCK); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1617 | *bp++ = htonl(vp->fid.vid); |
| 1618 | *bp++ = htonl(vp->fid.vnode); |
| 1619 | *bp++ = htonl(vp->fid.unique); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1620 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1621 | trace_afs_make_fs_call(call, &vp->fid); |
| 1622 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | /* |
| 1626 | * Deliver reply data to an FS.GiveUpAllCallBacks operation. |
| 1627 | */ |
| 1628 | static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call) |
| 1629 | { |
| 1630 | return afs_transfer_reply(call); |
| 1631 | } |
| 1632 | |
| 1633 | /* |
| 1634 | * FS.GiveUpAllCallBacks operation type |
| 1635 | */ |
| 1636 | static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = { |
| 1637 | .name = "FS.GiveUpAllCallBacks", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1638 | .op = afs_FS_GiveUpAllCallBacks, |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 1639 | .deliver = afs_deliver_fs_give_up_all_callbacks, |
| 1640 | .destructor = afs_flat_call_destructor, |
| 1641 | }; |
| 1642 | |
| 1643 | /* |
| 1644 | * Flush all the callbacks we have on a server. |
| 1645 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1646 | int afs_fs_give_up_all_callbacks(struct afs_net *net, |
| 1647 | struct afs_server *server, |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1648 | struct afs_addr_cursor *ac, |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1649 | struct key *key) |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 1650 | { |
| 1651 | struct afs_call *call; |
| 1652 | __be32 *bp; |
| 1653 | |
| 1654 | _enter(""); |
| 1655 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1656 | call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0); |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 1657 | if (!call) |
| 1658 | return -ENOMEM; |
| 1659 | |
| 1660 | call->key = key; |
| 1661 | |
| 1662 | /* marshall the parameters */ |
| 1663 | bp = call->request; |
| 1664 | *bp++ = htonl(FSGIVEUPALLCALLBACKS); |
| 1665 | |
David Howells | 977e5f8 | 2020-04-17 17:31:26 +0100 | [diff] [blame] | 1666 | call->server = afs_use_server(server, afs_server_trace_give_up_cb); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1667 | afs_make_call(ac, call, GFP_NOFS); |
| 1668 | return afs_wait_for_call_to_complete(call, ac); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | /* |
| 1672 | * Deliver reply data to an FS.GetCapabilities operation. |
| 1673 | */ |
| 1674 | static int afs_deliver_fs_get_capabilities(struct afs_call *call) |
| 1675 | { |
| 1676 | u32 count; |
| 1677 | int ret; |
| 1678 | |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 1679 | _enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter)); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1680 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1681 | switch (call->unmarshall) { |
| 1682 | case 0: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1683 | afs_extract_to_tmp(call); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1684 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1685 | fallthrough; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1686 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1687 | /* Extract the capabilities word count */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1688 | case 1: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1689 | ret = afs_extract_data(call, true); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1690 | if (ret < 0) |
| 1691 | return ret; |
| 1692 | |
| 1693 | count = ntohl(call->tmp); |
| 1694 | |
| 1695 | call->count = count; |
| 1696 | call->count2 = count; |
David Howells | 23a2891 | 2019-08-20 09:22:38 +0100 | [diff] [blame] | 1697 | afs_extract_discard(call, count * sizeof(__be32)); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1698 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1699 | fallthrough; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1700 | |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1701 | /* Extract capabilities words */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1702 | case 2: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1703 | ret = afs_extract_data(call, false); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1704 | if (ret < 0) |
| 1705 | return ret; |
| 1706 | |
| 1707 | /* TODO: Examine capabilities */ |
| 1708 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1709 | call->unmarshall++; |
| 1710 | break; |
| 1711 | } |
| 1712 | |
| 1713 | _leave(" = 0 [done]"); |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
| 1717 | /* |
| 1718 | * FS.GetCapabilities operation type |
| 1719 | */ |
| 1720 | static const struct afs_call_type afs_RXFSGetCapabilities = { |
| 1721 | .name = "FS.GetCapabilities", |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1722 | .op = afs_FS_GetCapabilities, |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1723 | .deliver = afs_deliver_fs_get_capabilities, |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 1724 | .done = afs_fileserver_probe_result, |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 1725 | .destructor = afs_flat_call_destructor, |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1726 | }; |
| 1727 | |
| 1728 | /* |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 1729 | * Probe a fileserver for the capabilities that it supports. This RPC can |
| 1730 | * reply with up to 196 words. The operation is asynchronous and if we managed |
| 1731 | * to allocate a call, true is returned the result is delivered through the |
| 1732 | * ->done() - otherwise we return false to indicate we didn't even try. |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1733 | */ |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 1734 | bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server, |
| 1735 | struct afs_addr_cursor *ac, struct key *key) |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1736 | { |
| 1737 | struct afs_call *call; |
| 1738 | __be32 *bp; |
| 1739 | |
| 1740 | _enter(""); |
| 1741 | |
| 1742 | call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4); |
| 1743 | if (!call) |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 1744 | return false; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1745 | |
| 1746 | call->key = key; |
David Howells | 977e5f8 | 2020-04-17 17:31:26 +0100 | [diff] [blame] | 1747 | call->server = afs_use_server(server, afs_server_trace_get_caps); |
David Howells | 30062bd | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 1748 | call->upgrade = true; |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1749 | call->async = true; |
David Howells | 94f699c | 2019-05-16 13:21:59 +0100 | [diff] [blame] | 1750 | call->max_lifespan = AFS_PROBE_MAX_LIFESPAN; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 1751 | |
| 1752 | /* marshall the parameters */ |
| 1753 | bp = call->request; |
| 1754 | *bp++ = htonl(FSGETCAPABILITIES); |
| 1755 | |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 1756 | trace_afs_make_fs_call(call, NULL); |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 1757 | afs_make_call(ac, call, GFP_NOFS); |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 1758 | afs_put_call(call); |
| 1759 | return true; |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1760 | } |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1761 | |
| 1762 | /* |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1763 | * Deliver reply data to an FS.InlineBulkStatus call |
| 1764 | */ |
| 1765 | static int afs_deliver_fs_inline_bulk_status(struct afs_call *call) |
| 1766 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1767 | struct afs_operation *op = call->op; |
David Howells | 8718275 | 2019-05-09 16:17:05 +0100 | [diff] [blame] | 1768 | struct afs_status_cb *scb; |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1769 | const __be32 *bp; |
| 1770 | u32 tmp; |
| 1771 | int ret; |
| 1772 | |
| 1773 | _enter("{%u}", call->unmarshall); |
| 1774 | |
| 1775 | switch (call->unmarshall) { |
| 1776 | case 0: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1777 | afs_extract_to_tmp(call); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1778 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1779 | fallthrough; |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1780 | |
| 1781 | /* Extract the file status count and array in two steps */ |
| 1782 | case 1: |
| 1783 | _debug("extract status count"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1784 | ret = afs_extract_data(call, true); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1785 | if (ret < 0) |
| 1786 | return ret; |
| 1787 | |
| 1788 | tmp = ntohl(call->tmp); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1789 | _debug("status count: %u/%u", tmp, op->nr_files); |
| 1790 | if (tmp != op->nr_files) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 1791 | return afs_protocol_error(call, afs_eproto_ibulkst_count); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1792 | |
| 1793 | call->count = 0; |
| 1794 | call->unmarshall++; |
| 1795 | more_counts: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1796 | afs_extract_to_buf(call, 21 * sizeof(__be32)); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1797 | fallthrough; |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1798 | |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1799 | case 2: |
| 1800 | _debug("extract status array %u", call->count); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1801 | ret = afs_extract_data(call, true); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1802 | if (ret < 0) |
| 1803 | return ret; |
| 1804 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1805 | switch (call->count) { |
| 1806 | case 0: |
| 1807 | scb = &op->file[0].scb; |
| 1808 | break; |
| 1809 | case 1: |
| 1810 | scb = &op->file[1].scb; |
| 1811 | break; |
| 1812 | default: |
| 1813 | scb = &op->more_files[call->count - 2].scb; |
| 1814 | break; |
| 1815 | } |
| 1816 | |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1817 | bp = call->buffer; |
David Howells | 38355ee | 2020-04-08 16:13:20 +0100 | [diff] [blame] | 1818 | xdr_decode_AFSFetchStatus(&bp, call, scb); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1819 | |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1820 | call->count++; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1821 | if (call->count < op->nr_files) |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1822 | goto more_counts; |
| 1823 | |
| 1824 | call->count = 0; |
| 1825 | call->unmarshall++; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1826 | afs_extract_to_tmp(call); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1827 | fallthrough; |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1828 | |
| 1829 | /* Extract the callback count and array in two steps */ |
| 1830 | case 3: |
| 1831 | _debug("extract CB count"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1832 | ret = afs_extract_data(call, true); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1833 | if (ret < 0) |
| 1834 | return ret; |
| 1835 | |
| 1836 | tmp = ntohl(call->tmp); |
| 1837 | _debug("CB count: %u", tmp); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1838 | if (tmp != op->nr_files) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 1839 | return afs_protocol_error(call, afs_eproto_ibulkst_cb_count); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1840 | call->count = 0; |
| 1841 | call->unmarshall++; |
| 1842 | more_cbs: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1843 | afs_extract_to_buf(call, 3 * sizeof(__be32)); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1844 | fallthrough; |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1845 | |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1846 | case 4: |
| 1847 | _debug("extract CB array"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1848 | ret = afs_extract_data(call, true); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1849 | if (ret < 0) |
| 1850 | return ret; |
| 1851 | |
| 1852 | _debug("unmarshall CB array"); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1853 | switch (call->count) { |
| 1854 | case 0: |
| 1855 | scb = &op->file[0].scb; |
| 1856 | break; |
| 1857 | case 1: |
| 1858 | scb = &op->file[1].scb; |
| 1859 | break; |
| 1860 | default: |
| 1861 | scb = &op->more_files[call->count - 2].scb; |
| 1862 | break; |
| 1863 | } |
| 1864 | |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1865 | bp = call->buffer; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 1866 | xdr_decode_AFSCallBack(&bp, call, scb); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1867 | call->count++; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1868 | if (call->count < op->nr_files) |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1869 | goto more_cbs; |
| 1870 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1871 | afs_extract_to_buf(call, 6 * sizeof(__be32)); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1872 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1873 | fallthrough; |
Gustavo A. R. Silva | 2988160 | 2019-05-19 18:43:53 -0500 | [diff] [blame] | 1874 | |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1875 | case 5: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 1876 | ret = afs_extract_data(call, false); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1877 | if (ret < 0) |
| 1878 | return ret; |
| 1879 | |
| 1880 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1881 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1882 | |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1883 | call->unmarshall++; |
| 1884 | |
| 1885 | case 6: |
| 1886 | break; |
| 1887 | } |
| 1888 | |
| 1889 | _leave(" = 0 [done]"); |
| 1890 | return 0; |
| 1891 | } |
| 1892 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1893 | static void afs_done_fs_inline_bulk_status(struct afs_call *call) |
| 1894 | { |
| 1895 | if (call->error == -ECONNABORTED && |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 1896 | call->abort_code == RX_INVALID_OPERATION) { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1897 | set_bit(AFS_SERVER_FL_NO_IBULK, &call->server->flags); |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 1898 | if (call->op) |
| 1899 | set_bit(AFS_VOLUME_MAYBE_NO_IBULK, &call->op->volume->flags); |
| 1900 | } |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1901 | } |
| 1902 | |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1903 | /* |
| 1904 | * FS.InlineBulkStatus operation type |
| 1905 | */ |
| 1906 | static const struct afs_call_type afs_RXFSInlineBulkStatus = { |
| 1907 | .name = "FS.InlineBulkStatus", |
| 1908 | .op = afs_FS_InlineBulkStatus, |
| 1909 | .deliver = afs_deliver_fs_inline_bulk_status, |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1910 | .done = afs_done_fs_inline_bulk_status, |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1911 | .destructor = afs_flat_call_destructor, |
| 1912 | }; |
| 1913 | |
| 1914 | /* |
| 1915 | * Fetch the status information for up to 50 files |
| 1916 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1917 | void afs_fs_inline_bulk_status(struct afs_operation *op) |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1918 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1919 | struct afs_vnode_param *dvp = &op->file[0]; |
| 1920 | struct afs_vnode_param *vp = &op->file[1]; |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1921 | struct afs_call *call; |
| 1922 | __be32 *bp; |
| 1923 | int i; |
| 1924 | |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 1925 | if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1926 | op->error = -ENOTSUPP; |
| 1927 | return; |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1928 | } |
| 1929 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1930 | _enter(",%x,{%llx:%llu},%u", |
| 1931 | key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files); |
| 1932 | |
| 1933 | call = afs_alloc_flat_call(op->net, &afs_RXFSInlineBulkStatus, |
| 1934 | (2 + op->nr_files * 3) * 4, |
| 1935 | 21 * 4); |
| 1936 | if (!call) |
| 1937 | return afs_op_nomem(op); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1938 | |
| 1939 | /* marshall the parameters */ |
| 1940 | bp = call->request; |
| 1941 | *bp++ = htonl(FSINLINEBULKSTATUS); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1942 | *bp++ = htonl(op->nr_files); |
| 1943 | *bp++ = htonl(dvp->fid.vid); |
| 1944 | *bp++ = htonl(dvp->fid.vnode); |
| 1945 | *bp++ = htonl(dvp->fid.unique); |
| 1946 | *bp++ = htonl(vp->fid.vid); |
| 1947 | *bp++ = htonl(vp->fid.vnode); |
| 1948 | *bp++ = htonl(vp->fid.unique); |
| 1949 | for (i = 0; i < op->nr_files - 2; i++) { |
| 1950 | *bp++ = htonl(op->more_files[i].fid.vid); |
| 1951 | *bp++ = htonl(op->more_files[i].fid.vnode); |
| 1952 | *bp++ = htonl(op->more_files[i].fid.unique); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1953 | } |
| 1954 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1955 | trace_afs_make_fs_call(call, &vp->fid); |
| 1956 | afs_make_op_call(op, call, GFP_NOFS); |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 1957 | } |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 1958 | |
| 1959 | /* |
| 1960 | * deliver reply data to an FS.FetchACL |
| 1961 | */ |
| 1962 | static int afs_deliver_fs_fetch_acl(struct afs_call *call) |
| 1963 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1964 | struct afs_operation *op = call->op; |
| 1965 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 1966 | struct afs_acl *acl; |
| 1967 | const __be32 *bp; |
| 1968 | unsigned int size; |
| 1969 | int ret; |
| 1970 | |
| 1971 | _enter("{%u}", call->unmarshall); |
| 1972 | |
| 1973 | switch (call->unmarshall) { |
| 1974 | case 0: |
| 1975 | afs_extract_to_tmp(call); |
| 1976 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1977 | fallthrough; |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 1978 | |
| 1979 | /* extract the returned data length */ |
| 1980 | case 1: |
| 1981 | ret = afs_extract_data(call, true); |
| 1982 | if (ret < 0) |
| 1983 | return ret; |
| 1984 | |
| 1985 | size = call->count2 = ntohl(call->tmp); |
| 1986 | size = round_up(size, 4); |
| 1987 | |
| 1988 | acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL); |
| 1989 | if (!acl) |
| 1990 | return -ENOMEM; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 1991 | op->acl = acl; |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 1992 | acl->size = call->count2; |
| 1993 | afs_extract_begin(call, acl->data, size); |
| 1994 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1995 | fallthrough; |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 1996 | |
| 1997 | /* extract the returned data */ |
| 1998 | case 2: |
| 1999 | ret = afs_extract_data(call, true); |
| 2000 | if (ret < 0) |
| 2001 | return ret; |
| 2002 | |
| 2003 | afs_extract_to_buf(call, (21 + 6) * 4); |
| 2004 | call->unmarshall++; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2005 | fallthrough; |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2006 | |
| 2007 | /* extract the metadata */ |
| 2008 | case 3: |
| 2009 | ret = afs_extract_data(call, false); |
| 2010 | if (ret < 0) |
| 2011 | return ret; |
| 2012 | |
| 2013 | bp = call->buffer; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2014 | xdr_decode_AFSFetchStatus(&bp, call, &vp->scb); |
| 2015 | xdr_decode_AFSVolSync(&bp, &op->volsync); |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2016 | |
| 2017 | call->unmarshall++; |
| 2018 | |
| 2019 | case 4: |
| 2020 | break; |
| 2021 | } |
| 2022 | |
| 2023 | _leave(" = 0 [done]"); |
| 2024 | return 0; |
| 2025 | } |
| 2026 | |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2027 | /* |
| 2028 | * FS.FetchACL operation type |
| 2029 | */ |
| 2030 | static const struct afs_call_type afs_RXFSFetchACL = { |
| 2031 | .name = "FS.FetchACL", |
| 2032 | .op = afs_FS_FetchACL, |
| 2033 | .deliver = afs_deliver_fs_fetch_acl, |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2034 | }; |
| 2035 | |
| 2036 | /* |
| 2037 | * Fetch the ACL for a file. |
| 2038 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2039 | void afs_fs_fetch_acl(struct afs_operation *op) |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2040 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2041 | struct afs_vnode_param *vp = &op->file[0]; |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2042 | struct afs_call *call; |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2043 | __be32 *bp; |
| 2044 | |
| 2045 | _enter(",%x,{%llx:%llu},,", |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2046 | key_serial(op->key), vp->fid.vid, vp->fid.vnode); |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2047 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2048 | call = afs_alloc_flat_call(op->net, &afs_RXFSFetchACL, 16, (21 + 6) * 4); |
| 2049 | if (!call) |
| 2050 | return afs_op_nomem(op); |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2051 | |
| 2052 | /* marshall the parameters */ |
| 2053 | bp = call->request; |
| 2054 | bp[0] = htonl(FSFETCHACL); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2055 | bp[1] = htonl(vp->fid.vid); |
| 2056 | bp[2] = htonl(vp->fid.vnode); |
| 2057 | bp[3] = htonl(vp->fid.unique); |
David Howells | 260f082 | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2058 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2059 | trace_afs_make_fs_call(call, &vp->fid); |
| 2060 | afs_make_op_call(op, call, GFP_KERNEL); |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | /* |
Joe Gorse | b10494a | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2064 | * FS.StoreACL operation type |
| 2065 | */ |
| 2066 | static const struct afs_call_type afs_RXFSStoreACL = { |
| 2067 | .name = "FS.StoreACL", |
| 2068 | .op = afs_FS_StoreACL, |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 2069 | .deliver = afs_deliver_fs_file_status_and_vol, |
Joe Gorse | b10494a | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2070 | .destructor = afs_flat_call_destructor, |
| 2071 | }; |
| 2072 | |
| 2073 | /* |
| 2074 | * Fetch the ACL for a file. |
| 2075 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2076 | void afs_fs_store_acl(struct afs_operation *op) |
Joe Gorse | b10494a | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2077 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2078 | struct afs_vnode_param *vp = &op->file[0]; |
Joe Gorse | b10494a | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2079 | struct afs_call *call; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2080 | const struct afs_acl *acl = op->acl; |
Joe Gorse | b10494a | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2081 | size_t size; |
| 2082 | __be32 *bp; |
| 2083 | |
| 2084 | _enter(",%x,{%llx:%llu},,", |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2085 | key_serial(op->key), vp->fid.vid, vp->fid.vnode); |
Joe Gorse | b10494a | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2086 | |
| 2087 | size = round_up(acl->size, 4); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2088 | call = afs_alloc_flat_call(op->net, &afs_RXFSStoreACL, |
Joe Gorse | b10494a | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2089 | 5 * 4 + size, (21 + 6) * 4); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2090 | if (!call) |
| 2091 | return afs_op_nomem(op); |
Joe Gorse | b10494a | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2092 | |
| 2093 | /* marshall the parameters */ |
| 2094 | bp = call->request; |
| 2095 | bp[0] = htonl(FSSTOREACL); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2096 | bp[1] = htonl(vp->fid.vid); |
| 2097 | bp[2] = htonl(vp->fid.vnode); |
| 2098 | bp[3] = htonl(vp->fid.unique); |
Joe Gorse | b10494a | 2019-04-25 14:26:52 +0100 | [diff] [blame] | 2099 | bp[4] = htonl(acl->size); |
| 2100 | memcpy(&bp[5], acl->data, acl->size); |
| 2101 | if (acl->size != size) |
| 2102 | memset((void *)&bp[5] + acl->size, 0, size - acl->size); |
| 2103 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 2104 | trace_afs_make_fs_call(call, &vp->fid); |
| 2105 | afs_make_op_call(op, call, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | } |