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