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