blob: 3854d16e14b18c7e38317b7b361ad92dd0a3e9b2 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells08e0e7c2007-04-26 15:55:03 -07002/* AFS File Server client stubs
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
David Howells08e0e7c2007-04-26 15:55:03 -07004 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Written by David Howells (dhowells@redhat.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/sched.h>
David Howells08e0e7c2007-04-26 15:55:03 -070011#include <linux/circ_buf.h>
Jeff Laytona01179e2017-12-11 06:35:11 -050012#include <linux/iversion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070014#include "afs_fs.h"
David Howellsdd9fbcb2018-04-06 14:17:24 +010015#include "xdr_fs.h"
David Howells30062bd2018-10-20 00:57:58 +010016#include "protocol_yfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
David Howellsd2ddc772017-11-02 15:27:50 +000018static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
David Howellsc435ee32017-11-02 15:27:49 +000019{
David Howellsd2ddc772017-11-02 15:27:50 +000020 call->cbi = afs_get_cb_interest(cbi);
David Howellsc435ee32017-11-02 15:27:49 +000021}
22
David Howells6db3ac32017-03-16 16:27:44 +000023/*
David Howells260a9802007-04-26 15:59:35 -070024 * decode an AFSFid block
25 */
26static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
27{
28 const __be32 *bp = *_bp;
29
30 fid->vid = ntohl(*bp++);
31 fid->vnode = ntohl(*bp++);
32 fid->unique = ntohl(*bp++);
33 *_bp = bp;
34}
35
36/*
David Howells888b3382018-04-06 14:17:24 +010037 * Dump a bad file status record.
38 */
39static void xdr_dump_bad(const __be32 *bp)
40{
41 __be32 x[4];
42 int i;
43
44 pr_notice("AFS XDR: Bad status record\n");
45 for (i = 0; i < 5 * 4 * 4; i += 16) {
46 memcpy(x, bp, 16);
47 bp += 4;
48 pr_notice("%03x: %08x %08x %08x %08x\n",
49 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
50 }
51
52 memcpy(x, bp, 4);
53 pr_notice("0x50: %08x\n", ntohl(x[0]));
54}
55
56/*
David Howellsdd9fbcb2018-04-06 14:17:24 +010057 * decode an AFSFetchStatus block
58 */
David Howellsa58823a2019-05-09 15:16:10 +010059static int xdr_decode_AFSFetchStatus(const __be32 **_bp,
60 struct afs_call *call,
61 struct afs_status_cb *scb)
David Howellsdd9fbcb2018-04-06 14:17:24 +010062{
63 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
David Howellsa58823a2019-05-09 15:16:10 +010064 struct afs_file_status *status = &scb->status;
David Howells684b0f62018-05-10 21:51:47 +010065 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
David Howellsdd9fbcb2018-04-06 14:17:24 +010066 u64 data_version, size;
67 u32 type, abort_code;
David Howellsc72057b2020-04-08 16:13:20 +010068 int ret;
David Howellsdd9fbcb2018-04-06 14:17:24 +010069
David Howells684b0f62018-05-10 21:51:47 +010070 abort_code = ntohl(xdr->abort_code);
71
David Howellsdd9fbcb2018-04-06 14:17:24 +010072 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
David Howells684b0f62018-05-10 21:51:47 +010073 if (xdr->if_version == htonl(0) &&
74 abort_code != 0 &&
75 inline_error) {
76 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
77 * whereby it doesn't set the interface version in the error
78 * case.
79 */
80 status->abort_code = abort_code;
David Howellsa38a7552019-05-14 12:29:11 +010081 scb->have_error = true;
David Howellsc72057b2020-04-08 16:13:20 +010082 goto good;
David Howells684b0f62018-05-10 21:51:47 +010083 }
84
David Howellsdd9fbcb2018-04-06 14:17:24 +010085 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
86 goto bad;
87 }
88
David Howells684b0f62018-05-10 21:51:47 +010089 if (abort_code != 0 && inline_error) {
90 status->abort_code = abort_code;
David Howells3e0d9892020-04-08 17:32:10 +010091 scb->have_error = true;
David Howellsc72057b2020-04-08 16:13:20 +010092 goto good;
David Howells684b0f62018-05-10 21:51:47 +010093 }
94
David Howellsdd9fbcb2018-04-06 14:17:24 +010095 type = ntohl(xdr->type);
David Howellsdd9fbcb2018-04-06 14:17:24 +010096 switch (type) {
97 case AFS_FTYPE_FILE:
98 case AFS_FTYPE_DIR:
99 case AFS_FTYPE_SYMLINK:
David Howellsdd9fbcb2018-04-06 14:17:24 +0100100 status->type = type;
101 break;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100102 default:
103 goto bad;
104 }
105
David Howellsa58823a2019-05-09 15:16:10 +0100106 status->nlink = ntohl(xdr->nlink);
107 status->author = ntohl(xdr->author);
108 status->owner = ntohl(xdr->owner);
109 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
110 status->anon_access = ntohl(xdr->anon_access);
111 status->mode = ntohl(xdr->mode) & S_IALLUGO;
112 status->group = ntohl(xdr->group);
113 status->lock_count = ntohl(xdr->lock_count);
David Howellsdd9fbcb2018-04-06 14:17:24 +0100114
David Howellsd4936802018-10-20 00:57:58 +0100115 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
116 status->mtime_client.tv_nsec = 0;
117 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
118 status->mtime_server.tv_nsec = 0;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100119
120 size = (u64)ntohl(xdr->size_lo);
121 size |= (u64)ntohl(xdr->size_hi) << 32;
David Howells63a46812018-04-06 14:17:25 +0100122 status->size = size;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100123
124 data_version = (u64)ntohl(xdr->data_version_lo);
125 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
David Howellsa58823a2019-05-09 15:16:10 +0100126 status->data_version = data_version;
David Howellsa38a7552019-05-14 12:29:11 +0100127 scb->have_status = true;
David Howellsc72057b2020-04-08 16:13:20 +0100128good:
129 ret = 0;
130advance:
David Howellsdd9fbcb2018-04-06 14:17:24 +0100131 *_bp = (const void *)*_bp + sizeof(*xdr);
David Howellsc72057b2020-04-08 16:13:20 +0100132 return ret;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100133
134bad:
135 xdr_dump_bad(*_bp);
David Howellsc72057b2020-04-08 16:13:20 +0100136 ret = afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
137 goto advance;
David Howellsc875c762018-05-23 11:32:06 +0100138}
139
David Howells78107052019-05-09 17:56:53 +0100140static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
141{
142 return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
143}
144
David Howellsa58823a2019-05-09 15:16:10 +0100145static void xdr_decode_AFSCallBack(const __be32 **_bp,
146 struct afs_call *call,
147 struct afs_status_cb *scb)
David Howells78107052019-05-09 17:56:53 +0100148{
David Howellsa58823a2019-05-09 15:16:10 +0100149 struct afs_callback *cb = &scb->callback;
David Howells78107052019-05-09 17:56:53 +0100150 const __be32 *bp = *_bp;
151
David Howells7c712452019-05-14 15:35:44 +0100152 bp++; /* version */
David Howells78107052019-05-09 17:56:53 +0100153 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
David Howells7c712452019-05-14 15:35:44 +0100154 bp++; /* type */
David Howellsa58823a2019-05-09 15:16:10 +0100155 scb->have_cb = true;
David Howells78107052019-05-09 17:56:53 +0100156 *_bp = bp;
157}
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159/*
David Howells08e0e7c2007-04-26 15:55:03 -0700160 * decode an AFSVolSync block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 */
David Howells08e0e7c2007-04-26 15:55:03 -0700162static void xdr_decode_AFSVolSync(const __be32 **_bp,
163 struct afs_volsync *volsync)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
David Howells08e0e7c2007-04-26 15:55:03 -0700165 const __be32 *bp = *_bp;
David Howells30062bd2018-10-20 00:57:58 +0100166 u32 creation;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
David Howells30062bd2018-10-20 00:57:58 +0100168 creation = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700169 bp++; /* spare2 */
170 bp++; /* spare3 */
171 bp++; /* spare4 */
172 bp++; /* spare5 */
173 bp++; /* spare6 */
174 *_bp = bp;
David Howells30062bd2018-10-20 00:57:58 +0100175
176 if (volsync)
177 volsync->creation = creation;
David Howellsec268152007-04-26 15:49:28 -0700178}
David Howells08e0e7c2007-04-26 15:55:03 -0700179
180/*
David Howells31143d52007-05-09 02:33:46 -0700181 * encode the requested attributes into an AFSStoreStatus block
182 */
183static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
184{
185 __be32 *bp = *_bp;
186 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
187
188 mask = 0;
189 if (attr->ia_valid & ATTR_MTIME) {
190 mask |= AFS_SET_MTIME;
191 mtime = attr->ia_mtime.tv_sec;
192 }
193
194 if (attr->ia_valid & ATTR_UID) {
195 mask |= AFS_SET_OWNER;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800196 owner = from_kuid(&init_user_ns, attr->ia_uid);
David Howells31143d52007-05-09 02:33:46 -0700197 }
198
199 if (attr->ia_valid & ATTR_GID) {
200 mask |= AFS_SET_GROUP;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800201 group = from_kgid(&init_user_ns, attr->ia_gid);
David Howells31143d52007-05-09 02:33:46 -0700202 }
203
204 if (attr->ia_valid & ATTR_MODE) {
205 mask |= AFS_SET_MODE;
206 mode = attr->ia_mode & S_IALLUGO;
207 }
208
209 *bp++ = htonl(mask);
210 *bp++ = htonl(mtime);
211 *bp++ = htonl(owner);
212 *bp++ = htonl(group);
213 *bp++ = htonl(mode);
214 *bp++ = 0; /* segment size */
215 *_bp = bp;
216}
217
218/*
David Howells45222b92007-05-10 22:22:20 -0700219 * decode an AFSFetchVolumeStatus block
220 */
221static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
222 struct afs_volume_status *vs)
223{
224 const __be32 *bp = *_bp;
225
226 vs->vid = ntohl(*bp++);
227 vs->parent_id = ntohl(*bp++);
228 vs->online = ntohl(*bp++);
229 vs->in_service = ntohl(*bp++);
230 vs->blessed = ntohl(*bp++);
231 vs->needs_salvage = ntohl(*bp++);
232 vs->type = ntohl(*bp++);
233 vs->min_quota = ntohl(*bp++);
234 vs->max_quota = ntohl(*bp++);
235 vs->blocks_in_use = ntohl(*bp++);
236 vs->part_blocks_avail = ntohl(*bp++);
237 vs->part_max_blocks = ntohl(*bp++);
David Howells30062bd2018-10-20 00:57:58 +0100238 vs->vol_copy_date = 0;
239 vs->vol_backup_date = 0;
David Howells45222b92007-05-10 22:22:20 -0700240 *_bp = bp;
241}
242
243/*
David Howells08e0e7c2007-04-26 15:55:03 -0700244 * deliver reply data to an FS.FetchStatus
245 */
David Howells5cf9dd52018-04-09 21:12:31 +0100246static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
David Howells08e0e7c2007-04-26 15:55:03 -0700247{
248 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100249 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700250
David Howellsd0016482016-08-30 20:42:14 +0100251 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100252 if (ret < 0)
253 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700254
255 /* unmarshall the reply once we've received all of it */
256 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100257 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100258 if (ret < 0)
259 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100260 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
David Howellsffba7182019-05-09 22:22:50 +0100261 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells08e0e7c2007-04-26 15:55:03 -0700262
263 _leave(" = 0 [done]");
264 return 0;
265}
266
267/*
268 * FS.FetchStatus operation type
269 */
David Howells5cf9dd52018-04-09 21:12:31 +0100270static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
271 .name = "FS.FetchStatus(vnode)",
David Howells025db802017-11-02 15:27:51 +0000272 .op = afs_FS_FetchStatus,
David Howells5cf9dd52018-04-09 21:12:31 +0100273 .deliver = afs_deliver_fs_fetch_status_vnode,
David Howells08e0e7c2007-04-26 15:55:03 -0700274 .destructor = afs_flat_call_destructor,
275};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277/*
278 * fetch the status information for a file
279 */
David Howellsa58823a2019-05-09 15:16:10 +0100280int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_status_cb *scb,
281 struct afs_volsync *volsync)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
David Howellsd2ddc772017-11-02 15:27:50 +0000283 struct afs_vnode *vnode = fc->vnode;
David Howells08e0e7c2007-04-26 15:55:03 -0700284 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000285 struct afs_net *net = afs_v2net(vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 __be32 *bp;
287
David Howells30062bd2018-10-20 00:57:58 +0100288 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100289 return yfs_fs_fetch_file_status(fc, scb, volsync);
David Howells30062bd2018-10-20 00:57:58 +0100290
David Howells3b6492d2018-10-20 00:57:57 +0100291 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +0000292 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
David Howells5cf9dd52018-04-09 21:12:31 +0100294 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
295 16, (21 + 3 + 6) * 4);
David Howellsd2ddc772017-11-02 15:27:50 +0000296 if (!call) {
297 fc->ac.error = -ENOMEM;
David Howells08e0e7c2007-04-26 15:55:03 -0700298 return -ENOMEM;
David Howellsd2ddc772017-11-02 15:27:50 +0000299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
David Howellsd2ddc772017-11-02 15:27:50 +0000301 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100302 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +0100303 call->out_volsync = volsync;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700306 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 bp[0] = htonl(FSFETCHSTATUS);
308 bp[1] = htonl(vnode->fid.vid);
309 bp[2] = htonl(vnode->fid.vnode);
310 bp[3] = htonl(vnode->fid.unique);
311
David Howellsd2ddc772017-11-02 15:27:50 +0000312 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000313 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +0100314
David Howells20b83912019-05-08 16:16:31 +0100315 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100316 afs_make_call(&fc->ac, call, GFP_NOFS);
317 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsec268152007-04-26 15:49:28 -0700318}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320/*
David Howells08e0e7c2007-04-26 15:55:03 -0700321 * deliver reply data to an FS.FetchData
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 */
David Howellsd0016482016-08-30 20:42:14 +0100323static int afs_deliver_fs_fetch_data(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
David Howellsffba7182019-05-09 22:22:50 +0100325 struct afs_read *req = call->read_request;
David Howells08e0e7c2007-04-26 15:55:03 -0700326 const __be32 *bp;
David Howells196ee9c2017-01-05 10:38:34 +0000327 unsigned int size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700329
David Howells12bdcf32018-10-20 00:57:56 +0100330 _enter("{%u,%zu/%llu}",
David Howellsfc276122019-11-21 09:12:17 +0000331 call->unmarshall, iov_iter_count(call->iter), req->actual_len);
David Howells08e0e7c2007-04-26 15:55:03 -0700332
333 switch (call->unmarshall) {
334 case 0:
David Howells196ee9c2017-01-05 10:38:34 +0000335 req->actual_len = 0;
David Howells12bdcf32018-10-20 00:57:56 +0100336 req->index = 0;
337 req->offset = req->pos & (PAGE_SIZE - 1);
David Howells08e0e7c2007-04-26 15:55:03 -0700338 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +0100339 if (call->operation_ID == FSFETCHDATA64) {
340 afs_extract_to_tmp64(call);
341 } else {
342 call->tmp_u = htonl(0);
343 afs_extract_to_tmp(call);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700344 }
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500345 /* Fall through */
David Howells08e0e7c2007-04-26 15:55:03 -0700346
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500347 /* extract the returned data length */
David Howells12bdcf32018-10-20 00:57:56 +0100348 case 1:
David Howells08e0e7c2007-04-26 15:55:03 -0700349 _debug("extract data length");
David Howells12bdcf32018-10-20 00:57:56 +0100350 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100351 if (ret < 0)
352 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700353
David Howells12bdcf32018-10-20 00:57:56 +0100354 req->actual_len = be64_to_cpu(call->tmp64);
David Howells196ee9c2017-01-05 10:38:34 +0000355 _debug("DATA length: %llu", req->actual_len);
David Howells12bdcf32018-10-20 00:57:56 +0100356 req->remain = min(req->len, req->actual_len);
357 if (req->remain == 0)
David Howells196ee9c2017-01-05 10:38:34 +0000358 goto no_more_data;
David Howells12bdcf32018-10-20 00:57:56 +0100359
David Howells08e0e7c2007-04-26 15:55:03 -0700360 call->unmarshall++;
361
David Howells196ee9c2017-01-05 10:38:34 +0000362 begin_page:
David Howells6db3ac32017-03-16 16:27:44 +0000363 ASSERTCMP(req->index, <, req->nr_pages);
David Howells12bdcf32018-10-20 00:57:56 +0100364 if (req->remain > PAGE_SIZE - req->offset)
365 size = PAGE_SIZE - req->offset;
David Howells196ee9c2017-01-05 10:38:34 +0000366 else
367 size = req->remain;
David Howells12bdcf32018-10-20 00:57:56 +0100368 call->bvec[0].bv_len = size;
369 call->bvec[0].bv_offset = req->offset;
370 call->bvec[0].bv_page = req->pages[req->index];
David Howellsfc276122019-11-21 09:12:17 +0000371 iov_iter_bvec(&call->def_iter, READ, call->bvec, 1, size);
David Howells12bdcf32018-10-20 00:57:56 +0100372 ASSERTCMP(size, <=, PAGE_SIZE);
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500373 /* Fall through */
David Howells196ee9c2017-01-05 10:38:34 +0000374
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500375 /* extract the returned data */
David Howells12bdcf32018-10-20 00:57:56 +0100376 case 2:
377 _debug("extract data %zu/%llu",
David Howellsfc276122019-11-21 09:12:17 +0000378 iov_iter_count(call->iter), req->remain);
David Howells196ee9c2017-01-05 10:38:34 +0000379
David Howells12bdcf32018-10-20 00:57:56 +0100380 ret = afs_extract_data(call, true);
David Howells196ee9c2017-01-05 10:38:34 +0000381 if (ret < 0)
382 return ret;
David Howells12bdcf32018-10-20 00:57:56 +0100383 req->remain -= call->bvec[0].bv_len;
384 req->offset += call->bvec[0].bv_len;
385 ASSERTCMP(req->offset, <=, PAGE_SIZE);
386 if (req->offset == PAGE_SIZE) {
387 req->offset = 0;
David Howells29f06982017-03-16 16:27:46 +0000388 req->index++;
David Howells12bdcf32018-10-20 00:57:56 +0100389 if (req->remain > 0)
David Howells196ee9c2017-01-05 10:38:34 +0000390 goto begin_page;
David Howells08e0e7c2007-04-26 15:55:03 -0700391 }
David Howells12bdcf32018-10-20 00:57:56 +0100392
393 ASSERTCMP(req->remain, ==, 0);
394 if (req->actual_len <= req->len)
395 goto no_more_data;
David Howells6db3ac32017-03-16 16:27:44 +0000396
397 /* Discard any excess data the server gave us */
David Howells23a28912019-08-20 09:22:38 +0100398 afs_extract_discard(call, req->actual_len - req->len);
David Howells12bdcf32018-10-20 00:57:56 +0100399 call->unmarshall = 3;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600400 /* Fall through */
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500401
David Howells12bdcf32018-10-20 00:57:56 +0100402 case 3:
403 _debug("extract discard %zu/%llu",
David Howellsfc276122019-11-21 09:12:17 +0000404 iov_iter_count(call->iter), req->actual_len - req->len);
David Howells6db3ac32017-03-16 16:27:44 +0000405
David Howells12bdcf32018-10-20 00:57:56 +0100406 ret = afs_extract_data(call, true);
David Howells6db3ac32017-03-16 16:27:44 +0000407 if (ret < 0)
408 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700409
David Howells196ee9c2017-01-05 10:38:34 +0000410 no_more_data:
David Howells12bdcf32018-10-20 00:57:56 +0100411 call->unmarshall = 4;
412 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500413 /* Fall through */
David Howells08e0e7c2007-04-26 15:55:03 -0700414
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500415 /* extract the metadata */
David Howells12bdcf32018-10-20 00:57:56 +0100416 case 4:
417 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100418 if (ret < 0)
419 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700420
421 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100422 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100423 if (ret < 0)
424 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100425 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
David Howellsffba7182019-05-09 22:22:50 +0100426 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells08e0e7c2007-04-26 15:55:03 -0700427
David Howellsa58823a2019-05-09 15:16:10 +0100428 req->data_version = call->out_scb->status.data_version;
429 req->file_size = call->out_scb->status.size;
430
David Howells08e0e7c2007-04-26 15:55:03 -0700431 call->unmarshall++;
432
David Howells12bdcf32018-10-20 00:57:56 +0100433 case 5:
David Howells08e0e7c2007-04-26 15:55:03 -0700434 break;
435 }
436
David Howells6db3ac32017-03-16 16:27:44 +0000437 for (; req->index < req->nr_pages; req->index++) {
David Howells12bdcf32018-10-20 00:57:56 +0100438 if (req->offset < PAGE_SIZE)
David Howells6db3ac32017-03-16 16:27:44 +0000439 zero_user_segment(req->pages[req->index],
David Howells12bdcf32018-10-20 00:57:56 +0100440 req->offset, PAGE_SIZE);
David Howells12bdcf32018-10-20 00:57:56 +0100441 req->offset = 0;
David Howells416351f2007-05-09 02:33:45 -0700442 }
443
David Howells9d1be4f2020-05-17 21:21:05 +0100444 if (req->page_done)
445 for (req->index = 0; req->index < req->nr_pages; req->index++)
446 req->page_done(req);
447
David Howells08e0e7c2007-04-26 15:55:03 -0700448 _leave(" = 0 [done]");
449 return 0;
450}
451
David Howells196ee9c2017-01-05 10:38:34 +0000452static void afs_fetch_data_destructor(struct afs_call *call)
453{
David Howellsffba7182019-05-09 22:22:50 +0100454 struct afs_read *req = call->read_request;
David Howells196ee9c2017-01-05 10:38:34 +0000455
456 afs_put_read(req);
457 afs_flat_call_destructor(call);
458}
459
David Howells08e0e7c2007-04-26 15:55:03 -0700460/*
461 * FS.FetchData operation type
462 */
463static const struct afs_call_type afs_RXFSFetchData = {
David Howells00d3b7a2007-04-26 15:57:07 -0700464 .name = "FS.FetchData",
David Howells025db802017-11-02 15:27:51 +0000465 .op = afs_FS_FetchData,
David Howells08e0e7c2007-04-26 15:55:03 -0700466 .deliver = afs_deliver_fs_fetch_data,
David Howells196ee9c2017-01-05 10:38:34 +0000467 .destructor = afs_fetch_data_destructor,
David Howells08e0e7c2007-04-26 15:55:03 -0700468};
469
David Howellsb9b1f8d2007-05-10 03:15:21 -0700470static const struct afs_call_type afs_RXFSFetchData64 = {
471 .name = "FS.FetchData64",
David Howells025db802017-11-02 15:27:51 +0000472 .op = afs_FS_FetchData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -0700473 .deliver = afs_deliver_fs_fetch_data,
David Howells196ee9c2017-01-05 10:38:34 +0000474 .destructor = afs_fetch_data_destructor,
David Howellsb9b1f8d2007-05-10 03:15:21 -0700475};
476
477/*
478 * fetch data from a very large file
479 */
David Howellsa58823a2019-05-09 15:16:10 +0100480static int afs_fs_fetch_data64(struct afs_fs_cursor *fc,
481 struct afs_status_cb *scb,
482 struct afs_read *req)
David Howellsb9b1f8d2007-05-10 03:15:21 -0700483{
David Howellsd2ddc772017-11-02 15:27:50 +0000484 struct afs_vnode *vnode = fc->vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700485 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000486 struct afs_net *net = afs_v2net(vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700487 __be32 *bp;
488
489 _enter("");
490
David Howellsf044c882017-11-02 15:27:45 +0000491 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700492 if (!call)
493 return -ENOMEM;
494
David Howellsd2ddc772017-11-02 15:27:50 +0000495 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100496 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +0100497 call->out_volsync = NULL;
David Howellsd4438a22019-11-21 09:12:17 +0000498 call->read_request = afs_get_read(req);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700499
500 /* marshall the parameters */
501 bp = call->request;
502 bp[0] = htonl(FSFETCHDATA64);
503 bp[1] = htonl(vnode->fid.vid);
504 bp[2] = htonl(vnode->fid.vnode);
505 bp[3] = htonl(vnode->fid.unique);
David Howells196ee9c2017-01-05 10:38:34 +0000506 bp[4] = htonl(upper_32_bits(req->pos));
507 bp[5] = htonl(lower_32_bits(req->pos));
David Howellsb9b1f8d2007-05-10 03:15:21 -0700508 bp[6] = 0;
David Howells196ee9c2017-01-05 10:38:34 +0000509 bp[7] = htonl(lower_32_bits(req->len));
David Howellsb9b1f8d2007-05-10 03:15:21 -0700510
David Howellsd2ddc772017-11-02 15:27:50 +0000511 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000512 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +0100513 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100514 afs_make_call(&fc->ac, call, GFP_NOFS);
515 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700516}
517
David Howells08e0e7c2007-04-26 15:55:03 -0700518/*
519 * fetch data from a file
520 */
David Howellsa58823a2019-05-09 15:16:10 +0100521int afs_fs_fetch_data(struct afs_fs_cursor *fc,
522 struct afs_status_cb *scb,
523 struct afs_read *req)
David Howells08e0e7c2007-04-26 15:55:03 -0700524{
David Howellsd2ddc772017-11-02 15:27:50 +0000525 struct afs_vnode *vnode = fc->vnode;
David Howells08e0e7c2007-04-26 15:55:03 -0700526 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000527 struct afs_net *net = afs_v2net(vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 __be32 *bp;
529
David Howells30062bd2018-10-20 00:57:58 +0100530 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100531 return yfs_fs_fetch_data(fc, scb, req);
David Howells30062bd2018-10-20 00:57:58 +0100532
David Howells196ee9c2017-01-05 10:38:34 +0000533 if (upper_32_bits(req->pos) ||
534 upper_32_bits(req->len) ||
535 upper_32_bits(req->pos + req->len))
David Howellsa58823a2019-05-09 15:16:10 +0100536 return afs_fs_fetch_data64(fc, scb, req);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700537
David Howells08e0e7c2007-04-26 15:55:03 -0700538 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
David Howellsf044c882017-11-02 15:27:45 +0000540 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700541 if (!call)
542 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
David Howellsd2ddc772017-11-02 15:27:50 +0000544 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100545 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +0100546 call->out_volsync = NULL;
David Howellsd4438a22019-11-21 09:12:17 +0000547 call->read_request = afs_get_read(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700550 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 bp[0] = htonl(FSFETCHDATA);
David Howells08e0e7c2007-04-26 15:55:03 -0700552 bp[1] = htonl(vnode->fid.vid);
553 bp[2] = htonl(vnode->fid.vnode);
554 bp[3] = htonl(vnode->fid.unique);
David Howells196ee9c2017-01-05 10:38:34 +0000555 bp[4] = htonl(lower_32_bits(req->pos));
556 bp[5] = htonl(lower_32_bits(req->len));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
David Howellsd2ddc772017-11-02 15:27:50 +0000558 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000559 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +0100560 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100561 afs_make_call(&fc->ac, call, GFP_NOFS);
562 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsec268152007-04-26 15:49:28 -0700563}
David Howells260a9802007-04-26 15:59:35 -0700564
565/*
566 * deliver reply data to an FS.CreateFile or an FS.MakeDir
567 */
David Howellsd0016482016-08-30 20:42:14 +0100568static int afs_deliver_fs_create_vnode(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700569{
David Howells260a9802007-04-26 15:59:35 -0700570 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100571 int ret;
David Howells260a9802007-04-26 15:59:35 -0700572
David Howellsd0016482016-08-30 20:42:14 +0100573 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100574 if (ret < 0)
575 return ret;
David Howells260a9802007-04-26 15:59:35 -0700576
577 /* unmarshall the reply once we've received all of it */
578 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +0100579 xdr_decode_AFSFid(&bp, call->out_fid);
David Howellsa58823a2019-05-09 15:16:10 +0100580 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100581 if (ret < 0)
582 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100583 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100584 if (ret < 0)
585 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100586 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
David Howellsffba7182019-05-09 22:22:50 +0100587 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260a9802007-04-26 15:59:35 -0700588
589 _leave(" = 0 [done]");
590 return 0;
591}
592
593/*
594 * FS.CreateFile and FS.MakeDir operation type
595 */
David Howells025db802017-11-02 15:27:51 +0000596static const struct afs_call_type afs_RXFSCreateFile = {
597 .name = "FS.CreateFile",
598 .op = afs_FS_CreateFile,
599 .deliver = afs_deliver_fs_create_vnode,
600 .destructor = afs_flat_call_destructor,
601};
602
603static const struct afs_call_type afs_RXFSMakeDir = {
604 .name = "FS.MakeDir",
605 .op = afs_FS_MakeDir,
David Howells260a9802007-04-26 15:59:35 -0700606 .deliver = afs_deliver_fs_create_vnode,
David Howells260a9802007-04-26 15:59:35 -0700607 .destructor = afs_flat_call_destructor,
608};
609
610/*
611 * create a file or make a directory
612 */
David Howells8b2a4642017-11-02 15:27:50 +0000613int afs_fs_create(struct afs_fs_cursor *fc,
David Howells260a9802007-04-26 15:59:35 -0700614 const char *name,
615 umode_t mode,
David Howellsa58823a2019-05-09 15:16:10 +0100616 struct afs_status_cb *dvnode_scb,
David Howells260a9802007-04-26 15:59:35 -0700617 struct afs_fid *newfid,
David Howellsa58823a2019-05-09 15:16:10 +0100618 struct afs_status_cb *new_scb)
David Howells260a9802007-04-26 15:59:35 -0700619{
David Howellsffba7182019-05-09 22:22:50 +0100620 struct afs_vnode *dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700621 struct afs_call *call;
David Howellsffba7182019-05-09 22:22:50 +0100622 struct afs_net *net = afs_v2net(dvnode);
David Howells260a9802007-04-26 15:59:35 -0700623 size_t namesz, reqsz, padsz;
624 __be32 *bp;
625
David Howells30062bd2018-10-20 00:57:58 +0100626 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
627 if (S_ISDIR(mode))
David Howellsa58823a2019-05-09 15:16:10 +0100628 return yfs_fs_make_dir(fc, name, mode, dvnode_scb,
629 newfid, new_scb);
David Howells30062bd2018-10-20 00:57:58 +0100630 else
David Howellsa58823a2019-05-09 15:16:10 +0100631 return yfs_fs_create_file(fc, name, mode, dvnode_scb,
632 newfid, new_scb);
David Howells30062bd2018-10-20 00:57:58 +0100633 }
634
David Howells260a9802007-04-26 15:59:35 -0700635 _enter("");
636
637 namesz = strlen(name);
638 padsz = (4 - (namesz & 3)) & 3;
639 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
640
David Howells025db802017-11-02 15:27:51 +0000641 call = afs_alloc_flat_call(
642 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
643 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700644 if (!call)
645 return -ENOMEM;
646
David Howellsd2ddc772017-11-02 15:27:50 +0000647 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100648 call->out_dir_scb = dvnode_scb;
David Howellsffba7182019-05-09 22:22:50 +0100649 call->out_fid = newfid;
David Howellsa58823a2019-05-09 15:16:10 +0100650 call->out_scb = new_scb;
David Howells260a9802007-04-26 15:59:35 -0700651
652 /* marshall the parameters */
653 bp = call->request;
654 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
David Howellsffba7182019-05-09 22:22:50 +0100655 *bp++ = htonl(dvnode->fid.vid);
656 *bp++ = htonl(dvnode->fid.vnode);
657 *bp++ = htonl(dvnode->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700658 *bp++ = htonl(namesz);
659 memcpy(bp, name, namesz);
660 bp = (void *) bp + namesz;
661 if (padsz > 0) {
662 memset(bp, 0, padsz);
663 bp = (void *) bp + padsz;
664 }
Marc Dionneab94f5d2017-03-16 16:27:47 +0000665 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
David Howellsffba7182019-05-09 22:22:50 +0100666 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells260a9802007-04-26 15:59:35 -0700667 *bp++ = 0; /* owner */
668 *bp++ = 0; /* group */
669 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
670 *bp++ = 0; /* segment size */
671
David Howellsd2ddc772017-11-02 15:27:50 +0000672 afs_use_fs_server(call, fc->cbi);
David Howellsffba7182019-05-09 22:22:50 +0100673 trace_afs_make_fs_call1(call, &dvnode->fid, name);
David Howells20b83912019-05-08 16:16:31 +0100674 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100675 afs_make_call(&fc->ac, call, GFP_NOFS);
676 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -0700677}
678
679/*
David Howellsffba7182019-05-09 22:22:50 +0100680 * Deliver reply data to any operation that returns directory status and volume
Joe Gorseb10494a2019-04-25 14:26:52 +0100681 * sync.
David Howells260a9802007-04-26 15:59:35 -0700682 */
David Howellsffba7182019-05-09 22:22:50 +0100683static int afs_deliver_fs_dir_status_and_vol(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700684{
David Howells260a9802007-04-26 15:59:35 -0700685 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100686 int ret;
David Howells260a9802007-04-26 15:59:35 -0700687
David Howellsd0016482016-08-30 20:42:14 +0100688 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100689 if (ret < 0)
690 return ret;
David Howells260a9802007-04-26 15:59:35 -0700691
692 /* unmarshall the reply once we've received all of it */
693 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100694 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100695 if (ret < 0)
696 return ret;
David Howellsffba7182019-05-09 22:22:50 +0100697 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260a9802007-04-26 15:59:35 -0700698
699 _leave(" = 0 [done]");
700 return 0;
701}
702
703/*
704 * FS.RemoveDir/FS.RemoveFile operation type
705 */
David Howells025db802017-11-02 15:27:51 +0000706static const struct afs_call_type afs_RXFSRemoveFile = {
707 .name = "FS.RemoveFile",
708 .op = afs_FS_RemoveFile,
David Howellsffba7182019-05-09 22:22:50 +0100709 .deliver = afs_deliver_fs_dir_status_and_vol,
David Howells025db802017-11-02 15:27:51 +0000710 .destructor = afs_flat_call_destructor,
711};
712
713static const struct afs_call_type afs_RXFSRemoveDir = {
714 .name = "FS.RemoveDir",
715 .op = afs_FS_RemoveDir,
David Howellsffba7182019-05-09 22:22:50 +0100716 .deliver = afs_deliver_fs_dir_status_and_vol,
David Howells260a9802007-04-26 15:59:35 -0700717 .destructor = afs_flat_call_destructor,
718};
719
720/*
721 * remove a file or directory
722 */
David Howells30062bd2018-10-20 00:57:58 +0100723int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
David Howellsa58823a2019-05-09 15:16:10 +0100724 const char *name, bool isdir, struct afs_status_cb *dvnode_scb)
David Howells260a9802007-04-26 15:59:35 -0700725{
David Howells30062bd2018-10-20 00:57:58 +0100726 struct afs_vnode *dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700727 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100728 struct afs_net *net = afs_v2net(dvnode);
David Howells260a9802007-04-26 15:59:35 -0700729 size_t namesz, reqsz, padsz;
730 __be32 *bp;
731
David Howells30062bd2018-10-20 00:57:58 +0100732 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100733 return yfs_fs_remove(fc, vnode, name, isdir, dvnode_scb);
David Howells30062bd2018-10-20 00:57:58 +0100734
David Howells260a9802007-04-26 15:59:35 -0700735 _enter("");
736
737 namesz = strlen(name);
738 padsz = (4 - (namesz & 3)) & 3;
739 reqsz = (5 * 4) + namesz + padsz;
740
David Howells025db802017-11-02 15:27:51 +0000741 call = afs_alloc_flat_call(
742 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
743 reqsz, (21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700744 if (!call)
745 return -ENOMEM;
746
David Howellsd2ddc772017-11-02 15:27:50 +0000747 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100748 call->out_dir_scb = dvnode_scb;
David Howells260a9802007-04-26 15:59:35 -0700749
750 /* marshall the parameters */
751 bp = call->request;
752 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
David Howells30062bd2018-10-20 00:57:58 +0100753 *bp++ = htonl(dvnode->fid.vid);
754 *bp++ = htonl(dvnode->fid.vnode);
755 *bp++ = htonl(dvnode->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700756 *bp++ = htonl(namesz);
757 memcpy(bp, name, namesz);
758 bp = (void *) bp + namesz;
759 if (padsz > 0) {
760 memset(bp, 0, padsz);
761 bp = (void *) bp + padsz;
762 }
763
David Howellsd2ddc772017-11-02 15:27:50 +0000764 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +0100765 trace_afs_make_fs_call1(call, &dvnode->fid, name);
David Howells20b83912019-05-08 16:16:31 +0100766 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100767 afs_make_call(&fc->ac, call, GFP_NOFS);
768 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -0700769}
770
771/*
772 * deliver reply data to an FS.Link
773 */
David Howellsd0016482016-08-30 20:42:14 +0100774static int afs_deliver_fs_link(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700775{
David Howells260a9802007-04-26 15:59:35 -0700776 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100777 int ret;
David Howells260a9802007-04-26 15:59:35 -0700778
David Howellsd0016482016-08-30 20:42:14 +0100779 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700780
David Howellsd0016482016-08-30 20:42:14 +0100781 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100782 if (ret < 0)
783 return ret;
David Howells260a9802007-04-26 15:59:35 -0700784
785 /* unmarshall the reply once we've received all of it */
786 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100787 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100788 if (ret < 0)
789 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100790 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100791 if (ret < 0)
792 return ret;
David Howellsffba7182019-05-09 22:22:50 +0100793 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260a9802007-04-26 15:59:35 -0700794
795 _leave(" = 0 [done]");
796 return 0;
797}
798
799/*
800 * FS.Link operation type
801 */
802static const struct afs_call_type afs_RXFSLink = {
803 .name = "FS.Link",
David Howells025db802017-11-02 15:27:51 +0000804 .op = afs_FS_Link,
David Howells260a9802007-04-26 15:59:35 -0700805 .deliver = afs_deliver_fs_link,
David Howells260a9802007-04-26 15:59:35 -0700806 .destructor = afs_flat_call_destructor,
807};
808
809/*
810 * make a hard link
811 */
David Howellsd2ddc772017-11-02 15:27:50 +0000812int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
David Howellsa58823a2019-05-09 15:16:10 +0100813 const char *name,
814 struct afs_status_cb *dvnode_scb,
815 struct afs_status_cb *vnode_scb)
David Howells260a9802007-04-26 15:59:35 -0700816{
David Howellsd2ddc772017-11-02 15:27:50 +0000817 struct afs_vnode *dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700818 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000819 struct afs_net *net = afs_v2net(vnode);
David Howells260a9802007-04-26 15:59:35 -0700820 size_t namesz, reqsz, padsz;
821 __be32 *bp;
822
David Howells30062bd2018-10-20 00:57:58 +0100823 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100824 return yfs_fs_link(fc, vnode, name, dvnode_scb, vnode_scb);
David Howells30062bd2018-10-20 00:57:58 +0100825
David Howells260a9802007-04-26 15:59:35 -0700826 _enter("");
827
828 namesz = strlen(name);
829 padsz = (4 - (namesz & 3)) & 3;
830 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
831
David Howellsf044c882017-11-02 15:27:45 +0000832 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700833 if (!call)
834 return -ENOMEM;
835
David Howellsd2ddc772017-11-02 15:27:50 +0000836 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100837 call->out_dir_scb = dvnode_scb;
838 call->out_scb = vnode_scb;
David Howells260a9802007-04-26 15:59:35 -0700839
840 /* marshall the parameters */
841 bp = call->request;
842 *bp++ = htonl(FSLINK);
843 *bp++ = htonl(dvnode->fid.vid);
844 *bp++ = htonl(dvnode->fid.vnode);
845 *bp++ = htonl(dvnode->fid.unique);
846 *bp++ = htonl(namesz);
847 memcpy(bp, name, namesz);
848 bp = (void *) bp + namesz;
849 if (padsz > 0) {
850 memset(bp, 0, padsz);
851 bp = (void *) bp + padsz;
852 }
853 *bp++ = htonl(vnode->fid.vid);
854 *bp++ = htonl(vnode->fid.vnode);
855 *bp++ = htonl(vnode->fid.unique);
856
David Howellsd2ddc772017-11-02 15:27:50 +0000857 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +0100858 trace_afs_make_fs_call1(call, &vnode->fid, name);
David Howells20b83912019-05-08 16:16:31 +0100859 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100860 afs_make_call(&fc->ac, call, GFP_NOFS);
861 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -0700862}
863
864/*
865 * deliver reply data to an FS.Symlink
866 */
David Howellsd0016482016-08-30 20:42:14 +0100867static int afs_deliver_fs_symlink(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700868{
David Howells260a9802007-04-26 15:59:35 -0700869 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100870 int ret;
David Howells260a9802007-04-26 15:59:35 -0700871
David Howellsd0016482016-08-30 20:42:14 +0100872 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700873
David Howellsd0016482016-08-30 20:42:14 +0100874 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100875 if (ret < 0)
876 return ret;
David Howells260a9802007-04-26 15:59:35 -0700877
878 /* unmarshall the reply once we've received all of it */
879 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +0100880 xdr_decode_AFSFid(&bp, call->out_fid);
David Howellsa58823a2019-05-09 15:16:10 +0100881 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100882 if (ret < 0)
883 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100884 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100885 if (ret < 0)
886 return ret;
David Howellsffba7182019-05-09 22:22:50 +0100887 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260a9802007-04-26 15:59:35 -0700888
889 _leave(" = 0 [done]");
890 return 0;
891}
892
893/*
894 * FS.Symlink operation type
895 */
896static const struct afs_call_type afs_RXFSSymlink = {
897 .name = "FS.Symlink",
David Howells025db802017-11-02 15:27:51 +0000898 .op = afs_FS_Symlink,
David Howells260a9802007-04-26 15:59:35 -0700899 .deliver = afs_deliver_fs_symlink,
David Howells260a9802007-04-26 15:59:35 -0700900 .destructor = afs_flat_call_destructor,
901};
902
903/*
904 * create a symbolic link
905 */
David Howells8b2a4642017-11-02 15:27:50 +0000906int afs_fs_symlink(struct afs_fs_cursor *fc,
David Howells260a9802007-04-26 15:59:35 -0700907 const char *name,
908 const char *contents,
David Howellsa58823a2019-05-09 15:16:10 +0100909 struct afs_status_cb *dvnode_scb,
David Howells260a9802007-04-26 15:59:35 -0700910 struct afs_fid *newfid,
David Howellsa58823a2019-05-09 15:16:10 +0100911 struct afs_status_cb *new_scb)
David Howells260a9802007-04-26 15:59:35 -0700912{
David Howellsffba7182019-05-09 22:22:50 +0100913 struct afs_vnode *dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700914 struct afs_call *call;
David Howellsffba7182019-05-09 22:22:50 +0100915 struct afs_net *net = afs_v2net(dvnode);
David Howells260a9802007-04-26 15:59:35 -0700916 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
917 __be32 *bp;
918
David Howells30062bd2018-10-20 00:57:58 +0100919 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100920 return yfs_fs_symlink(fc, name, contents, dvnode_scb,
921 newfid, new_scb);
David Howells30062bd2018-10-20 00:57:58 +0100922
David Howells260a9802007-04-26 15:59:35 -0700923 _enter("");
924
925 namesz = strlen(name);
926 padsz = (4 - (namesz & 3)) & 3;
927
928 c_namesz = strlen(contents);
929 c_padsz = (4 - (c_namesz & 3)) & 3;
930
931 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
932
David Howellsf044c882017-11-02 15:27:45 +0000933 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
David Howells260a9802007-04-26 15:59:35 -0700934 (3 + 21 + 21 + 6) * 4);
935 if (!call)
936 return -ENOMEM;
937
David Howellsd2ddc772017-11-02 15:27:50 +0000938 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100939 call->out_dir_scb = dvnode_scb;
David Howellsffba7182019-05-09 22:22:50 +0100940 call->out_fid = newfid;
David Howellsa58823a2019-05-09 15:16:10 +0100941 call->out_scb = new_scb;
David Howells260a9802007-04-26 15:59:35 -0700942
943 /* marshall the parameters */
944 bp = call->request;
945 *bp++ = htonl(FSSYMLINK);
David Howellsffba7182019-05-09 22:22:50 +0100946 *bp++ = htonl(dvnode->fid.vid);
947 *bp++ = htonl(dvnode->fid.vnode);
948 *bp++ = htonl(dvnode->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700949 *bp++ = htonl(namesz);
950 memcpy(bp, name, namesz);
951 bp = (void *) bp + namesz;
952 if (padsz > 0) {
953 memset(bp, 0, padsz);
954 bp = (void *) bp + padsz;
955 }
956 *bp++ = htonl(c_namesz);
957 memcpy(bp, contents, c_namesz);
958 bp = (void *) bp + c_namesz;
959 if (c_padsz > 0) {
960 memset(bp, 0, c_padsz);
961 bp = (void *) bp + c_padsz;
962 }
Marc Dionneab94f5d2017-03-16 16:27:47 +0000963 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
David Howellsffba7182019-05-09 22:22:50 +0100964 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells260a9802007-04-26 15:59:35 -0700965 *bp++ = 0; /* owner */
966 *bp++ = 0; /* group */
967 *bp++ = htonl(S_IRWXUGO); /* unix mode */
968 *bp++ = 0; /* segment size */
969
David Howellsd2ddc772017-11-02 15:27:50 +0000970 afs_use_fs_server(call, fc->cbi);
David Howellsffba7182019-05-09 22:22:50 +0100971 trace_afs_make_fs_call1(call, &dvnode->fid, name);
David Howells20b83912019-05-08 16:16:31 +0100972 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100973 afs_make_call(&fc->ac, call, GFP_NOFS);
974 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -0700975}
976
977/*
978 * deliver reply data to an FS.Rename
979 */
David Howellsd0016482016-08-30 20:42:14 +0100980static int afs_deliver_fs_rename(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700981{
David Howells260a9802007-04-26 15:59:35 -0700982 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100983 int ret;
David Howells260a9802007-04-26 15:59:35 -0700984
David Howellsd0016482016-08-30 20:42:14 +0100985 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100986 if (ret < 0)
987 return ret;
David Howells260a9802007-04-26 15:59:35 -0700988
David Howellsb98f0ec2020-04-08 20:56:20 +0100989 /* If the two dirs are the same, we have two copies of the same status
990 * report, so we just decode it twice.
991 */
David Howells260a9802007-04-26 15:59:35 -0700992 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100993 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100994 if (ret < 0)
995 return ret;
David Howellsb98f0ec2020-04-08 20:56:20 +0100996 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
997 if (ret < 0)
998 return ret;
David Howellsffba7182019-05-09 22:22:50 +0100999 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260a9802007-04-26 15:59:35 -07001000
1001 _leave(" = 0 [done]");
1002 return 0;
1003}
1004
1005/*
1006 * FS.Rename operation type
1007 */
1008static const struct afs_call_type afs_RXFSRename = {
1009 .name = "FS.Rename",
David Howells025db802017-11-02 15:27:51 +00001010 .op = afs_FS_Rename,
David Howells260a9802007-04-26 15:59:35 -07001011 .deliver = afs_deliver_fs_rename,
David Howells260a9802007-04-26 15:59:35 -07001012 .destructor = afs_flat_call_destructor,
1013};
1014
1015/*
David Howellsa58823a2019-05-09 15:16:10 +01001016 * Rename/move a file or directory.
David Howells260a9802007-04-26 15:59:35 -07001017 */
David Howells8b2a4642017-11-02 15:27:50 +00001018int afs_fs_rename(struct afs_fs_cursor *fc,
David Howells260a9802007-04-26 15:59:35 -07001019 const char *orig_name,
1020 struct afs_vnode *new_dvnode,
David Howells63a46812018-04-06 14:17:25 +01001021 const char *new_name,
David Howellsa58823a2019-05-09 15:16:10 +01001022 struct afs_status_cb *orig_dvnode_scb,
1023 struct afs_status_cb *new_dvnode_scb)
David Howells260a9802007-04-26 15:59:35 -07001024{
David Howellsd2ddc772017-11-02 15:27:50 +00001025 struct afs_vnode *orig_dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -07001026 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001027 struct afs_net *net = afs_v2net(orig_dvnode);
David Howells260a9802007-04-26 15:59:35 -07001028 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1029 __be32 *bp;
1030
David Howells30062bd2018-10-20 00:57:58 +01001031 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1032 return yfs_fs_rename(fc, orig_name,
1033 new_dvnode, new_name,
David Howellsa58823a2019-05-09 15:16:10 +01001034 orig_dvnode_scb,
1035 new_dvnode_scb);
David Howells30062bd2018-10-20 00:57:58 +01001036
David Howells260a9802007-04-26 15:59:35 -07001037 _enter("");
1038
1039 o_namesz = strlen(orig_name);
1040 o_padsz = (4 - (o_namesz & 3)) & 3;
1041
1042 n_namesz = strlen(new_name);
1043 n_padsz = (4 - (n_namesz & 3)) & 3;
1044
1045 reqsz = (4 * 4) +
1046 4 + o_namesz + o_padsz +
1047 (3 * 4) +
1048 4 + n_namesz + n_padsz;
1049
David Howellsf044c882017-11-02 15:27:45 +00001050 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -07001051 if (!call)
1052 return -ENOMEM;
1053
David Howellsd2ddc772017-11-02 15:27:50 +00001054 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001055 call->out_dir_scb = orig_dvnode_scb;
1056 call->out_scb = new_dvnode_scb;
David Howells260a9802007-04-26 15:59:35 -07001057
1058 /* marshall the parameters */
1059 bp = call->request;
1060 *bp++ = htonl(FSRENAME);
1061 *bp++ = htonl(orig_dvnode->fid.vid);
1062 *bp++ = htonl(orig_dvnode->fid.vnode);
1063 *bp++ = htonl(orig_dvnode->fid.unique);
1064 *bp++ = htonl(o_namesz);
1065 memcpy(bp, orig_name, o_namesz);
1066 bp = (void *) bp + o_namesz;
1067 if (o_padsz > 0) {
1068 memset(bp, 0, o_padsz);
1069 bp = (void *) bp + o_padsz;
1070 }
1071
1072 *bp++ = htonl(new_dvnode->fid.vid);
1073 *bp++ = htonl(new_dvnode->fid.vnode);
1074 *bp++ = htonl(new_dvnode->fid.unique);
1075 *bp++ = htonl(n_namesz);
1076 memcpy(bp, new_name, n_namesz);
1077 bp = (void *) bp + n_namesz;
1078 if (n_padsz > 0) {
1079 memset(bp, 0, n_padsz);
1080 bp = (void *) bp + n_padsz;
1081 }
1082
David Howellsd2ddc772017-11-02 15:27:50 +00001083 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +01001084 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
David Howells20b83912019-05-08 16:16:31 +01001085 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001086 afs_make_call(&fc->ac, call, GFP_NOFS);
1087 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -07001088}
David Howells31143d52007-05-09 02:33:46 -07001089
1090/*
1091 * deliver reply data to an FS.StoreData
1092 */
David Howellsd0016482016-08-30 20:42:14 +01001093static int afs_deliver_fs_store_data(struct afs_call *call)
David Howells31143d52007-05-09 02:33:46 -07001094{
David Howells31143d52007-05-09 02:33:46 -07001095 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001096 int ret;
David Howells31143d52007-05-09 02:33:46 -07001097
David Howellsd0016482016-08-30 20:42:14 +01001098 _enter("");
David Howells31143d52007-05-09 02:33:46 -07001099
David Howellsd0016482016-08-30 20:42:14 +01001100 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001101 if (ret < 0)
1102 return ret;
David Howells31143d52007-05-09 02:33:46 -07001103
1104 /* unmarshall the reply once we've received all of it */
1105 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01001106 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +01001107 if (ret < 0)
1108 return ret;
David Howellsffba7182019-05-09 22:22:50 +01001109 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells31143d52007-05-09 02:33:46 -07001110
David Howells31143d52007-05-09 02:33:46 -07001111 _leave(" = 0 [done]");
1112 return 0;
1113}
1114
1115/*
1116 * FS.StoreData operation type
1117 */
1118static const struct afs_call_type afs_RXFSStoreData = {
1119 .name = "FS.StoreData",
David Howells025db802017-11-02 15:27:51 +00001120 .op = afs_FS_StoreData,
David Howells31143d52007-05-09 02:33:46 -07001121 .deliver = afs_deliver_fs_store_data,
David Howells31143d52007-05-09 02:33:46 -07001122 .destructor = afs_flat_call_destructor,
1123};
1124
David Howellsb9b1f8d2007-05-10 03:15:21 -07001125static const struct afs_call_type afs_RXFSStoreData64 = {
1126 .name = "FS.StoreData64",
David Howells025db802017-11-02 15:27:51 +00001127 .op = afs_FS_StoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001128 .deliver = afs_deliver_fs_store_data,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001129 .destructor = afs_flat_call_destructor,
1130};
1131
1132/*
1133 * store a set of pages to a very large file
1134 */
David Howells8b2a4642017-11-02 15:27:50 +00001135static int afs_fs_store_data64(struct afs_fs_cursor *fc,
David Howells4343d002017-11-02 15:27:52 +00001136 struct address_space *mapping,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001137 pgoff_t first, pgoff_t last,
1138 unsigned offset, unsigned to,
David Howellsa58823a2019-05-09 15:16:10 +01001139 loff_t size, loff_t pos, loff_t i_size,
1140 struct afs_status_cb *scb)
David Howellsb9b1f8d2007-05-10 03:15:21 -07001141{
David Howells4343d002017-11-02 15:27:52 +00001142 struct afs_vnode *vnode = fc->vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001143 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001144 struct afs_net *net = afs_v2net(vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001145 __be32 *bp;
1146
David Howells3b6492d2018-10-20 00:57:57 +01001147 _enter(",%x,{%llx:%llu},,",
David Howells4343d002017-11-02 15:27:52 +00001148 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001149
David Howellsf044c882017-11-02 15:27:45 +00001150 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001151 (4 + 6 + 3 * 2) * 4,
1152 (21 + 6) * 4);
1153 if (!call)
1154 return -ENOMEM;
1155
David Howells4343d002017-11-02 15:27:52 +00001156 call->key = fc->key;
1157 call->mapping = mapping;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001158 call->first = first;
1159 call->last = last;
1160 call->first_offset = offset;
1161 call->last_to = to;
1162 call->send_pages = true;
David Howellsa58823a2019-05-09 15:16:10 +01001163 call->out_scb = scb;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001164
1165 /* marshall the parameters */
1166 bp = call->request;
1167 *bp++ = htonl(FSSTOREDATA64);
1168 *bp++ = htonl(vnode->fid.vid);
1169 *bp++ = htonl(vnode->fid.vnode);
1170 *bp++ = htonl(vnode->fid.unique);
1171
Marc Dionneab94f5d2017-03-16 16:27:47 +00001172 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1173 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howellsb9b1f8d2007-05-10 03:15:21 -07001174 *bp++ = 0; /* owner */
1175 *bp++ = 0; /* group */
1176 *bp++ = 0; /* unix mode */
1177 *bp++ = 0; /* segment size */
1178
1179 *bp++ = htonl(pos >> 32);
1180 *bp++ = htonl((u32) pos);
1181 *bp++ = htonl(size >> 32);
1182 *bp++ = htonl((u32) size);
1183 *bp++ = htonl(i_size >> 32);
1184 *bp++ = htonl((u32) i_size);
1185
David Howells025db802017-11-02 15:27:51 +00001186 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001187 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001188 afs_make_call(&fc->ac, call, GFP_NOFS);
1189 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001190}
1191
David Howells31143d52007-05-09 02:33:46 -07001192/*
1193 * store a set of pages
1194 */
David Howells4343d002017-11-02 15:27:52 +00001195int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
David Howells31143d52007-05-09 02:33:46 -07001196 pgoff_t first, pgoff_t last,
David Howellsa58823a2019-05-09 15:16:10 +01001197 unsigned offset, unsigned to,
1198 struct afs_status_cb *scb)
David Howells31143d52007-05-09 02:33:46 -07001199{
David Howells4343d002017-11-02 15:27:52 +00001200 struct afs_vnode *vnode = fc->vnode;
David Howells31143d52007-05-09 02:33:46 -07001201 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001202 struct afs_net *net = afs_v2net(vnode);
David Howells31143d52007-05-09 02:33:46 -07001203 loff_t size, pos, i_size;
1204 __be32 *bp;
1205
David Howells30062bd2018-10-20 00:57:58 +01001206 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001207 return yfs_fs_store_data(fc, mapping, first, last, offset, to, scb);
David Howells30062bd2018-10-20 00:57:58 +01001208
David Howells3b6492d2018-10-20 00:57:57 +01001209 _enter(",%x,{%llx:%llu},,",
David Howells4343d002017-11-02 15:27:52 +00001210 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001211
David Howells146a1192017-03-16 16:27:47 +00001212 size = (loff_t)to - (loff_t)offset;
David Howells31143d52007-05-09 02:33:46 -07001213 if (first != last)
1214 size += (loff_t)(last - first) << PAGE_SHIFT;
1215 pos = (loff_t)first << PAGE_SHIFT;
1216 pos += offset;
1217
1218 i_size = i_size_read(&vnode->vfs_inode);
1219 if (pos + size > i_size)
1220 i_size = size + pos;
1221
1222 _debug("size %llx, at %llx, i_size %llx",
1223 (unsigned long long) size, (unsigned long long) pos,
1224 (unsigned long long) i_size);
1225
David Howellsb9b1f8d2007-05-10 03:15:21 -07001226 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
David Howells4343d002017-11-02 15:27:52 +00001227 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
David Howellsa58823a2019-05-09 15:16:10 +01001228 size, pos, i_size, scb);
David Howells31143d52007-05-09 02:33:46 -07001229
David Howellsf044c882017-11-02 15:27:45 +00001230 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
David Howells31143d52007-05-09 02:33:46 -07001231 (4 + 6 + 3) * 4,
1232 (21 + 6) * 4);
1233 if (!call)
1234 return -ENOMEM;
1235
David Howells4343d002017-11-02 15:27:52 +00001236 call->key = fc->key;
1237 call->mapping = mapping;
David Howells31143d52007-05-09 02:33:46 -07001238 call->first = first;
1239 call->last = last;
1240 call->first_offset = offset;
1241 call->last_to = to;
1242 call->send_pages = true;
David Howellsa58823a2019-05-09 15:16:10 +01001243 call->out_scb = scb;
David Howells31143d52007-05-09 02:33:46 -07001244
1245 /* marshall the parameters */
1246 bp = call->request;
1247 *bp++ = htonl(FSSTOREDATA);
1248 *bp++ = htonl(vnode->fid.vid);
1249 *bp++ = htonl(vnode->fid.vnode);
1250 *bp++ = htonl(vnode->fid.unique);
1251
Marc Dionneab94f5d2017-03-16 16:27:47 +00001252 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1253 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells31143d52007-05-09 02:33:46 -07001254 *bp++ = 0; /* owner */
1255 *bp++ = 0; /* group */
1256 *bp++ = 0; /* unix mode */
1257 *bp++ = 0; /* segment size */
1258
1259 *bp++ = htonl(pos);
1260 *bp++ = htonl(size);
1261 *bp++ = htonl(i_size);
1262
David Howellsd2ddc772017-11-02 15:27:50 +00001263 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001264 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001265 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001266 afs_make_call(&fc->ac, call, GFP_NOFS);
1267 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells31143d52007-05-09 02:33:46 -07001268}
1269
1270/*
1271 * deliver reply data to an FS.StoreStatus
1272 */
David Howellsd0016482016-08-30 20:42:14 +01001273static int afs_deliver_fs_store_status(struct afs_call *call)
David Howells31143d52007-05-09 02:33:46 -07001274{
David Howells31143d52007-05-09 02:33:46 -07001275 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001276 int ret;
David Howells31143d52007-05-09 02:33:46 -07001277
David Howellsd0016482016-08-30 20:42:14 +01001278 _enter("");
David Howells31143d52007-05-09 02:33:46 -07001279
David Howellsd0016482016-08-30 20:42:14 +01001280 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001281 if (ret < 0)
1282 return ret;
David Howells31143d52007-05-09 02:33:46 -07001283
1284 /* unmarshall the reply once we've received all of it */
David Howells31143d52007-05-09 02:33:46 -07001285 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01001286 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +01001287 if (ret < 0)
1288 return ret;
David Howellsffba7182019-05-09 22:22:50 +01001289 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells31143d52007-05-09 02:33:46 -07001290
1291 _leave(" = 0 [done]");
1292 return 0;
1293}
1294
1295/*
1296 * FS.StoreStatus operation type
1297 */
1298static const struct afs_call_type afs_RXFSStoreStatus = {
1299 .name = "FS.StoreStatus",
David Howells025db802017-11-02 15:27:51 +00001300 .op = afs_FS_StoreStatus,
David Howells31143d52007-05-09 02:33:46 -07001301 .deliver = afs_deliver_fs_store_status,
David Howells31143d52007-05-09 02:33:46 -07001302 .destructor = afs_flat_call_destructor,
1303};
1304
1305static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1306 .name = "FS.StoreData",
David Howells025db802017-11-02 15:27:51 +00001307 .op = afs_FS_StoreData,
David Howells31143d52007-05-09 02:33:46 -07001308 .deliver = afs_deliver_fs_store_status,
David Howells31143d52007-05-09 02:33:46 -07001309 .destructor = afs_flat_call_destructor,
1310};
1311
David Howellsb9b1f8d2007-05-10 03:15:21 -07001312static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1313 .name = "FS.StoreData64",
David Howells025db802017-11-02 15:27:51 +00001314 .op = afs_FS_StoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001315 .deliver = afs_deliver_fs_store_status,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001316 .destructor = afs_flat_call_destructor,
1317};
1318
1319/*
1320 * set the attributes on a very large file, using FS.StoreData rather than
1321 * FS.StoreStatus so as to alter the file size also
1322 */
David Howellsa58823a2019-05-09 15:16:10 +01001323static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr,
1324 struct afs_status_cb *scb)
David Howellsb9b1f8d2007-05-10 03:15:21 -07001325{
David Howellsd2ddc772017-11-02 15:27:50 +00001326 struct afs_vnode *vnode = fc->vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001327 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001328 struct afs_net *net = afs_v2net(vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001329 __be32 *bp;
1330
David Howells3b6492d2018-10-20 00:57:57 +01001331 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +00001332 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001333
1334 ASSERT(attr->ia_valid & ATTR_SIZE);
1335
David Howellsf044c882017-11-02 15:27:45 +00001336 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001337 (4 + 6 + 3 * 2) * 4,
1338 (21 + 6) * 4);
1339 if (!call)
1340 return -ENOMEM;
1341
David Howellsd2ddc772017-11-02 15:27:50 +00001342 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001343 call->out_scb = scb;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001344
1345 /* marshall the parameters */
1346 bp = call->request;
1347 *bp++ = htonl(FSSTOREDATA64);
1348 *bp++ = htonl(vnode->fid.vid);
1349 *bp++ = htonl(vnode->fid.vnode);
1350 *bp++ = htonl(vnode->fid.unique);
1351
1352 xdr_encode_AFS_StoreStatus(&bp, attr);
1353
David Howells8c7ae382019-03-27 22:48:02 +00001354 *bp++ = htonl(attr->ia_size >> 32); /* position of start of write */
1355 *bp++ = htonl((u32) attr->ia_size);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001356 *bp++ = 0; /* size of write */
1357 *bp++ = 0;
1358 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1359 *bp++ = htonl((u32) attr->ia_size);
1360
David Howellsd2ddc772017-11-02 15:27:50 +00001361 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001362 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001363 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001364 afs_make_call(&fc->ac, call, GFP_NOFS);
1365 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001366}
1367
David Howells31143d52007-05-09 02:33:46 -07001368/*
1369 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1370 * so as to alter the file size also
1371 */
David Howellsa58823a2019-05-09 15:16:10 +01001372static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr,
1373 struct afs_status_cb *scb)
David Howells31143d52007-05-09 02:33:46 -07001374{
David Howellsd2ddc772017-11-02 15:27:50 +00001375 struct afs_vnode *vnode = fc->vnode;
David Howells31143d52007-05-09 02:33:46 -07001376 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001377 struct afs_net *net = afs_v2net(vnode);
David Howells31143d52007-05-09 02:33:46 -07001378 __be32 *bp;
1379
David Howells3b6492d2018-10-20 00:57:57 +01001380 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +00001381 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001382
1383 ASSERT(attr->ia_valid & ATTR_SIZE);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001384 if (attr->ia_size >> 32)
David Howellsa58823a2019-05-09 15:16:10 +01001385 return afs_fs_setattr_size64(fc, attr, scb);
David Howells31143d52007-05-09 02:33:46 -07001386
David Howellsf044c882017-11-02 15:27:45 +00001387 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
David Howells31143d52007-05-09 02:33:46 -07001388 (4 + 6 + 3) * 4,
1389 (21 + 6) * 4);
1390 if (!call)
1391 return -ENOMEM;
1392
David Howellsd2ddc772017-11-02 15:27:50 +00001393 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001394 call->out_scb = scb;
David Howells31143d52007-05-09 02:33:46 -07001395
1396 /* marshall the parameters */
1397 bp = call->request;
1398 *bp++ = htonl(FSSTOREDATA);
1399 *bp++ = htonl(vnode->fid.vid);
1400 *bp++ = htonl(vnode->fid.vnode);
1401 *bp++ = htonl(vnode->fid.unique);
1402
1403 xdr_encode_AFS_StoreStatus(&bp, attr);
1404
David Howells8c7ae382019-03-27 22:48:02 +00001405 *bp++ = htonl(attr->ia_size); /* position of start of write */
David Howells31143d52007-05-09 02:33:46 -07001406 *bp++ = 0; /* size of write */
1407 *bp++ = htonl(attr->ia_size); /* new file length */
1408
David Howellsd2ddc772017-11-02 15:27:50 +00001409 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001410 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001411 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001412 afs_make_call(&fc->ac, call, GFP_NOFS);
1413 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells31143d52007-05-09 02:33:46 -07001414}
1415
1416/*
1417 * set the attributes on a file, using FS.StoreData if there's a change in file
1418 * size, and FS.StoreStatus otherwise
1419 */
David Howellsa58823a2019-05-09 15:16:10 +01001420int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr,
1421 struct afs_status_cb *scb)
David Howells31143d52007-05-09 02:33:46 -07001422{
David Howellsd2ddc772017-11-02 15:27:50 +00001423 struct afs_vnode *vnode = fc->vnode;
David Howells31143d52007-05-09 02:33:46 -07001424 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001425 struct afs_net *net = afs_v2net(vnode);
David Howells31143d52007-05-09 02:33:46 -07001426 __be32 *bp;
1427
David Howells30062bd2018-10-20 00:57:58 +01001428 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001429 return yfs_fs_setattr(fc, attr, scb);
David Howells30062bd2018-10-20 00:57:58 +01001430
David Howells31143d52007-05-09 02:33:46 -07001431 if (attr->ia_valid & ATTR_SIZE)
David Howellsa58823a2019-05-09 15:16:10 +01001432 return afs_fs_setattr_size(fc, attr, scb);
David Howells31143d52007-05-09 02:33:46 -07001433
David Howells3b6492d2018-10-20 00:57:57 +01001434 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +00001435 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001436
David Howellsf044c882017-11-02 15:27:45 +00001437 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
David Howells31143d52007-05-09 02:33:46 -07001438 (4 + 6) * 4,
1439 (21 + 6) * 4);
1440 if (!call)
1441 return -ENOMEM;
1442
David Howellsd2ddc772017-11-02 15:27:50 +00001443 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001444 call->out_scb = scb;
David Howells31143d52007-05-09 02:33:46 -07001445
1446 /* marshall the parameters */
1447 bp = call->request;
1448 *bp++ = htonl(FSSTORESTATUS);
1449 *bp++ = htonl(vnode->fid.vid);
1450 *bp++ = htonl(vnode->fid.vnode);
1451 *bp++ = htonl(vnode->fid.unique);
1452
1453 xdr_encode_AFS_StoreStatus(&bp, attr);
1454
David Howellsd2ddc772017-11-02 15:27:50 +00001455 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001456 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001457 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001458 afs_make_call(&fc->ac, call, GFP_NOFS);
1459 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells31143d52007-05-09 02:33:46 -07001460}
David Howells45222b92007-05-10 22:22:20 -07001461
1462/*
1463 * deliver reply data to an FS.GetVolumeStatus
1464 */
David Howellsd0016482016-08-30 20:42:14 +01001465static int afs_deliver_fs_get_volume_status(struct afs_call *call)
David Howells45222b92007-05-10 22:22:20 -07001466{
1467 const __be32 *bp;
1468 char *p;
David Howells12bdcf32018-10-20 00:57:56 +01001469 u32 size;
David Howells45222b92007-05-10 22:22:20 -07001470 int ret;
1471
David Howellsd0016482016-08-30 20:42:14 +01001472 _enter("{%u}", call->unmarshall);
David Howells45222b92007-05-10 22:22:20 -07001473
1474 switch (call->unmarshall) {
1475 case 0:
David Howells45222b92007-05-10 22:22:20 -07001476 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01001477 afs_extract_to_buf(call, 12 * 4);
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001478 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001479
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001480 /* extract the returned status record */
David Howells45222b92007-05-10 22:22:20 -07001481 case 1:
1482 _debug("extract status");
David Howells12bdcf32018-10-20 00:57:56 +01001483 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001484 if (ret < 0)
1485 return ret;
David Howells45222b92007-05-10 22:22:20 -07001486
1487 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +01001488 xdr_decode_AFSFetchVolumeStatus(&bp, call->out_volstatus);
David Howells45222b92007-05-10 22:22:20 -07001489 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01001490 afs_extract_to_tmp(call);
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001491 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001492
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001493 /* extract the volume name length */
David Howells45222b92007-05-10 22:22:20 -07001494 case 2:
David Howells12bdcf32018-10-20 00:57:56 +01001495 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001496 if (ret < 0)
1497 return ret;
David Howells45222b92007-05-10 22:22:20 -07001498
1499 call->count = ntohl(call->tmp);
1500 _debug("volname length: %u", call->count);
1501 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001502 return afs_protocol_error(call, -EBADMSG,
1503 afs_eproto_volname_len);
David Howells12bdcf32018-10-20 00:57:56 +01001504 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001505 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001506 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001507 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001508
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001509 /* extract the volume name */
David Howells45222b92007-05-10 22:22:20 -07001510 case 3:
1511 _debug("extract volname");
David Howells12bdcf32018-10-20 00:57:56 +01001512 ret = afs_extract_data(call, true);
1513 if (ret < 0)
1514 return ret;
David Howells45222b92007-05-10 22:22:20 -07001515
David Howellsffba7182019-05-09 22:22:50 +01001516 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001517 p[call->count] = 0;
1518 _debug("volname '%s'", p);
David Howells12bdcf32018-10-20 00:57:56 +01001519 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001520 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001521 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001522
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001523 /* extract the offline message length */
David Howells12bdcf32018-10-20 00:57:56 +01001524 case 4:
1525 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001526 if (ret < 0)
1527 return ret;
David Howells45222b92007-05-10 22:22:20 -07001528
1529 call->count = ntohl(call->tmp);
1530 _debug("offline msg length: %u", call->count);
1531 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001532 return afs_protocol_error(call, -EBADMSG,
1533 afs_eproto_offline_msg_len);
David Howells12bdcf32018-10-20 00:57:56 +01001534 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001535 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001536 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001537 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001538
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001539 /* extract the offline message */
David Howells12bdcf32018-10-20 00:57:56 +01001540 case 5:
David Howells45222b92007-05-10 22:22:20 -07001541 _debug("extract offline");
David Howells12bdcf32018-10-20 00:57:56 +01001542 ret = afs_extract_data(call, true);
1543 if (ret < 0)
1544 return ret;
David Howells45222b92007-05-10 22:22:20 -07001545
David Howellsffba7182019-05-09 22:22:50 +01001546 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001547 p[call->count] = 0;
1548 _debug("offline '%s'", p);
1549
David Howells12bdcf32018-10-20 00:57:56 +01001550 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001551 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001552 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001553
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001554 /* extract the message of the day length */
David Howells12bdcf32018-10-20 00:57:56 +01001555 case 6:
1556 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001557 if (ret < 0)
1558 return ret;
David Howells45222b92007-05-10 22:22:20 -07001559
1560 call->count = ntohl(call->tmp);
1561 _debug("motd length: %u", call->count);
1562 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001563 return afs_protocol_error(call, -EBADMSG,
1564 afs_eproto_motd_len);
David Howells12bdcf32018-10-20 00:57:56 +01001565 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001566 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001567 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001568 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001569
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001570 /* extract the message of the day */
David Howells12bdcf32018-10-20 00:57:56 +01001571 case 7:
David Howells45222b92007-05-10 22:22:20 -07001572 _debug("extract motd");
David Howells12bdcf32018-10-20 00:57:56 +01001573 ret = afs_extract_data(call, false);
1574 if (ret < 0)
1575 return ret;
David Howells45222b92007-05-10 22:22:20 -07001576
David Howellsffba7182019-05-09 22:22:50 +01001577 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001578 p[call->count] = 0;
1579 _debug("motd '%s'", p);
1580
David Howells45222b92007-05-10 22:22:20 -07001581 call->unmarshall++;
1582
David Howells12bdcf32018-10-20 00:57:56 +01001583 case 8:
David Howells45222b92007-05-10 22:22:20 -07001584 break;
1585 }
1586
David Howells45222b92007-05-10 22:22:20 -07001587 _leave(" = 0 [done]");
1588 return 0;
1589}
1590
1591/*
David Howells45222b92007-05-10 22:22:20 -07001592 * FS.GetVolumeStatus operation type
1593 */
1594static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1595 .name = "FS.GetVolumeStatus",
David Howells025db802017-11-02 15:27:51 +00001596 .op = afs_FS_GetVolumeStatus,
David Howells45222b92007-05-10 22:22:20 -07001597 .deliver = afs_deliver_fs_get_volume_status,
David Howellsffba7182019-05-09 22:22:50 +01001598 .destructor = afs_flat_call_destructor,
David Howells45222b92007-05-10 22:22:20 -07001599};
1600
1601/*
1602 * fetch the status of a volume
1603 */
David Howells8b2a4642017-11-02 15:27:50 +00001604int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
David Howellsd2ddc772017-11-02 15:27:50 +00001605 struct afs_volume_status *vs)
David Howells45222b92007-05-10 22:22:20 -07001606{
David Howellsd2ddc772017-11-02 15:27:50 +00001607 struct afs_vnode *vnode = fc->vnode;
David Howells45222b92007-05-10 22:22:20 -07001608 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001609 struct afs_net *net = afs_v2net(vnode);
David Howells45222b92007-05-10 22:22:20 -07001610 __be32 *bp;
David Howells45222b92007-05-10 22:22:20 -07001611
David Howells30062bd2018-10-20 00:57:58 +01001612 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1613 return yfs_fs_get_volume_status(fc, vs);
1614
David Howells45222b92007-05-10 22:22:20 -07001615 _enter("");
1616
David Howellsffba7182019-05-09 22:22:50 +01001617 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4,
1618 max(12 * 4, AFSOPAQUEMAX + 1));
1619 if (!call)
David Howells45222b92007-05-10 22:22:20 -07001620 return -ENOMEM;
1621
David Howellsd2ddc772017-11-02 15:27:50 +00001622 call->key = fc->key;
David Howellsffba7182019-05-09 22:22:50 +01001623 call->out_volstatus = vs;
David Howells45222b92007-05-10 22:22:20 -07001624
1625 /* marshall the parameters */
1626 bp = call->request;
1627 bp[0] = htonl(FSGETVOLUMESTATUS);
1628 bp[1] = htonl(vnode->fid.vid);
1629
David Howellsd2ddc772017-11-02 15:27:50 +00001630 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001631 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001632 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001633 afs_make_call(&fc->ac, call, GFP_NOFS);
1634 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells45222b92007-05-10 22:22:20 -07001635}
David Howellse8d6c552007-07-15 23:40:12 -07001636
1637/*
1638 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1639 */
David Howellsd0016482016-08-30 20:42:14 +01001640static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
David Howellse8d6c552007-07-15 23:40:12 -07001641{
1642 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001643 int ret;
David Howellse8d6c552007-07-15 23:40:12 -07001644
David Howellsd0016482016-08-30 20:42:14 +01001645 _enter("{%u}", call->unmarshall);
David Howellse8d6c552007-07-15 23:40:12 -07001646
David Howellsd0016482016-08-30 20:42:14 +01001647 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001648 if (ret < 0)
1649 return ret;
David Howellse8d6c552007-07-15 23:40:12 -07001650
1651 /* unmarshall the reply once we've received all of it */
1652 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +01001653 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howellse8d6c552007-07-15 23:40:12 -07001654
1655 _leave(" = 0 [done]");
1656 return 0;
1657}
1658
1659/*
1660 * FS.SetLock operation type
1661 */
1662static const struct afs_call_type afs_RXFSSetLock = {
1663 .name = "FS.SetLock",
David Howells025db802017-11-02 15:27:51 +00001664 .op = afs_FS_SetLock,
David Howellse8d6c552007-07-15 23:40:12 -07001665 .deliver = afs_deliver_fs_xxxx_lock,
David Howellsa690f602019-04-25 14:26:50 +01001666 .done = afs_lock_op_done,
David Howellse8d6c552007-07-15 23:40:12 -07001667 .destructor = afs_flat_call_destructor,
1668};
1669
1670/*
1671 * FS.ExtendLock operation type
1672 */
1673static const struct afs_call_type afs_RXFSExtendLock = {
1674 .name = "FS.ExtendLock",
David Howells025db802017-11-02 15:27:51 +00001675 .op = afs_FS_ExtendLock,
David Howellse8d6c552007-07-15 23:40:12 -07001676 .deliver = afs_deliver_fs_xxxx_lock,
David Howellsa690f602019-04-25 14:26:50 +01001677 .done = afs_lock_op_done,
David Howellse8d6c552007-07-15 23:40:12 -07001678 .destructor = afs_flat_call_destructor,
1679};
1680
1681/*
1682 * FS.ReleaseLock operation type
1683 */
1684static const struct afs_call_type afs_RXFSReleaseLock = {
1685 .name = "FS.ReleaseLock",
David Howells025db802017-11-02 15:27:51 +00001686 .op = afs_FS_ReleaseLock,
David Howellse8d6c552007-07-15 23:40:12 -07001687 .deliver = afs_deliver_fs_xxxx_lock,
David Howellse8d6c552007-07-15 23:40:12 -07001688 .destructor = afs_flat_call_destructor,
1689};
1690
1691/*
David Howellsd2ddc772017-11-02 15:27:50 +00001692 * Set a lock on a file
David Howellse8d6c552007-07-15 23:40:12 -07001693 */
David Howellsa58823a2019-05-09 15:16:10 +01001694int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type,
1695 struct afs_status_cb *scb)
David Howellse8d6c552007-07-15 23:40:12 -07001696{
David Howellsd2ddc772017-11-02 15:27:50 +00001697 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001698 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001699 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001700 __be32 *bp;
1701
David Howells30062bd2018-10-20 00:57:58 +01001702 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001703 return yfs_fs_set_lock(fc, type, scb);
David Howells30062bd2018-10-20 00:57:58 +01001704
David Howellse8d6c552007-07-15 23:40:12 -07001705 _enter("");
1706
David Howellsf044c882017-11-02 15:27:45 +00001707 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001708 if (!call)
1709 return -ENOMEM;
1710
David Howellsd2ddc772017-11-02 15:27:50 +00001711 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001712 call->lvnode = vnode;
1713 call->out_scb = scb;
David Howellse8d6c552007-07-15 23:40:12 -07001714
1715 /* marshall the parameters */
1716 bp = call->request;
1717 *bp++ = htonl(FSSETLOCK);
1718 *bp++ = htonl(vnode->fid.vid);
1719 *bp++ = htonl(vnode->fid.vnode);
1720 *bp++ = htonl(vnode->fid.unique);
1721 *bp++ = htonl(type);
1722
David Howellsd2ddc772017-11-02 15:27:50 +00001723 afs_use_fs_server(call, fc->cbi);
David Howells6c6c1d62019-04-25 14:26:52 +01001724 trace_afs_make_fs_calli(call, &vnode->fid, type);
David Howells20b83912019-05-08 16:16:31 +01001725 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001726 afs_make_call(&fc->ac, call, GFP_NOFS);
1727 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellse8d6c552007-07-15 23:40:12 -07001728}
1729
1730/*
1731 * extend a lock on a file
1732 */
David Howellsa58823a2019-05-09 15:16:10 +01001733int afs_fs_extend_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
David Howellse8d6c552007-07-15 23:40:12 -07001734{
David Howellsd2ddc772017-11-02 15:27:50 +00001735 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001736 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001737 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001738 __be32 *bp;
1739
David Howells30062bd2018-10-20 00:57:58 +01001740 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001741 return yfs_fs_extend_lock(fc, scb);
David Howells30062bd2018-10-20 00:57:58 +01001742
David Howellse8d6c552007-07-15 23:40:12 -07001743 _enter("");
1744
David Howellsf044c882017-11-02 15:27:45 +00001745 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001746 if (!call)
1747 return -ENOMEM;
1748
David Howellsd2ddc772017-11-02 15:27:50 +00001749 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001750 call->lvnode = vnode;
1751 call->out_scb = scb;
David Howellse8d6c552007-07-15 23:40:12 -07001752
1753 /* marshall the parameters */
1754 bp = call->request;
1755 *bp++ = htonl(FSEXTENDLOCK);
1756 *bp++ = htonl(vnode->fid.vid);
1757 *bp++ = htonl(vnode->fid.vnode);
1758 *bp++ = htonl(vnode->fid.unique);
1759
David Howellsd2ddc772017-11-02 15:27:50 +00001760 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001761 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001762 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001763 afs_make_call(&fc->ac, call, GFP_NOFS);
1764 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellse8d6c552007-07-15 23:40:12 -07001765}
1766
1767/*
1768 * release a lock on a file
1769 */
David Howellsa58823a2019-05-09 15:16:10 +01001770int afs_fs_release_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
David Howellse8d6c552007-07-15 23:40:12 -07001771{
David Howellsd2ddc772017-11-02 15:27:50 +00001772 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001773 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001774 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001775 __be32 *bp;
1776
David Howells30062bd2018-10-20 00:57:58 +01001777 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001778 return yfs_fs_release_lock(fc, scb);
David Howells30062bd2018-10-20 00:57:58 +01001779
David Howellse8d6c552007-07-15 23:40:12 -07001780 _enter("");
1781
David Howellsf044c882017-11-02 15:27:45 +00001782 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001783 if (!call)
1784 return -ENOMEM;
1785
David Howellsd2ddc772017-11-02 15:27:50 +00001786 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001787 call->lvnode = vnode;
1788 call->out_scb = scb;
David Howellse8d6c552007-07-15 23:40:12 -07001789
1790 /* marshall the parameters */
1791 bp = call->request;
1792 *bp++ = htonl(FSRELEASELOCK);
1793 *bp++ = htonl(vnode->fid.vid);
1794 *bp++ = htonl(vnode->fid.vnode);
1795 *bp++ = htonl(vnode->fid.unique);
1796
David Howellsd2ddc772017-11-02 15:27:50 +00001797 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001798 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001799 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001800 afs_make_call(&fc->ac, call, GFP_NOFS);
1801 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsc435ee32017-11-02 15:27:49 +00001802}
1803
1804/*
1805 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1806 */
1807static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1808{
1809 return afs_transfer_reply(call);
1810}
1811
1812/*
1813 * FS.GiveUpAllCallBacks operation type
1814 */
1815static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1816 .name = "FS.GiveUpAllCallBacks",
David Howells025db802017-11-02 15:27:51 +00001817 .op = afs_FS_GiveUpAllCallBacks,
David Howellsc435ee32017-11-02 15:27:49 +00001818 .deliver = afs_deliver_fs_give_up_all_callbacks,
1819 .destructor = afs_flat_call_destructor,
1820};
1821
1822/*
1823 * Flush all the callbacks we have on a server.
1824 */
David Howellsd2ddc772017-11-02 15:27:50 +00001825int afs_fs_give_up_all_callbacks(struct afs_net *net,
1826 struct afs_server *server,
David Howells8b2a4642017-11-02 15:27:50 +00001827 struct afs_addr_cursor *ac,
David Howellsd2ddc772017-11-02 15:27:50 +00001828 struct key *key)
David Howellsc435ee32017-11-02 15:27:49 +00001829{
1830 struct afs_call *call;
1831 __be32 *bp;
1832
1833 _enter("");
1834
David Howellsd2ddc772017-11-02 15:27:50 +00001835 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
David Howellsc435ee32017-11-02 15:27:49 +00001836 if (!call)
1837 return -ENOMEM;
1838
1839 call->key = key;
1840
1841 /* marshall the parameters */
1842 bp = call->request;
1843 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1844
David Howells977e5f82020-04-17 17:31:26 +01001845 call->server = afs_use_server(server, afs_server_trace_give_up_cb);
David Howells0b9bf382019-04-25 14:26:50 +01001846 afs_make_call(ac, call, GFP_NOFS);
1847 return afs_wait_for_call_to_complete(call, ac);
David Howellsd2ddc772017-11-02 15:27:50 +00001848}
1849
1850/*
1851 * Deliver reply data to an FS.GetCapabilities operation.
1852 */
1853static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1854{
1855 u32 count;
1856 int ret;
1857
David Howellsfc276122019-11-21 09:12:17 +00001858 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
David Howellsd2ddc772017-11-02 15:27:50 +00001859
David Howellsd2ddc772017-11-02 15:27:50 +00001860 switch (call->unmarshall) {
1861 case 0:
David Howells12bdcf32018-10-20 00:57:56 +01001862 afs_extract_to_tmp(call);
David Howellsd2ddc772017-11-02 15:27:50 +00001863 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001864 /* Fall through */
David Howellsd2ddc772017-11-02 15:27:50 +00001865
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001866 /* Extract the capabilities word count */
David Howellsd2ddc772017-11-02 15:27:50 +00001867 case 1:
David Howells12bdcf32018-10-20 00:57:56 +01001868 ret = afs_extract_data(call, true);
David Howellsd2ddc772017-11-02 15:27:50 +00001869 if (ret < 0)
1870 return ret;
1871
1872 count = ntohl(call->tmp);
1873
1874 call->count = count;
1875 call->count2 = count;
David Howells23a28912019-08-20 09:22:38 +01001876 afs_extract_discard(call, count * sizeof(__be32));
David Howellsd2ddc772017-11-02 15:27:50 +00001877 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001878 /* Fall through */
David Howellsd2ddc772017-11-02 15:27:50 +00001879
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001880 /* Extract capabilities words */
David Howellsd2ddc772017-11-02 15:27:50 +00001881 case 2:
David Howells12bdcf32018-10-20 00:57:56 +01001882 ret = afs_extract_data(call, false);
David Howellsd2ddc772017-11-02 15:27:50 +00001883 if (ret < 0)
1884 return ret;
1885
1886 /* TODO: Examine capabilities */
1887
David Howellsd2ddc772017-11-02 15:27:50 +00001888 call->unmarshall++;
1889 break;
1890 }
1891
1892 _leave(" = 0 [done]");
1893 return 0;
1894}
1895
1896/*
1897 * FS.GetCapabilities operation type
1898 */
1899static const struct afs_call_type afs_RXFSGetCapabilities = {
1900 .name = "FS.GetCapabilities",
David Howells025db802017-11-02 15:27:51 +00001901 .op = afs_FS_GetCapabilities,
David Howellsd2ddc772017-11-02 15:27:50 +00001902 .deliver = afs_deliver_fs_get_capabilities,
David Howells3bf0fb62018-10-20 00:57:59 +01001903 .done = afs_fileserver_probe_result,
David Howellsffba7182019-05-09 22:22:50 +01001904 .destructor = afs_flat_call_destructor,
David Howellsd2ddc772017-11-02 15:27:50 +00001905};
1906
1907/*
1908 * Probe a fileserver for the capabilities that it supports. This can
1909 * return up to 196 words.
1910 */
David Howells0b9bf382019-04-25 14:26:50 +01001911struct afs_call *afs_fs_get_capabilities(struct afs_net *net,
1912 struct afs_server *server,
1913 struct afs_addr_cursor *ac,
1914 struct key *key,
1915 unsigned int server_index)
David Howellsd2ddc772017-11-02 15:27:50 +00001916{
1917 struct afs_call *call;
1918 __be32 *bp;
1919
1920 _enter("");
1921
1922 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1923 if (!call)
David Howells0b9bf382019-04-25 14:26:50 +01001924 return ERR_PTR(-ENOMEM);
David Howellsd2ddc772017-11-02 15:27:50 +00001925
1926 call->key = key;
David Howells977e5f82020-04-17 17:31:26 +01001927 call->server = afs_use_server(server, afs_server_trace_get_caps);
David Howellsffba7182019-05-09 22:22:50 +01001928 call->server_index = server_index;
David Howells30062bd2018-10-20 00:57:58 +01001929 call->upgrade = true;
David Howells0b9bf382019-04-25 14:26:50 +01001930 call->async = true;
David Howells94f699c2019-05-16 13:21:59 +01001931 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
David Howellsd2ddc772017-11-02 15:27:50 +00001932
1933 /* marshall the parameters */
1934 bp = call->request;
1935 *bp++ = htonl(FSGETCAPABILITIES);
1936
David Howells025db802017-11-02 15:27:51 +00001937 trace_afs_make_fs_call(call, NULL);
David Howells0b9bf382019-04-25 14:26:50 +01001938 afs_make_call(ac, call, GFP_NOFS);
1939 return call;
David Howellse8d6c552007-07-15 23:40:12 -07001940}
David Howells5cf9dd52018-04-09 21:12:31 +01001941
1942/*
1943 * Deliver reply data to an FS.FetchStatus with no vnode.
1944 */
1945static int afs_deliver_fs_fetch_status(struct afs_call *call)
1946{
David Howells5cf9dd52018-04-09 21:12:31 +01001947 const __be32 *bp;
1948 int ret;
1949
1950 ret = afs_transfer_reply(call);
1951 if (ret < 0)
1952 return ret;
1953
David Howells5cf9dd52018-04-09 21:12:31 +01001954 /* unmarshall the reply once we've received all of it */
1955 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01001956 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +01001957 if (ret < 0)
1958 return ret;
David Howellsa58823a2019-05-09 15:16:10 +01001959 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
1960 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells5cf9dd52018-04-09 21:12:31 +01001961
1962 _leave(" = 0 [done]");
1963 return 0;
1964}
1965
1966/*
1967 * FS.FetchStatus operation type
1968 */
1969static const struct afs_call_type afs_RXFSFetchStatus = {
1970 .name = "FS.FetchStatus",
1971 .op = afs_FS_FetchStatus,
1972 .deliver = afs_deliver_fs_fetch_status,
1973 .destructor = afs_flat_call_destructor,
1974};
1975
1976/*
1977 * Fetch the status information for a fid without needing a vnode handle.
1978 */
1979int afs_fs_fetch_status(struct afs_fs_cursor *fc,
1980 struct afs_net *net,
1981 struct afs_fid *fid,
David Howellsa58823a2019-05-09 15:16:10 +01001982 struct afs_status_cb *scb,
David Howells5cf9dd52018-04-09 21:12:31 +01001983 struct afs_volsync *volsync)
1984{
1985 struct afs_call *call;
1986 __be32 *bp;
1987
David Howells30062bd2018-10-20 00:57:58 +01001988 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001989 return yfs_fs_fetch_status(fc, net, fid, scb, volsync);
David Howells30062bd2018-10-20 00:57:58 +01001990
David Howells3b6492d2018-10-20 00:57:57 +01001991 _enter(",%x,{%llx:%llu},,",
David Howells5cf9dd52018-04-09 21:12:31 +01001992 key_serial(fc->key), fid->vid, fid->vnode);
1993
1994 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
1995 if (!call) {
1996 fc->ac.error = -ENOMEM;
1997 return -ENOMEM;
1998 }
1999
2000 call->key = fc->key;
David Howellsffba7182019-05-09 22:22:50 +01002001 call->out_fid = fid;
David Howellsa58823a2019-05-09 15:16:10 +01002002 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +01002003 call->out_volsync = volsync;
David Howells5cf9dd52018-04-09 21:12:31 +01002004
2005 /* marshall the parameters */
2006 bp = call->request;
2007 bp[0] = htonl(FSFETCHSTATUS);
2008 bp[1] = htonl(fid->vid);
2009 bp[2] = htonl(fid->vnode);
2010 bp[3] = htonl(fid->unique);
2011
David Howells5cf9dd52018-04-09 21:12:31 +01002012 afs_use_fs_server(call, fc->cbi);
2013 trace_afs_make_fs_call(call, fid);
David Howells20b83912019-05-08 16:16:31 +01002014 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01002015 afs_make_call(&fc->ac, call, GFP_NOFS);
2016 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells5cf9dd52018-04-09 21:12:31 +01002017}
2018
2019/*
2020 * Deliver reply data to an FS.InlineBulkStatus call
2021 */
2022static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2023{
David Howells87182752019-05-09 16:17:05 +01002024 struct afs_status_cb *scb;
David Howells5cf9dd52018-04-09 21:12:31 +01002025 const __be32 *bp;
2026 u32 tmp;
2027 int ret;
2028
2029 _enter("{%u}", call->unmarshall);
2030
2031 switch (call->unmarshall) {
2032 case 0:
David Howells12bdcf32018-10-20 00:57:56 +01002033 afs_extract_to_tmp(call);
David Howells5cf9dd52018-04-09 21:12:31 +01002034 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002035 /* Fall through */
David Howells5cf9dd52018-04-09 21:12:31 +01002036
2037 /* Extract the file status count and array in two steps */
2038 case 1:
2039 _debug("extract status count");
David Howells12bdcf32018-10-20 00:57:56 +01002040 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002041 if (ret < 0)
2042 return ret;
2043
2044 tmp = ntohl(call->tmp);
2045 _debug("status count: %u/%u", tmp, call->count2);
2046 if (tmp != call->count2)
David Howells160cb952018-10-20 00:57:56 +01002047 return afs_protocol_error(call, -EBADMSG,
2048 afs_eproto_ibulkst_count);
David Howells5cf9dd52018-04-09 21:12:31 +01002049
2050 call->count = 0;
2051 call->unmarshall++;
2052 more_counts:
David Howells12bdcf32018-10-20 00:57:56 +01002053 afs_extract_to_buf(call, 21 * sizeof(__be32));
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002054 /* Fall through */
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002055
David Howells5cf9dd52018-04-09 21:12:31 +01002056 case 2:
2057 _debug("extract status array %u", call->count);
David Howells12bdcf32018-10-20 00:57:56 +01002058 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002059 if (ret < 0)
2060 return ret;
2061
2062 bp = call->buffer;
David Howells87182752019-05-09 16:17:05 +01002063 scb = &call->out_scb[call->count];
David Howellsa58823a2019-05-09 15:16:10 +01002064 ret = xdr_decode_AFSFetchStatus(&bp, call, scb);
David Howells160cb952018-10-20 00:57:56 +01002065 if (ret < 0)
2066 return ret;
David Howells5cf9dd52018-04-09 21:12:31 +01002067
2068 call->count++;
2069 if (call->count < call->count2)
2070 goto more_counts;
2071
2072 call->count = 0;
2073 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01002074 afs_extract_to_tmp(call);
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002075 /* Fall through */
David Howells5cf9dd52018-04-09 21:12:31 +01002076
2077 /* Extract the callback count and array in two steps */
2078 case 3:
2079 _debug("extract CB count");
David Howells12bdcf32018-10-20 00:57:56 +01002080 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002081 if (ret < 0)
2082 return ret;
2083
2084 tmp = ntohl(call->tmp);
2085 _debug("CB count: %u", tmp);
2086 if (tmp != call->count2)
David Howells160cb952018-10-20 00:57:56 +01002087 return afs_protocol_error(call, -EBADMSG,
2088 afs_eproto_ibulkst_cb_count);
David Howells5cf9dd52018-04-09 21:12:31 +01002089 call->count = 0;
2090 call->unmarshall++;
2091 more_cbs:
David Howells12bdcf32018-10-20 00:57:56 +01002092 afs_extract_to_buf(call, 3 * sizeof(__be32));
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002093 /* Fall through */
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002094
David Howells5cf9dd52018-04-09 21:12:31 +01002095 case 4:
2096 _debug("extract CB array");
David Howells12bdcf32018-10-20 00:57:56 +01002097 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002098 if (ret < 0)
2099 return ret;
2100
2101 _debug("unmarshall CB array");
2102 bp = call->buffer;
David Howells87182752019-05-09 16:17:05 +01002103 scb = &call->out_scb[call->count];
David Howellsa58823a2019-05-09 15:16:10 +01002104 xdr_decode_AFSCallBack(&bp, call, scb);
David Howells5cf9dd52018-04-09 21:12:31 +01002105 call->count++;
2106 if (call->count < call->count2)
2107 goto more_cbs;
2108
David Howells12bdcf32018-10-20 00:57:56 +01002109 afs_extract_to_buf(call, 6 * sizeof(__be32));
David Howells5cf9dd52018-04-09 21:12:31 +01002110 call->unmarshall++;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002111 /* Fall through */
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002112
David Howells5cf9dd52018-04-09 21:12:31 +01002113 case 5:
David Howells12bdcf32018-10-20 00:57:56 +01002114 ret = afs_extract_data(call, false);
David Howells5cf9dd52018-04-09 21:12:31 +01002115 if (ret < 0)
2116 return ret;
2117
2118 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +01002119 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells5cf9dd52018-04-09 21:12:31 +01002120
David Howells5cf9dd52018-04-09 21:12:31 +01002121 call->unmarshall++;
2122
2123 case 6:
2124 break;
2125 }
2126
2127 _leave(" = 0 [done]");
2128 return 0;
2129}
2130
2131/*
2132 * FS.InlineBulkStatus operation type
2133 */
2134static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2135 .name = "FS.InlineBulkStatus",
2136 .op = afs_FS_InlineBulkStatus,
2137 .deliver = afs_deliver_fs_inline_bulk_status,
2138 .destructor = afs_flat_call_destructor,
2139};
2140
2141/*
2142 * Fetch the status information for up to 50 files
2143 */
2144int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2145 struct afs_net *net,
2146 struct afs_fid *fids,
David Howells87182752019-05-09 16:17:05 +01002147 struct afs_status_cb *statuses,
David Howells5cf9dd52018-04-09 21:12:31 +01002148 unsigned int nr_fids,
2149 struct afs_volsync *volsync)
2150{
2151 struct afs_call *call;
2152 __be32 *bp;
2153 int i;
2154
David Howells30062bd2018-10-20 00:57:58 +01002155 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howells87182752019-05-09 16:17:05 +01002156 return yfs_fs_inline_bulk_status(fc, net, fids, statuses,
David Howells30062bd2018-10-20 00:57:58 +01002157 nr_fids, volsync);
2158
David Howells3b6492d2018-10-20 00:57:57 +01002159 _enter(",%x,{%llx:%llu},%u",
David Howells5cf9dd52018-04-09 21:12:31 +01002160 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2161
2162 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2163 (2 + nr_fids * 3) * 4,
2164 21 * 4);
2165 if (!call) {
2166 fc->ac.error = -ENOMEM;
2167 return -ENOMEM;
2168 }
2169
2170 call->key = fc->key;
David Howells87182752019-05-09 16:17:05 +01002171 call->out_scb = statuses;
David Howellsffba7182019-05-09 22:22:50 +01002172 call->out_volsync = volsync;
David Howells5cf9dd52018-04-09 21:12:31 +01002173 call->count2 = nr_fids;
2174
2175 /* marshall the parameters */
2176 bp = call->request;
2177 *bp++ = htonl(FSINLINEBULKSTATUS);
2178 *bp++ = htonl(nr_fids);
2179 for (i = 0; i < nr_fids; i++) {
2180 *bp++ = htonl(fids[i].vid);
2181 *bp++ = htonl(fids[i].vnode);
2182 *bp++ = htonl(fids[i].unique);
2183 }
2184
David Howells5cf9dd52018-04-09 21:12:31 +01002185 afs_use_fs_server(call, fc->cbi);
2186 trace_afs_make_fs_call(call, &fids[0]);
David Howells20b83912019-05-08 16:16:31 +01002187 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01002188 afs_make_call(&fc->ac, call, GFP_NOFS);
2189 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells5cf9dd52018-04-09 21:12:31 +01002190}
David Howells260f0822019-04-25 14:26:52 +01002191
2192/*
2193 * deliver reply data to an FS.FetchACL
2194 */
2195static int afs_deliver_fs_fetch_acl(struct afs_call *call)
2196{
David Howells260f0822019-04-25 14:26:52 +01002197 struct afs_acl *acl;
2198 const __be32 *bp;
2199 unsigned int size;
2200 int ret;
2201
2202 _enter("{%u}", call->unmarshall);
2203
2204 switch (call->unmarshall) {
2205 case 0:
2206 afs_extract_to_tmp(call);
2207 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002208 /* Fall through */
David Howells260f0822019-04-25 14:26:52 +01002209
2210 /* extract the returned data length */
2211 case 1:
2212 ret = afs_extract_data(call, true);
2213 if (ret < 0)
2214 return ret;
2215
2216 size = call->count2 = ntohl(call->tmp);
2217 size = round_up(size, 4);
2218
2219 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2220 if (!acl)
2221 return -ENOMEM;
David Howellsffba7182019-05-09 22:22:50 +01002222 call->ret_acl = acl;
David Howells260f0822019-04-25 14:26:52 +01002223 acl->size = call->count2;
2224 afs_extract_begin(call, acl->data, size);
2225 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002226 /* Fall through */
David Howells260f0822019-04-25 14:26:52 +01002227
2228 /* extract the returned data */
2229 case 2:
2230 ret = afs_extract_data(call, true);
2231 if (ret < 0)
2232 return ret;
2233
2234 afs_extract_to_buf(call, (21 + 6) * 4);
2235 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002236 /* Fall through */
David Howells260f0822019-04-25 14:26:52 +01002237
2238 /* extract the metadata */
2239 case 3:
2240 ret = afs_extract_data(call, false);
2241 if (ret < 0)
2242 return ret;
2243
2244 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01002245 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells260f0822019-04-25 14:26:52 +01002246 if (ret < 0)
2247 return ret;
David Howellsffba7182019-05-09 22:22:50 +01002248 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260f0822019-04-25 14:26:52 +01002249
2250 call->unmarshall++;
2251
2252 case 4:
2253 break;
2254 }
2255
2256 _leave(" = 0 [done]");
2257 return 0;
2258}
2259
2260static void afs_destroy_fs_fetch_acl(struct afs_call *call)
2261{
David Howellsffba7182019-05-09 22:22:50 +01002262 kfree(call->ret_acl);
David Howells260f0822019-04-25 14:26:52 +01002263 afs_flat_call_destructor(call);
2264}
2265
2266/*
2267 * FS.FetchACL operation type
2268 */
2269static const struct afs_call_type afs_RXFSFetchACL = {
2270 .name = "FS.FetchACL",
2271 .op = afs_FS_FetchACL,
2272 .deliver = afs_deliver_fs_fetch_acl,
2273 .destructor = afs_destroy_fs_fetch_acl,
2274};
2275
2276/*
2277 * Fetch the ACL for a file.
2278 */
David Howellsa58823a2019-05-09 15:16:10 +01002279struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc,
2280 struct afs_status_cb *scb)
David Howells260f0822019-04-25 14:26:52 +01002281{
2282 struct afs_vnode *vnode = fc->vnode;
2283 struct afs_call *call;
2284 struct afs_net *net = afs_v2net(vnode);
2285 __be32 *bp;
2286
2287 _enter(",%x,{%llx:%llu},,",
2288 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2289
2290 call = afs_alloc_flat_call(net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2291 if (!call) {
2292 fc->ac.error = -ENOMEM;
2293 return ERR_PTR(-ENOMEM);
2294 }
2295
2296 call->key = fc->key;
David Howellsffba7182019-05-09 22:22:50 +01002297 call->ret_acl = NULL;
David Howellsa58823a2019-05-09 15:16:10 +01002298 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +01002299 call->out_volsync = NULL;
David Howells260f0822019-04-25 14:26:52 +01002300
2301 /* marshall the parameters */
2302 bp = call->request;
2303 bp[0] = htonl(FSFETCHACL);
2304 bp[1] = htonl(vnode->fid.vid);
2305 bp[2] = htonl(vnode->fid.vnode);
2306 bp[3] = htonl(vnode->fid.unique);
2307
David Howells260f0822019-04-25 14:26:52 +01002308 afs_use_fs_server(call, fc->cbi);
2309 trace_afs_make_fs_call(call, &vnode->fid);
2310 afs_make_call(&fc->ac, call, GFP_KERNEL);
2311 return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2312}
Joe Gorseb10494a2019-04-25 14:26:52 +01002313
2314/*
David Howellsffba7182019-05-09 22:22:50 +01002315 * Deliver reply data to any operation that returns file status and volume
2316 * sync.
2317 */
2318static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
2319{
David Howellsffba7182019-05-09 22:22:50 +01002320 const __be32 *bp;
2321 int ret;
2322
David Howellsffba7182019-05-09 22:22:50 +01002323 ret = afs_transfer_reply(call);
2324 if (ret < 0)
2325 return ret;
2326
David Howellsffba7182019-05-09 22:22:50 +01002327 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01002328 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howellsffba7182019-05-09 22:22:50 +01002329 if (ret < 0)
2330 return ret;
2331 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2332
2333 _leave(" = 0 [done]");
2334 return 0;
2335}
2336
2337/*
Joe Gorseb10494a2019-04-25 14:26:52 +01002338 * FS.StoreACL operation type
2339 */
2340static const struct afs_call_type afs_RXFSStoreACL = {
2341 .name = "FS.StoreACL",
2342 .op = afs_FS_StoreACL,
David Howellsffba7182019-05-09 22:22:50 +01002343 .deliver = afs_deliver_fs_file_status_and_vol,
Joe Gorseb10494a2019-04-25 14:26:52 +01002344 .destructor = afs_flat_call_destructor,
2345};
2346
2347/*
2348 * Fetch the ACL for a file.
2349 */
David Howellsa58823a2019-05-09 15:16:10 +01002350int afs_fs_store_acl(struct afs_fs_cursor *fc, const struct afs_acl *acl,
2351 struct afs_status_cb *scb)
Joe Gorseb10494a2019-04-25 14:26:52 +01002352{
2353 struct afs_vnode *vnode = fc->vnode;
2354 struct afs_call *call;
2355 struct afs_net *net = afs_v2net(vnode);
2356 size_t size;
2357 __be32 *bp;
2358
2359 _enter(",%x,{%llx:%llu},,",
2360 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2361
2362 size = round_up(acl->size, 4);
2363 call = afs_alloc_flat_call(net, &afs_RXFSStoreACL,
2364 5 * 4 + size, (21 + 6) * 4);
2365 if (!call) {
2366 fc->ac.error = -ENOMEM;
2367 return -ENOMEM;
2368 }
2369
2370 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01002371 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +01002372 call->out_volsync = NULL;
Joe Gorseb10494a2019-04-25 14:26:52 +01002373
2374 /* marshall the parameters */
2375 bp = call->request;
2376 bp[0] = htonl(FSSTOREACL);
2377 bp[1] = htonl(vnode->fid.vid);
2378 bp[2] = htonl(vnode->fid.vnode);
2379 bp[3] = htonl(vnode->fid.unique);
2380 bp[4] = htonl(acl->size);
2381 memcpy(&bp[5], acl->data, acl->size);
2382 if (acl->size != size)
2383 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2384
2385 trace_afs_make_fs_call(call, &vnode->fid);
2386 afs_make_call(&fc->ac, call, GFP_KERNEL);
2387 return afs_wait_for_call_to_complete(call, &fc->ac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388}