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