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