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