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