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