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