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