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