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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "internal.h" |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 17 | #include "afs_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | /* |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame^] | 20 | * We need somewhere to discard into in case the server helpfully returns more |
| 21 | * than we asked for in FS.FetchData{,64}. |
| 22 | */ |
| 23 | static u8 afs_discard_buffer[64]; |
| 24 | |
| 25 | /* |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 26 | * decode an AFSFid block |
| 27 | */ |
| 28 | static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid) |
| 29 | { |
| 30 | const __be32 *bp = *_bp; |
| 31 | |
| 32 | fid->vid = ntohl(*bp++); |
| 33 | fid->vnode = ntohl(*bp++); |
| 34 | fid->unique = ntohl(*bp++); |
| 35 | *_bp = bp; |
| 36 | } |
| 37 | |
| 38 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 39 | * decode an AFSFetchStatus block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 41 | static void xdr_decode_AFSFetchStatus(const __be32 **_bp, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 42 | struct afs_file_status *status, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 43 | struct afs_vnode *vnode, |
| 44 | afs_dataversion_t *store_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 46 | afs_dataversion_t expected_version; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 47 | const __be32 *bp = *_bp; |
| 48 | umode_t mode; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 49 | u64 data_version, size; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 50 | u32 changed = 0; /* becomes non-zero if ctime-type changes seen */ |
Eric W. Biederman | a0a5386 | 2012-02-07 16:20:48 -0800 | [diff] [blame] | 51 | kuid_t owner; |
| 52 | kgid_t group; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 53 | |
| 54 | #define EXTRACT(DST) \ |
| 55 | do { \ |
| 56 | u32 x = ntohl(*bp++); \ |
| 57 | changed |= DST - x; \ |
| 58 | DST = x; \ |
| 59 | } while (0) |
| 60 | |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 61 | status->if_version = ntohl(*bp++); |
| 62 | EXTRACT(status->type); |
| 63 | EXTRACT(status->nlink); |
| 64 | size = ntohl(*bp++); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 65 | data_version = ntohl(*bp++); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 66 | EXTRACT(status->author); |
Eric W. Biederman | a0a5386 | 2012-02-07 16:20:48 -0800 | [diff] [blame] | 67 | owner = make_kuid(&init_user_ns, ntohl(*bp++)); |
| 68 | changed |= !uid_eq(owner, status->owner); |
| 69 | status->owner = owner; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 70 | EXTRACT(status->caller_access); /* call ticket dependent */ |
| 71 | EXTRACT(status->anon_access); |
| 72 | EXTRACT(status->mode); |
| 73 | EXTRACT(status->parent.vnode); |
| 74 | EXTRACT(status->parent.unique); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 75 | bp++; /* seg size */ |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 76 | status->mtime_client = ntohl(*bp++); |
| 77 | status->mtime_server = ntohl(*bp++); |
Eric W. Biederman | a0a5386 | 2012-02-07 16:20:48 -0800 | [diff] [blame] | 78 | group = make_kgid(&init_user_ns, ntohl(*bp++)); |
| 79 | changed |= !gid_eq(group, status->group); |
| 80 | status->group = group; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 81 | bp++; /* sync counter */ |
| 82 | data_version |= (u64) ntohl(*bp++) << 32; |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 83 | EXTRACT(status->lock_count); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 84 | size |= (u64) ntohl(*bp++) << 32; |
| 85 | bp++; /* spare 4 */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 86 | *_bp = bp; |
| 87 | |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 88 | if (size != status->size) { |
| 89 | status->size = size; |
| 90 | changed |= true; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 91 | } |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 92 | status->mode &= S_IALLUGO; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 93 | |
| 94 | _debug("vnode time %lx, %lx", |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 95 | status->mtime_client, status->mtime_server); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 96 | |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 97 | if (vnode) { |
| 98 | status->parent.vid = vnode->fid.vid; |
| 99 | if (changed && !test_bit(AFS_VNODE_UNSET, &vnode->flags)) { |
| 100 | _debug("vnode changed"); |
| 101 | i_size_write(&vnode->vfs_inode, size); |
| 102 | vnode->vfs_inode.i_uid = status->owner; |
| 103 | vnode->vfs_inode.i_gid = status->group; |
David Howells | d6e43f7 | 2011-06-14 00:45:44 +0100 | [diff] [blame] | 104 | vnode->vfs_inode.i_generation = vnode->fid.unique; |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 105 | set_nlink(&vnode->vfs_inode, status->nlink); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 106 | |
| 107 | mode = vnode->vfs_inode.i_mode; |
| 108 | mode &= ~S_IALLUGO; |
| 109 | mode |= status->mode; |
| 110 | barrier(); |
| 111 | vnode->vfs_inode.i_mode = mode; |
| 112 | } |
| 113 | |
| 114 | vnode->vfs_inode.i_ctime.tv_sec = status->mtime_server; |
| 115 | vnode->vfs_inode.i_mtime = vnode->vfs_inode.i_ctime; |
| 116 | vnode->vfs_inode.i_atime = vnode->vfs_inode.i_ctime; |
David Howells | d6e43f7 | 2011-06-14 00:45:44 +0100 | [diff] [blame] | 117 | vnode->vfs_inode.i_version = data_version; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 118 | } |
| 119 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 120 | expected_version = status->data_version; |
| 121 | if (store_version) |
| 122 | expected_version = *store_version; |
| 123 | |
| 124 | if (expected_version != data_version) { |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 125 | status->data_version = data_version; |
| 126 | if (vnode && !test_bit(AFS_VNODE_UNSET, &vnode->flags)) { |
| 127 | _debug("vnode modified %llx on {%x:%u}", |
David S. Miller | ba3e0e1 | 2007-04-26 16:06:22 -0700 | [diff] [blame] | 128 | (unsigned long long) data_version, |
| 129 | vnode->fid.vid, vnode->fid.vnode); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 130 | set_bit(AFS_VNODE_MODIFIED, &vnode->flags); |
| 131 | set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags); |
| 132 | } |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 133 | } else if (store_version) { |
| 134 | status->data_version = data_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 139 | * decode an AFSCallBack block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 141 | static void xdr_decode_AFSCallBack(const __be32 **_bp, struct afs_vnode *vnode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 143 | const __be32 *bp = *_bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 145 | vnode->cb_version = ntohl(*bp++); |
| 146 | vnode->cb_expiry = ntohl(*bp++); |
| 147 | vnode->cb_type = ntohl(*bp++); |
| 148 | vnode->cb_expires = vnode->cb_expiry + get_seconds(); |
| 149 | *_bp = bp; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 152 | static void xdr_decode_AFSCallBack_raw(const __be32 **_bp, |
| 153 | struct afs_callback *cb) |
| 154 | { |
| 155 | const __be32 *bp = *_bp; |
| 156 | |
| 157 | cb->version = ntohl(*bp++); |
| 158 | cb->expiry = ntohl(*bp++); |
| 159 | cb->type = ntohl(*bp++); |
| 160 | *_bp = bp; |
| 161 | } |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 164 | * decode an AFSVolSync block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 166 | static void xdr_decode_AFSVolSync(const __be32 **_bp, |
| 167 | struct afs_volsync *volsync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 169 | const __be32 *bp = *_bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 171 | volsync->creation = ntohl(*bp++); |
| 172 | bp++; /* spare2 */ |
| 173 | bp++; /* spare3 */ |
| 174 | bp++; /* spare4 */ |
| 175 | bp++; /* spare5 */ |
| 176 | bp++; /* spare6 */ |
| 177 | *_bp = bp; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 178 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 179 | |
| 180 | /* |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 181 | * encode the requested attributes into an AFSStoreStatus block |
| 182 | */ |
| 183 | static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr) |
| 184 | { |
| 185 | __be32 *bp = *_bp; |
| 186 | u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0; |
| 187 | |
| 188 | mask = 0; |
| 189 | if (attr->ia_valid & ATTR_MTIME) { |
| 190 | mask |= AFS_SET_MTIME; |
| 191 | mtime = attr->ia_mtime.tv_sec; |
| 192 | } |
| 193 | |
| 194 | if (attr->ia_valid & ATTR_UID) { |
| 195 | mask |= AFS_SET_OWNER; |
Eric W. Biederman | a0a5386 | 2012-02-07 16:20:48 -0800 | [diff] [blame] | 196 | owner = from_kuid(&init_user_ns, attr->ia_uid); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | if (attr->ia_valid & ATTR_GID) { |
| 200 | mask |= AFS_SET_GROUP; |
Eric W. Biederman | a0a5386 | 2012-02-07 16:20:48 -0800 | [diff] [blame] | 201 | group = from_kgid(&init_user_ns, attr->ia_gid); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | if (attr->ia_valid & ATTR_MODE) { |
| 205 | mask |= AFS_SET_MODE; |
| 206 | mode = attr->ia_mode & S_IALLUGO; |
| 207 | } |
| 208 | |
| 209 | *bp++ = htonl(mask); |
| 210 | *bp++ = htonl(mtime); |
| 211 | *bp++ = htonl(owner); |
| 212 | *bp++ = htonl(group); |
| 213 | *bp++ = htonl(mode); |
| 214 | *bp++ = 0; /* segment size */ |
| 215 | *_bp = bp; |
| 216 | } |
| 217 | |
| 218 | /* |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 219 | * decode an AFSFetchVolumeStatus block |
| 220 | */ |
| 221 | static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp, |
| 222 | struct afs_volume_status *vs) |
| 223 | { |
| 224 | const __be32 *bp = *_bp; |
| 225 | |
| 226 | vs->vid = ntohl(*bp++); |
| 227 | vs->parent_id = ntohl(*bp++); |
| 228 | vs->online = ntohl(*bp++); |
| 229 | vs->in_service = ntohl(*bp++); |
| 230 | vs->blessed = ntohl(*bp++); |
| 231 | vs->needs_salvage = ntohl(*bp++); |
| 232 | vs->type = ntohl(*bp++); |
| 233 | vs->min_quota = ntohl(*bp++); |
| 234 | vs->max_quota = ntohl(*bp++); |
| 235 | vs->blocks_in_use = ntohl(*bp++); |
| 236 | vs->part_blocks_avail = ntohl(*bp++); |
| 237 | vs->part_max_blocks = ntohl(*bp++); |
| 238 | *_bp = bp; |
| 239 | } |
| 240 | |
| 241 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 242 | * deliver reply data to an FS.FetchStatus |
| 243 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 244 | static int afs_deliver_fs_fetch_status(struct afs_call *call) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 245 | { |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 246 | struct afs_vnode *vnode = call->reply; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 247 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 248 | int ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 249 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 250 | _enter(""); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 251 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 252 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 253 | if (ret < 0) |
| 254 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 255 | |
| 256 | /* unmarshall the reply once we've received all of it */ |
| 257 | bp = call->buffer; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 258 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 259 | xdr_decode_AFSCallBack(&bp, vnode); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 260 | if (call->reply2) |
| 261 | xdr_decode_AFSVolSync(&bp, call->reply2); |
| 262 | |
| 263 | _leave(" = 0 [done]"); |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | * FS.FetchStatus operation type |
| 269 | */ |
| 270 | static const struct afs_call_type afs_RXFSFetchStatus = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 271 | .name = "FS.FetchStatus", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 272 | .deliver = afs_deliver_fs_fetch_status, |
| 273 | .abort_to_error = afs_abort_to_error, |
| 274 | .destructor = afs_flat_call_destructor, |
| 275 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | /* |
| 278 | * fetch the status information for a file |
| 279 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 280 | int afs_fs_fetch_file_status(struct afs_server *server, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 281 | struct key *key, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 282 | struct afs_vnode *vnode, |
| 283 | struct afs_volsync *volsync, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 284 | bool async) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 286 | struct afs_call *call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | __be32 *bp; |
| 288 | |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 289 | _enter(",%x,{%x:%u},,", |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 290 | key_serial(key), vnode->fid.vid, vnode->fid.vnode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 292 | call = afs_alloc_flat_call(&afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 293 | if (!call) |
| 294 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 296 | call->key = key; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 297 | call->reply = vnode; |
| 298 | call->reply2 = volsync; |
| 299 | call->service_id = FS_SERVICE; |
| 300 | call->port = htons(AFS_FS_PORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | /* marshall the parameters */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 303 | bp = call->request; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | bp[0] = htonl(FSFETCHSTATUS); |
| 305 | bp[1] = htonl(vnode->fid.vid); |
| 306 | bp[2] = htonl(vnode->fid.vnode); |
| 307 | bp[3] = htonl(vnode->fid.unique); |
| 308 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 309 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 313 | * deliver reply data to an FS.FetchData |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 315 | static int afs_deliver_fs_fetch_data(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 317 | struct afs_vnode *vnode = call->reply; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 318 | struct afs_read *req = call->reply3; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 319 | const __be32 *bp; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 320 | unsigned int size; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 321 | void *buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | int ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 323 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 324 | _enter("{%u,%zu/%u;%u/%llu}", |
| 325 | call->unmarshall, call->offset, call->count, |
| 326 | req->remain, req->actual_len); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 327 | |
| 328 | switch (call->unmarshall) { |
| 329 | case 0: |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 330 | req->actual_len = 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 331 | call->offset = 0; |
| 332 | call->unmarshall++; |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 333 | if (call->operation_ID != FSFETCHDATA64) { |
| 334 | call->unmarshall++; |
| 335 | goto no_msw; |
| 336 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 337 | |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 338 | /* extract the upper part of the returned data length of an |
| 339 | * FSFETCHDATA64 op (which should always be 0 using this |
| 340 | * client) */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 341 | case 1: |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 342 | _debug("extract data length (MSW)"); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 343 | ret = afs_extract_data(call, &call->tmp, 4, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 344 | if (ret < 0) |
| 345 | return ret; |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 346 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 347 | req->actual_len = ntohl(call->tmp); |
| 348 | req->actual_len <<= 32; |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 349 | call->offset = 0; |
| 350 | call->unmarshall++; |
| 351 | |
| 352 | no_msw: |
| 353 | /* extract the returned data length */ |
| 354 | case 2: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 355 | _debug("extract data length"); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 356 | ret = afs_extract_data(call, &call->tmp, 4, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 357 | if (ret < 0) |
| 358 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 359 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 360 | req->actual_len |= ntohl(call->tmp); |
| 361 | _debug("DATA length: %llu", req->actual_len); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 362 | |
| 363 | req->remain = req->actual_len; |
| 364 | call->offset = req->pos & (PAGE_SIZE - 1); |
| 365 | req->index = 0; |
| 366 | if (req->actual_len == 0) |
| 367 | goto no_more_data; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 368 | call->unmarshall++; |
| 369 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 370 | begin_page: |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame^] | 371 | ASSERTCMP(req->index, <, req->nr_pages); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 372 | if (req->remain > PAGE_SIZE - call->offset) |
| 373 | size = PAGE_SIZE - call->offset; |
| 374 | else |
| 375 | size = req->remain; |
| 376 | call->count = call->offset + size; |
| 377 | ASSERTCMP(call->count, <=, PAGE_SIZE); |
| 378 | req->remain -= size; |
| 379 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 380 | /* extract the returned data */ |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 381 | case 3: |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 382 | _debug("extract data %u/%llu %zu/%u", |
| 383 | req->remain, req->actual_len, call->offset, call->count); |
| 384 | |
| 385 | buffer = kmap(req->pages[req->index]); |
| 386 | ret = afs_extract_data(call, buffer, call->count, true); |
| 387 | kunmap(req->pages[req->index]); |
| 388 | if (ret < 0) |
| 389 | return ret; |
| 390 | if (call->offset == PAGE_SIZE) { |
| 391 | if (req->page_done) |
| 392 | req->page_done(call, req); |
| 393 | if (req->remain > 0) { |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 394 | call->offset = 0; |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame^] | 395 | req->index++; |
| 396 | if (req->index >= req->nr_pages) |
| 397 | goto begin_discard; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 398 | goto begin_page; |
| 399 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 400 | } |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame^] | 401 | goto no_more_data; |
| 402 | |
| 403 | /* Discard any excess data the server gave us */ |
| 404 | begin_discard: |
| 405 | case 4: |
| 406 | size = min_t(size_t, sizeof(afs_discard_buffer), req->remain); |
| 407 | call->count = size; |
| 408 | _debug("extract discard %u/%llu %zu/%u", |
| 409 | req->remain, req->actual_len, call->offset, call->count); |
| 410 | |
| 411 | call->offset = 0; |
| 412 | ret = afs_extract_data(call, afs_discard_buffer, call->count, true); |
| 413 | req->remain -= call->offset; |
| 414 | if (ret < 0) |
| 415 | return ret; |
| 416 | if (req->remain > 0) |
| 417 | goto begin_discard; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 418 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 419 | no_more_data: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 420 | call->offset = 0; |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame^] | 421 | call->unmarshall = 5; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 422 | |
| 423 | /* extract the metadata */ |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame^] | 424 | case 5: |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 425 | ret = afs_extract_data(call, call->buffer, |
| 426 | (21 + 3 + 6) * 4, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 427 | if (ret < 0) |
| 428 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 429 | |
| 430 | bp = call->buffer; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 431 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 432 | xdr_decode_AFSCallBack(&bp, vnode); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 433 | if (call->reply2) |
| 434 | xdr_decode_AFSVolSync(&bp, call->reply2); |
| 435 | |
| 436 | call->offset = 0; |
| 437 | call->unmarshall++; |
| 438 | |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame^] | 439 | case 6: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 440 | break; |
| 441 | } |
| 442 | |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame^] | 443 | for (; req->index < req->nr_pages; req->index++) { |
| 444 | if (call->count < PAGE_SIZE) |
| 445 | zero_user_segment(req->pages[req->index], |
| 446 | call->count, PAGE_SIZE); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 447 | if (req->page_done) |
| 448 | req->page_done(call, req); |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame^] | 449 | call->count = 0; |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 450 | } |
| 451 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 452 | _leave(" = 0 [done]"); |
| 453 | return 0; |
| 454 | } |
| 455 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 456 | static void afs_fetch_data_destructor(struct afs_call *call) |
| 457 | { |
| 458 | struct afs_read *req = call->reply3; |
| 459 | |
| 460 | afs_put_read(req); |
| 461 | afs_flat_call_destructor(call); |
| 462 | } |
| 463 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 464 | /* |
| 465 | * FS.FetchData operation type |
| 466 | */ |
| 467 | static const struct afs_call_type afs_RXFSFetchData = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 468 | .name = "FS.FetchData", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 469 | .deliver = afs_deliver_fs_fetch_data, |
| 470 | .abort_to_error = afs_abort_to_error, |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 471 | .destructor = afs_fetch_data_destructor, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 472 | }; |
| 473 | |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 474 | static const struct afs_call_type afs_RXFSFetchData64 = { |
| 475 | .name = "FS.FetchData64", |
| 476 | .deliver = afs_deliver_fs_fetch_data, |
| 477 | .abort_to_error = afs_abort_to_error, |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 478 | .destructor = afs_fetch_data_destructor, |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 479 | }; |
| 480 | |
| 481 | /* |
| 482 | * fetch data from a very large file |
| 483 | */ |
| 484 | static int afs_fs_fetch_data64(struct afs_server *server, |
| 485 | struct key *key, |
| 486 | struct afs_vnode *vnode, |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 487 | struct afs_read *req, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 488 | bool async) |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 489 | { |
| 490 | struct afs_call *call; |
| 491 | __be32 *bp; |
| 492 | |
| 493 | _enter(""); |
| 494 | |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 495 | call = afs_alloc_flat_call(&afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4); |
| 496 | if (!call) |
| 497 | return -ENOMEM; |
| 498 | |
| 499 | call->key = key; |
| 500 | call->reply = vnode; |
| 501 | call->reply2 = NULL; /* volsync */ |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 502 | call->reply3 = req; |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 503 | call->service_id = FS_SERVICE; |
| 504 | call->port = htons(AFS_FS_PORT); |
| 505 | call->operation_ID = FSFETCHDATA64; |
| 506 | |
| 507 | /* marshall the parameters */ |
| 508 | bp = call->request; |
| 509 | bp[0] = htonl(FSFETCHDATA64); |
| 510 | bp[1] = htonl(vnode->fid.vid); |
| 511 | bp[2] = htonl(vnode->fid.vnode); |
| 512 | bp[3] = htonl(vnode->fid.unique); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 513 | bp[4] = htonl(upper_32_bits(req->pos)); |
| 514 | bp[5] = htonl(lower_32_bits(req->pos)); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 515 | bp[6] = 0; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 516 | bp[7] = htonl(lower_32_bits(req->len)); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 517 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 518 | atomic_inc(&req->usage); |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 519 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 520 | } |
| 521 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 522 | /* |
| 523 | * fetch data from a file |
| 524 | */ |
| 525 | int afs_fs_fetch_data(struct afs_server *server, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 526 | struct key *key, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 527 | struct afs_vnode *vnode, |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 528 | struct afs_read *req, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 529 | bool async) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 530 | { |
| 531 | struct afs_call *call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | __be32 *bp; |
| 533 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 534 | if (upper_32_bits(req->pos) || |
| 535 | upper_32_bits(req->len) || |
| 536 | upper_32_bits(req->pos + req->len)) |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 537 | return afs_fs_fetch_data64(server, key, vnode, req, async); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 538 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 539 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 541 | call = afs_alloc_flat_call(&afs_RXFSFetchData, 24, (21 + 3 + 6) * 4); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 542 | if (!call) |
| 543 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 545 | call->key = key; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 546 | call->reply = vnode; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 547 | call->reply2 = NULL; /* volsync */ |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 548 | call->reply3 = req; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 549 | call->service_id = FS_SERVICE; |
| 550 | call->port = htons(AFS_FS_PORT); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 551 | call->operation_ID = FSFETCHDATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
| 553 | /* marshall the parameters */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 554 | bp = call->request; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | bp[0] = htonl(FSFETCHDATA); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 556 | bp[1] = htonl(vnode->fid.vid); |
| 557 | bp[2] = htonl(vnode->fid.vnode); |
| 558 | bp[3] = htonl(vnode->fid.unique); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 559 | bp[4] = htonl(lower_32_bits(req->pos)); |
| 560 | bp[5] = htonl(lower_32_bits(req->len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 562 | atomic_inc(&req->usage); |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 563 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 567 | * deliver reply data to an FS.GiveUpCallBacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 569 | static int afs_deliver_fs_give_up_callbacks(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 571 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 573 | /* shouldn't be any reply data */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 574 | return afs_extract_data(call, NULL, 0, false); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 577 | /* |
| 578 | * FS.GiveUpCallBacks operation type |
| 579 | */ |
| 580 | static const struct afs_call_type afs_RXFSGiveUpCallBacks = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 581 | .name = "FS.GiveUpCallBacks", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 582 | .deliver = afs_deliver_fs_give_up_callbacks, |
| 583 | .abort_to_error = afs_abort_to_error, |
| 584 | .destructor = afs_flat_call_destructor, |
| 585 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 587 | /* |
| 588 | * give up a set of callbacks |
| 589 | * - the callbacks are held in the server->cb_break ring |
| 590 | */ |
| 591 | int afs_fs_give_up_callbacks(struct afs_server *server, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 592 | bool async) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 593 | { |
| 594 | struct afs_call *call; |
| 595 | size_t ncallbacks; |
| 596 | __be32 *bp, *tp; |
| 597 | int loop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 599 | ncallbacks = CIRC_CNT(server->cb_break_head, server->cb_break_tail, |
| 600 | ARRAY_SIZE(server->cb_break)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 602 | _enter("{%zu},", ncallbacks); |
| 603 | |
| 604 | if (ncallbacks == 0) |
| 605 | return 0; |
| 606 | if (ncallbacks > AFSCBMAX) |
| 607 | ncallbacks = AFSCBMAX; |
| 608 | |
| 609 | _debug("break %zu callbacks", ncallbacks); |
| 610 | |
| 611 | call = afs_alloc_flat_call(&afs_RXFSGiveUpCallBacks, |
| 612 | 12 + ncallbacks * 6 * 4, 0); |
| 613 | if (!call) |
| 614 | return -ENOMEM; |
| 615 | |
| 616 | call->service_id = FS_SERVICE; |
| 617 | call->port = htons(AFS_FS_PORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | /* marshall the parameters */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 620 | bp = call->request; |
| 621 | tp = bp + 2 + ncallbacks * 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | *bp++ = htonl(FSGIVEUPCALLBACKS); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 623 | *bp++ = htonl(ncallbacks); |
| 624 | *tp++ = htonl(ncallbacks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 626 | atomic_sub(ncallbacks, &server->cb_break_n); |
| 627 | for (loop = ncallbacks; loop > 0; loop--) { |
| 628 | struct afs_callback *cb = |
| 629 | &server->cb_break[server->cb_break_tail]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 631 | *bp++ = htonl(cb->fid.vid); |
| 632 | *bp++ = htonl(cb->fid.vnode); |
| 633 | *bp++ = htonl(cb->fid.unique); |
| 634 | *tp++ = htonl(cb->version); |
| 635 | *tp++ = htonl(cb->expiry); |
| 636 | *tp++ = htonl(cb->type); |
| 637 | smp_mb(); |
| 638 | server->cb_break_tail = |
| 639 | (server->cb_break_tail + 1) & |
| 640 | (ARRAY_SIZE(server->cb_break) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 643 | ASSERT(ncallbacks > 0); |
| 644 | wake_up_nr(&server->cb_break_waitq, ncallbacks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 646 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 647 | } |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 648 | |
| 649 | /* |
| 650 | * deliver reply data to an FS.CreateFile or an FS.MakeDir |
| 651 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 652 | static int afs_deliver_fs_create_vnode(struct afs_call *call) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 653 | { |
| 654 | struct afs_vnode *vnode = call->reply; |
| 655 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 656 | int ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 657 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 658 | _enter("{%u}", call->unmarshall); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 659 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 660 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 661 | if (ret < 0) |
| 662 | return ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 663 | |
| 664 | /* unmarshall the reply once we've received all of it */ |
| 665 | bp = call->buffer; |
| 666 | xdr_decode_AFSFid(&bp, call->reply2); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 667 | xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL, NULL); |
| 668 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 669 | xdr_decode_AFSCallBack_raw(&bp, call->reply4); |
| 670 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
| 671 | |
| 672 | _leave(" = 0 [done]"); |
| 673 | return 0; |
| 674 | } |
| 675 | |
| 676 | /* |
| 677 | * FS.CreateFile and FS.MakeDir operation type |
| 678 | */ |
| 679 | static const struct afs_call_type afs_RXFSCreateXXXX = { |
| 680 | .name = "FS.CreateXXXX", |
| 681 | .deliver = afs_deliver_fs_create_vnode, |
| 682 | .abort_to_error = afs_abort_to_error, |
| 683 | .destructor = afs_flat_call_destructor, |
| 684 | }; |
| 685 | |
| 686 | /* |
| 687 | * create a file or make a directory |
| 688 | */ |
| 689 | int afs_fs_create(struct afs_server *server, |
| 690 | struct key *key, |
| 691 | struct afs_vnode *vnode, |
| 692 | const char *name, |
| 693 | umode_t mode, |
| 694 | struct afs_fid *newfid, |
| 695 | struct afs_file_status *newstatus, |
| 696 | struct afs_callback *newcb, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 697 | bool async) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 698 | { |
| 699 | struct afs_call *call; |
| 700 | size_t namesz, reqsz, padsz; |
| 701 | __be32 *bp; |
| 702 | |
| 703 | _enter(""); |
| 704 | |
| 705 | namesz = strlen(name); |
| 706 | padsz = (4 - (namesz & 3)) & 3; |
| 707 | reqsz = (5 * 4) + namesz + padsz + (6 * 4); |
| 708 | |
| 709 | call = afs_alloc_flat_call(&afs_RXFSCreateXXXX, reqsz, |
| 710 | (3 + 21 + 21 + 3 + 6) * 4); |
| 711 | if (!call) |
| 712 | return -ENOMEM; |
| 713 | |
| 714 | call->key = key; |
| 715 | call->reply = vnode; |
| 716 | call->reply2 = newfid; |
| 717 | call->reply3 = newstatus; |
| 718 | call->reply4 = newcb; |
| 719 | call->service_id = FS_SERVICE; |
| 720 | call->port = htons(AFS_FS_PORT); |
| 721 | |
| 722 | /* marshall the parameters */ |
| 723 | bp = call->request; |
| 724 | *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE); |
| 725 | *bp++ = htonl(vnode->fid.vid); |
| 726 | *bp++ = htonl(vnode->fid.vnode); |
| 727 | *bp++ = htonl(vnode->fid.unique); |
| 728 | *bp++ = htonl(namesz); |
| 729 | memcpy(bp, name, namesz); |
| 730 | bp = (void *) bp + namesz; |
| 731 | if (padsz > 0) { |
| 732 | memset(bp, 0, padsz); |
| 733 | bp = (void *) bp + padsz; |
| 734 | } |
| 735 | *bp++ = htonl(AFS_SET_MODE); |
| 736 | *bp++ = 0; /* mtime */ |
| 737 | *bp++ = 0; /* owner */ |
| 738 | *bp++ = 0; /* group */ |
| 739 | *bp++ = htonl(mode & S_IALLUGO); /* unix mode */ |
| 740 | *bp++ = 0; /* segment size */ |
| 741 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 742 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /* |
| 746 | * deliver reply data to an FS.RemoveFile or FS.RemoveDir |
| 747 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 748 | static int afs_deliver_fs_remove(struct afs_call *call) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 749 | { |
| 750 | struct afs_vnode *vnode = call->reply; |
| 751 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 752 | int ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 753 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 754 | _enter("{%u}", call->unmarshall); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 755 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 756 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 757 | if (ret < 0) |
| 758 | return ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 759 | |
| 760 | /* unmarshall the reply once we've received all of it */ |
| 761 | bp = call->buffer; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 762 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 763 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
| 764 | |
| 765 | _leave(" = 0 [done]"); |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | /* |
| 770 | * FS.RemoveDir/FS.RemoveFile operation type |
| 771 | */ |
| 772 | static const struct afs_call_type afs_RXFSRemoveXXXX = { |
| 773 | .name = "FS.RemoveXXXX", |
| 774 | .deliver = afs_deliver_fs_remove, |
| 775 | .abort_to_error = afs_abort_to_error, |
| 776 | .destructor = afs_flat_call_destructor, |
| 777 | }; |
| 778 | |
| 779 | /* |
| 780 | * remove a file or directory |
| 781 | */ |
| 782 | int afs_fs_remove(struct afs_server *server, |
| 783 | struct key *key, |
| 784 | struct afs_vnode *vnode, |
| 785 | const char *name, |
| 786 | bool isdir, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 787 | bool async) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 788 | { |
| 789 | struct afs_call *call; |
| 790 | size_t namesz, reqsz, padsz; |
| 791 | __be32 *bp; |
| 792 | |
| 793 | _enter(""); |
| 794 | |
| 795 | namesz = strlen(name); |
| 796 | padsz = (4 - (namesz & 3)) & 3; |
| 797 | reqsz = (5 * 4) + namesz + padsz; |
| 798 | |
| 799 | call = afs_alloc_flat_call(&afs_RXFSRemoveXXXX, reqsz, (21 + 6) * 4); |
| 800 | if (!call) |
| 801 | return -ENOMEM; |
| 802 | |
| 803 | call->key = key; |
| 804 | call->reply = vnode; |
| 805 | call->service_id = FS_SERVICE; |
| 806 | call->port = htons(AFS_FS_PORT); |
| 807 | |
| 808 | /* marshall the parameters */ |
| 809 | bp = call->request; |
| 810 | *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE); |
| 811 | *bp++ = htonl(vnode->fid.vid); |
| 812 | *bp++ = htonl(vnode->fid.vnode); |
| 813 | *bp++ = htonl(vnode->fid.unique); |
| 814 | *bp++ = htonl(namesz); |
| 815 | memcpy(bp, name, namesz); |
| 816 | bp = (void *) bp + namesz; |
| 817 | if (padsz > 0) { |
| 818 | memset(bp, 0, padsz); |
| 819 | bp = (void *) bp + padsz; |
| 820 | } |
| 821 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 822 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | /* |
| 826 | * deliver reply data to an FS.Link |
| 827 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 828 | static int afs_deliver_fs_link(struct afs_call *call) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 829 | { |
| 830 | struct afs_vnode *dvnode = call->reply, *vnode = call->reply2; |
| 831 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 832 | int ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 833 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 834 | _enter("{%u}", call->unmarshall); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 835 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 836 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 837 | if (ret < 0) |
| 838 | return ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 839 | |
| 840 | /* unmarshall the reply once we've received all of it */ |
| 841 | bp = call->buffer; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 842 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
| 843 | xdr_decode_AFSFetchStatus(&bp, &dvnode->status, dvnode, NULL); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 844 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
| 845 | |
| 846 | _leave(" = 0 [done]"); |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * FS.Link operation type |
| 852 | */ |
| 853 | static const struct afs_call_type afs_RXFSLink = { |
| 854 | .name = "FS.Link", |
| 855 | .deliver = afs_deliver_fs_link, |
| 856 | .abort_to_error = afs_abort_to_error, |
| 857 | .destructor = afs_flat_call_destructor, |
| 858 | }; |
| 859 | |
| 860 | /* |
| 861 | * make a hard link |
| 862 | */ |
| 863 | int afs_fs_link(struct afs_server *server, |
| 864 | struct key *key, |
| 865 | struct afs_vnode *dvnode, |
| 866 | struct afs_vnode *vnode, |
| 867 | const char *name, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 868 | bool async) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 869 | { |
| 870 | struct afs_call *call; |
| 871 | size_t namesz, reqsz, padsz; |
| 872 | __be32 *bp; |
| 873 | |
| 874 | _enter(""); |
| 875 | |
| 876 | namesz = strlen(name); |
| 877 | padsz = (4 - (namesz & 3)) & 3; |
| 878 | reqsz = (5 * 4) + namesz + padsz + (3 * 4); |
| 879 | |
| 880 | call = afs_alloc_flat_call(&afs_RXFSLink, reqsz, (21 + 21 + 6) * 4); |
| 881 | if (!call) |
| 882 | return -ENOMEM; |
| 883 | |
| 884 | call->key = key; |
| 885 | call->reply = dvnode; |
| 886 | call->reply2 = vnode; |
| 887 | call->service_id = FS_SERVICE; |
| 888 | call->port = htons(AFS_FS_PORT); |
| 889 | |
| 890 | /* marshall the parameters */ |
| 891 | bp = call->request; |
| 892 | *bp++ = htonl(FSLINK); |
| 893 | *bp++ = htonl(dvnode->fid.vid); |
| 894 | *bp++ = htonl(dvnode->fid.vnode); |
| 895 | *bp++ = htonl(dvnode->fid.unique); |
| 896 | *bp++ = htonl(namesz); |
| 897 | memcpy(bp, name, namesz); |
| 898 | bp = (void *) bp + namesz; |
| 899 | if (padsz > 0) { |
| 900 | memset(bp, 0, padsz); |
| 901 | bp = (void *) bp + padsz; |
| 902 | } |
| 903 | *bp++ = htonl(vnode->fid.vid); |
| 904 | *bp++ = htonl(vnode->fid.vnode); |
| 905 | *bp++ = htonl(vnode->fid.unique); |
| 906 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 907 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /* |
| 911 | * deliver reply data to an FS.Symlink |
| 912 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 913 | static int afs_deliver_fs_symlink(struct afs_call *call) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 914 | { |
| 915 | struct afs_vnode *vnode = call->reply; |
| 916 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 917 | int ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 918 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 919 | _enter("{%u}", call->unmarshall); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 920 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 921 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 922 | if (ret < 0) |
| 923 | return ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 924 | |
| 925 | /* unmarshall the reply once we've received all of it */ |
| 926 | bp = call->buffer; |
| 927 | xdr_decode_AFSFid(&bp, call->reply2); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 928 | xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL, NULL); |
| 929 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 930 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
| 931 | |
| 932 | _leave(" = 0 [done]"); |
| 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | /* |
| 937 | * FS.Symlink operation type |
| 938 | */ |
| 939 | static const struct afs_call_type afs_RXFSSymlink = { |
| 940 | .name = "FS.Symlink", |
| 941 | .deliver = afs_deliver_fs_symlink, |
| 942 | .abort_to_error = afs_abort_to_error, |
| 943 | .destructor = afs_flat_call_destructor, |
| 944 | }; |
| 945 | |
| 946 | /* |
| 947 | * create a symbolic link |
| 948 | */ |
| 949 | int afs_fs_symlink(struct afs_server *server, |
| 950 | struct key *key, |
| 951 | struct afs_vnode *vnode, |
| 952 | const char *name, |
| 953 | const char *contents, |
| 954 | struct afs_fid *newfid, |
| 955 | struct afs_file_status *newstatus, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 956 | bool async) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 957 | { |
| 958 | struct afs_call *call; |
| 959 | size_t namesz, reqsz, padsz, c_namesz, c_padsz; |
| 960 | __be32 *bp; |
| 961 | |
| 962 | _enter(""); |
| 963 | |
| 964 | namesz = strlen(name); |
| 965 | padsz = (4 - (namesz & 3)) & 3; |
| 966 | |
| 967 | c_namesz = strlen(contents); |
| 968 | c_padsz = (4 - (c_namesz & 3)) & 3; |
| 969 | |
| 970 | reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4); |
| 971 | |
| 972 | call = afs_alloc_flat_call(&afs_RXFSSymlink, reqsz, |
| 973 | (3 + 21 + 21 + 6) * 4); |
| 974 | if (!call) |
| 975 | return -ENOMEM; |
| 976 | |
| 977 | call->key = key; |
| 978 | call->reply = vnode; |
| 979 | call->reply2 = newfid; |
| 980 | call->reply3 = newstatus; |
| 981 | call->service_id = FS_SERVICE; |
| 982 | call->port = htons(AFS_FS_PORT); |
| 983 | |
| 984 | /* marshall the parameters */ |
| 985 | bp = call->request; |
| 986 | *bp++ = htonl(FSSYMLINK); |
| 987 | *bp++ = htonl(vnode->fid.vid); |
| 988 | *bp++ = htonl(vnode->fid.vnode); |
| 989 | *bp++ = htonl(vnode->fid.unique); |
| 990 | *bp++ = htonl(namesz); |
| 991 | memcpy(bp, name, namesz); |
| 992 | bp = (void *) bp + namesz; |
| 993 | if (padsz > 0) { |
| 994 | memset(bp, 0, padsz); |
| 995 | bp = (void *) bp + padsz; |
| 996 | } |
| 997 | *bp++ = htonl(c_namesz); |
| 998 | memcpy(bp, contents, c_namesz); |
| 999 | bp = (void *) bp + c_namesz; |
| 1000 | if (c_padsz > 0) { |
| 1001 | memset(bp, 0, c_padsz); |
| 1002 | bp = (void *) bp + c_padsz; |
| 1003 | } |
| 1004 | *bp++ = htonl(AFS_SET_MODE); |
| 1005 | *bp++ = 0; /* mtime */ |
| 1006 | *bp++ = 0; /* owner */ |
| 1007 | *bp++ = 0; /* group */ |
| 1008 | *bp++ = htonl(S_IRWXUGO); /* unix mode */ |
| 1009 | *bp++ = 0; /* segment size */ |
| 1010 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1011 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | * deliver reply data to an FS.Rename |
| 1016 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1017 | static int afs_deliver_fs_rename(struct afs_call *call) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1018 | { |
| 1019 | struct afs_vnode *orig_dvnode = call->reply, *new_dvnode = call->reply2; |
| 1020 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1021 | int ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1022 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1023 | _enter("{%u}", call->unmarshall); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1024 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1025 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1026 | if (ret < 0) |
| 1027 | return ret; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1028 | |
| 1029 | /* unmarshall the reply once we've received all of it */ |
| 1030 | bp = call->buffer; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1031 | xdr_decode_AFSFetchStatus(&bp, &orig_dvnode->status, orig_dvnode, NULL); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1032 | if (new_dvnode != orig_dvnode) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1033 | xdr_decode_AFSFetchStatus(&bp, &new_dvnode->status, new_dvnode, |
| 1034 | NULL); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1035 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
| 1036 | |
| 1037 | _leave(" = 0 [done]"); |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | /* |
| 1042 | * FS.Rename operation type |
| 1043 | */ |
| 1044 | static const struct afs_call_type afs_RXFSRename = { |
| 1045 | .name = "FS.Rename", |
| 1046 | .deliver = afs_deliver_fs_rename, |
| 1047 | .abort_to_error = afs_abort_to_error, |
| 1048 | .destructor = afs_flat_call_destructor, |
| 1049 | }; |
| 1050 | |
| 1051 | /* |
| 1052 | * create a symbolic link |
| 1053 | */ |
| 1054 | int afs_fs_rename(struct afs_server *server, |
| 1055 | struct key *key, |
| 1056 | struct afs_vnode *orig_dvnode, |
| 1057 | const char *orig_name, |
| 1058 | struct afs_vnode *new_dvnode, |
| 1059 | const char *new_name, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1060 | bool async) |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1061 | { |
| 1062 | struct afs_call *call; |
| 1063 | size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz; |
| 1064 | __be32 *bp; |
| 1065 | |
| 1066 | _enter(""); |
| 1067 | |
| 1068 | o_namesz = strlen(orig_name); |
| 1069 | o_padsz = (4 - (o_namesz & 3)) & 3; |
| 1070 | |
| 1071 | n_namesz = strlen(new_name); |
| 1072 | n_padsz = (4 - (n_namesz & 3)) & 3; |
| 1073 | |
| 1074 | reqsz = (4 * 4) + |
| 1075 | 4 + o_namesz + o_padsz + |
| 1076 | (3 * 4) + |
| 1077 | 4 + n_namesz + n_padsz; |
| 1078 | |
| 1079 | call = afs_alloc_flat_call(&afs_RXFSRename, reqsz, (21 + 21 + 6) * 4); |
| 1080 | if (!call) |
| 1081 | return -ENOMEM; |
| 1082 | |
| 1083 | call->key = key; |
| 1084 | call->reply = orig_dvnode; |
| 1085 | call->reply2 = new_dvnode; |
| 1086 | call->service_id = FS_SERVICE; |
| 1087 | call->port = htons(AFS_FS_PORT); |
| 1088 | |
| 1089 | /* marshall the parameters */ |
| 1090 | bp = call->request; |
| 1091 | *bp++ = htonl(FSRENAME); |
| 1092 | *bp++ = htonl(orig_dvnode->fid.vid); |
| 1093 | *bp++ = htonl(orig_dvnode->fid.vnode); |
| 1094 | *bp++ = htonl(orig_dvnode->fid.unique); |
| 1095 | *bp++ = htonl(o_namesz); |
| 1096 | memcpy(bp, orig_name, o_namesz); |
| 1097 | bp = (void *) bp + o_namesz; |
| 1098 | if (o_padsz > 0) { |
| 1099 | memset(bp, 0, o_padsz); |
| 1100 | bp = (void *) bp + o_padsz; |
| 1101 | } |
| 1102 | |
| 1103 | *bp++ = htonl(new_dvnode->fid.vid); |
| 1104 | *bp++ = htonl(new_dvnode->fid.vnode); |
| 1105 | *bp++ = htonl(new_dvnode->fid.unique); |
| 1106 | *bp++ = htonl(n_namesz); |
| 1107 | memcpy(bp, new_name, n_namesz); |
| 1108 | bp = (void *) bp + n_namesz; |
| 1109 | if (n_padsz > 0) { |
| 1110 | memset(bp, 0, n_padsz); |
| 1111 | bp = (void *) bp + n_padsz; |
| 1112 | } |
| 1113 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1114 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 1115 | } |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1116 | |
| 1117 | /* |
| 1118 | * deliver reply data to an FS.StoreData |
| 1119 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1120 | static int afs_deliver_fs_store_data(struct afs_call *call) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1121 | { |
| 1122 | struct afs_vnode *vnode = call->reply; |
| 1123 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1124 | int ret; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1125 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1126 | _enter(""); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1127 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1128 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1129 | if (ret < 0) |
| 1130 | return ret; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1131 | |
| 1132 | /* unmarshall the reply once we've received all of it */ |
| 1133 | bp = call->buffer; |
| 1134 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, |
| 1135 | &call->store_version); |
| 1136 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
| 1137 | |
| 1138 | afs_pages_written_back(vnode, call); |
| 1139 | |
| 1140 | _leave(" = 0 [done]"); |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | /* |
| 1145 | * FS.StoreData operation type |
| 1146 | */ |
| 1147 | static const struct afs_call_type afs_RXFSStoreData = { |
| 1148 | .name = "FS.StoreData", |
| 1149 | .deliver = afs_deliver_fs_store_data, |
| 1150 | .abort_to_error = afs_abort_to_error, |
| 1151 | .destructor = afs_flat_call_destructor, |
| 1152 | }; |
| 1153 | |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1154 | static const struct afs_call_type afs_RXFSStoreData64 = { |
| 1155 | .name = "FS.StoreData64", |
| 1156 | .deliver = afs_deliver_fs_store_data, |
| 1157 | .abort_to_error = afs_abort_to_error, |
| 1158 | .destructor = afs_flat_call_destructor, |
| 1159 | }; |
| 1160 | |
| 1161 | /* |
| 1162 | * store a set of pages to a very large file |
| 1163 | */ |
| 1164 | static int afs_fs_store_data64(struct afs_server *server, |
| 1165 | struct afs_writeback *wb, |
| 1166 | pgoff_t first, pgoff_t last, |
| 1167 | unsigned offset, unsigned to, |
| 1168 | loff_t size, loff_t pos, loff_t i_size, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1169 | bool async) |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1170 | { |
| 1171 | struct afs_vnode *vnode = wb->vnode; |
| 1172 | struct afs_call *call; |
| 1173 | __be32 *bp; |
| 1174 | |
| 1175 | _enter(",%x,{%x:%u},,", |
| 1176 | key_serial(wb->key), vnode->fid.vid, vnode->fid.vnode); |
| 1177 | |
| 1178 | call = afs_alloc_flat_call(&afs_RXFSStoreData64, |
| 1179 | (4 + 6 + 3 * 2) * 4, |
| 1180 | (21 + 6) * 4); |
| 1181 | if (!call) |
| 1182 | return -ENOMEM; |
| 1183 | |
| 1184 | call->wb = wb; |
| 1185 | call->key = wb->key; |
| 1186 | call->reply = vnode; |
| 1187 | call->service_id = FS_SERVICE; |
| 1188 | call->port = htons(AFS_FS_PORT); |
| 1189 | call->mapping = vnode->vfs_inode.i_mapping; |
| 1190 | call->first = first; |
| 1191 | call->last = last; |
| 1192 | call->first_offset = offset; |
| 1193 | call->last_to = to; |
| 1194 | call->send_pages = true; |
| 1195 | call->store_version = vnode->status.data_version + 1; |
| 1196 | |
| 1197 | /* marshall the parameters */ |
| 1198 | bp = call->request; |
| 1199 | *bp++ = htonl(FSSTOREDATA64); |
| 1200 | *bp++ = htonl(vnode->fid.vid); |
| 1201 | *bp++ = htonl(vnode->fid.vnode); |
| 1202 | *bp++ = htonl(vnode->fid.unique); |
| 1203 | |
| 1204 | *bp++ = 0; /* mask */ |
| 1205 | *bp++ = 0; /* mtime */ |
| 1206 | *bp++ = 0; /* owner */ |
| 1207 | *bp++ = 0; /* group */ |
| 1208 | *bp++ = 0; /* unix mode */ |
| 1209 | *bp++ = 0; /* segment size */ |
| 1210 | |
| 1211 | *bp++ = htonl(pos >> 32); |
| 1212 | *bp++ = htonl((u32) pos); |
| 1213 | *bp++ = htonl(size >> 32); |
| 1214 | *bp++ = htonl((u32) size); |
| 1215 | *bp++ = htonl(i_size >> 32); |
| 1216 | *bp++ = htonl((u32) i_size); |
| 1217 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1218 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1221 | /* |
| 1222 | * store a set of pages |
| 1223 | */ |
| 1224 | int afs_fs_store_data(struct afs_server *server, struct afs_writeback *wb, |
| 1225 | pgoff_t first, pgoff_t last, |
| 1226 | unsigned offset, unsigned to, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1227 | bool async) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1228 | { |
| 1229 | struct afs_vnode *vnode = wb->vnode; |
| 1230 | struct afs_call *call; |
| 1231 | loff_t size, pos, i_size; |
| 1232 | __be32 *bp; |
| 1233 | |
| 1234 | _enter(",%x,{%x:%u},,", |
| 1235 | key_serial(wb->key), vnode->fid.vid, vnode->fid.vnode); |
| 1236 | |
| 1237 | size = to - offset; |
| 1238 | if (first != last) |
| 1239 | size += (loff_t)(last - first) << PAGE_SHIFT; |
| 1240 | pos = (loff_t)first << PAGE_SHIFT; |
| 1241 | pos += offset; |
| 1242 | |
| 1243 | i_size = i_size_read(&vnode->vfs_inode); |
| 1244 | if (pos + size > i_size) |
| 1245 | i_size = size + pos; |
| 1246 | |
| 1247 | _debug("size %llx, at %llx, i_size %llx", |
| 1248 | (unsigned long long) size, (unsigned long long) pos, |
| 1249 | (unsigned long long) i_size); |
| 1250 | |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1251 | if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32) |
| 1252 | return afs_fs_store_data64(server, wb, first, last, offset, to, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1253 | size, pos, i_size, async); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1254 | |
| 1255 | call = afs_alloc_flat_call(&afs_RXFSStoreData, |
| 1256 | (4 + 6 + 3) * 4, |
| 1257 | (21 + 6) * 4); |
| 1258 | if (!call) |
| 1259 | return -ENOMEM; |
| 1260 | |
| 1261 | call->wb = wb; |
| 1262 | call->key = wb->key; |
| 1263 | call->reply = vnode; |
| 1264 | call->service_id = FS_SERVICE; |
| 1265 | call->port = htons(AFS_FS_PORT); |
| 1266 | call->mapping = vnode->vfs_inode.i_mapping; |
| 1267 | call->first = first; |
| 1268 | call->last = last; |
| 1269 | call->first_offset = offset; |
| 1270 | call->last_to = to; |
| 1271 | call->send_pages = true; |
| 1272 | call->store_version = vnode->status.data_version + 1; |
| 1273 | |
| 1274 | /* marshall the parameters */ |
| 1275 | bp = call->request; |
| 1276 | *bp++ = htonl(FSSTOREDATA); |
| 1277 | *bp++ = htonl(vnode->fid.vid); |
| 1278 | *bp++ = htonl(vnode->fid.vnode); |
| 1279 | *bp++ = htonl(vnode->fid.unique); |
| 1280 | |
| 1281 | *bp++ = 0; /* mask */ |
| 1282 | *bp++ = 0; /* mtime */ |
| 1283 | *bp++ = 0; /* owner */ |
| 1284 | *bp++ = 0; /* group */ |
| 1285 | *bp++ = 0; /* unix mode */ |
| 1286 | *bp++ = 0; /* segment size */ |
| 1287 | |
| 1288 | *bp++ = htonl(pos); |
| 1289 | *bp++ = htonl(size); |
| 1290 | *bp++ = htonl(i_size); |
| 1291 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1292 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | /* |
| 1296 | * deliver reply data to an FS.StoreStatus |
| 1297 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1298 | static int afs_deliver_fs_store_status(struct afs_call *call) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1299 | { |
| 1300 | afs_dataversion_t *store_version; |
| 1301 | struct afs_vnode *vnode = call->reply; |
| 1302 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1303 | int ret; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1304 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1305 | _enter(""); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1306 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1307 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1308 | if (ret < 0) |
| 1309 | return ret; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1310 | |
| 1311 | /* unmarshall the reply once we've received all of it */ |
| 1312 | store_version = NULL; |
| 1313 | if (call->operation_ID == FSSTOREDATA) |
| 1314 | store_version = &call->store_version; |
| 1315 | |
| 1316 | bp = call->buffer; |
| 1317 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, store_version); |
| 1318 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
| 1319 | |
| 1320 | _leave(" = 0 [done]"); |
| 1321 | return 0; |
| 1322 | } |
| 1323 | |
| 1324 | /* |
| 1325 | * FS.StoreStatus operation type |
| 1326 | */ |
| 1327 | static const struct afs_call_type afs_RXFSStoreStatus = { |
| 1328 | .name = "FS.StoreStatus", |
| 1329 | .deliver = afs_deliver_fs_store_status, |
| 1330 | .abort_to_error = afs_abort_to_error, |
| 1331 | .destructor = afs_flat_call_destructor, |
| 1332 | }; |
| 1333 | |
| 1334 | static const struct afs_call_type afs_RXFSStoreData_as_Status = { |
| 1335 | .name = "FS.StoreData", |
| 1336 | .deliver = afs_deliver_fs_store_status, |
| 1337 | .abort_to_error = afs_abort_to_error, |
| 1338 | .destructor = afs_flat_call_destructor, |
| 1339 | }; |
| 1340 | |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1341 | static const struct afs_call_type afs_RXFSStoreData64_as_Status = { |
| 1342 | .name = "FS.StoreData64", |
| 1343 | .deliver = afs_deliver_fs_store_status, |
| 1344 | .abort_to_error = afs_abort_to_error, |
| 1345 | .destructor = afs_flat_call_destructor, |
| 1346 | }; |
| 1347 | |
| 1348 | /* |
| 1349 | * set the attributes on a very large file, using FS.StoreData rather than |
| 1350 | * FS.StoreStatus so as to alter the file size also |
| 1351 | */ |
| 1352 | static int afs_fs_setattr_size64(struct afs_server *server, struct key *key, |
| 1353 | struct afs_vnode *vnode, struct iattr *attr, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1354 | bool async) |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1355 | { |
| 1356 | struct afs_call *call; |
| 1357 | __be32 *bp; |
| 1358 | |
| 1359 | _enter(",%x,{%x:%u},,", |
| 1360 | key_serial(key), vnode->fid.vid, vnode->fid.vnode); |
| 1361 | |
| 1362 | ASSERT(attr->ia_valid & ATTR_SIZE); |
| 1363 | |
| 1364 | call = afs_alloc_flat_call(&afs_RXFSStoreData64_as_Status, |
| 1365 | (4 + 6 + 3 * 2) * 4, |
| 1366 | (21 + 6) * 4); |
| 1367 | if (!call) |
| 1368 | return -ENOMEM; |
| 1369 | |
| 1370 | call->key = key; |
| 1371 | call->reply = vnode; |
| 1372 | call->service_id = FS_SERVICE; |
| 1373 | call->port = htons(AFS_FS_PORT); |
| 1374 | call->store_version = vnode->status.data_version + 1; |
| 1375 | call->operation_ID = FSSTOREDATA; |
| 1376 | |
| 1377 | /* marshall the parameters */ |
| 1378 | bp = call->request; |
| 1379 | *bp++ = htonl(FSSTOREDATA64); |
| 1380 | *bp++ = htonl(vnode->fid.vid); |
| 1381 | *bp++ = htonl(vnode->fid.vnode); |
| 1382 | *bp++ = htonl(vnode->fid.unique); |
| 1383 | |
| 1384 | xdr_encode_AFS_StoreStatus(&bp, attr); |
| 1385 | |
| 1386 | *bp++ = 0; /* position of start of write */ |
| 1387 | *bp++ = 0; |
| 1388 | *bp++ = 0; /* size of write */ |
| 1389 | *bp++ = 0; |
| 1390 | *bp++ = htonl(attr->ia_size >> 32); /* new file length */ |
| 1391 | *bp++ = htonl((u32) attr->ia_size); |
| 1392 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1393 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1396 | /* |
| 1397 | * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus |
| 1398 | * so as to alter the file size also |
| 1399 | */ |
| 1400 | static int afs_fs_setattr_size(struct afs_server *server, struct key *key, |
| 1401 | struct afs_vnode *vnode, struct iattr *attr, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1402 | bool async) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1403 | { |
| 1404 | struct afs_call *call; |
| 1405 | __be32 *bp; |
| 1406 | |
| 1407 | _enter(",%x,{%x:%u},,", |
| 1408 | key_serial(key), vnode->fid.vid, vnode->fid.vnode); |
| 1409 | |
| 1410 | ASSERT(attr->ia_valid & ATTR_SIZE); |
David Howells | b9b1f8d | 2007-05-10 03:15:21 -0700 | [diff] [blame] | 1411 | if (attr->ia_size >> 32) |
| 1412 | return afs_fs_setattr_size64(server, key, vnode, attr, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1413 | async); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1414 | |
| 1415 | call = afs_alloc_flat_call(&afs_RXFSStoreData_as_Status, |
| 1416 | (4 + 6 + 3) * 4, |
| 1417 | (21 + 6) * 4); |
| 1418 | if (!call) |
| 1419 | return -ENOMEM; |
| 1420 | |
| 1421 | call->key = key; |
| 1422 | call->reply = vnode; |
| 1423 | call->service_id = FS_SERVICE; |
| 1424 | call->port = htons(AFS_FS_PORT); |
| 1425 | call->store_version = vnode->status.data_version + 1; |
| 1426 | call->operation_ID = FSSTOREDATA; |
| 1427 | |
| 1428 | /* marshall the parameters */ |
| 1429 | bp = call->request; |
| 1430 | *bp++ = htonl(FSSTOREDATA); |
| 1431 | *bp++ = htonl(vnode->fid.vid); |
| 1432 | *bp++ = htonl(vnode->fid.vnode); |
| 1433 | *bp++ = htonl(vnode->fid.unique); |
| 1434 | |
| 1435 | xdr_encode_AFS_StoreStatus(&bp, attr); |
| 1436 | |
| 1437 | *bp++ = 0; /* position of start of write */ |
| 1438 | *bp++ = 0; /* size of write */ |
| 1439 | *bp++ = htonl(attr->ia_size); /* new file length */ |
| 1440 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1441 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | /* |
| 1445 | * set the attributes on a file, using FS.StoreData if there's a change in file |
| 1446 | * size, and FS.StoreStatus otherwise |
| 1447 | */ |
| 1448 | int afs_fs_setattr(struct afs_server *server, struct key *key, |
| 1449 | struct afs_vnode *vnode, struct iattr *attr, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1450 | bool async) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1451 | { |
| 1452 | struct afs_call *call; |
| 1453 | __be32 *bp; |
| 1454 | |
| 1455 | if (attr->ia_valid & ATTR_SIZE) |
| 1456 | return afs_fs_setattr_size(server, key, vnode, attr, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1457 | async); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1458 | |
| 1459 | _enter(",%x,{%x:%u},,", |
| 1460 | key_serial(key), vnode->fid.vid, vnode->fid.vnode); |
| 1461 | |
| 1462 | call = afs_alloc_flat_call(&afs_RXFSStoreStatus, |
| 1463 | (4 + 6) * 4, |
| 1464 | (21 + 6) * 4); |
| 1465 | if (!call) |
| 1466 | return -ENOMEM; |
| 1467 | |
| 1468 | call->key = key; |
| 1469 | call->reply = vnode; |
| 1470 | call->service_id = FS_SERVICE; |
| 1471 | call->port = htons(AFS_FS_PORT); |
| 1472 | call->operation_ID = FSSTORESTATUS; |
| 1473 | |
| 1474 | /* marshall the parameters */ |
| 1475 | bp = call->request; |
| 1476 | *bp++ = htonl(FSSTORESTATUS); |
| 1477 | *bp++ = htonl(vnode->fid.vid); |
| 1478 | *bp++ = htonl(vnode->fid.vnode); |
| 1479 | *bp++ = htonl(vnode->fid.unique); |
| 1480 | |
| 1481 | xdr_encode_AFS_StoreStatus(&bp, attr); |
| 1482 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1483 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 1484 | } |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1485 | |
| 1486 | /* |
| 1487 | * deliver reply data to an FS.GetVolumeStatus |
| 1488 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1489 | static int afs_deliver_fs_get_volume_status(struct afs_call *call) |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1490 | { |
| 1491 | const __be32 *bp; |
| 1492 | char *p; |
| 1493 | int ret; |
| 1494 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1495 | _enter("{%u}", call->unmarshall); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1496 | |
| 1497 | switch (call->unmarshall) { |
| 1498 | case 0: |
| 1499 | call->offset = 0; |
| 1500 | call->unmarshall++; |
| 1501 | |
| 1502 | /* extract the returned status record */ |
| 1503 | case 1: |
| 1504 | _debug("extract status"); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1505 | ret = afs_extract_data(call, call->buffer, |
| 1506 | 12 * 4, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1507 | if (ret < 0) |
| 1508 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1509 | |
| 1510 | bp = call->buffer; |
| 1511 | xdr_decode_AFSFetchVolumeStatus(&bp, call->reply2); |
| 1512 | call->offset = 0; |
| 1513 | call->unmarshall++; |
| 1514 | |
| 1515 | /* extract the volume name length */ |
| 1516 | case 2: |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1517 | ret = afs_extract_data(call, &call->tmp, 4, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1518 | if (ret < 0) |
| 1519 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1520 | |
| 1521 | call->count = ntohl(call->tmp); |
| 1522 | _debug("volname length: %u", call->count); |
| 1523 | if (call->count >= AFSNAMEMAX) |
| 1524 | return -EBADMSG; |
| 1525 | call->offset = 0; |
| 1526 | call->unmarshall++; |
| 1527 | |
| 1528 | /* extract the volume name */ |
| 1529 | case 3: |
| 1530 | _debug("extract volname"); |
| 1531 | if (call->count > 0) { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1532 | ret = afs_extract_data(call, call->reply3, |
| 1533 | call->count, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1534 | if (ret < 0) |
| 1535 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | p = call->reply3; |
| 1539 | p[call->count] = 0; |
| 1540 | _debug("volname '%s'", p); |
| 1541 | |
| 1542 | call->offset = 0; |
| 1543 | call->unmarshall++; |
| 1544 | |
| 1545 | /* extract the volume name padding */ |
| 1546 | if ((call->count & 3) == 0) { |
| 1547 | call->unmarshall++; |
| 1548 | goto no_volname_padding; |
| 1549 | } |
| 1550 | call->count = 4 - (call->count & 3); |
| 1551 | |
| 1552 | case 4: |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1553 | ret = afs_extract_data(call, call->buffer, |
| 1554 | call->count, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1555 | if (ret < 0) |
| 1556 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1557 | |
| 1558 | call->offset = 0; |
| 1559 | call->unmarshall++; |
| 1560 | no_volname_padding: |
| 1561 | |
| 1562 | /* extract the offline message length */ |
| 1563 | case 5: |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1564 | ret = afs_extract_data(call, &call->tmp, 4, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1565 | if (ret < 0) |
| 1566 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1567 | |
| 1568 | call->count = ntohl(call->tmp); |
| 1569 | _debug("offline msg length: %u", call->count); |
| 1570 | if (call->count >= AFSNAMEMAX) |
| 1571 | return -EBADMSG; |
| 1572 | call->offset = 0; |
| 1573 | call->unmarshall++; |
| 1574 | |
| 1575 | /* extract the offline message */ |
| 1576 | case 6: |
| 1577 | _debug("extract offline"); |
| 1578 | if (call->count > 0) { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1579 | ret = afs_extract_data(call, call->reply3, |
| 1580 | call->count, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1581 | if (ret < 0) |
| 1582 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | p = call->reply3; |
| 1586 | p[call->count] = 0; |
| 1587 | _debug("offline '%s'", p); |
| 1588 | |
| 1589 | call->offset = 0; |
| 1590 | call->unmarshall++; |
| 1591 | |
| 1592 | /* extract the offline message padding */ |
| 1593 | if ((call->count & 3) == 0) { |
| 1594 | call->unmarshall++; |
| 1595 | goto no_offline_padding; |
| 1596 | } |
| 1597 | call->count = 4 - (call->count & 3); |
| 1598 | |
| 1599 | case 7: |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1600 | ret = afs_extract_data(call, call->buffer, |
| 1601 | call->count, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1602 | if (ret < 0) |
| 1603 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1604 | |
| 1605 | call->offset = 0; |
| 1606 | call->unmarshall++; |
| 1607 | no_offline_padding: |
| 1608 | |
| 1609 | /* extract the message of the day length */ |
| 1610 | case 8: |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1611 | ret = afs_extract_data(call, &call->tmp, 4, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1612 | if (ret < 0) |
| 1613 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1614 | |
| 1615 | call->count = ntohl(call->tmp); |
| 1616 | _debug("motd length: %u", call->count); |
| 1617 | if (call->count >= AFSNAMEMAX) |
| 1618 | return -EBADMSG; |
| 1619 | call->offset = 0; |
| 1620 | call->unmarshall++; |
| 1621 | |
| 1622 | /* extract the message of the day */ |
| 1623 | case 9: |
| 1624 | _debug("extract motd"); |
| 1625 | if (call->count > 0) { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1626 | ret = afs_extract_data(call, call->reply3, |
| 1627 | call->count, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1628 | if (ret < 0) |
| 1629 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | p = call->reply3; |
| 1633 | p[call->count] = 0; |
| 1634 | _debug("motd '%s'", p); |
| 1635 | |
| 1636 | call->offset = 0; |
| 1637 | call->unmarshall++; |
| 1638 | |
| 1639 | /* extract the message of the day padding */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1640 | call->count = (4 - (call->count & 3)) & 3; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1641 | |
| 1642 | case 10: |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1643 | ret = afs_extract_data(call, call->buffer, |
| 1644 | call->count, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1645 | if (ret < 0) |
| 1646 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1647 | |
| 1648 | call->offset = 0; |
| 1649 | call->unmarshall++; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1650 | case 11: |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1651 | break; |
| 1652 | } |
| 1653 | |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1654 | _leave(" = 0 [done]"); |
| 1655 | return 0; |
| 1656 | } |
| 1657 | |
| 1658 | /* |
| 1659 | * destroy an FS.GetVolumeStatus call |
| 1660 | */ |
| 1661 | static void afs_get_volume_status_call_destructor(struct afs_call *call) |
| 1662 | { |
| 1663 | kfree(call->reply3); |
| 1664 | call->reply3 = NULL; |
| 1665 | afs_flat_call_destructor(call); |
| 1666 | } |
| 1667 | |
| 1668 | /* |
| 1669 | * FS.GetVolumeStatus operation type |
| 1670 | */ |
| 1671 | static const struct afs_call_type afs_RXFSGetVolumeStatus = { |
| 1672 | .name = "FS.GetVolumeStatus", |
| 1673 | .deliver = afs_deliver_fs_get_volume_status, |
| 1674 | .abort_to_error = afs_abort_to_error, |
| 1675 | .destructor = afs_get_volume_status_call_destructor, |
| 1676 | }; |
| 1677 | |
| 1678 | /* |
| 1679 | * fetch the status of a volume |
| 1680 | */ |
| 1681 | int afs_fs_get_volume_status(struct afs_server *server, |
| 1682 | struct key *key, |
| 1683 | struct afs_vnode *vnode, |
| 1684 | struct afs_volume_status *vs, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1685 | bool async) |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1686 | { |
| 1687 | struct afs_call *call; |
| 1688 | __be32 *bp; |
| 1689 | void *tmpbuf; |
| 1690 | |
| 1691 | _enter(""); |
| 1692 | |
| 1693 | tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL); |
| 1694 | if (!tmpbuf) |
| 1695 | return -ENOMEM; |
| 1696 | |
| 1697 | call = afs_alloc_flat_call(&afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4); |
| 1698 | if (!call) { |
| 1699 | kfree(tmpbuf); |
| 1700 | return -ENOMEM; |
| 1701 | } |
| 1702 | |
| 1703 | call->key = key; |
| 1704 | call->reply = vnode; |
| 1705 | call->reply2 = vs; |
| 1706 | call->reply3 = tmpbuf; |
| 1707 | call->service_id = FS_SERVICE; |
| 1708 | call->port = htons(AFS_FS_PORT); |
| 1709 | |
| 1710 | /* marshall the parameters */ |
| 1711 | bp = call->request; |
| 1712 | bp[0] = htonl(FSGETVOLUMESTATUS); |
| 1713 | bp[1] = htonl(vnode->fid.vid); |
| 1714 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1715 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 1716 | } |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1717 | |
| 1718 | /* |
| 1719 | * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock |
| 1720 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1721 | static int afs_deliver_fs_xxxx_lock(struct afs_call *call) |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1722 | { |
| 1723 | const __be32 *bp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1724 | int ret; |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1725 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1726 | _enter("{%u}", call->unmarshall); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1727 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 1728 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 1729 | if (ret < 0) |
| 1730 | return ret; |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1731 | |
| 1732 | /* unmarshall the reply once we've received all of it */ |
| 1733 | bp = call->buffer; |
| 1734 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
| 1735 | |
| 1736 | _leave(" = 0 [done]"); |
| 1737 | return 0; |
| 1738 | } |
| 1739 | |
| 1740 | /* |
| 1741 | * FS.SetLock operation type |
| 1742 | */ |
| 1743 | static const struct afs_call_type afs_RXFSSetLock = { |
| 1744 | .name = "FS.SetLock", |
| 1745 | .deliver = afs_deliver_fs_xxxx_lock, |
| 1746 | .abort_to_error = afs_abort_to_error, |
| 1747 | .destructor = afs_flat_call_destructor, |
| 1748 | }; |
| 1749 | |
| 1750 | /* |
| 1751 | * FS.ExtendLock operation type |
| 1752 | */ |
| 1753 | static const struct afs_call_type afs_RXFSExtendLock = { |
| 1754 | .name = "FS.ExtendLock", |
| 1755 | .deliver = afs_deliver_fs_xxxx_lock, |
| 1756 | .abort_to_error = afs_abort_to_error, |
| 1757 | .destructor = afs_flat_call_destructor, |
| 1758 | }; |
| 1759 | |
| 1760 | /* |
| 1761 | * FS.ReleaseLock operation type |
| 1762 | */ |
| 1763 | static const struct afs_call_type afs_RXFSReleaseLock = { |
| 1764 | .name = "FS.ReleaseLock", |
| 1765 | .deliver = afs_deliver_fs_xxxx_lock, |
| 1766 | .abort_to_error = afs_abort_to_error, |
| 1767 | .destructor = afs_flat_call_destructor, |
| 1768 | }; |
| 1769 | |
| 1770 | /* |
| 1771 | * get a lock on a file |
| 1772 | */ |
| 1773 | int afs_fs_set_lock(struct afs_server *server, |
| 1774 | struct key *key, |
| 1775 | struct afs_vnode *vnode, |
| 1776 | afs_lock_type_t type, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1777 | bool async) |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1778 | { |
| 1779 | struct afs_call *call; |
| 1780 | __be32 *bp; |
| 1781 | |
| 1782 | _enter(""); |
| 1783 | |
| 1784 | call = afs_alloc_flat_call(&afs_RXFSSetLock, 5 * 4, 6 * 4); |
| 1785 | if (!call) |
| 1786 | return -ENOMEM; |
| 1787 | |
| 1788 | call->key = key; |
| 1789 | call->reply = vnode; |
| 1790 | call->service_id = FS_SERVICE; |
| 1791 | call->port = htons(AFS_FS_PORT); |
| 1792 | |
| 1793 | /* marshall the parameters */ |
| 1794 | bp = call->request; |
| 1795 | *bp++ = htonl(FSSETLOCK); |
| 1796 | *bp++ = htonl(vnode->fid.vid); |
| 1797 | *bp++ = htonl(vnode->fid.vnode); |
| 1798 | *bp++ = htonl(vnode->fid.unique); |
| 1799 | *bp++ = htonl(type); |
| 1800 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1801 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | /* |
| 1805 | * extend a lock on a file |
| 1806 | */ |
| 1807 | int afs_fs_extend_lock(struct afs_server *server, |
| 1808 | struct key *key, |
| 1809 | struct afs_vnode *vnode, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1810 | bool async) |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1811 | { |
| 1812 | struct afs_call *call; |
| 1813 | __be32 *bp; |
| 1814 | |
| 1815 | _enter(""); |
| 1816 | |
| 1817 | call = afs_alloc_flat_call(&afs_RXFSExtendLock, 4 * 4, 6 * 4); |
| 1818 | if (!call) |
| 1819 | return -ENOMEM; |
| 1820 | |
| 1821 | call->key = key; |
| 1822 | call->reply = vnode; |
| 1823 | call->service_id = FS_SERVICE; |
| 1824 | call->port = htons(AFS_FS_PORT); |
| 1825 | |
| 1826 | /* marshall the parameters */ |
| 1827 | bp = call->request; |
| 1828 | *bp++ = htonl(FSEXTENDLOCK); |
| 1829 | *bp++ = htonl(vnode->fid.vid); |
| 1830 | *bp++ = htonl(vnode->fid.vnode); |
| 1831 | *bp++ = htonl(vnode->fid.unique); |
| 1832 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1833 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | /* |
| 1837 | * release a lock on a file |
| 1838 | */ |
| 1839 | int afs_fs_release_lock(struct afs_server *server, |
| 1840 | struct key *key, |
| 1841 | struct afs_vnode *vnode, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1842 | bool async) |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1843 | { |
| 1844 | struct afs_call *call; |
| 1845 | __be32 *bp; |
| 1846 | |
| 1847 | _enter(""); |
| 1848 | |
| 1849 | call = afs_alloc_flat_call(&afs_RXFSReleaseLock, 4 * 4, 6 * 4); |
| 1850 | if (!call) |
| 1851 | return -ENOMEM; |
| 1852 | |
| 1853 | call->key = key; |
| 1854 | call->reply = vnode; |
| 1855 | call->service_id = FS_SERVICE; |
| 1856 | call->port = htons(AFS_FS_PORT); |
| 1857 | |
| 1858 | /* marshall the parameters */ |
| 1859 | bp = call->request; |
| 1860 | *bp++ = htonl(FSRELEASELOCK); |
| 1861 | *bp++ = htonl(vnode->fid.vid); |
| 1862 | *bp++ = htonl(vnode->fid.vnode); |
| 1863 | *bp++ = htonl(vnode->fid.unique); |
| 1864 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 1865 | return afs_make_call(&server->addr, call, GFP_NOFS, async); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 1866 | } |