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