blob: 283f486c59f42ec7b15135a645887e664b6cc5dc [file] [log] [blame]
David Howells08e0e7c2007-04-26 15:55:03 -07001/* AFS File Server client stubs
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David Howells08e0e7c2007-04-26 15:55:03 -07003 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/sched.h>
David Howells08e0e7c2007-04-26 15:55:03 -070015#include <linux/circ_buf.h>
Jeff Laytona01179e2017-12-11 06:35:11 -050016#include <linux/iversion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070018#include "afs_fs.h"
David Howellsdd9fbcb2018-04-06 14:17:24 +010019#include "xdr_fs.h"
David Howells30062bd2018-10-20 00:57:58 +010020#include "protocol_yfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
David Howells025db802017-11-02 15:27:51 +000022static const struct afs_fid afs_zero_fid;
23
David Howellsd2ddc772017-11-02 15:27:50 +000024static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
David Howellsc435ee32017-11-02 15:27:49 +000025{
David Howellsd2ddc772017-11-02 15:27:50 +000026 call->cbi = afs_get_cb_interest(cbi);
David Howellsc435ee32017-11-02 15:27:49 +000027}
28
David Howells6db3ac32017-03-16 16:27:44 +000029/*
David Howells260a9802007-04-26 15:59:35 -070030 * decode an AFSFid block
31 */
32static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
33{
34 const __be32 *bp = *_bp;
35
36 fid->vid = ntohl(*bp++);
37 fid->vnode = ntohl(*bp++);
38 fid->unique = ntohl(*bp++);
39 *_bp = bp;
40}
41
42/*
David Howells888b3382018-04-06 14:17:24 +010043 * Dump a bad file status record.
44 */
45static void xdr_dump_bad(const __be32 *bp)
46{
47 __be32 x[4];
48 int i;
49
50 pr_notice("AFS XDR: Bad status record\n");
51 for (i = 0; i < 5 * 4 * 4; i += 16) {
52 memcpy(x, bp, 16);
53 bp += 4;
54 pr_notice("%03x: %08x %08x %08x %08x\n",
55 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
56 }
57
58 memcpy(x, bp, 4);
59 pr_notice("0x50: %08x\n", ntohl(x[0]));
60}
61
62/*
David Howellsdd9fbcb2018-04-06 14:17:24 +010063 * Update the core inode struct from a returned status record.
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 */
David Howellsdd9fbcb2018-04-06 14:17:24 +010065void afs_update_inode_from_status(struct afs_vnode *vnode,
66 struct afs_file_status *status,
67 const afs_dataversion_t *expected_version,
68 u8 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Deepa Dinamani95582b02018-05-08 19:36:02 -070070 struct timespec64 t;
David Howells08e0e7c2007-04-26 15:55:03 -070071 umode_t mode;
David Howells08e0e7c2007-04-26 15:55:03 -070072
David Howellsd4936802018-10-20 00:57:58 +010073 t = status->mtime_client;
David Howellsdd9fbcb2018-04-06 14:17:24 +010074 vnode->vfs_inode.i_ctime = t;
75 vnode->vfs_inode.i_mtime = t;
76 vnode->vfs_inode.i_atime = t;
David Howellsc435ee32017-11-02 15:27:49 +000077
David Howellsdd9fbcb2018-04-06 14:17:24 +010078 if (flags & (AFS_VNODE_META_CHANGED | AFS_VNODE_NOT_YET_SET)) {
79 vnode->vfs_inode.i_uid = make_kuid(&init_user_ns, status->owner);
80 vnode->vfs_inode.i_gid = make_kgid(&init_user_ns, status->group);
81 set_nlink(&vnode->vfs_inode, status->nlink);
David Howells08e0e7c2007-04-26 15:55:03 -070082
David Howellsdd9fbcb2018-04-06 14:17:24 +010083 mode = vnode->vfs_inode.i_mode;
84 mode &= ~S_IALLUGO;
85 mode |= status->mode;
86 barrier();
87 vnode->vfs_inode.i_mode = mode;
David Howells888b3382018-04-06 14:17:24 +010088 }
89
David Howellsdd9fbcb2018-04-06 14:17:24 +010090 if (!(flags & AFS_VNODE_NOT_YET_SET)) {
91 if (expected_version &&
92 *expected_version != status->data_version) {
David Howells3b6492d2018-10-20 00:57:57 +010093 _debug("vnode modified %llx on {%llx:%llu} [exp %llx]",
David Howellsdd9fbcb2018-04-06 14:17:24 +010094 (unsigned long long) status->data_version,
95 vnode->fid.vid, vnode->fid.vnode,
96 (unsigned long long) *expected_version);
David Howellsa4ff7402018-04-06 14:17:24 +010097 vnode->invalid_before = status->data_version;
David Howellsf3ddee82018-04-06 14:17:25 +010098 if (vnode->status.type == AFS_FTYPE_DIR) {
99 if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
100 afs_stat_v(vnode, n_inval);
101 } else {
102 set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags);
103 }
David Howells63a46812018-04-06 14:17:25 +0100104 } else if (vnode->status.type == AFS_FTYPE_DIR) {
105 /* Expected directory change is handled elsewhere so
106 * that we can locally edit the directory and save on a
107 * download.
108 */
109 if (test_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
110 flags &= ~AFS_VNODE_DATA_CHANGED;
David Howells260a9802007-04-26 15:59:35 -0700111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
David Howellsc435ee32017-11-02 15:27:49 +0000113
David Howellsdd9fbcb2018-04-06 14:17:24 +0100114 if (flags & (AFS_VNODE_DATA_CHANGED | AFS_VNODE_NOT_YET_SET)) {
115 inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
116 i_size_write(&vnode->vfs_inode, status->size);
117 }
118}
119
120/*
121 * decode an AFSFetchStatus block
122 */
David Howells5f702c82018-04-06 14:17:25 +0100123static int xdr_decode_AFSFetchStatus(struct afs_call *call,
124 const __be32 **_bp,
David Howellsdd9fbcb2018-04-06 14:17:24 +0100125 struct afs_file_status *status,
126 struct afs_vnode *vnode,
127 const afs_dataversion_t *expected_version,
David Howellsf3ddee82018-04-06 14:17:25 +0100128 struct afs_read *read_req)
David Howellsdd9fbcb2018-04-06 14:17:24 +0100129{
130 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
David Howells684b0f62018-05-10 21:51:47 +0100131 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
David Howellsdd9fbcb2018-04-06 14:17:24 +0100132 u64 data_version, size;
133 u32 type, abort_code;
134 u8 flags = 0;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100135
David Howells684b0f62018-05-10 21:51:47 +0100136 abort_code = ntohl(xdr->abort_code);
137
David Howellsdd9fbcb2018-04-06 14:17:24 +0100138 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
David Howells684b0f62018-05-10 21:51:47 +0100139 if (xdr->if_version == htonl(0) &&
140 abort_code != 0 &&
141 inline_error) {
142 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
143 * whereby it doesn't set the interface version in the error
144 * case.
145 */
146 status->abort_code = abort_code;
Al Virode52cf92018-06-02 18:08:11 -0400147 return 0;
David Howells684b0f62018-05-10 21:51:47 +0100148 }
149
David Howellsdd9fbcb2018-04-06 14:17:24 +0100150 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
151 goto bad;
152 }
153
David Howells684b0f62018-05-10 21:51:47 +0100154 if (abort_code != 0 && inline_error) {
155 status->abort_code = abort_code;
Al Virode52cf92018-06-02 18:08:11 -0400156 return 0;
David Howells684b0f62018-05-10 21:51:47 +0100157 }
158
David Howellsdd9fbcb2018-04-06 14:17:24 +0100159 type = ntohl(xdr->type);
David Howellsdd9fbcb2018-04-06 14:17:24 +0100160 switch (type) {
161 case AFS_FTYPE_FILE:
162 case AFS_FTYPE_DIR:
163 case AFS_FTYPE_SYMLINK:
164 if (type != status->type &&
165 vnode &&
166 !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
David Howells3b6492d2018-10-20 00:57:57 +0100167 pr_warning("Vnode %llx:%llx:%x changed type %u to %u\n",
David Howellsdd9fbcb2018-04-06 14:17:24 +0100168 vnode->fid.vid,
169 vnode->fid.vnode,
170 vnode->fid.unique,
171 status->type, type);
172 goto bad;
173 }
174 status->type = type;
175 break;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100176 default:
177 goto bad;
178 }
179
180#define EXTRACT_M(FIELD) \
181 do { \
182 u32 x = ntohl(xdr->FIELD); \
183 if (status->FIELD != x) { \
184 flags |= AFS_VNODE_META_CHANGED; \
185 status->FIELD = x; \
186 } \
187 } while (0)
188
189 EXTRACT_M(nlink);
190 EXTRACT_M(author);
191 EXTRACT_M(owner);
192 EXTRACT_M(caller_access); /* call ticket dependent */
193 EXTRACT_M(anon_access);
194 EXTRACT_M(mode);
195 EXTRACT_M(group);
196
David Howellsd4936802018-10-20 00:57:58 +0100197 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
198 status->mtime_client.tv_nsec = 0;
199 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
200 status->mtime_server.tv_nsec = 0;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100201 status->lock_count = ntohl(xdr->lock_count);
202
203 size = (u64)ntohl(xdr->size_lo);
204 size |= (u64)ntohl(xdr->size_hi) << 32;
David Howells63a46812018-04-06 14:17:25 +0100205 status->size = size;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100206
207 data_version = (u64)ntohl(xdr->data_version_lo);
208 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
209 if (data_version != status->data_version) {
210 status->data_version = data_version;
211 flags |= AFS_VNODE_DATA_CHANGED;
212 }
David Howellsf3ddee82018-04-06 14:17:25 +0100213
214 if (read_req) {
215 read_req->data_version = data_version;
216 read_req->file_size = size;
217 }
David Howellsdd9fbcb2018-04-06 14:17:24 +0100218
219 *_bp = (const void *)*_bp + sizeof(*xdr);
220
221 if (vnode) {
222 if (test_bit(AFS_VNODE_UNSET, &vnode->flags))
223 flags |= AFS_VNODE_NOT_YET_SET;
224 afs_update_inode_from_status(vnode, status, expected_version,
225 flags);
226 }
227
David Howellsc875c762018-05-23 11:32:06 +0100228 return 0;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100229
230bad:
231 xdr_dump_bad(*_bp);
David Howells160cb952018-10-20 00:57:56 +0100232 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
David Howellsc875c762018-05-23 11:32:06 +0100233}
234
235/*
236 * Decode the file status. We need to lock the target vnode if we're going to
237 * update its status so that stat() sees the attributes update atomically.
238 */
239static int afs_decode_status(struct afs_call *call,
240 const __be32 **_bp,
241 struct afs_file_status *status,
242 struct afs_vnode *vnode,
243 const afs_dataversion_t *expected_version,
244 struct afs_read *read_req)
245{
246 int ret;
247
248 if (!vnode)
249 return xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
250 expected_version, read_req);
251
252 write_seqlock(&vnode->cb_lock);
253 ret = xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
254 expected_version, read_req);
255 write_sequnlock(&vnode->cb_lock);
256 return ret;
David Howellsec268152007-04-26 15:49:28 -0700257}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/*
David Howells08e0e7c2007-04-26 15:55:03 -0700260 * decode an AFSCallBack block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 */
David Howellsc435ee32017-11-02 15:27:49 +0000262static void xdr_decode_AFSCallBack(struct afs_call *call,
263 struct afs_vnode *vnode,
264 const __be32 **_bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
David Howellsd2ddc772017-11-02 15:27:50 +0000266 struct afs_cb_interest *old, *cbi = call->cbi;
David Howells08e0e7c2007-04-26 15:55:03 -0700267 const __be32 *bp = *_bp;
David Howellsc435ee32017-11-02 15:27:49 +0000268 u32 cb_expiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
David Howellsc435ee32017-11-02 15:27:49 +0000270 write_seqlock(&vnode->cb_lock);
271
David Howells18ac6182018-10-20 00:57:59 +0100272 if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
David Howellsc435ee32017-11-02 15:27:49 +0000273 vnode->cb_version = ntohl(*bp++);
274 cb_expiry = ntohl(*bp++);
275 vnode->cb_type = ntohl(*bp++);
276 vnode->cb_expires_at = cb_expiry + ktime_get_real_seconds();
David Howellsd2ddc772017-11-02 15:27:50 +0000277 old = vnode->cb_interest;
278 if (old != call->cbi) {
279 vnode->cb_interest = cbi;
280 cbi = old;
281 }
David Howellsc435ee32017-11-02 15:27:49 +0000282 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
283 } else {
284 bp += 3;
285 }
286
287 write_sequnlock(&vnode->cb_lock);
David Howellsd2ddc772017-11-02 15:27:50 +0000288 call->cbi = cbi;
David Howells08e0e7c2007-04-26 15:55:03 -0700289 *_bp = bp;
David Howellsec268152007-04-26 15:49:28 -0700290}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
David Howells12d8e952018-10-20 00:57:58 +0100292static ktime_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
293{
294 return ktime_add_ns(call->reply_time, expiry * NSEC_PER_SEC);
295}
296
297static void xdr_decode_AFSCallBack_raw(struct afs_call *call,
298 const __be32 **_bp,
David Howells260a9802007-04-26 15:59:35 -0700299 struct afs_callback *cb)
300{
301 const __be32 *bp = *_bp;
302
303 cb->version = ntohl(*bp++);
David Howells12d8e952018-10-20 00:57:58 +0100304 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
David Howells260a9802007-04-26 15:59:35 -0700305 cb->type = ntohl(*bp++);
306 *_bp = bp;
307}
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/*
David Howells08e0e7c2007-04-26 15:55:03 -0700310 * decode an AFSVolSync block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 */
David Howells08e0e7c2007-04-26 15:55:03 -0700312static void xdr_decode_AFSVolSync(const __be32 **_bp,
313 struct afs_volsync *volsync)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
David Howells08e0e7c2007-04-26 15:55:03 -0700315 const __be32 *bp = *_bp;
David Howells30062bd2018-10-20 00:57:58 +0100316 u32 creation;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
David Howells30062bd2018-10-20 00:57:58 +0100318 creation = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700319 bp++; /* spare2 */
320 bp++; /* spare3 */
321 bp++; /* spare4 */
322 bp++; /* spare5 */
323 bp++; /* spare6 */
324 *_bp = bp;
David Howells30062bd2018-10-20 00:57:58 +0100325
326 if (volsync)
327 volsync->creation = creation;
David Howellsec268152007-04-26 15:49:28 -0700328}
David Howells08e0e7c2007-04-26 15:55:03 -0700329
330/*
David Howells31143d52007-05-09 02:33:46 -0700331 * encode the requested attributes into an AFSStoreStatus block
332 */
333static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
334{
335 __be32 *bp = *_bp;
336 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
337
338 mask = 0;
339 if (attr->ia_valid & ATTR_MTIME) {
340 mask |= AFS_SET_MTIME;
341 mtime = attr->ia_mtime.tv_sec;
342 }
343
344 if (attr->ia_valid & ATTR_UID) {
345 mask |= AFS_SET_OWNER;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800346 owner = from_kuid(&init_user_ns, attr->ia_uid);
David Howells31143d52007-05-09 02:33:46 -0700347 }
348
349 if (attr->ia_valid & ATTR_GID) {
350 mask |= AFS_SET_GROUP;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800351 group = from_kgid(&init_user_ns, attr->ia_gid);
David Howells31143d52007-05-09 02:33:46 -0700352 }
353
354 if (attr->ia_valid & ATTR_MODE) {
355 mask |= AFS_SET_MODE;
356 mode = attr->ia_mode & S_IALLUGO;
357 }
358
359 *bp++ = htonl(mask);
360 *bp++ = htonl(mtime);
361 *bp++ = htonl(owner);
362 *bp++ = htonl(group);
363 *bp++ = htonl(mode);
364 *bp++ = 0; /* segment size */
365 *_bp = bp;
366}
367
368/*
David Howells45222b92007-05-10 22:22:20 -0700369 * decode an AFSFetchVolumeStatus block
370 */
371static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
372 struct afs_volume_status *vs)
373{
374 const __be32 *bp = *_bp;
375
376 vs->vid = ntohl(*bp++);
377 vs->parent_id = ntohl(*bp++);
378 vs->online = ntohl(*bp++);
379 vs->in_service = ntohl(*bp++);
380 vs->blessed = ntohl(*bp++);
381 vs->needs_salvage = ntohl(*bp++);
382 vs->type = ntohl(*bp++);
383 vs->min_quota = ntohl(*bp++);
384 vs->max_quota = ntohl(*bp++);
385 vs->blocks_in_use = ntohl(*bp++);
386 vs->part_blocks_avail = ntohl(*bp++);
387 vs->part_max_blocks = ntohl(*bp++);
David Howells30062bd2018-10-20 00:57:58 +0100388 vs->vol_copy_date = 0;
389 vs->vol_backup_date = 0;
David Howells45222b92007-05-10 22:22:20 -0700390 *_bp = bp;
391}
392
393/*
David Howells08e0e7c2007-04-26 15:55:03 -0700394 * deliver reply data to an FS.FetchStatus
395 */
David Howells5cf9dd52018-04-09 21:12:31 +0100396static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
David Howells08e0e7c2007-04-26 15:55:03 -0700397{
David Howells97e30432017-11-02 15:27:48 +0000398 struct afs_vnode *vnode = call->reply[0];
David Howells08e0e7c2007-04-26 15:55:03 -0700399 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100400 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700401
David Howellsd0016482016-08-30 20:42:14 +0100402 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100403 if (ret < 0)
404 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700405
David Howells3b6492d2018-10-20 00:57:57 +0100406 _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
David Howellsc435ee32017-11-02 15:27:49 +0000407
David Howells08e0e7c2007-04-26 15:55:03 -0700408 /* unmarshall the reply once we've received all of it */
409 bp = call->buffer;
David Howells160cb952018-10-20 00:57:56 +0100410 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
411 &call->expected_version, NULL);
412 if (ret < 0)
413 return ret;
David Howellsc435ee32017-11-02 15:27:49 +0000414 xdr_decode_AFSCallBack(call, vnode, &bp);
David Howells30062bd2018-10-20 00:57:58 +0100415 xdr_decode_AFSVolSync(&bp, call->reply[1]);
David Howells08e0e7c2007-04-26 15:55:03 -0700416
417 _leave(" = 0 [done]");
418 return 0;
419}
420
421/*
422 * FS.FetchStatus operation type
423 */
David Howells5cf9dd52018-04-09 21:12:31 +0100424static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
425 .name = "FS.FetchStatus(vnode)",
David Howells025db802017-11-02 15:27:51 +0000426 .op = afs_FS_FetchStatus,
David Howells5cf9dd52018-04-09 21:12:31 +0100427 .deliver = afs_deliver_fs_fetch_status_vnode,
David Howells08e0e7c2007-04-26 15:55:03 -0700428 .destructor = afs_flat_call_destructor,
429};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431/*
432 * fetch the status information for a file
433 */
David Howells0c3a5ac2018-04-06 14:17:24 +0100434int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_volsync *volsync,
435 bool new_inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
David Howellsd2ddc772017-11-02 15:27:50 +0000437 struct afs_vnode *vnode = fc->vnode;
David Howells08e0e7c2007-04-26 15:55:03 -0700438 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000439 struct afs_net *net = afs_v2net(vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 __be32 *bp;
441
David Howells30062bd2018-10-20 00:57:58 +0100442 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
443 return yfs_fs_fetch_file_status(fc, volsync, new_inode);
444
David Howells3b6492d2018-10-20 00:57:57 +0100445 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +0000446 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
David Howells5cf9dd52018-04-09 21:12:31 +0100448 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
449 16, (21 + 3 + 6) * 4);
David Howellsd2ddc772017-11-02 15:27:50 +0000450 if (!call) {
451 fc->ac.error = -ENOMEM;
David Howells08e0e7c2007-04-26 15:55:03 -0700452 return -ENOMEM;
David Howellsd2ddc772017-11-02 15:27:50 +0000453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
David Howellsd2ddc772017-11-02 15:27:50 +0000455 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +0000456 call->reply[0] = vnode;
457 call->reply[1] = volsync;
David Howells0c3a5ac2018-04-06 14:17:24 +0100458 call->expected_version = new_inode ? 1 : vnode->status.data_version;
David Howells12d8e952018-10-20 00:57:58 +0100459 call->want_reply_time = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700462 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 bp[0] = htonl(FSFETCHSTATUS);
464 bp[1] = htonl(vnode->fid.vid);
465 bp[2] = htonl(vnode->fid.vnode);
466 bp[3] = htonl(vnode->fid.unique);
467
David Howellsd2ddc772017-11-02 15:27:50 +0000468 call->cb_break = fc->cb_break;
469 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000470 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +0100471
472 afs_make_call(&fc->ac, call, GFP_NOFS);
473 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsec268152007-04-26 15:49:28 -0700474}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476/*
David Howells08e0e7c2007-04-26 15:55:03 -0700477 * deliver reply data to an FS.FetchData
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 */
David Howellsd0016482016-08-30 20:42:14 +0100479static int afs_deliver_fs_fetch_data(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
David Howells97e30432017-11-02 15:27:48 +0000481 struct afs_vnode *vnode = call->reply[0];
482 struct afs_read *req = call->reply[2];
David Howells08e0e7c2007-04-26 15:55:03 -0700483 const __be32 *bp;
David Howells196ee9c2017-01-05 10:38:34 +0000484 unsigned int size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700486
David Howells12bdcf32018-10-20 00:57:56 +0100487 _enter("{%u,%zu/%llu}",
488 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
David Howells08e0e7c2007-04-26 15:55:03 -0700489
490 switch (call->unmarshall) {
491 case 0:
David Howells196ee9c2017-01-05 10:38:34 +0000492 req->actual_len = 0;
David Howells12bdcf32018-10-20 00:57:56 +0100493 req->index = 0;
494 req->offset = req->pos & (PAGE_SIZE - 1);
David Howells08e0e7c2007-04-26 15:55:03 -0700495 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +0100496 if (call->operation_ID == FSFETCHDATA64) {
497 afs_extract_to_tmp64(call);
498 } else {
499 call->tmp_u = htonl(0);
500 afs_extract_to_tmp(call);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700501 }
David Howells08e0e7c2007-04-26 15:55:03 -0700502
David Howellsb9b1f8d2007-05-10 03:15:21 -0700503 /* extract the returned data length */
David Howells12bdcf32018-10-20 00:57:56 +0100504 case 1:
David Howells08e0e7c2007-04-26 15:55:03 -0700505 _debug("extract data length");
David Howells12bdcf32018-10-20 00:57:56 +0100506 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100507 if (ret < 0)
508 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700509
David Howells12bdcf32018-10-20 00:57:56 +0100510 req->actual_len = be64_to_cpu(call->tmp64);
David Howells196ee9c2017-01-05 10:38:34 +0000511 _debug("DATA length: %llu", req->actual_len);
David Howells12bdcf32018-10-20 00:57:56 +0100512 req->remain = min(req->len, req->actual_len);
513 if (req->remain == 0)
David Howells196ee9c2017-01-05 10:38:34 +0000514 goto no_more_data;
David Howells12bdcf32018-10-20 00:57:56 +0100515
David Howells08e0e7c2007-04-26 15:55:03 -0700516 call->unmarshall++;
517
David Howells196ee9c2017-01-05 10:38:34 +0000518 begin_page:
David Howells6db3ac32017-03-16 16:27:44 +0000519 ASSERTCMP(req->index, <, req->nr_pages);
David Howells12bdcf32018-10-20 00:57:56 +0100520 if (req->remain > PAGE_SIZE - req->offset)
521 size = PAGE_SIZE - req->offset;
David Howells196ee9c2017-01-05 10:38:34 +0000522 else
523 size = req->remain;
David Howells12bdcf32018-10-20 00:57:56 +0100524 call->bvec[0].bv_len = size;
525 call->bvec[0].bv_offset = req->offset;
526 call->bvec[0].bv_page = req->pages[req->index];
527 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
528 ASSERTCMP(size, <=, PAGE_SIZE);
David Howells196ee9c2017-01-05 10:38:34 +0000529
David Howells08e0e7c2007-04-26 15:55:03 -0700530 /* extract the returned data */
David Howells12bdcf32018-10-20 00:57:56 +0100531 case 2:
532 _debug("extract data %zu/%llu",
533 iov_iter_count(&call->iter), req->remain);
David Howells196ee9c2017-01-05 10:38:34 +0000534
David Howells12bdcf32018-10-20 00:57:56 +0100535 ret = afs_extract_data(call, true);
David Howells196ee9c2017-01-05 10:38:34 +0000536 if (ret < 0)
537 return ret;
David Howells12bdcf32018-10-20 00:57:56 +0100538 req->remain -= call->bvec[0].bv_len;
539 req->offset += call->bvec[0].bv_len;
540 ASSERTCMP(req->offset, <=, PAGE_SIZE);
541 if (req->offset == PAGE_SIZE) {
542 req->offset = 0;
David Howells196ee9c2017-01-05 10:38:34 +0000543 if (req->page_done)
544 req->page_done(call, req);
David Howells29f06982017-03-16 16:27:46 +0000545 req->index++;
David Howells12bdcf32018-10-20 00:57:56 +0100546 if (req->remain > 0)
David Howells196ee9c2017-01-05 10:38:34 +0000547 goto begin_page;
David Howells08e0e7c2007-04-26 15:55:03 -0700548 }
David Howells12bdcf32018-10-20 00:57:56 +0100549
550 ASSERTCMP(req->remain, ==, 0);
551 if (req->actual_len <= req->len)
552 goto no_more_data;
David Howells6db3ac32017-03-16 16:27:44 +0000553
554 /* Discard any excess data the server gave us */
David Howells12bdcf32018-10-20 00:57:56 +0100555 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
556 call->unmarshall = 3;
557 case 3:
558 _debug("extract discard %zu/%llu",
559 iov_iter_count(&call->iter), req->actual_len - req->len);
David Howells6db3ac32017-03-16 16:27:44 +0000560
David Howells12bdcf32018-10-20 00:57:56 +0100561 ret = afs_extract_data(call, true);
David Howells6db3ac32017-03-16 16:27:44 +0000562 if (ret < 0)
563 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700564
David Howells196ee9c2017-01-05 10:38:34 +0000565 no_more_data:
David Howells12bdcf32018-10-20 00:57:56 +0100566 call->unmarshall = 4;
567 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700568
569 /* extract the metadata */
David Howells12bdcf32018-10-20 00:57:56 +0100570 case 4:
571 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100572 if (ret < 0)
573 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700574
575 bp = call->buffer;
David Howells160cb952018-10-20 00:57:56 +0100576 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
577 &vnode->status.data_version, req);
578 if (ret < 0)
579 return ret;
David Howellsc435ee32017-11-02 15:27:49 +0000580 xdr_decode_AFSCallBack(call, vnode, &bp);
David Howells30062bd2018-10-20 00:57:58 +0100581 xdr_decode_AFSVolSync(&bp, call->reply[1]);
David Howells08e0e7c2007-04-26 15:55:03 -0700582
David Howells08e0e7c2007-04-26 15:55:03 -0700583 call->unmarshall++;
584
David Howells12bdcf32018-10-20 00:57:56 +0100585 case 5:
David Howells08e0e7c2007-04-26 15:55:03 -0700586 break;
587 }
588
David Howells6db3ac32017-03-16 16:27:44 +0000589 for (; req->index < req->nr_pages; req->index++) {
David Howells12bdcf32018-10-20 00:57:56 +0100590 if (req->offset < PAGE_SIZE)
David Howells6db3ac32017-03-16 16:27:44 +0000591 zero_user_segment(req->pages[req->index],
David Howells12bdcf32018-10-20 00:57:56 +0100592 req->offset, PAGE_SIZE);
David Howells196ee9c2017-01-05 10:38:34 +0000593 if (req->page_done)
594 req->page_done(call, req);
David Howells12bdcf32018-10-20 00:57:56 +0100595 req->offset = 0;
David Howells416351f2007-05-09 02:33:45 -0700596 }
597
David Howells08e0e7c2007-04-26 15:55:03 -0700598 _leave(" = 0 [done]");
599 return 0;
600}
601
David Howells196ee9c2017-01-05 10:38:34 +0000602static void afs_fetch_data_destructor(struct afs_call *call)
603{
David Howells97e30432017-11-02 15:27:48 +0000604 struct afs_read *req = call->reply[2];
David Howells196ee9c2017-01-05 10:38:34 +0000605
606 afs_put_read(req);
607 afs_flat_call_destructor(call);
608}
609
David Howells08e0e7c2007-04-26 15:55:03 -0700610/*
611 * FS.FetchData operation type
612 */
613static const struct afs_call_type afs_RXFSFetchData = {
David Howells00d3b7a2007-04-26 15:57:07 -0700614 .name = "FS.FetchData",
David Howells025db802017-11-02 15:27:51 +0000615 .op = afs_FS_FetchData,
David Howells08e0e7c2007-04-26 15:55:03 -0700616 .deliver = afs_deliver_fs_fetch_data,
David Howells196ee9c2017-01-05 10:38:34 +0000617 .destructor = afs_fetch_data_destructor,
David Howells08e0e7c2007-04-26 15:55:03 -0700618};
619
David Howellsb9b1f8d2007-05-10 03:15:21 -0700620static const struct afs_call_type afs_RXFSFetchData64 = {
621 .name = "FS.FetchData64",
David Howells025db802017-11-02 15:27:51 +0000622 .op = afs_FS_FetchData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -0700623 .deliver = afs_deliver_fs_fetch_data,
David Howells196ee9c2017-01-05 10:38:34 +0000624 .destructor = afs_fetch_data_destructor,
David Howellsb9b1f8d2007-05-10 03:15:21 -0700625};
626
627/*
628 * fetch data from a very large file
629 */
David Howellsd2ddc772017-11-02 15:27:50 +0000630static int afs_fs_fetch_data64(struct afs_fs_cursor *fc, struct afs_read *req)
David Howellsb9b1f8d2007-05-10 03:15:21 -0700631{
David Howellsd2ddc772017-11-02 15:27:50 +0000632 struct afs_vnode *vnode = fc->vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700633 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000634 struct afs_net *net = afs_v2net(vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700635 __be32 *bp;
636
637 _enter("");
638
David Howellsf044c882017-11-02 15:27:45 +0000639 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700640 if (!call)
641 return -ENOMEM;
642
David Howellsd2ddc772017-11-02 15:27:50 +0000643 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +0000644 call->reply[0] = vnode;
645 call->reply[1] = NULL; /* volsync */
646 call->reply[2] = req;
David Howells0c3a5ac2018-04-06 14:17:24 +0100647 call->expected_version = vnode->status.data_version;
David Howells12d8e952018-10-20 00:57:58 +0100648 call->want_reply_time = true;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700649
650 /* marshall the parameters */
651 bp = call->request;
652 bp[0] = htonl(FSFETCHDATA64);
653 bp[1] = htonl(vnode->fid.vid);
654 bp[2] = htonl(vnode->fid.vnode);
655 bp[3] = htonl(vnode->fid.unique);
David Howells196ee9c2017-01-05 10:38:34 +0000656 bp[4] = htonl(upper_32_bits(req->pos));
657 bp[5] = htonl(lower_32_bits(req->pos));
David Howellsb9b1f8d2007-05-10 03:15:21 -0700658 bp[6] = 0;
David Howells196ee9c2017-01-05 10:38:34 +0000659 bp[7] = htonl(lower_32_bits(req->len));
David Howellsb9b1f8d2007-05-10 03:15:21 -0700660
David Howellsf3ddee82018-04-06 14:17:25 +0100661 refcount_inc(&req->usage);
David Howellsd2ddc772017-11-02 15:27:50 +0000662 call->cb_break = fc->cb_break;
663 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000664 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +0100665 afs_make_call(&fc->ac, call, GFP_NOFS);
666 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700667}
668
David Howells08e0e7c2007-04-26 15:55:03 -0700669/*
670 * fetch data from a file
671 */
David Howellsd2ddc772017-11-02 15:27:50 +0000672int afs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
David Howells08e0e7c2007-04-26 15:55:03 -0700673{
David Howellsd2ddc772017-11-02 15:27:50 +0000674 struct afs_vnode *vnode = fc->vnode;
David Howells08e0e7c2007-04-26 15:55:03 -0700675 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000676 struct afs_net *net = afs_v2net(vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 __be32 *bp;
678
David Howells30062bd2018-10-20 00:57:58 +0100679 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
680 return yfs_fs_fetch_data(fc, req);
681
David Howells196ee9c2017-01-05 10:38:34 +0000682 if (upper_32_bits(req->pos) ||
683 upper_32_bits(req->len) ||
684 upper_32_bits(req->pos + req->len))
David Howellsd2ddc772017-11-02 15:27:50 +0000685 return afs_fs_fetch_data64(fc, req);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700686
David Howells08e0e7c2007-04-26 15:55:03 -0700687 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
David Howellsf044c882017-11-02 15:27:45 +0000689 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700690 if (!call)
691 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
David Howellsd2ddc772017-11-02 15:27:50 +0000693 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +0000694 call->reply[0] = vnode;
695 call->reply[1] = NULL; /* volsync */
696 call->reply[2] = req;
David Howells0c3a5ac2018-04-06 14:17:24 +0100697 call->expected_version = vnode->status.data_version;
David Howells12d8e952018-10-20 00:57:58 +0100698 call->want_reply_time = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700701 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 bp[0] = htonl(FSFETCHDATA);
David Howells08e0e7c2007-04-26 15:55:03 -0700703 bp[1] = htonl(vnode->fid.vid);
704 bp[2] = htonl(vnode->fid.vnode);
705 bp[3] = htonl(vnode->fid.unique);
David Howells196ee9c2017-01-05 10:38:34 +0000706 bp[4] = htonl(lower_32_bits(req->pos));
707 bp[5] = htonl(lower_32_bits(req->len));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
David Howellsf3ddee82018-04-06 14:17:25 +0100709 refcount_inc(&req->usage);
David Howellsd2ddc772017-11-02 15:27:50 +0000710 call->cb_break = fc->cb_break;
711 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000712 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +0100713 afs_make_call(&fc->ac, call, GFP_NOFS);
714 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsec268152007-04-26 15:49:28 -0700715}
David Howells260a9802007-04-26 15:59:35 -0700716
717/*
718 * deliver reply data to an FS.CreateFile or an FS.MakeDir
719 */
David Howellsd0016482016-08-30 20:42:14 +0100720static int afs_deliver_fs_create_vnode(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700721{
David Howells97e30432017-11-02 15:27:48 +0000722 struct afs_vnode *vnode = call->reply[0];
David Howells260a9802007-04-26 15:59:35 -0700723 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100724 int ret;
David Howells260a9802007-04-26 15:59:35 -0700725
David Howellsd0016482016-08-30 20:42:14 +0100726 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700727
David Howellsd0016482016-08-30 20:42:14 +0100728 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100729 if (ret < 0)
730 return ret;
David Howells260a9802007-04-26 15:59:35 -0700731
732 /* unmarshall the reply once we've received all of it */
733 bp = call->buffer;
David Howells97e30432017-11-02 15:27:48 +0000734 xdr_decode_AFSFid(&bp, call->reply[1]);
David Howells160cb952018-10-20 00:57:56 +0100735 ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
736 if (ret < 0)
737 return ret;
738 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
739 &call->expected_version, NULL);
740 if (ret < 0)
741 return ret;
David Howells12d8e952018-10-20 00:57:58 +0100742 xdr_decode_AFSCallBack_raw(call, &bp, call->reply[3]);
David Howells97e30432017-11-02 15:27:48 +0000743 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
David Howells260a9802007-04-26 15:59:35 -0700744
745 _leave(" = 0 [done]");
746 return 0;
747}
748
749/*
750 * FS.CreateFile and FS.MakeDir operation type
751 */
David Howells025db802017-11-02 15:27:51 +0000752static const struct afs_call_type afs_RXFSCreateFile = {
753 .name = "FS.CreateFile",
754 .op = afs_FS_CreateFile,
755 .deliver = afs_deliver_fs_create_vnode,
756 .destructor = afs_flat_call_destructor,
757};
758
759static const struct afs_call_type afs_RXFSMakeDir = {
760 .name = "FS.MakeDir",
761 .op = afs_FS_MakeDir,
David Howells260a9802007-04-26 15:59:35 -0700762 .deliver = afs_deliver_fs_create_vnode,
David Howells260a9802007-04-26 15:59:35 -0700763 .destructor = afs_flat_call_destructor,
764};
765
766/*
767 * create a file or make a directory
768 */
David Howells8b2a4642017-11-02 15:27:50 +0000769int afs_fs_create(struct afs_fs_cursor *fc,
David Howells260a9802007-04-26 15:59:35 -0700770 const char *name,
771 umode_t mode,
David Howells63a46812018-04-06 14:17:25 +0100772 u64 current_data_version,
David Howells260a9802007-04-26 15:59:35 -0700773 struct afs_fid *newfid,
774 struct afs_file_status *newstatus,
David Howellsd2ddc772017-11-02 15:27:50 +0000775 struct afs_callback *newcb)
David Howells260a9802007-04-26 15:59:35 -0700776{
David Howellsd2ddc772017-11-02 15:27:50 +0000777 struct afs_vnode *vnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700778 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000779 struct afs_net *net = afs_v2net(vnode);
David Howells260a9802007-04-26 15:59:35 -0700780 size_t namesz, reqsz, padsz;
781 __be32 *bp;
782
David Howells30062bd2018-10-20 00:57:58 +0100783 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
784 if (S_ISDIR(mode))
785 return yfs_fs_make_dir(fc, name, mode, current_data_version,
786 newfid, newstatus, newcb);
787 else
788 return yfs_fs_create_file(fc, name, mode, current_data_version,
789 newfid, newstatus, newcb);
790 }
791
David Howells260a9802007-04-26 15:59:35 -0700792 _enter("");
793
794 namesz = strlen(name);
795 padsz = (4 - (namesz & 3)) & 3;
796 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
797
David Howells025db802017-11-02 15:27:51 +0000798 call = afs_alloc_flat_call(
799 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
800 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700801 if (!call)
802 return -ENOMEM;
803
David Howellsd2ddc772017-11-02 15:27:50 +0000804 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +0000805 call->reply[0] = vnode;
806 call->reply[1] = newfid;
807 call->reply[2] = newstatus;
808 call->reply[3] = newcb;
David Howells63a46812018-04-06 14:17:25 +0100809 call->expected_version = current_data_version + 1;
David Howells12d8e952018-10-20 00:57:58 +0100810 call->want_reply_time = true;
David Howells260a9802007-04-26 15:59:35 -0700811
812 /* marshall the parameters */
813 bp = call->request;
814 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
815 *bp++ = htonl(vnode->fid.vid);
816 *bp++ = htonl(vnode->fid.vnode);
817 *bp++ = htonl(vnode->fid.unique);
818 *bp++ = htonl(namesz);
819 memcpy(bp, name, namesz);
820 bp = (void *) bp + namesz;
821 if (padsz > 0) {
822 memset(bp, 0, padsz);
823 bp = (void *) bp + padsz;
824 }
Marc Dionneab94f5d2017-03-16 16:27:47 +0000825 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
826 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells260a9802007-04-26 15:59:35 -0700827 *bp++ = 0; /* owner */
828 *bp++ = 0; /* group */
829 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
830 *bp++ = 0; /* segment size */
831
David Howellsd2ddc772017-11-02 15:27:50 +0000832 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +0100833 trace_afs_make_fs_call1(call, &vnode->fid, name);
David Howells0b9bf382019-04-25 14:26:50 +0100834 afs_make_call(&fc->ac, call, GFP_NOFS);
835 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -0700836}
837
838/*
839 * deliver reply data to an FS.RemoveFile or FS.RemoveDir
840 */
David Howellsd0016482016-08-30 20:42:14 +0100841static int afs_deliver_fs_remove(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700842{
David Howells97e30432017-11-02 15:27:48 +0000843 struct afs_vnode *vnode = call->reply[0];
David Howells260a9802007-04-26 15:59:35 -0700844 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100845 int ret;
David Howells260a9802007-04-26 15:59:35 -0700846
David Howellsd0016482016-08-30 20:42:14 +0100847 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700848
David Howellsd0016482016-08-30 20:42:14 +0100849 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100850 if (ret < 0)
851 return ret;
David Howells260a9802007-04-26 15:59:35 -0700852
853 /* unmarshall the reply once we've received all of it */
854 bp = call->buffer;
David Howells160cb952018-10-20 00:57:56 +0100855 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
856 &call->expected_version, NULL);
857 if (ret < 0)
858 return ret;
David Howells97e30432017-11-02 15:27:48 +0000859 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
David Howells260a9802007-04-26 15:59:35 -0700860
861 _leave(" = 0 [done]");
862 return 0;
863}
864
865/*
866 * FS.RemoveDir/FS.RemoveFile operation type
867 */
David Howells025db802017-11-02 15:27:51 +0000868static const struct afs_call_type afs_RXFSRemoveFile = {
869 .name = "FS.RemoveFile",
870 .op = afs_FS_RemoveFile,
871 .deliver = afs_deliver_fs_remove,
872 .destructor = afs_flat_call_destructor,
873};
874
875static const struct afs_call_type afs_RXFSRemoveDir = {
876 .name = "FS.RemoveDir",
877 .op = afs_FS_RemoveDir,
David Howells260a9802007-04-26 15:59:35 -0700878 .deliver = afs_deliver_fs_remove,
David Howells260a9802007-04-26 15:59:35 -0700879 .destructor = afs_flat_call_destructor,
880};
881
882/*
883 * remove a file or directory
884 */
David Howells30062bd2018-10-20 00:57:58 +0100885int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
886 const char *name, bool isdir, u64 current_data_version)
David Howells260a9802007-04-26 15:59:35 -0700887{
David Howells30062bd2018-10-20 00:57:58 +0100888 struct afs_vnode *dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700889 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100890 struct afs_net *net = afs_v2net(dvnode);
David Howells260a9802007-04-26 15:59:35 -0700891 size_t namesz, reqsz, padsz;
892 __be32 *bp;
893
David Howells30062bd2018-10-20 00:57:58 +0100894 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
895 return yfs_fs_remove(fc, vnode, name, isdir, current_data_version);
896
David Howells260a9802007-04-26 15:59:35 -0700897 _enter("");
898
899 namesz = strlen(name);
900 padsz = (4 - (namesz & 3)) & 3;
901 reqsz = (5 * 4) + namesz + padsz;
902
David Howells025db802017-11-02 15:27:51 +0000903 call = afs_alloc_flat_call(
904 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
905 reqsz, (21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700906 if (!call)
907 return -ENOMEM;
908
David Howellsd2ddc772017-11-02 15:27:50 +0000909 call->key = fc->key;
David Howells30062bd2018-10-20 00:57:58 +0100910 call->reply[0] = dvnode;
911 call->reply[1] = vnode;
David Howells63a46812018-04-06 14:17:25 +0100912 call->expected_version = current_data_version + 1;
David Howells260a9802007-04-26 15:59:35 -0700913
914 /* marshall the parameters */
915 bp = call->request;
916 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
David Howells30062bd2018-10-20 00:57:58 +0100917 *bp++ = htonl(dvnode->fid.vid);
918 *bp++ = htonl(dvnode->fid.vnode);
919 *bp++ = htonl(dvnode->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700920 *bp++ = htonl(namesz);
921 memcpy(bp, name, namesz);
922 bp = (void *) bp + namesz;
923 if (padsz > 0) {
924 memset(bp, 0, padsz);
925 bp = (void *) bp + padsz;
926 }
927
David Howellsd2ddc772017-11-02 15:27:50 +0000928 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +0100929 trace_afs_make_fs_call1(call, &dvnode->fid, name);
David Howells0b9bf382019-04-25 14:26:50 +0100930 afs_make_call(&fc->ac, call, GFP_NOFS);
931 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -0700932}
933
934/*
935 * deliver reply data to an FS.Link
936 */
David Howellsd0016482016-08-30 20:42:14 +0100937static int afs_deliver_fs_link(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700938{
David Howells97e30432017-11-02 15:27:48 +0000939 struct afs_vnode *dvnode = call->reply[0], *vnode = call->reply[1];
David Howells260a9802007-04-26 15:59:35 -0700940 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100941 int ret;
David Howells260a9802007-04-26 15:59:35 -0700942
David Howellsd0016482016-08-30 20:42:14 +0100943 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700944
David Howellsd0016482016-08-30 20:42:14 +0100945 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100946 if (ret < 0)
947 return ret;
David Howells260a9802007-04-26 15:59:35 -0700948
949 /* unmarshall the reply once we've received all of it */
950 bp = call->buffer;
David Howells160cb952018-10-20 00:57:56 +0100951 ret = afs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
952 if (ret < 0)
953 return ret;
954 ret = afs_decode_status(call, &bp, &dvnode->status, dvnode,
955 &call->expected_version, NULL);
956 if (ret < 0)
957 return ret;
David Howells97e30432017-11-02 15:27:48 +0000958 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
David Howells260a9802007-04-26 15:59:35 -0700959
960 _leave(" = 0 [done]");
961 return 0;
962}
963
964/*
965 * FS.Link operation type
966 */
967static const struct afs_call_type afs_RXFSLink = {
968 .name = "FS.Link",
David Howells025db802017-11-02 15:27:51 +0000969 .op = afs_FS_Link,
David Howells260a9802007-04-26 15:59:35 -0700970 .deliver = afs_deliver_fs_link,
David Howells260a9802007-04-26 15:59:35 -0700971 .destructor = afs_flat_call_destructor,
972};
973
974/*
975 * make a hard link
976 */
David Howellsd2ddc772017-11-02 15:27:50 +0000977int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
David Howells63a46812018-04-06 14:17:25 +0100978 const char *name, u64 current_data_version)
David Howells260a9802007-04-26 15:59:35 -0700979{
David Howellsd2ddc772017-11-02 15:27:50 +0000980 struct afs_vnode *dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700981 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000982 struct afs_net *net = afs_v2net(vnode);
David Howells260a9802007-04-26 15:59:35 -0700983 size_t namesz, reqsz, padsz;
984 __be32 *bp;
985
David Howells30062bd2018-10-20 00:57:58 +0100986 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
987 return yfs_fs_link(fc, vnode, name, current_data_version);
988
David Howells260a9802007-04-26 15:59:35 -0700989 _enter("");
990
991 namesz = strlen(name);
992 padsz = (4 - (namesz & 3)) & 3;
993 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
994
David Howellsf044c882017-11-02 15:27:45 +0000995 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700996 if (!call)
997 return -ENOMEM;
998
David Howellsd2ddc772017-11-02 15:27:50 +0000999 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +00001000 call->reply[0] = dvnode;
1001 call->reply[1] = vnode;
David Howells63a46812018-04-06 14:17:25 +01001002 call->expected_version = current_data_version + 1;
David Howells260a9802007-04-26 15:59:35 -07001003
1004 /* marshall the parameters */
1005 bp = call->request;
1006 *bp++ = htonl(FSLINK);
1007 *bp++ = htonl(dvnode->fid.vid);
1008 *bp++ = htonl(dvnode->fid.vnode);
1009 *bp++ = htonl(dvnode->fid.unique);
1010 *bp++ = htonl(namesz);
1011 memcpy(bp, name, namesz);
1012 bp = (void *) bp + namesz;
1013 if (padsz > 0) {
1014 memset(bp, 0, padsz);
1015 bp = (void *) bp + padsz;
1016 }
1017 *bp++ = htonl(vnode->fid.vid);
1018 *bp++ = htonl(vnode->fid.vnode);
1019 *bp++ = htonl(vnode->fid.unique);
1020
David Howellsd2ddc772017-11-02 15:27:50 +00001021 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +01001022 trace_afs_make_fs_call1(call, &vnode->fid, name);
David Howells0b9bf382019-04-25 14:26:50 +01001023 afs_make_call(&fc->ac, call, GFP_NOFS);
1024 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -07001025}
1026
1027/*
1028 * deliver reply data to an FS.Symlink
1029 */
David Howellsd0016482016-08-30 20:42:14 +01001030static int afs_deliver_fs_symlink(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -07001031{
David Howells97e30432017-11-02 15:27:48 +00001032 struct afs_vnode *vnode = call->reply[0];
David Howells260a9802007-04-26 15:59:35 -07001033 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001034 int ret;
David Howells260a9802007-04-26 15:59:35 -07001035
David Howellsd0016482016-08-30 20:42:14 +01001036 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -07001037
David Howellsd0016482016-08-30 20:42:14 +01001038 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001039 if (ret < 0)
1040 return ret;
David Howells260a9802007-04-26 15:59:35 -07001041
1042 /* unmarshall the reply once we've received all of it */
1043 bp = call->buffer;
David Howells97e30432017-11-02 15:27:48 +00001044 xdr_decode_AFSFid(&bp, call->reply[1]);
David Howells160cb952018-10-20 00:57:56 +01001045 ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
1046 if (ret < 0)
1047 return ret;
1048 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1049 &call->expected_version, NULL);
1050 if (ret < 0)
1051 return ret;
David Howells97e30432017-11-02 15:27:48 +00001052 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
David Howells260a9802007-04-26 15:59:35 -07001053
1054 _leave(" = 0 [done]");
1055 return 0;
1056}
1057
1058/*
1059 * FS.Symlink operation type
1060 */
1061static const struct afs_call_type afs_RXFSSymlink = {
1062 .name = "FS.Symlink",
David Howells025db802017-11-02 15:27:51 +00001063 .op = afs_FS_Symlink,
David Howells260a9802007-04-26 15:59:35 -07001064 .deliver = afs_deliver_fs_symlink,
David Howells260a9802007-04-26 15:59:35 -07001065 .destructor = afs_flat_call_destructor,
1066};
1067
1068/*
1069 * create a symbolic link
1070 */
David Howells8b2a4642017-11-02 15:27:50 +00001071int afs_fs_symlink(struct afs_fs_cursor *fc,
David Howells260a9802007-04-26 15:59:35 -07001072 const char *name,
1073 const char *contents,
David Howells63a46812018-04-06 14:17:25 +01001074 u64 current_data_version,
David Howells260a9802007-04-26 15:59:35 -07001075 struct afs_fid *newfid,
David Howellsd2ddc772017-11-02 15:27:50 +00001076 struct afs_file_status *newstatus)
David Howells260a9802007-04-26 15:59:35 -07001077{
David Howellsd2ddc772017-11-02 15:27:50 +00001078 struct afs_vnode *vnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -07001079 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001080 struct afs_net *net = afs_v2net(vnode);
David Howells260a9802007-04-26 15:59:35 -07001081 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
1082 __be32 *bp;
1083
David Howells30062bd2018-10-20 00:57:58 +01001084 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1085 return yfs_fs_symlink(fc, name, contents, current_data_version,
1086 newfid, newstatus);
1087
David Howells260a9802007-04-26 15:59:35 -07001088 _enter("");
1089
1090 namesz = strlen(name);
1091 padsz = (4 - (namesz & 3)) & 3;
1092
1093 c_namesz = strlen(contents);
1094 c_padsz = (4 - (c_namesz & 3)) & 3;
1095
1096 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
1097
David Howellsf044c882017-11-02 15:27:45 +00001098 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
David Howells260a9802007-04-26 15:59:35 -07001099 (3 + 21 + 21 + 6) * 4);
1100 if (!call)
1101 return -ENOMEM;
1102
David Howellsd2ddc772017-11-02 15:27:50 +00001103 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +00001104 call->reply[0] = vnode;
1105 call->reply[1] = newfid;
1106 call->reply[2] = newstatus;
David Howells63a46812018-04-06 14:17:25 +01001107 call->expected_version = current_data_version + 1;
David Howells260a9802007-04-26 15:59:35 -07001108
1109 /* marshall the parameters */
1110 bp = call->request;
1111 *bp++ = htonl(FSSYMLINK);
1112 *bp++ = htonl(vnode->fid.vid);
1113 *bp++ = htonl(vnode->fid.vnode);
1114 *bp++ = htonl(vnode->fid.unique);
1115 *bp++ = htonl(namesz);
1116 memcpy(bp, name, namesz);
1117 bp = (void *) bp + namesz;
1118 if (padsz > 0) {
1119 memset(bp, 0, padsz);
1120 bp = (void *) bp + padsz;
1121 }
1122 *bp++ = htonl(c_namesz);
1123 memcpy(bp, contents, c_namesz);
1124 bp = (void *) bp + c_namesz;
1125 if (c_padsz > 0) {
1126 memset(bp, 0, c_padsz);
1127 bp = (void *) bp + c_padsz;
1128 }
Marc Dionneab94f5d2017-03-16 16:27:47 +00001129 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
1130 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells260a9802007-04-26 15:59:35 -07001131 *bp++ = 0; /* owner */
1132 *bp++ = 0; /* group */
1133 *bp++ = htonl(S_IRWXUGO); /* unix mode */
1134 *bp++ = 0; /* segment size */
1135
David Howellsd2ddc772017-11-02 15:27:50 +00001136 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +01001137 trace_afs_make_fs_call1(call, &vnode->fid, name);
David Howells0b9bf382019-04-25 14:26:50 +01001138 afs_make_call(&fc->ac, call, GFP_NOFS);
1139 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -07001140}
1141
1142/*
1143 * deliver reply data to an FS.Rename
1144 */
David Howellsd0016482016-08-30 20:42:14 +01001145static int afs_deliver_fs_rename(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -07001146{
David Howells97e30432017-11-02 15:27:48 +00001147 struct afs_vnode *orig_dvnode = call->reply[0], *new_dvnode = call->reply[1];
David Howells260a9802007-04-26 15:59:35 -07001148 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001149 int ret;
David Howells260a9802007-04-26 15:59:35 -07001150
David Howellsd0016482016-08-30 20:42:14 +01001151 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -07001152
David Howellsd0016482016-08-30 20:42:14 +01001153 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001154 if (ret < 0)
1155 return ret;
David Howells260a9802007-04-26 15:59:35 -07001156
1157 /* unmarshall the reply once we've received all of it */
1158 bp = call->buffer;
David Howells160cb952018-10-20 00:57:56 +01001159 ret = afs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1160 &call->expected_version, NULL);
1161 if (ret < 0)
1162 return ret;
1163 if (new_dvnode != orig_dvnode) {
1164 ret = afs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1165 &call->expected_version_2, NULL);
1166 if (ret < 0)
1167 return ret;
1168 }
David Howells97e30432017-11-02 15:27:48 +00001169 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
David Howells260a9802007-04-26 15:59:35 -07001170
1171 _leave(" = 0 [done]");
1172 return 0;
1173}
1174
1175/*
1176 * FS.Rename operation type
1177 */
1178static const struct afs_call_type afs_RXFSRename = {
1179 .name = "FS.Rename",
David Howells025db802017-11-02 15:27:51 +00001180 .op = afs_FS_Rename,
David Howells260a9802007-04-26 15:59:35 -07001181 .deliver = afs_deliver_fs_rename,
David Howells260a9802007-04-26 15:59:35 -07001182 .destructor = afs_flat_call_destructor,
1183};
1184
1185/*
1186 * create a symbolic link
1187 */
David Howells8b2a4642017-11-02 15:27:50 +00001188int afs_fs_rename(struct afs_fs_cursor *fc,
David Howells260a9802007-04-26 15:59:35 -07001189 const char *orig_name,
1190 struct afs_vnode *new_dvnode,
David Howells63a46812018-04-06 14:17:25 +01001191 const char *new_name,
1192 u64 current_orig_data_version,
1193 u64 current_new_data_version)
David Howells260a9802007-04-26 15:59:35 -07001194{
David Howellsd2ddc772017-11-02 15:27:50 +00001195 struct afs_vnode *orig_dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -07001196 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001197 struct afs_net *net = afs_v2net(orig_dvnode);
David Howells260a9802007-04-26 15:59:35 -07001198 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1199 __be32 *bp;
1200
David Howells30062bd2018-10-20 00:57:58 +01001201 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1202 return yfs_fs_rename(fc, orig_name,
1203 new_dvnode, new_name,
1204 current_orig_data_version,
1205 current_new_data_version);
1206
David Howells260a9802007-04-26 15:59:35 -07001207 _enter("");
1208
1209 o_namesz = strlen(orig_name);
1210 o_padsz = (4 - (o_namesz & 3)) & 3;
1211
1212 n_namesz = strlen(new_name);
1213 n_padsz = (4 - (n_namesz & 3)) & 3;
1214
1215 reqsz = (4 * 4) +
1216 4 + o_namesz + o_padsz +
1217 (3 * 4) +
1218 4 + n_namesz + n_padsz;
1219
David Howellsf044c882017-11-02 15:27:45 +00001220 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -07001221 if (!call)
1222 return -ENOMEM;
1223
David Howellsd2ddc772017-11-02 15:27:50 +00001224 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +00001225 call->reply[0] = orig_dvnode;
1226 call->reply[1] = new_dvnode;
David Howells63a46812018-04-06 14:17:25 +01001227 call->expected_version = current_orig_data_version + 1;
1228 call->expected_version_2 = current_new_data_version + 1;
David Howells260a9802007-04-26 15:59:35 -07001229
1230 /* marshall the parameters */
1231 bp = call->request;
1232 *bp++ = htonl(FSRENAME);
1233 *bp++ = htonl(orig_dvnode->fid.vid);
1234 *bp++ = htonl(orig_dvnode->fid.vnode);
1235 *bp++ = htonl(orig_dvnode->fid.unique);
1236 *bp++ = htonl(o_namesz);
1237 memcpy(bp, orig_name, o_namesz);
1238 bp = (void *) bp + o_namesz;
1239 if (o_padsz > 0) {
1240 memset(bp, 0, o_padsz);
1241 bp = (void *) bp + o_padsz;
1242 }
1243
1244 *bp++ = htonl(new_dvnode->fid.vid);
1245 *bp++ = htonl(new_dvnode->fid.vnode);
1246 *bp++ = htonl(new_dvnode->fid.unique);
1247 *bp++ = htonl(n_namesz);
1248 memcpy(bp, new_name, n_namesz);
1249 bp = (void *) bp + n_namesz;
1250 if (n_padsz > 0) {
1251 memset(bp, 0, n_padsz);
1252 bp = (void *) bp + n_padsz;
1253 }
1254
David Howellsd2ddc772017-11-02 15:27:50 +00001255 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +01001256 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
David Howells0b9bf382019-04-25 14:26:50 +01001257 afs_make_call(&fc->ac, call, GFP_NOFS);
1258 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -07001259}
David Howells31143d52007-05-09 02:33:46 -07001260
1261/*
1262 * deliver reply data to an FS.StoreData
1263 */
David Howellsd0016482016-08-30 20:42:14 +01001264static int afs_deliver_fs_store_data(struct afs_call *call)
David Howells31143d52007-05-09 02:33:46 -07001265{
David Howells97e30432017-11-02 15:27:48 +00001266 struct afs_vnode *vnode = call->reply[0];
David Howells31143d52007-05-09 02:33:46 -07001267 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001268 int ret;
David Howells31143d52007-05-09 02:33:46 -07001269
David Howellsd0016482016-08-30 20:42:14 +01001270 _enter("");
David Howells31143d52007-05-09 02:33:46 -07001271
David Howellsd0016482016-08-30 20:42:14 +01001272 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001273 if (ret < 0)
1274 return ret;
David Howells31143d52007-05-09 02:33:46 -07001275
1276 /* unmarshall the reply once we've received all of it */
1277 bp = call->buffer;
David Howells160cb952018-10-20 00:57:56 +01001278 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1279 &call->expected_version, NULL);
1280 if (ret < 0)
1281 return ret;
David Howells97e30432017-11-02 15:27:48 +00001282 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
David Howells31143d52007-05-09 02:33:46 -07001283
1284 afs_pages_written_back(vnode, call);
1285
1286 _leave(" = 0 [done]");
1287 return 0;
1288}
1289
1290/*
1291 * FS.StoreData operation type
1292 */
1293static const struct afs_call_type afs_RXFSStoreData = {
1294 .name = "FS.StoreData",
David Howells025db802017-11-02 15:27:51 +00001295 .op = afs_FS_StoreData,
David Howells31143d52007-05-09 02:33:46 -07001296 .deliver = afs_deliver_fs_store_data,
David Howells31143d52007-05-09 02:33:46 -07001297 .destructor = afs_flat_call_destructor,
1298};
1299
David Howellsb9b1f8d2007-05-10 03:15:21 -07001300static const struct afs_call_type afs_RXFSStoreData64 = {
1301 .name = "FS.StoreData64",
David Howells025db802017-11-02 15:27:51 +00001302 .op = afs_FS_StoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001303 .deliver = afs_deliver_fs_store_data,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001304 .destructor = afs_flat_call_destructor,
1305};
1306
1307/*
1308 * store a set of pages to a very large file
1309 */
David Howells8b2a4642017-11-02 15:27:50 +00001310static int afs_fs_store_data64(struct afs_fs_cursor *fc,
David Howells4343d002017-11-02 15:27:52 +00001311 struct address_space *mapping,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001312 pgoff_t first, pgoff_t last,
1313 unsigned offset, unsigned to,
David Howellsd2ddc772017-11-02 15:27:50 +00001314 loff_t size, loff_t pos, loff_t i_size)
David Howellsb9b1f8d2007-05-10 03:15:21 -07001315{
David Howells4343d002017-11-02 15:27:52 +00001316 struct afs_vnode *vnode = fc->vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001317 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001318 struct afs_net *net = afs_v2net(vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001319 __be32 *bp;
1320
David Howells3b6492d2018-10-20 00:57:57 +01001321 _enter(",%x,{%llx:%llu},,",
David Howells4343d002017-11-02 15:27:52 +00001322 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001323
David Howellsf044c882017-11-02 15:27:45 +00001324 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001325 (4 + 6 + 3 * 2) * 4,
1326 (21 + 6) * 4);
1327 if (!call)
1328 return -ENOMEM;
1329
David Howells4343d002017-11-02 15:27:52 +00001330 call->key = fc->key;
1331 call->mapping = mapping;
David Howells97e30432017-11-02 15:27:48 +00001332 call->reply[0] = vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001333 call->first = first;
1334 call->last = last;
1335 call->first_offset = offset;
1336 call->last_to = to;
1337 call->send_pages = true;
David Howells0c3a5ac2018-04-06 14:17:24 +01001338 call->expected_version = vnode->status.data_version + 1;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001339
1340 /* marshall the parameters */
1341 bp = call->request;
1342 *bp++ = htonl(FSSTOREDATA64);
1343 *bp++ = htonl(vnode->fid.vid);
1344 *bp++ = htonl(vnode->fid.vnode);
1345 *bp++ = htonl(vnode->fid.unique);
1346
Marc Dionneab94f5d2017-03-16 16:27:47 +00001347 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1348 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howellsb9b1f8d2007-05-10 03:15:21 -07001349 *bp++ = 0; /* owner */
1350 *bp++ = 0; /* group */
1351 *bp++ = 0; /* unix mode */
1352 *bp++ = 0; /* segment size */
1353
1354 *bp++ = htonl(pos >> 32);
1355 *bp++ = htonl((u32) pos);
1356 *bp++ = htonl(size >> 32);
1357 *bp++ = htonl((u32) size);
1358 *bp++ = htonl(i_size >> 32);
1359 *bp++ = htonl((u32) i_size);
1360
David Howells025db802017-11-02 15:27:51 +00001361 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +01001362 afs_make_call(&fc->ac, call, GFP_NOFS);
1363 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001364}
1365
David Howells31143d52007-05-09 02:33:46 -07001366/*
1367 * store a set of pages
1368 */
David Howells4343d002017-11-02 15:27:52 +00001369int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
David Howells31143d52007-05-09 02:33:46 -07001370 pgoff_t first, pgoff_t last,
David Howellsd2ddc772017-11-02 15:27:50 +00001371 unsigned offset, unsigned to)
David Howells31143d52007-05-09 02:33:46 -07001372{
David Howells4343d002017-11-02 15:27:52 +00001373 struct afs_vnode *vnode = fc->vnode;
David Howells31143d52007-05-09 02:33:46 -07001374 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001375 struct afs_net *net = afs_v2net(vnode);
David Howells31143d52007-05-09 02:33:46 -07001376 loff_t size, pos, i_size;
1377 __be32 *bp;
1378
David Howells30062bd2018-10-20 00:57:58 +01001379 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1380 return yfs_fs_store_data(fc, mapping, first, last, offset, to);
1381
David Howells3b6492d2018-10-20 00:57:57 +01001382 _enter(",%x,{%llx:%llu},,",
David Howells4343d002017-11-02 15:27:52 +00001383 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001384
David Howells146a1192017-03-16 16:27:47 +00001385 size = (loff_t)to - (loff_t)offset;
David Howells31143d52007-05-09 02:33:46 -07001386 if (first != last)
1387 size += (loff_t)(last - first) << PAGE_SHIFT;
1388 pos = (loff_t)first << PAGE_SHIFT;
1389 pos += offset;
1390
1391 i_size = i_size_read(&vnode->vfs_inode);
1392 if (pos + size > i_size)
1393 i_size = size + pos;
1394
1395 _debug("size %llx, at %llx, i_size %llx",
1396 (unsigned long long) size, (unsigned long long) pos,
1397 (unsigned long long) i_size);
1398
David Howellsb9b1f8d2007-05-10 03:15:21 -07001399 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
David Howells4343d002017-11-02 15:27:52 +00001400 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
David Howellsd2ddc772017-11-02 15:27:50 +00001401 size, pos, i_size);
David Howells31143d52007-05-09 02:33:46 -07001402
David Howellsf044c882017-11-02 15:27:45 +00001403 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
David Howells31143d52007-05-09 02:33:46 -07001404 (4 + 6 + 3) * 4,
1405 (21 + 6) * 4);
1406 if (!call)
1407 return -ENOMEM;
1408
David Howells4343d002017-11-02 15:27:52 +00001409 call->key = fc->key;
1410 call->mapping = mapping;
David Howells97e30432017-11-02 15:27:48 +00001411 call->reply[0] = vnode;
David Howells31143d52007-05-09 02:33:46 -07001412 call->first = first;
1413 call->last = last;
1414 call->first_offset = offset;
1415 call->last_to = to;
1416 call->send_pages = true;
David Howells0c3a5ac2018-04-06 14:17:24 +01001417 call->expected_version = vnode->status.data_version + 1;
David Howells31143d52007-05-09 02:33:46 -07001418
1419 /* marshall the parameters */
1420 bp = call->request;
1421 *bp++ = htonl(FSSTOREDATA);
1422 *bp++ = htonl(vnode->fid.vid);
1423 *bp++ = htonl(vnode->fid.vnode);
1424 *bp++ = htonl(vnode->fid.unique);
1425
Marc Dionneab94f5d2017-03-16 16:27:47 +00001426 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1427 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells31143d52007-05-09 02:33:46 -07001428 *bp++ = 0; /* owner */
1429 *bp++ = 0; /* group */
1430 *bp++ = 0; /* unix mode */
1431 *bp++ = 0; /* segment size */
1432
1433 *bp++ = htonl(pos);
1434 *bp++ = htonl(size);
1435 *bp++ = htonl(i_size);
1436
David Howellsd2ddc772017-11-02 15:27:50 +00001437 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001438 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +01001439 afs_make_call(&fc->ac, call, GFP_NOFS);
1440 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells31143d52007-05-09 02:33:46 -07001441}
1442
1443/*
1444 * deliver reply data to an FS.StoreStatus
1445 */
David Howellsd0016482016-08-30 20:42:14 +01001446static int afs_deliver_fs_store_status(struct afs_call *call)
David Howells31143d52007-05-09 02:33:46 -07001447{
David Howells97e30432017-11-02 15:27:48 +00001448 struct afs_vnode *vnode = call->reply[0];
David Howells31143d52007-05-09 02:33:46 -07001449 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001450 int ret;
David Howells31143d52007-05-09 02:33:46 -07001451
David Howellsd0016482016-08-30 20:42:14 +01001452 _enter("");
David Howells31143d52007-05-09 02:33:46 -07001453
David Howellsd0016482016-08-30 20:42:14 +01001454 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001455 if (ret < 0)
1456 return ret;
David Howells31143d52007-05-09 02:33:46 -07001457
1458 /* unmarshall the reply once we've received all of it */
David Howells31143d52007-05-09 02:33:46 -07001459 bp = call->buffer;
David Howells160cb952018-10-20 00:57:56 +01001460 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1461 &call->expected_version, NULL);
1462 if (ret < 0)
1463 return ret;
David Howells97e30432017-11-02 15:27:48 +00001464 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
David Howells31143d52007-05-09 02:33:46 -07001465
1466 _leave(" = 0 [done]");
1467 return 0;
1468}
1469
1470/*
1471 * FS.StoreStatus operation type
1472 */
1473static const struct afs_call_type afs_RXFSStoreStatus = {
1474 .name = "FS.StoreStatus",
David Howells025db802017-11-02 15:27:51 +00001475 .op = afs_FS_StoreStatus,
David Howells31143d52007-05-09 02:33:46 -07001476 .deliver = afs_deliver_fs_store_status,
David Howells31143d52007-05-09 02:33:46 -07001477 .destructor = afs_flat_call_destructor,
1478};
1479
1480static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1481 .name = "FS.StoreData",
David Howells025db802017-11-02 15:27:51 +00001482 .op = afs_FS_StoreData,
David Howells31143d52007-05-09 02:33:46 -07001483 .deliver = afs_deliver_fs_store_status,
David Howells31143d52007-05-09 02:33:46 -07001484 .destructor = afs_flat_call_destructor,
1485};
1486
David Howellsb9b1f8d2007-05-10 03:15:21 -07001487static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1488 .name = "FS.StoreData64",
David Howells025db802017-11-02 15:27:51 +00001489 .op = afs_FS_StoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001490 .deliver = afs_deliver_fs_store_status,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001491 .destructor = afs_flat_call_destructor,
1492};
1493
1494/*
1495 * set the attributes on a very large file, using FS.StoreData rather than
1496 * FS.StoreStatus so as to alter the file size also
1497 */
David Howellsd2ddc772017-11-02 15:27:50 +00001498static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr)
David Howellsb9b1f8d2007-05-10 03:15:21 -07001499{
David Howellsd2ddc772017-11-02 15:27:50 +00001500 struct afs_vnode *vnode = fc->vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001501 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001502 struct afs_net *net = afs_v2net(vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001503 __be32 *bp;
1504
David Howells3b6492d2018-10-20 00:57:57 +01001505 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +00001506 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001507
1508 ASSERT(attr->ia_valid & ATTR_SIZE);
1509
David Howellsf044c882017-11-02 15:27:45 +00001510 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001511 (4 + 6 + 3 * 2) * 4,
1512 (21 + 6) * 4);
1513 if (!call)
1514 return -ENOMEM;
1515
David Howellsd2ddc772017-11-02 15:27:50 +00001516 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +00001517 call->reply[0] = vnode;
David Howells0c3a5ac2018-04-06 14:17:24 +01001518 call->expected_version = vnode->status.data_version + 1;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001519
1520 /* marshall the parameters */
1521 bp = call->request;
1522 *bp++ = htonl(FSSTOREDATA64);
1523 *bp++ = htonl(vnode->fid.vid);
1524 *bp++ = htonl(vnode->fid.vnode);
1525 *bp++ = htonl(vnode->fid.unique);
1526
1527 xdr_encode_AFS_StoreStatus(&bp, attr);
1528
David Howells8c7ae382019-03-27 22:48:02 +00001529 *bp++ = htonl(attr->ia_size >> 32); /* position of start of write */
1530 *bp++ = htonl((u32) attr->ia_size);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001531 *bp++ = 0; /* size of write */
1532 *bp++ = 0;
1533 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1534 *bp++ = htonl((u32) attr->ia_size);
1535
David Howellsd2ddc772017-11-02 15:27:50 +00001536 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001537 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +01001538 afs_make_call(&fc->ac, call, GFP_NOFS);
1539 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001540}
1541
David Howells31143d52007-05-09 02:33:46 -07001542/*
1543 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1544 * so as to alter the file size also
1545 */
David Howellsd2ddc772017-11-02 15:27:50 +00001546static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
David Howells31143d52007-05-09 02:33:46 -07001547{
David Howellsd2ddc772017-11-02 15:27:50 +00001548 struct afs_vnode *vnode = fc->vnode;
David Howells31143d52007-05-09 02:33:46 -07001549 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001550 struct afs_net *net = afs_v2net(vnode);
David Howells31143d52007-05-09 02:33:46 -07001551 __be32 *bp;
1552
David Howells3b6492d2018-10-20 00:57:57 +01001553 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +00001554 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001555
1556 ASSERT(attr->ia_valid & ATTR_SIZE);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001557 if (attr->ia_size >> 32)
David Howellsd2ddc772017-11-02 15:27:50 +00001558 return afs_fs_setattr_size64(fc, attr);
David Howells31143d52007-05-09 02:33:46 -07001559
David Howellsf044c882017-11-02 15:27:45 +00001560 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
David Howells31143d52007-05-09 02:33:46 -07001561 (4 + 6 + 3) * 4,
1562 (21 + 6) * 4);
1563 if (!call)
1564 return -ENOMEM;
1565
David Howellsd2ddc772017-11-02 15:27:50 +00001566 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +00001567 call->reply[0] = vnode;
David Howells0c3a5ac2018-04-06 14:17:24 +01001568 call->expected_version = vnode->status.data_version + 1;
David Howells31143d52007-05-09 02:33:46 -07001569
1570 /* marshall the parameters */
1571 bp = call->request;
1572 *bp++ = htonl(FSSTOREDATA);
1573 *bp++ = htonl(vnode->fid.vid);
1574 *bp++ = htonl(vnode->fid.vnode);
1575 *bp++ = htonl(vnode->fid.unique);
1576
1577 xdr_encode_AFS_StoreStatus(&bp, attr);
1578
David Howells8c7ae382019-03-27 22:48:02 +00001579 *bp++ = htonl(attr->ia_size); /* position of start of write */
David Howells31143d52007-05-09 02:33:46 -07001580 *bp++ = 0; /* size of write */
1581 *bp++ = htonl(attr->ia_size); /* new file length */
1582
David Howellsd2ddc772017-11-02 15:27:50 +00001583 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001584 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +01001585 afs_make_call(&fc->ac, call, GFP_NOFS);
1586 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells31143d52007-05-09 02:33:46 -07001587}
1588
1589/*
1590 * set the attributes on a file, using FS.StoreData if there's a change in file
1591 * size, and FS.StoreStatus otherwise
1592 */
David Howellsd2ddc772017-11-02 15:27:50 +00001593int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
David Howells31143d52007-05-09 02:33:46 -07001594{
David Howellsd2ddc772017-11-02 15:27:50 +00001595 struct afs_vnode *vnode = fc->vnode;
David Howells31143d52007-05-09 02:33:46 -07001596 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001597 struct afs_net *net = afs_v2net(vnode);
David Howells31143d52007-05-09 02:33:46 -07001598 __be32 *bp;
1599
David Howells30062bd2018-10-20 00:57:58 +01001600 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1601 return yfs_fs_setattr(fc, attr);
1602
David Howells31143d52007-05-09 02:33:46 -07001603 if (attr->ia_valid & ATTR_SIZE)
David Howellsd2ddc772017-11-02 15:27:50 +00001604 return afs_fs_setattr_size(fc, attr);
David Howells31143d52007-05-09 02:33:46 -07001605
David Howells3b6492d2018-10-20 00:57:57 +01001606 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +00001607 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001608
David Howellsf044c882017-11-02 15:27:45 +00001609 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
David Howells31143d52007-05-09 02:33:46 -07001610 (4 + 6) * 4,
1611 (21 + 6) * 4);
1612 if (!call)
1613 return -ENOMEM;
1614
David Howellsd2ddc772017-11-02 15:27:50 +00001615 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +00001616 call->reply[0] = vnode;
David Howells0c3a5ac2018-04-06 14:17:24 +01001617 call->expected_version = vnode->status.data_version;
David Howells31143d52007-05-09 02:33:46 -07001618
1619 /* marshall the parameters */
1620 bp = call->request;
1621 *bp++ = htonl(FSSTORESTATUS);
1622 *bp++ = htonl(vnode->fid.vid);
1623 *bp++ = htonl(vnode->fid.vnode);
1624 *bp++ = htonl(vnode->fid.unique);
1625
1626 xdr_encode_AFS_StoreStatus(&bp, attr);
1627
David Howellsd2ddc772017-11-02 15:27:50 +00001628 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001629 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +01001630 afs_make_call(&fc->ac, call, GFP_NOFS);
1631 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells31143d52007-05-09 02:33:46 -07001632}
David Howells45222b92007-05-10 22:22:20 -07001633
1634/*
1635 * deliver reply data to an FS.GetVolumeStatus
1636 */
David Howellsd0016482016-08-30 20:42:14 +01001637static int afs_deliver_fs_get_volume_status(struct afs_call *call)
David Howells45222b92007-05-10 22:22:20 -07001638{
1639 const __be32 *bp;
1640 char *p;
David Howells12bdcf32018-10-20 00:57:56 +01001641 u32 size;
David Howells45222b92007-05-10 22:22:20 -07001642 int ret;
1643
David Howellsd0016482016-08-30 20:42:14 +01001644 _enter("{%u}", call->unmarshall);
David Howells45222b92007-05-10 22:22:20 -07001645
1646 switch (call->unmarshall) {
1647 case 0:
David Howells45222b92007-05-10 22:22:20 -07001648 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01001649 afs_extract_to_buf(call, 12 * 4);
David Howells45222b92007-05-10 22:22:20 -07001650
1651 /* extract the returned status record */
1652 case 1:
1653 _debug("extract status");
David Howells12bdcf32018-10-20 00:57:56 +01001654 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001655 if (ret < 0)
1656 return ret;
David Howells45222b92007-05-10 22:22:20 -07001657
1658 bp = call->buffer;
David Howells97e30432017-11-02 15:27:48 +00001659 xdr_decode_AFSFetchVolumeStatus(&bp, call->reply[1]);
David Howells45222b92007-05-10 22:22:20 -07001660 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01001661 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001662
1663 /* extract the volume name length */
1664 case 2:
David Howells12bdcf32018-10-20 00:57:56 +01001665 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001666 if (ret < 0)
1667 return ret;
David Howells45222b92007-05-10 22:22:20 -07001668
1669 call->count = ntohl(call->tmp);
1670 _debug("volname length: %u", call->count);
1671 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001672 return afs_protocol_error(call, -EBADMSG,
1673 afs_eproto_volname_len);
David Howells12bdcf32018-10-20 00:57:56 +01001674 size = (call->count + 3) & ~3; /* It's padded */
1675 afs_extract_begin(call, call->reply[2], size);
David Howells45222b92007-05-10 22:22:20 -07001676 call->unmarshall++;
1677
1678 /* extract the volume name */
1679 case 3:
1680 _debug("extract volname");
David Howells12bdcf32018-10-20 00:57:56 +01001681 ret = afs_extract_data(call, true);
1682 if (ret < 0)
1683 return ret;
David Howells45222b92007-05-10 22:22:20 -07001684
David Howells97e30432017-11-02 15:27:48 +00001685 p = call->reply[2];
David Howells45222b92007-05-10 22:22:20 -07001686 p[call->count] = 0;
1687 _debug("volname '%s'", p);
David Howells12bdcf32018-10-20 00:57:56 +01001688 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001689 call->unmarshall++;
1690
David Howells45222b92007-05-10 22:22:20 -07001691 /* extract the offline message length */
David Howells12bdcf32018-10-20 00:57:56 +01001692 case 4:
1693 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001694 if (ret < 0)
1695 return ret;
David Howells45222b92007-05-10 22:22:20 -07001696
1697 call->count = ntohl(call->tmp);
1698 _debug("offline msg length: %u", call->count);
1699 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001700 return afs_protocol_error(call, -EBADMSG,
1701 afs_eproto_offline_msg_len);
David Howells12bdcf32018-10-20 00:57:56 +01001702 size = (call->count + 3) & ~3; /* It's padded */
1703 afs_extract_begin(call, call->reply[2], size);
David Howells45222b92007-05-10 22:22:20 -07001704 call->unmarshall++;
1705
1706 /* extract the offline message */
David Howells12bdcf32018-10-20 00:57:56 +01001707 case 5:
David Howells45222b92007-05-10 22:22:20 -07001708 _debug("extract offline");
David Howells12bdcf32018-10-20 00:57:56 +01001709 ret = afs_extract_data(call, true);
1710 if (ret < 0)
1711 return ret;
David Howells45222b92007-05-10 22:22:20 -07001712
David Howells97e30432017-11-02 15:27:48 +00001713 p = call->reply[2];
David Howells45222b92007-05-10 22:22:20 -07001714 p[call->count] = 0;
1715 _debug("offline '%s'", p);
1716
David Howells12bdcf32018-10-20 00:57:56 +01001717 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001718 call->unmarshall++;
1719
David Howells45222b92007-05-10 22:22:20 -07001720 /* extract the message of the day length */
David Howells12bdcf32018-10-20 00:57:56 +01001721 case 6:
1722 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001723 if (ret < 0)
1724 return ret;
David Howells45222b92007-05-10 22:22:20 -07001725
1726 call->count = ntohl(call->tmp);
1727 _debug("motd length: %u", call->count);
1728 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001729 return afs_protocol_error(call, -EBADMSG,
1730 afs_eproto_motd_len);
David Howells12bdcf32018-10-20 00:57:56 +01001731 size = (call->count + 3) & ~3; /* It's padded */
1732 afs_extract_begin(call, call->reply[2], size);
David Howells45222b92007-05-10 22:22:20 -07001733 call->unmarshall++;
1734
1735 /* extract the message of the day */
David Howells12bdcf32018-10-20 00:57:56 +01001736 case 7:
David Howells45222b92007-05-10 22:22:20 -07001737 _debug("extract motd");
David Howells12bdcf32018-10-20 00:57:56 +01001738 ret = afs_extract_data(call, false);
1739 if (ret < 0)
1740 return ret;
David Howells45222b92007-05-10 22:22:20 -07001741
David Howells97e30432017-11-02 15:27:48 +00001742 p = call->reply[2];
David Howells45222b92007-05-10 22:22:20 -07001743 p[call->count] = 0;
1744 _debug("motd '%s'", p);
1745
David Howells45222b92007-05-10 22:22:20 -07001746 call->unmarshall++;
1747
David Howells12bdcf32018-10-20 00:57:56 +01001748 case 8:
David Howells45222b92007-05-10 22:22:20 -07001749 break;
1750 }
1751
David Howells45222b92007-05-10 22:22:20 -07001752 _leave(" = 0 [done]");
1753 return 0;
1754}
1755
1756/*
1757 * destroy an FS.GetVolumeStatus call
1758 */
1759static void afs_get_volume_status_call_destructor(struct afs_call *call)
1760{
David Howells97e30432017-11-02 15:27:48 +00001761 kfree(call->reply[2]);
1762 call->reply[2] = NULL;
David Howells45222b92007-05-10 22:22:20 -07001763 afs_flat_call_destructor(call);
1764}
1765
1766/*
1767 * FS.GetVolumeStatus operation type
1768 */
1769static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1770 .name = "FS.GetVolumeStatus",
David Howells025db802017-11-02 15:27:51 +00001771 .op = afs_FS_GetVolumeStatus,
David Howells45222b92007-05-10 22:22:20 -07001772 .deliver = afs_deliver_fs_get_volume_status,
David Howells45222b92007-05-10 22:22:20 -07001773 .destructor = afs_get_volume_status_call_destructor,
1774};
1775
1776/*
1777 * fetch the status of a volume
1778 */
David Howells8b2a4642017-11-02 15:27:50 +00001779int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
David Howellsd2ddc772017-11-02 15:27:50 +00001780 struct afs_volume_status *vs)
David Howells45222b92007-05-10 22:22:20 -07001781{
David Howellsd2ddc772017-11-02 15:27:50 +00001782 struct afs_vnode *vnode = fc->vnode;
David Howells45222b92007-05-10 22:22:20 -07001783 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001784 struct afs_net *net = afs_v2net(vnode);
David Howells45222b92007-05-10 22:22:20 -07001785 __be32 *bp;
1786 void *tmpbuf;
1787
David Howells30062bd2018-10-20 00:57:58 +01001788 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1789 return yfs_fs_get_volume_status(fc, vs);
1790
David Howells45222b92007-05-10 22:22:20 -07001791 _enter("");
1792
1793 tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1794 if (!tmpbuf)
1795 return -ENOMEM;
1796
David Howellsf044c882017-11-02 15:27:45 +00001797 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
David Howells45222b92007-05-10 22:22:20 -07001798 if (!call) {
1799 kfree(tmpbuf);
1800 return -ENOMEM;
1801 }
1802
David Howellsd2ddc772017-11-02 15:27:50 +00001803 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +00001804 call->reply[0] = vnode;
1805 call->reply[1] = vs;
1806 call->reply[2] = tmpbuf;
David Howells45222b92007-05-10 22:22:20 -07001807
1808 /* marshall the parameters */
1809 bp = call->request;
1810 bp[0] = htonl(FSGETVOLUMESTATUS);
1811 bp[1] = htonl(vnode->fid.vid);
1812
David Howellsd2ddc772017-11-02 15:27:50 +00001813 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001814 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +01001815 afs_make_call(&fc->ac, call, GFP_NOFS);
1816 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells45222b92007-05-10 22:22:20 -07001817}
David Howellse8d6c552007-07-15 23:40:12 -07001818
1819/*
1820 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1821 */
David Howellsd0016482016-08-30 20:42:14 +01001822static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
David Howellse8d6c552007-07-15 23:40:12 -07001823{
1824 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001825 int ret;
David Howellse8d6c552007-07-15 23:40:12 -07001826
David Howellsd0016482016-08-30 20:42:14 +01001827 _enter("{%u}", call->unmarshall);
David Howellse8d6c552007-07-15 23:40:12 -07001828
David Howellsd0016482016-08-30 20:42:14 +01001829 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001830 if (ret < 0)
1831 return ret;
David Howellse8d6c552007-07-15 23:40:12 -07001832
1833 /* unmarshall the reply once we've received all of it */
1834 bp = call->buffer;
David Howells97e30432017-11-02 15:27:48 +00001835 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
David Howellse8d6c552007-07-15 23:40:12 -07001836
1837 _leave(" = 0 [done]");
1838 return 0;
1839}
1840
1841/*
1842 * FS.SetLock operation type
1843 */
1844static const struct afs_call_type afs_RXFSSetLock = {
1845 .name = "FS.SetLock",
David Howells025db802017-11-02 15:27:51 +00001846 .op = afs_FS_SetLock,
David Howellse8d6c552007-07-15 23:40:12 -07001847 .deliver = afs_deliver_fs_xxxx_lock,
David Howellsa690f602019-04-25 14:26:50 +01001848 .done = afs_lock_op_done,
David Howellse8d6c552007-07-15 23:40:12 -07001849 .destructor = afs_flat_call_destructor,
1850};
1851
1852/*
1853 * FS.ExtendLock operation type
1854 */
1855static const struct afs_call_type afs_RXFSExtendLock = {
1856 .name = "FS.ExtendLock",
David Howells025db802017-11-02 15:27:51 +00001857 .op = afs_FS_ExtendLock,
David Howellse8d6c552007-07-15 23:40:12 -07001858 .deliver = afs_deliver_fs_xxxx_lock,
David Howellsa690f602019-04-25 14:26:50 +01001859 .done = afs_lock_op_done,
David Howellse8d6c552007-07-15 23:40:12 -07001860 .destructor = afs_flat_call_destructor,
1861};
1862
1863/*
1864 * FS.ReleaseLock operation type
1865 */
1866static const struct afs_call_type afs_RXFSReleaseLock = {
1867 .name = "FS.ReleaseLock",
David Howells025db802017-11-02 15:27:51 +00001868 .op = afs_FS_ReleaseLock,
David Howellse8d6c552007-07-15 23:40:12 -07001869 .deliver = afs_deliver_fs_xxxx_lock,
David Howellse8d6c552007-07-15 23:40:12 -07001870 .destructor = afs_flat_call_destructor,
1871};
1872
1873/*
David Howellsd2ddc772017-11-02 15:27:50 +00001874 * Set a lock on a file
David Howellse8d6c552007-07-15 23:40:12 -07001875 */
David Howellsd2ddc772017-11-02 15:27:50 +00001876int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
David Howellse8d6c552007-07-15 23:40:12 -07001877{
David Howellsd2ddc772017-11-02 15:27:50 +00001878 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001879 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001880 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001881 __be32 *bp;
1882
David Howells30062bd2018-10-20 00:57:58 +01001883 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1884 return yfs_fs_set_lock(fc, type);
1885
David Howellse8d6c552007-07-15 23:40:12 -07001886 _enter("");
1887
David Howellsf044c882017-11-02 15:27:45 +00001888 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001889 if (!call)
1890 return -ENOMEM;
1891
David Howellsd2ddc772017-11-02 15:27:50 +00001892 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +00001893 call->reply[0] = vnode;
David Howellsa690f602019-04-25 14:26:50 +01001894 call->want_reply_time = true;
David Howellse8d6c552007-07-15 23:40:12 -07001895
1896 /* marshall the parameters */
1897 bp = call->request;
1898 *bp++ = htonl(FSSETLOCK);
1899 *bp++ = htonl(vnode->fid.vid);
1900 *bp++ = htonl(vnode->fid.vnode);
1901 *bp++ = htonl(vnode->fid.unique);
1902 *bp++ = htonl(type);
1903
David Howellsd2ddc772017-11-02 15:27:50 +00001904 afs_use_fs_server(call, fc->cbi);
David Howells6c6c1d62019-04-25 14:26:52 +01001905 trace_afs_make_fs_calli(call, &vnode->fid, type);
David Howells0b9bf382019-04-25 14:26:50 +01001906 afs_make_call(&fc->ac, call, GFP_NOFS);
1907 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellse8d6c552007-07-15 23:40:12 -07001908}
1909
1910/*
1911 * extend a lock on a file
1912 */
David Howellsd2ddc772017-11-02 15:27:50 +00001913int afs_fs_extend_lock(struct afs_fs_cursor *fc)
David Howellse8d6c552007-07-15 23:40:12 -07001914{
David Howellsd2ddc772017-11-02 15:27:50 +00001915 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001916 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001917 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001918 __be32 *bp;
1919
David Howells30062bd2018-10-20 00:57:58 +01001920 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1921 return yfs_fs_extend_lock(fc);
1922
David Howellse8d6c552007-07-15 23:40:12 -07001923 _enter("");
1924
David Howellsf044c882017-11-02 15:27:45 +00001925 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001926 if (!call)
1927 return -ENOMEM;
1928
David Howellsd2ddc772017-11-02 15:27:50 +00001929 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +00001930 call->reply[0] = vnode;
David Howellsa690f602019-04-25 14:26:50 +01001931 call->want_reply_time = true;
David Howellse8d6c552007-07-15 23:40:12 -07001932
1933 /* marshall the parameters */
1934 bp = call->request;
1935 *bp++ = htonl(FSEXTENDLOCK);
1936 *bp++ = htonl(vnode->fid.vid);
1937 *bp++ = htonl(vnode->fid.vnode);
1938 *bp++ = htonl(vnode->fid.unique);
1939
David Howellsd2ddc772017-11-02 15:27:50 +00001940 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001941 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +01001942 afs_make_call(&fc->ac, call, GFP_NOFS);
1943 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellse8d6c552007-07-15 23:40:12 -07001944}
1945
1946/*
1947 * release a lock on a file
1948 */
David Howellsd2ddc772017-11-02 15:27:50 +00001949int afs_fs_release_lock(struct afs_fs_cursor *fc)
David Howellse8d6c552007-07-15 23:40:12 -07001950{
David Howellsd2ddc772017-11-02 15:27:50 +00001951 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001952 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001953 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001954 __be32 *bp;
1955
David Howells30062bd2018-10-20 00:57:58 +01001956 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1957 return yfs_fs_release_lock(fc);
1958
David Howellse8d6c552007-07-15 23:40:12 -07001959 _enter("");
1960
David Howellsf044c882017-11-02 15:27:45 +00001961 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001962 if (!call)
1963 return -ENOMEM;
1964
David Howellsd2ddc772017-11-02 15:27:50 +00001965 call->key = fc->key;
David Howells97e30432017-11-02 15:27:48 +00001966 call->reply[0] = vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001967
1968 /* marshall the parameters */
1969 bp = call->request;
1970 *bp++ = htonl(FSRELEASELOCK);
1971 *bp++ = htonl(vnode->fid.vid);
1972 *bp++ = htonl(vnode->fid.vnode);
1973 *bp++ = htonl(vnode->fid.unique);
1974
David Howellsd2ddc772017-11-02 15:27:50 +00001975 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001976 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +01001977 afs_make_call(&fc->ac, call, GFP_NOFS);
1978 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsc435ee32017-11-02 15:27:49 +00001979}
1980
1981/*
1982 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1983 */
1984static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1985{
1986 return afs_transfer_reply(call);
1987}
1988
1989/*
1990 * FS.GiveUpAllCallBacks operation type
1991 */
1992static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1993 .name = "FS.GiveUpAllCallBacks",
David Howells025db802017-11-02 15:27:51 +00001994 .op = afs_FS_GiveUpAllCallBacks,
David Howellsc435ee32017-11-02 15:27:49 +00001995 .deliver = afs_deliver_fs_give_up_all_callbacks,
1996 .destructor = afs_flat_call_destructor,
1997};
1998
1999/*
2000 * Flush all the callbacks we have on a server.
2001 */
David Howellsd2ddc772017-11-02 15:27:50 +00002002int afs_fs_give_up_all_callbacks(struct afs_net *net,
2003 struct afs_server *server,
David Howells8b2a4642017-11-02 15:27:50 +00002004 struct afs_addr_cursor *ac,
David Howellsd2ddc772017-11-02 15:27:50 +00002005 struct key *key)
David Howellsc435ee32017-11-02 15:27:49 +00002006{
2007 struct afs_call *call;
2008 __be32 *bp;
2009
2010 _enter("");
2011
David Howellsd2ddc772017-11-02 15:27:50 +00002012 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
David Howellsc435ee32017-11-02 15:27:49 +00002013 if (!call)
2014 return -ENOMEM;
2015
2016 call->key = key;
2017
2018 /* marshall the parameters */
2019 bp = call->request;
2020 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
2021
2022 /* Can't take a ref on server */
David Howells0b9bf382019-04-25 14:26:50 +01002023 afs_make_call(ac, call, GFP_NOFS);
2024 return afs_wait_for_call_to_complete(call, ac);
David Howellsd2ddc772017-11-02 15:27:50 +00002025}
2026
2027/*
2028 * Deliver reply data to an FS.GetCapabilities operation.
2029 */
2030static int afs_deliver_fs_get_capabilities(struct afs_call *call)
2031{
2032 u32 count;
2033 int ret;
2034
David Howells12bdcf32018-10-20 00:57:56 +01002035 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
David Howellsd2ddc772017-11-02 15:27:50 +00002036
David Howellsd2ddc772017-11-02 15:27:50 +00002037 switch (call->unmarshall) {
2038 case 0:
David Howells12bdcf32018-10-20 00:57:56 +01002039 afs_extract_to_tmp(call);
David Howellsd2ddc772017-11-02 15:27:50 +00002040 call->unmarshall++;
2041
2042 /* Extract the capabilities word count */
2043 case 1:
David Howells12bdcf32018-10-20 00:57:56 +01002044 ret = afs_extract_data(call, true);
David Howellsd2ddc772017-11-02 15:27:50 +00002045 if (ret < 0)
2046 return ret;
2047
2048 count = ntohl(call->tmp);
2049
2050 call->count = count;
2051 call->count2 = count;
David Howells12bdcf32018-10-20 00:57:56 +01002052 iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
David Howellsd2ddc772017-11-02 15:27:50 +00002053 call->unmarshall++;
2054
2055 /* Extract capabilities words */
2056 case 2:
David Howells12bdcf32018-10-20 00:57:56 +01002057 ret = afs_extract_data(call, false);
David Howellsd2ddc772017-11-02 15:27:50 +00002058 if (ret < 0)
2059 return ret;
2060
2061 /* TODO: Examine capabilities */
2062
David Howellsd2ddc772017-11-02 15:27:50 +00002063 call->unmarshall++;
2064 break;
2065 }
2066
2067 _leave(" = 0 [done]");
2068 return 0;
2069}
2070
David Howells3bf0fb62018-10-20 00:57:59 +01002071static void afs_destroy_fs_get_capabilities(struct afs_call *call)
2072{
2073 struct afs_server *server = call->reply[0];
2074
2075 afs_put_server(call->net, server);
2076 afs_flat_call_destructor(call);
2077}
2078
David Howellsd2ddc772017-11-02 15:27:50 +00002079/*
2080 * FS.GetCapabilities operation type
2081 */
2082static const struct afs_call_type afs_RXFSGetCapabilities = {
2083 .name = "FS.GetCapabilities",
David Howells025db802017-11-02 15:27:51 +00002084 .op = afs_FS_GetCapabilities,
David Howellsd2ddc772017-11-02 15:27:50 +00002085 .deliver = afs_deliver_fs_get_capabilities,
David Howells3bf0fb62018-10-20 00:57:59 +01002086 .done = afs_fileserver_probe_result,
2087 .destructor = afs_destroy_fs_get_capabilities,
David Howellsd2ddc772017-11-02 15:27:50 +00002088};
2089
2090/*
2091 * Probe a fileserver for the capabilities that it supports. This can
2092 * return up to 196 words.
2093 */
David Howells0b9bf382019-04-25 14:26:50 +01002094struct afs_call *afs_fs_get_capabilities(struct afs_net *net,
2095 struct afs_server *server,
2096 struct afs_addr_cursor *ac,
2097 struct key *key,
2098 unsigned int server_index)
David Howellsd2ddc772017-11-02 15:27:50 +00002099{
2100 struct afs_call *call;
2101 __be32 *bp;
2102
2103 _enter("");
2104
2105 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
2106 if (!call)
David Howells0b9bf382019-04-25 14:26:50 +01002107 return ERR_PTR(-ENOMEM);
David Howellsd2ddc772017-11-02 15:27:50 +00002108
2109 call->key = key;
David Howells3bf0fb62018-10-20 00:57:59 +01002110 call->reply[0] = afs_get_server(server);
2111 call->reply[1] = (void *)(long)server_index;
David Howells30062bd2018-10-20 00:57:58 +01002112 call->upgrade = true;
David Howells3bf0fb62018-10-20 00:57:59 +01002113 call->want_reply_time = true;
David Howells0b9bf382019-04-25 14:26:50 +01002114 call->async = true;
David Howellsd2ddc772017-11-02 15:27:50 +00002115
2116 /* marshall the parameters */
2117 bp = call->request;
2118 *bp++ = htonl(FSGETCAPABILITIES);
2119
2120 /* Can't take a ref on server */
David Howells025db802017-11-02 15:27:51 +00002121 trace_afs_make_fs_call(call, NULL);
David Howells0b9bf382019-04-25 14:26:50 +01002122 afs_make_call(ac, call, GFP_NOFS);
2123 return call;
David Howellse8d6c552007-07-15 23:40:12 -07002124}
David Howells5cf9dd52018-04-09 21:12:31 +01002125
2126/*
2127 * Deliver reply data to an FS.FetchStatus with no vnode.
2128 */
2129static int afs_deliver_fs_fetch_status(struct afs_call *call)
2130{
2131 struct afs_file_status *status = call->reply[1];
2132 struct afs_callback *callback = call->reply[2];
2133 struct afs_volsync *volsync = call->reply[3];
David Howells36bb5f42018-10-20 00:57:58 +01002134 struct afs_fid *fid = call->reply[0];
David Howells5cf9dd52018-04-09 21:12:31 +01002135 const __be32 *bp;
2136 int ret;
2137
2138 ret = afs_transfer_reply(call);
2139 if (ret < 0)
2140 return ret;
2141
David Howells36bb5f42018-10-20 00:57:58 +01002142 _enter("{%llx:%llu}", fid->vid, fid->vnode);
David Howells5cf9dd52018-04-09 21:12:31 +01002143
2144 /* unmarshall the reply once we've received all of it */
2145 bp = call->buffer;
David Howells36bb5f42018-10-20 00:57:58 +01002146 ret = afs_decode_status(call, &bp, status, NULL,
David Howells160cb952018-10-20 00:57:56 +01002147 &call->expected_version, NULL);
2148 if (ret < 0)
2149 return ret;
David Howells12d8e952018-10-20 00:57:58 +01002150 xdr_decode_AFSCallBack_raw(call, &bp, callback);
David Howells30062bd2018-10-20 00:57:58 +01002151 xdr_decode_AFSVolSync(&bp, volsync);
David Howells5cf9dd52018-04-09 21:12:31 +01002152
2153 _leave(" = 0 [done]");
2154 return 0;
2155}
2156
2157/*
2158 * FS.FetchStatus operation type
2159 */
2160static const struct afs_call_type afs_RXFSFetchStatus = {
2161 .name = "FS.FetchStatus",
2162 .op = afs_FS_FetchStatus,
2163 .deliver = afs_deliver_fs_fetch_status,
2164 .destructor = afs_flat_call_destructor,
2165};
2166
2167/*
2168 * Fetch the status information for a fid without needing a vnode handle.
2169 */
2170int afs_fs_fetch_status(struct afs_fs_cursor *fc,
2171 struct afs_net *net,
2172 struct afs_fid *fid,
2173 struct afs_file_status *status,
2174 struct afs_callback *callback,
2175 struct afs_volsync *volsync)
2176{
2177 struct afs_call *call;
2178 __be32 *bp;
2179
David Howells30062bd2018-10-20 00:57:58 +01002180 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2181 return yfs_fs_fetch_status(fc, net, fid, status, callback, volsync);
2182
David Howells3b6492d2018-10-20 00:57:57 +01002183 _enter(",%x,{%llx:%llu},,",
David Howells5cf9dd52018-04-09 21:12:31 +01002184 key_serial(fc->key), fid->vid, fid->vnode);
2185
2186 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
2187 if (!call) {
2188 fc->ac.error = -ENOMEM;
2189 return -ENOMEM;
2190 }
2191
2192 call->key = fc->key;
David Howells36bb5f42018-10-20 00:57:58 +01002193 call->reply[0] = fid;
David Howells5cf9dd52018-04-09 21:12:31 +01002194 call->reply[1] = status;
2195 call->reply[2] = callback;
2196 call->reply[3] = volsync;
David Howells0c3a5ac2018-04-06 14:17:24 +01002197 call->expected_version = 1; /* vnode->status.data_version */
David Howells12d8e952018-10-20 00:57:58 +01002198 call->want_reply_time = true;
David Howells5cf9dd52018-04-09 21:12:31 +01002199
2200 /* marshall the parameters */
2201 bp = call->request;
2202 bp[0] = htonl(FSFETCHSTATUS);
2203 bp[1] = htonl(fid->vid);
2204 bp[2] = htonl(fid->vnode);
2205 bp[3] = htonl(fid->unique);
2206
2207 call->cb_break = fc->cb_break;
2208 afs_use_fs_server(call, fc->cbi);
2209 trace_afs_make_fs_call(call, fid);
David Howells0b9bf382019-04-25 14:26:50 +01002210 afs_make_call(&fc->ac, call, GFP_NOFS);
2211 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells5cf9dd52018-04-09 21:12:31 +01002212}
2213
2214/*
2215 * Deliver reply data to an FS.InlineBulkStatus call
2216 */
2217static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2218{
2219 struct afs_file_status *statuses;
2220 struct afs_callback *callbacks;
2221 struct afs_vnode *vnode = call->reply[0];
2222 const __be32 *bp;
2223 u32 tmp;
2224 int ret;
2225
2226 _enter("{%u}", call->unmarshall);
2227
2228 switch (call->unmarshall) {
2229 case 0:
David Howells12bdcf32018-10-20 00:57:56 +01002230 afs_extract_to_tmp(call);
David Howells5cf9dd52018-04-09 21:12:31 +01002231 call->unmarshall++;
2232
2233 /* Extract the file status count and array in two steps */
2234 case 1:
2235 _debug("extract status count");
David Howells12bdcf32018-10-20 00:57:56 +01002236 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002237 if (ret < 0)
2238 return ret;
2239
2240 tmp = ntohl(call->tmp);
2241 _debug("status count: %u/%u", tmp, call->count2);
2242 if (tmp != call->count2)
David Howells160cb952018-10-20 00:57:56 +01002243 return afs_protocol_error(call, -EBADMSG,
2244 afs_eproto_ibulkst_count);
David Howells5cf9dd52018-04-09 21:12:31 +01002245
2246 call->count = 0;
2247 call->unmarshall++;
2248 more_counts:
David Howells12bdcf32018-10-20 00:57:56 +01002249 afs_extract_to_buf(call, 21 * sizeof(__be32));
David Howells5cf9dd52018-04-09 21:12:31 +01002250
2251 case 2:
2252 _debug("extract status array %u", call->count);
David Howells12bdcf32018-10-20 00:57:56 +01002253 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002254 if (ret < 0)
2255 return ret;
2256
2257 bp = call->buffer;
2258 statuses = call->reply[1];
David Howells160cb952018-10-20 00:57:56 +01002259 ret = afs_decode_status(call, &bp, &statuses[call->count],
2260 call->count == 0 ? vnode : NULL,
2261 NULL, NULL);
2262 if (ret < 0)
2263 return ret;
David Howells5cf9dd52018-04-09 21:12:31 +01002264
2265 call->count++;
2266 if (call->count < call->count2)
2267 goto more_counts;
2268
2269 call->count = 0;
2270 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01002271 afs_extract_to_tmp(call);
David Howells5cf9dd52018-04-09 21:12:31 +01002272
2273 /* Extract the callback count and array in two steps */
2274 case 3:
2275 _debug("extract CB count");
David Howells12bdcf32018-10-20 00:57:56 +01002276 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002277 if (ret < 0)
2278 return ret;
2279
2280 tmp = ntohl(call->tmp);
2281 _debug("CB count: %u", tmp);
2282 if (tmp != call->count2)
David Howells160cb952018-10-20 00:57:56 +01002283 return afs_protocol_error(call, -EBADMSG,
2284 afs_eproto_ibulkst_cb_count);
David Howells5cf9dd52018-04-09 21:12:31 +01002285 call->count = 0;
2286 call->unmarshall++;
2287 more_cbs:
David Howells12bdcf32018-10-20 00:57:56 +01002288 afs_extract_to_buf(call, 3 * sizeof(__be32));
David Howells5cf9dd52018-04-09 21:12:31 +01002289
2290 case 4:
2291 _debug("extract CB array");
David Howells12bdcf32018-10-20 00:57:56 +01002292 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002293 if (ret < 0)
2294 return ret;
2295
2296 _debug("unmarshall CB array");
2297 bp = call->buffer;
2298 callbacks = call->reply[2];
2299 callbacks[call->count].version = ntohl(bp[0]);
David Howells12d8e952018-10-20 00:57:58 +01002300 callbacks[call->count].expires_at = xdr_decode_expiry(call, ntohl(bp[1]));
David Howells5cf9dd52018-04-09 21:12:31 +01002301 callbacks[call->count].type = ntohl(bp[2]);
2302 statuses = call->reply[1];
2303 if (call->count == 0 && vnode && statuses[0].abort_code == 0)
2304 xdr_decode_AFSCallBack(call, vnode, &bp);
2305 call->count++;
2306 if (call->count < call->count2)
2307 goto more_cbs;
2308
David Howells12bdcf32018-10-20 00:57:56 +01002309 afs_extract_to_buf(call, 6 * sizeof(__be32));
David Howells5cf9dd52018-04-09 21:12:31 +01002310 call->unmarshall++;
2311
2312 case 5:
David Howells12bdcf32018-10-20 00:57:56 +01002313 ret = afs_extract_data(call, false);
David Howells5cf9dd52018-04-09 21:12:31 +01002314 if (ret < 0)
2315 return ret;
2316
2317 bp = call->buffer;
David Howells30062bd2018-10-20 00:57:58 +01002318 xdr_decode_AFSVolSync(&bp, call->reply[3]);
David Howells5cf9dd52018-04-09 21:12:31 +01002319
David Howells5cf9dd52018-04-09 21:12:31 +01002320 call->unmarshall++;
2321
2322 case 6:
2323 break;
2324 }
2325
2326 _leave(" = 0 [done]");
2327 return 0;
2328}
2329
2330/*
2331 * FS.InlineBulkStatus operation type
2332 */
2333static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2334 .name = "FS.InlineBulkStatus",
2335 .op = afs_FS_InlineBulkStatus,
2336 .deliver = afs_deliver_fs_inline_bulk_status,
2337 .destructor = afs_flat_call_destructor,
2338};
2339
2340/*
2341 * Fetch the status information for up to 50 files
2342 */
2343int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2344 struct afs_net *net,
2345 struct afs_fid *fids,
2346 struct afs_file_status *statuses,
2347 struct afs_callback *callbacks,
2348 unsigned int nr_fids,
2349 struct afs_volsync *volsync)
2350{
2351 struct afs_call *call;
2352 __be32 *bp;
2353 int i;
2354
David Howells30062bd2018-10-20 00:57:58 +01002355 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2356 return yfs_fs_inline_bulk_status(fc, net, fids, statuses, callbacks,
2357 nr_fids, volsync);
2358
David Howells3b6492d2018-10-20 00:57:57 +01002359 _enter(",%x,{%llx:%llu},%u",
David Howells5cf9dd52018-04-09 21:12:31 +01002360 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2361
2362 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2363 (2 + nr_fids * 3) * 4,
2364 21 * 4);
2365 if (!call) {
2366 fc->ac.error = -ENOMEM;
2367 return -ENOMEM;
2368 }
2369
2370 call->key = fc->key;
2371 call->reply[0] = NULL; /* vnode for fid[0] */
2372 call->reply[1] = statuses;
2373 call->reply[2] = callbacks;
2374 call->reply[3] = volsync;
2375 call->count2 = nr_fids;
David Howells12d8e952018-10-20 00:57:58 +01002376 call->want_reply_time = true;
David Howells5cf9dd52018-04-09 21:12:31 +01002377
2378 /* marshall the parameters */
2379 bp = call->request;
2380 *bp++ = htonl(FSINLINEBULKSTATUS);
2381 *bp++ = htonl(nr_fids);
2382 for (i = 0; i < nr_fids; i++) {
2383 *bp++ = htonl(fids[i].vid);
2384 *bp++ = htonl(fids[i].vnode);
2385 *bp++ = htonl(fids[i].unique);
2386 }
2387
2388 call->cb_break = fc->cb_break;
2389 afs_use_fs_server(call, fc->cbi);
2390 trace_afs_make_fs_call(call, &fids[0]);
David Howells0b9bf382019-04-25 14:26:50 +01002391 afs_make_call(&fc->ac, call, GFP_NOFS);
2392 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells5cf9dd52018-04-09 21:12:31 +01002393}
David Howells260f0822019-04-25 14:26:52 +01002394
2395/*
2396 * deliver reply data to an FS.FetchACL
2397 */
2398static int afs_deliver_fs_fetch_acl(struct afs_call *call)
2399{
2400 struct afs_vnode *vnode = call->reply[1];
2401 struct afs_acl *acl;
2402 const __be32 *bp;
2403 unsigned int size;
2404 int ret;
2405
2406 _enter("{%u}", call->unmarshall);
2407
2408 switch (call->unmarshall) {
2409 case 0:
2410 afs_extract_to_tmp(call);
2411 call->unmarshall++;
2412
2413 /* extract the returned data length */
2414 case 1:
2415 ret = afs_extract_data(call, true);
2416 if (ret < 0)
2417 return ret;
2418
2419 size = call->count2 = ntohl(call->tmp);
2420 size = round_up(size, 4);
2421
2422 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2423 if (!acl)
2424 return -ENOMEM;
2425 call->reply[0] = acl;
2426 acl->size = call->count2;
2427 afs_extract_begin(call, acl->data, size);
2428 call->unmarshall++;
2429
2430 /* extract the returned data */
2431 case 2:
2432 ret = afs_extract_data(call, true);
2433 if (ret < 0)
2434 return ret;
2435
2436 afs_extract_to_buf(call, (21 + 6) * 4);
2437 call->unmarshall++;
2438
2439 /* extract the metadata */
2440 case 3:
2441 ret = afs_extract_data(call, false);
2442 if (ret < 0)
2443 return ret;
2444
2445 bp = call->buffer;
2446 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
2447 &vnode->status.data_version, NULL);
2448 if (ret < 0)
2449 return ret;
2450 xdr_decode_AFSVolSync(&bp, call->reply[2]);
2451
2452 call->unmarshall++;
2453
2454 case 4:
2455 break;
2456 }
2457
2458 _leave(" = 0 [done]");
2459 return 0;
2460}
2461
2462static void afs_destroy_fs_fetch_acl(struct afs_call *call)
2463{
2464 kfree(call->reply[0]);
2465 afs_flat_call_destructor(call);
2466}
2467
2468/*
2469 * FS.FetchACL operation type
2470 */
2471static const struct afs_call_type afs_RXFSFetchACL = {
2472 .name = "FS.FetchACL",
2473 .op = afs_FS_FetchACL,
2474 .deliver = afs_deliver_fs_fetch_acl,
2475 .destructor = afs_destroy_fs_fetch_acl,
2476};
2477
2478/*
2479 * Fetch the ACL for a file.
2480 */
2481struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc)
2482{
2483 struct afs_vnode *vnode = fc->vnode;
2484 struct afs_call *call;
2485 struct afs_net *net = afs_v2net(vnode);
2486 __be32 *bp;
2487
2488 _enter(",%x,{%llx:%llu},,",
2489 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2490
2491 call = afs_alloc_flat_call(net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2492 if (!call) {
2493 fc->ac.error = -ENOMEM;
2494 return ERR_PTR(-ENOMEM);
2495 }
2496
2497 call->key = fc->key;
2498 call->reply[0] = NULL;
2499 call->reply[1] = vnode;
2500 call->reply[2] = NULL; /* volsync */
2501 call->ret_reply0 = true;
2502
2503 /* marshall the parameters */
2504 bp = call->request;
2505 bp[0] = htonl(FSFETCHACL);
2506 bp[1] = htonl(vnode->fid.vid);
2507 bp[2] = htonl(vnode->fid.vnode);
2508 bp[3] = htonl(vnode->fid.unique);
2509
2510 call->cb_break = fc->cb_break;
2511 afs_use_fs_server(call, fc->cbi);
2512 trace_afs_make_fs_call(call, &vnode->fid);
2513 afs_make_call(&fc->ac, call, GFP_KERNEL);
2514 return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2515}