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