blob: 48298408d6ac7a944285a0f273e23b4925f8def4 [file] [log] [blame]
David Howells08e0e7c2007-04-26 15:55:03 -07001/* AFS File Server client stubs
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David Howells08e0e7c2007-04-26 15:55:03 -07003 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/sched.h>
David Howells08e0e7c2007-04-26 15:55:03 -070015#include <linux/circ_buf.h>
Jeff Laytona01179e2017-12-11 06:35:11 -050016#include <linux/iversion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070018#include "afs_fs.h"
David Howellsdd9fbcb2018-04-06 14:17:24 +010019#include "xdr_fs.h"
David Howells30062bd2018-10-20 00:57:58 +010020#include "protocol_yfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
David Howells025db802017-11-02 15:27:51 +000022static const struct afs_fid afs_zero_fid;
23
David Howellsd2ddc772017-11-02 15:27:50 +000024static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
David Howellsc435ee32017-11-02 15:27:49 +000025{
David Howellsd2ddc772017-11-02 15:27:50 +000026 call->cbi = afs_get_cb_interest(cbi);
David Howellsc435ee32017-11-02 15:27:49 +000027}
28
David Howells6db3ac32017-03-16 16:27:44 +000029/*
David Howells260a9802007-04-26 15:59:35 -070030 * decode an AFSFid block
31 */
32static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
33{
34 const __be32 *bp = *_bp;
35
36 fid->vid = ntohl(*bp++);
37 fid->vnode = ntohl(*bp++);
38 fid->unique = ntohl(*bp++);
39 *_bp = bp;
40}
41
42/*
David Howells888b3382018-04-06 14:17:24 +010043 * Dump a bad file status record.
44 */
45static void xdr_dump_bad(const __be32 *bp)
46{
47 __be32 x[4];
48 int i;
49
50 pr_notice("AFS XDR: Bad status record\n");
51 for (i = 0; i < 5 * 4 * 4; i += 16) {
52 memcpy(x, bp, 16);
53 bp += 4;
54 pr_notice("%03x: %08x %08x %08x %08x\n",
55 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
56 }
57
58 memcpy(x, bp, 4);
59 pr_notice("0x50: %08x\n", ntohl(x[0]));
60}
61
62/*
David Howellsdd9fbcb2018-04-06 14:17:24 +010063 * decode an AFSFetchStatus block
64 */
David Howellsa58823a2019-05-09 15:16:10 +010065static int xdr_decode_AFSFetchStatus(const __be32 **_bp,
66 struct afs_call *call,
67 struct afs_status_cb *scb)
David Howellsdd9fbcb2018-04-06 14:17:24 +010068{
69 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
David Howellsa58823a2019-05-09 15:16:10 +010070 struct afs_file_status *status = &scb->status;
David Howells684b0f62018-05-10 21:51:47 +010071 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
David Howellsdd9fbcb2018-04-06 14:17:24 +010072 u64 data_version, size;
73 u32 type, abort_code;
David Howellsdd9fbcb2018-04-06 14:17:24 +010074
David Howells684b0f62018-05-10 21:51:47 +010075 abort_code = ntohl(xdr->abort_code);
76
David Howellsdd9fbcb2018-04-06 14:17:24 +010077 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
David Howells684b0f62018-05-10 21:51:47 +010078 if (xdr->if_version == htonl(0) &&
79 abort_code != 0 &&
80 inline_error) {
81 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
82 * whereby it doesn't set the interface version in the error
83 * case.
84 */
85 status->abort_code = abort_code;
David Howellsa38a7552019-05-14 12:29:11 +010086 scb->have_error = true;
Al Virode52cf92018-06-02 18:08:11 -040087 return 0;
David Howells684b0f62018-05-10 21:51:47 +010088 }
89
David Howellsdd9fbcb2018-04-06 14:17:24 +010090 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
91 goto bad;
92 }
93
David Howells684b0f62018-05-10 21:51:47 +010094 if (abort_code != 0 && inline_error) {
95 status->abort_code = abort_code;
Al Virode52cf92018-06-02 18:08:11 -040096 return 0;
David Howells684b0f62018-05-10 21:51:47 +010097 }
98
David Howellsdd9fbcb2018-04-06 14:17:24 +010099 type = ntohl(xdr->type);
David Howellsdd9fbcb2018-04-06 14:17:24 +0100100 switch (type) {
101 case AFS_FTYPE_FILE:
102 case AFS_FTYPE_DIR:
103 case AFS_FTYPE_SYMLINK:
David Howellsdd9fbcb2018-04-06 14:17:24 +0100104 status->type = type;
105 break;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100106 default:
107 goto bad;
108 }
109
David Howellsa58823a2019-05-09 15:16:10 +0100110 status->nlink = ntohl(xdr->nlink);
111 status->author = ntohl(xdr->author);
112 status->owner = ntohl(xdr->owner);
113 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
114 status->anon_access = ntohl(xdr->anon_access);
115 status->mode = ntohl(xdr->mode) & S_IALLUGO;
116 status->group = ntohl(xdr->group);
117 status->lock_count = ntohl(xdr->lock_count);
David Howellsdd9fbcb2018-04-06 14:17:24 +0100118
David Howellsd4936802018-10-20 00:57:58 +0100119 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
120 status->mtime_client.tv_nsec = 0;
121 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
122 status->mtime_server.tv_nsec = 0;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100123
124 size = (u64)ntohl(xdr->size_lo);
125 size |= (u64)ntohl(xdr->size_hi) << 32;
David Howells63a46812018-04-06 14:17:25 +0100126 status->size = size;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100127
128 data_version = (u64)ntohl(xdr->data_version_lo);
129 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
David Howellsa58823a2019-05-09 15:16:10 +0100130 status->data_version = data_version;
David Howellsa38a7552019-05-14 12:29:11 +0100131 scb->have_status = true;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100132
133 *_bp = (const void *)*_bp + sizeof(*xdr);
David Howellsc875c762018-05-23 11:32:06 +0100134 return 0;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100135
136bad:
137 xdr_dump_bad(*_bp);
David Howells160cb952018-10-20 00:57:56 +0100138 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
David Howellsc875c762018-05-23 11:32:06 +0100139}
140
David Howells78107052019-05-09 17:56:53 +0100141static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
142{
143 return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
144}
145
David Howellsa58823a2019-05-09 15:16:10 +0100146static void xdr_decode_AFSCallBack(const __be32 **_bp,
147 struct afs_call *call,
148 struct afs_status_cb *scb)
David Howells78107052019-05-09 17:56:53 +0100149{
David Howellsa58823a2019-05-09 15:16:10 +0100150 struct afs_callback *cb = &scb->callback;
David Howells78107052019-05-09 17:56:53 +0100151 const __be32 *bp = *_bp;
152
David Howells7c712452019-05-14 15:35:44 +0100153 bp++; /* version */
David Howells78107052019-05-09 17:56:53 +0100154 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
David Howells7c712452019-05-14 15:35:44 +0100155 bp++; /* type */
David Howellsa58823a2019-05-09 15:16:10 +0100156 scb->have_cb = true;
David Howells78107052019-05-09 17:56:53 +0100157 *_bp = bp;
158}
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160/*
David Howells08e0e7c2007-04-26 15:55:03 -0700161 * decode an AFSVolSync block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 */
David Howells08e0e7c2007-04-26 15:55:03 -0700163static void xdr_decode_AFSVolSync(const __be32 **_bp,
164 struct afs_volsync *volsync)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
David Howells08e0e7c2007-04-26 15:55:03 -0700166 const __be32 *bp = *_bp;
David Howells30062bd2018-10-20 00:57:58 +0100167 u32 creation;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
David Howells30062bd2018-10-20 00:57:58 +0100169 creation = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700170 bp++; /* spare2 */
171 bp++; /* spare3 */
172 bp++; /* spare4 */
173 bp++; /* spare5 */
174 bp++; /* spare6 */
175 *_bp = bp;
David Howells30062bd2018-10-20 00:57:58 +0100176
177 if (volsync)
178 volsync->creation = creation;
David Howellsec268152007-04-26 15:49:28 -0700179}
David Howells08e0e7c2007-04-26 15:55:03 -0700180
181/*
David Howells31143d52007-05-09 02:33:46 -0700182 * encode the requested attributes into an AFSStoreStatus block
183 */
184static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
185{
186 __be32 *bp = *_bp;
187 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
188
189 mask = 0;
190 if (attr->ia_valid & ATTR_MTIME) {
191 mask |= AFS_SET_MTIME;
192 mtime = attr->ia_mtime.tv_sec;
193 }
194
195 if (attr->ia_valid & ATTR_UID) {
196 mask |= AFS_SET_OWNER;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800197 owner = from_kuid(&init_user_ns, attr->ia_uid);
David Howells31143d52007-05-09 02:33:46 -0700198 }
199
200 if (attr->ia_valid & ATTR_GID) {
201 mask |= AFS_SET_GROUP;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800202 group = from_kgid(&init_user_ns, attr->ia_gid);
David Howells31143d52007-05-09 02:33:46 -0700203 }
204
205 if (attr->ia_valid & ATTR_MODE) {
206 mask |= AFS_SET_MODE;
207 mode = attr->ia_mode & S_IALLUGO;
208 }
209
210 *bp++ = htonl(mask);
211 *bp++ = htonl(mtime);
212 *bp++ = htonl(owner);
213 *bp++ = htonl(group);
214 *bp++ = htonl(mode);
215 *bp++ = 0; /* segment size */
216 *_bp = bp;
217}
218
219/*
David Howells45222b92007-05-10 22:22:20 -0700220 * decode an AFSFetchVolumeStatus block
221 */
222static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
223 struct afs_volume_status *vs)
224{
225 const __be32 *bp = *_bp;
226
227 vs->vid = ntohl(*bp++);
228 vs->parent_id = ntohl(*bp++);
229 vs->online = ntohl(*bp++);
230 vs->in_service = ntohl(*bp++);
231 vs->blessed = ntohl(*bp++);
232 vs->needs_salvage = ntohl(*bp++);
233 vs->type = ntohl(*bp++);
234 vs->min_quota = ntohl(*bp++);
235 vs->max_quota = ntohl(*bp++);
236 vs->blocks_in_use = ntohl(*bp++);
237 vs->part_blocks_avail = ntohl(*bp++);
238 vs->part_max_blocks = ntohl(*bp++);
David Howells30062bd2018-10-20 00:57:58 +0100239 vs->vol_copy_date = 0;
240 vs->vol_backup_date = 0;
David Howells45222b92007-05-10 22:22:20 -0700241 *_bp = bp;
242}
243
244/*
David Howells08e0e7c2007-04-26 15:55:03 -0700245 * deliver reply data to an FS.FetchStatus
246 */
David Howells5cf9dd52018-04-09 21:12:31 +0100247static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
David Howells08e0e7c2007-04-26 15:55:03 -0700248{
249 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100250 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700251
David Howellsd0016482016-08-30 20:42:14 +0100252 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100253 if (ret < 0)
254 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700255
256 /* unmarshall the reply once we've received all of it */
257 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100258 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100259 if (ret < 0)
260 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100261 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
David Howellsffba7182019-05-09 22:22:50 +0100262 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells08e0e7c2007-04-26 15:55:03 -0700263
264 _leave(" = 0 [done]");
265 return 0;
266}
267
268/*
269 * FS.FetchStatus operation type
270 */
David Howells5cf9dd52018-04-09 21:12:31 +0100271static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
272 .name = "FS.FetchStatus(vnode)",
David Howells025db802017-11-02 15:27:51 +0000273 .op = afs_FS_FetchStatus,
David Howells5cf9dd52018-04-09 21:12:31 +0100274 .deliver = afs_deliver_fs_fetch_status_vnode,
David Howells08e0e7c2007-04-26 15:55:03 -0700275 .destructor = afs_flat_call_destructor,
276};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278/*
279 * fetch the status information for a file
280 */
David Howellsa58823a2019-05-09 15:16:10 +0100281int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_status_cb *scb,
282 struct afs_volsync *volsync)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
David Howellsd2ddc772017-11-02 15:27:50 +0000284 struct afs_vnode *vnode = fc->vnode;
David Howells08e0e7c2007-04-26 15:55:03 -0700285 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000286 struct afs_net *net = afs_v2net(vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 __be32 *bp;
288
David Howells30062bd2018-10-20 00:57:58 +0100289 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100290 return yfs_fs_fetch_file_status(fc, scb, volsync);
David Howells30062bd2018-10-20 00:57:58 +0100291
David Howells3b6492d2018-10-20 00:57:57 +0100292 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +0000293 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
David Howells5cf9dd52018-04-09 21:12:31 +0100295 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
296 16, (21 + 3 + 6) * 4);
David Howellsd2ddc772017-11-02 15:27:50 +0000297 if (!call) {
298 fc->ac.error = -ENOMEM;
David Howells08e0e7c2007-04-26 15:55:03 -0700299 return -ENOMEM;
David Howellsd2ddc772017-11-02 15:27:50 +0000300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
David Howellsd2ddc772017-11-02 15:27:50 +0000302 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100303 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +0100304 call->out_volsync = volsync;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700307 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 bp[0] = htonl(FSFETCHSTATUS);
309 bp[1] = htonl(vnode->fid.vid);
310 bp[2] = htonl(vnode->fid.vnode);
311 bp[3] = htonl(vnode->fid.unique);
312
David Howellsd2ddc772017-11-02 15:27:50 +0000313 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000314 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +0100315
David Howells20b83912019-05-08 16:16:31 +0100316 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100317 afs_make_call(&fc->ac, call, GFP_NOFS);
318 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsec268152007-04-26 15:49:28 -0700319}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321/*
David Howells08e0e7c2007-04-26 15:55:03 -0700322 * deliver reply data to an FS.FetchData
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 */
David Howellsd0016482016-08-30 20:42:14 +0100324static int afs_deliver_fs_fetch_data(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
David Howellsffba7182019-05-09 22:22:50 +0100326 struct afs_read *req = call->read_request;
David Howells08e0e7c2007-04-26 15:55:03 -0700327 const __be32 *bp;
David Howells196ee9c2017-01-05 10:38:34 +0000328 unsigned int size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700330
David Howells12bdcf32018-10-20 00:57:56 +0100331 _enter("{%u,%zu/%llu}",
332 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
David Howells08e0e7c2007-04-26 15:55:03 -0700333
334 switch (call->unmarshall) {
335 case 0:
David Howells196ee9c2017-01-05 10:38:34 +0000336 req->actual_len = 0;
David Howells12bdcf32018-10-20 00:57:56 +0100337 req->index = 0;
338 req->offset = req->pos & (PAGE_SIZE - 1);
David Howells08e0e7c2007-04-26 15:55:03 -0700339 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +0100340 if (call->operation_ID == FSFETCHDATA64) {
341 afs_extract_to_tmp64(call);
342 } else {
343 call->tmp_u = htonl(0);
344 afs_extract_to_tmp(call);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700345 }
David Howells08e0e7c2007-04-26 15:55:03 -0700346
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600347 /* Fall through - and 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];
371 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
372 ASSERTCMP(size, <=, PAGE_SIZE);
David Howells196ee9c2017-01-05 10:38:34 +0000373
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600374 /* Fall through - and extract the returned data */
David Howells12bdcf32018-10-20 00:57:56 +0100375 case 2:
376 _debug("extract data %zu/%llu",
377 iov_iter_count(&call->iter), req->remain);
David Howells196ee9c2017-01-05 10:38:34 +0000378
David Howells12bdcf32018-10-20 00:57:56 +0100379 ret = afs_extract_data(call, true);
David Howells196ee9c2017-01-05 10:38:34 +0000380 if (ret < 0)
381 return ret;
David Howells12bdcf32018-10-20 00:57:56 +0100382 req->remain -= call->bvec[0].bv_len;
383 req->offset += call->bvec[0].bv_len;
384 ASSERTCMP(req->offset, <=, PAGE_SIZE);
385 if (req->offset == PAGE_SIZE) {
386 req->offset = 0;
David Howells196ee9c2017-01-05 10:38:34 +0000387 if (req->page_done)
David Howellsa58823a2019-05-09 15:16:10 +0100388 req->page_done(req);
David Howells29f06982017-03-16 16:27:46 +0000389 req->index++;
David Howells12bdcf32018-10-20 00:57:56 +0100390 if (req->remain > 0)
David Howells196ee9c2017-01-05 10:38:34 +0000391 goto begin_page;
David Howells08e0e7c2007-04-26 15:55:03 -0700392 }
David Howells12bdcf32018-10-20 00:57:56 +0100393
394 ASSERTCMP(req->remain, ==, 0);
395 if (req->actual_len <= req->len)
396 goto no_more_data;
David Howells6db3ac32017-03-16 16:27:44 +0000397
398 /* Discard any excess data the server gave us */
David Howells12bdcf32018-10-20 00:57:56 +0100399 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
400 call->unmarshall = 3;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600401
402 /* Fall through */
David Howells12bdcf32018-10-20 00:57:56 +0100403 case 3:
404 _debug("extract discard %zu/%llu",
405 iov_iter_count(&call->iter), req->actual_len - req->len);
David Howells6db3ac32017-03-16 16:27:44 +0000406
David Howells12bdcf32018-10-20 00:57:56 +0100407 ret = afs_extract_data(call, true);
David Howells6db3ac32017-03-16 16:27:44 +0000408 if (ret < 0)
409 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700410
David Howells196ee9c2017-01-05 10:38:34 +0000411 no_more_data:
David Howells12bdcf32018-10-20 00:57:56 +0100412 call->unmarshall = 4;
413 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700414
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600415 /* Fall through - and 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 Howells196ee9c2017-01-05 10:38:34 +0000441 if (req->page_done)
David Howellsa58823a2019-05-09 15:16:10 +0100442 req->page_done(req);
David Howells12bdcf32018-10-20 00:57:56 +0100443 req->offset = 0;
David Howells416351f2007-05-09 02:33:45 -0700444 }
445
David Howells08e0e7c2007-04-26 15:55:03 -0700446 _leave(" = 0 [done]");
447 return 0;
448}
449
David Howells196ee9c2017-01-05 10:38:34 +0000450static void afs_fetch_data_destructor(struct afs_call *call)
451{
David Howellsffba7182019-05-09 22:22:50 +0100452 struct afs_read *req = call->read_request;
David Howells196ee9c2017-01-05 10:38:34 +0000453
454 afs_put_read(req);
455 afs_flat_call_destructor(call);
456}
457
David Howells08e0e7c2007-04-26 15:55:03 -0700458/*
459 * FS.FetchData operation type
460 */
461static const struct afs_call_type afs_RXFSFetchData = {
David Howells00d3b7a2007-04-26 15:57:07 -0700462 .name = "FS.FetchData",
David Howells025db802017-11-02 15:27:51 +0000463 .op = afs_FS_FetchData,
David Howells08e0e7c2007-04-26 15:55:03 -0700464 .deliver = afs_deliver_fs_fetch_data,
David Howells196ee9c2017-01-05 10:38:34 +0000465 .destructor = afs_fetch_data_destructor,
David Howells08e0e7c2007-04-26 15:55:03 -0700466};
467
David Howellsb9b1f8d2007-05-10 03:15:21 -0700468static const struct afs_call_type afs_RXFSFetchData64 = {
469 .name = "FS.FetchData64",
David Howells025db802017-11-02 15:27:51 +0000470 .op = afs_FS_FetchData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -0700471 .deliver = afs_deliver_fs_fetch_data,
David Howells196ee9c2017-01-05 10:38:34 +0000472 .destructor = afs_fetch_data_destructor,
David Howellsb9b1f8d2007-05-10 03:15:21 -0700473};
474
475/*
476 * fetch data from a very large file
477 */
David Howellsa58823a2019-05-09 15:16:10 +0100478static int afs_fs_fetch_data64(struct afs_fs_cursor *fc,
479 struct afs_status_cb *scb,
480 struct afs_read *req)
David Howellsb9b1f8d2007-05-10 03:15:21 -0700481{
David Howellsd2ddc772017-11-02 15:27:50 +0000482 struct afs_vnode *vnode = fc->vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700483 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000484 struct afs_net *net = afs_v2net(vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700485 __be32 *bp;
486
487 _enter("");
488
David Howellsf044c882017-11-02 15:27:45 +0000489 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700490 if (!call)
491 return -ENOMEM;
492
David Howellsd2ddc772017-11-02 15:27:50 +0000493 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100494 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +0100495 call->out_volsync = NULL;
496 call->read_request = req;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700497
498 /* marshall the parameters */
499 bp = call->request;
500 bp[0] = htonl(FSFETCHDATA64);
501 bp[1] = htonl(vnode->fid.vid);
502 bp[2] = htonl(vnode->fid.vnode);
503 bp[3] = htonl(vnode->fid.unique);
David Howells196ee9c2017-01-05 10:38:34 +0000504 bp[4] = htonl(upper_32_bits(req->pos));
505 bp[5] = htonl(lower_32_bits(req->pos));
David Howellsb9b1f8d2007-05-10 03:15:21 -0700506 bp[6] = 0;
David Howells196ee9c2017-01-05 10:38:34 +0000507 bp[7] = htonl(lower_32_bits(req->len));
David Howellsb9b1f8d2007-05-10 03:15:21 -0700508
David Howellsf3ddee82018-04-06 14:17:25 +0100509 refcount_inc(&req->usage);
David Howellsd2ddc772017-11-02 15:27:50 +0000510 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000511 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +0100512 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100513 afs_make_call(&fc->ac, call, GFP_NOFS);
514 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700515}
516
David Howells08e0e7c2007-04-26 15:55:03 -0700517/*
518 * fetch data from a file
519 */
David Howellsa58823a2019-05-09 15:16:10 +0100520int afs_fs_fetch_data(struct afs_fs_cursor *fc,
521 struct afs_status_cb *scb,
522 struct afs_read *req)
David Howells08e0e7c2007-04-26 15:55:03 -0700523{
David Howellsd2ddc772017-11-02 15:27:50 +0000524 struct afs_vnode *vnode = fc->vnode;
David Howells08e0e7c2007-04-26 15:55:03 -0700525 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000526 struct afs_net *net = afs_v2net(vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 __be32 *bp;
528
David Howells30062bd2018-10-20 00:57:58 +0100529 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100530 return yfs_fs_fetch_data(fc, scb, req);
David Howells30062bd2018-10-20 00:57:58 +0100531
David Howells196ee9c2017-01-05 10:38:34 +0000532 if (upper_32_bits(req->pos) ||
533 upper_32_bits(req->len) ||
534 upper_32_bits(req->pos + req->len))
David Howellsa58823a2019-05-09 15:16:10 +0100535 return afs_fs_fetch_data64(fc, scb, req);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700536
David Howells08e0e7c2007-04-26 15:55:03 -0700537 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
David Howellsf044c882017-11-02 15:27:45 +0000539 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700540 if (!call)
541 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
David Howellsd2ddc772017-11-02 15:27:50 +0000543 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100544 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +0100545 call->out_volsync = NULL;
546 call->read_request = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700549 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 bp[0] = htonl(FSFETCHDATA);
David Howells08e0e7c2007-04-26 15:55:03 -0700551 bp[1] = htonl(vnode->fid.vid);
552 bp[2] = htonl(vnode->fid.vnode);
553 bp[3] = htonl(vnode->fid.unique);
David Howells196ee9c2017-01-05 10:38:34 +0000554 bp[4] = htonl(lower_32_bits(req->pos));
555 bp[5] = htonl(lower_32_bits(req->len));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
David Howellsf3ddee82018-04-06 14:17:25 +0100557 refcount_inc(&req->usage);
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
989 /* unmarshall the reply once we've received all of it */
990 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100991 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100992 if (ret < 0)
993 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100994 if (call->out_dir_scb != call->out_scb) {
995 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100996 if (ret < 0)
997 return ret;
998 }
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);
David Howells45222b92007-05-10 22:22:20 -07001478
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06001479 /* Fall through - and extract the returned status record */
David Howells45222b92007-05-10 22:22:20 -07001480 case 1:
1481 _debug("extract status");
David Howells12bdcf32018-10-20 00:57:56 +01001482 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001483 if (ret < 0)
1484 return ret;
David Howells45222b92007-05-10 22:22:20 -07001485
1486 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +01001487 xdr_decode_AFSFetchVolumeStatus(&bp, call->out_volstatus);
David Howells45222b92007-05-10 22:22:20 -07001488 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01001489 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001490
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06001491 /* Fall through - and extract the volume name length */
David Howells45222b92007-05-10 22:22:20 -07001492 case 2:
David Howells12bdcf32018-10-20 00:57:56 +01001493 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001494 if (ret < 0)
1495 return ret;
David Howells45222b92007-05-10 22:22:20 -07001496
1497 call->count = ntohl(call->tmp);
1498 _debug("volname length: %u", call->count);
1499 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001500 return afs_protocol_error(call, -EBADMSG,
1501 afs_eproto_volname_len);
David Howells12bdcf32018-10-20 00:57:56 +01001502 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001503 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001504 call->unmarshall++;
1505
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06001506 /* Fall through - and extract the volume name */
David Howells45222b92007-05-10 22:22:20 -07001507 case 3:
1508 _debug("extract volname");
David Howells12bdcf32018-10-20 00:57:56 +01001509 ret = afs_extract_data(call, true);
1510 if (ret < 0)
1511 return ret;
David Howells45222b92007-05-10 22:22:20 -07001512
David Howellsffba7182019-05-09 22:22:50 +01001513 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001514 p[call->count] = 0;
1515 _debug("volname '%s'", p);
David Howells12bdcf32018-10-20 00:57:56 +01001516 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001517 call->unmarshall++;
1518
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06001519 /* Fall through - and extract the offline message length */
David Howells12bdcf32018-10-20 00:57:56 +01001520 case 4:
1521 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001522 if (ret < 0)
1523 return ret;
David Howells45222b92007-05-10 22:22:20 -07001524
1525 call->count = ntohl(call->tmp);
1526 _debug("offline msg length: %u", call->count);
1527 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001528 return afs_protocol_error(call, -EBADMSG,
1529 afs_eproto_offline_msg_len);
David Howells12bdcf32018-10-20 00:57:56 +01001530 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001531 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001532 call->unmarshall++;
1533
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06001534 /* Fall through - and extract the offline message */
David Howells12bdcf32018-10-20 00:57:56 +01001535 case 5:
David Howells45222b92007-05-10 22:22:20 -07001536 _debug("extract offline");
David Howells12bdcf32018-10-20 00:57:56 +01001537 ret = afs_extract_data(call, true);
1538 if (ret < 0)
1539 return ret;
David Howells45222b92007-05-10 22:22:20 -07001540
David Howellsffba7182019-05-09 22:22:50 +01001541 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001542 p[call->count] = 0;
1543 _debug("offline '%s'", p);
1544
David Howells12bdcf32018-10-20 00:57:56 +01001545 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001546 call->unmarshall++;
1547
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06001548 /* Fall through - and extract the message of the day length */
David Howells12bdcf32018-10-20 00:57:56 +01001549 case 6:
1550 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001551 if (ret < 0)
1552 return ret;
David Howells45222b92007-05-10 22:22:20 -07001553
1554 call->count = ntohl(call->tmp);
1555 _debug("motd length: %u", call->count);
1556 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001557 return afs_protocol_error(call, -EBADMSG,
1558 afs_eproto_motd_len);
David Howells12bdcf32018-10-20 00:57:56 +01001559 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001560 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001561 call->unmarshall++;
1562
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06001563 /* Fall through - and extract the message of the day */
David Howells12bdcf32018-10-20 00:57:56 +01001564 case 7:
David Howells45222b92007-05-10 22:22:20 -07001565 _debug("extract motd");
David Howells12bdcf32018-10-20 00:57:56 +01001566 ret = afs_extract_data(call, false);
1567 if (ret < 0)
1568 return ret;
David Howells45222b92007-05-10 22:22:20 -07001569
David Howellsffba7182019-05-09 22:22:50 +01001570 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001571 p[call->count] = 0;
1572 _debug("motd '%s'", p);
1573
David Howells45222b92007-05-10 22:22:20 -07001574 call->unmarshall++;
1575
David Howells12bdcf32018-10-20 00:57:56 +01001576 case 8:
David Howells45222b92007-05-10 22:22:20 -07001577 break;
1578 }
1579
David Howells45222b92007-05-10 22:22:20 -07001580 _leave(" = 0 [done]");
1581 return 0;
1582}
1583
1584/*
David Howells45222b92007-05-10 22:22:20 -07001585 * FS.GetVolumeStatus operation type
1586 */
1587static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1588 .name = "FS.GetVolumeStatus",
David Howells025db802017-11-02 15:27:51 +00001589 .op = afs_FS_GetVolumeStatus,
David Howells45222b92007-05-10 22:22:20 -07001590 .deliver = afs_deliver_fs_get_volume_status,
David Howellsffba7182019-05-09 22:22:50 +01001591 .destructor = afs_flat_call_destructor,
David Howells45222b92007-05-10 22:22:20 -07001592};
1593
1594/*
1595 * fetch the status of a volume
1596 */
David Howells8b2a4642017-11-02 15:27:50 +00001597int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
David Howellsd2ddc772017-11-02 15:27:50 +00001598 struct afs_volume_status *vs)
David Howells45222b92007-05-10 22:22:20 -07001599{
David Howellsd2ddc772017-11-02 15:27:50 +00001600 struct afs_vnode *vnode = fc->vnode;
David Howells45222b92007-05-10 22:22:20 -07001601 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001602 struct afs_net *net = afs_v2net(vnode);
David Howells45222b92007-05-10 22:22:20 -07001603 __be32 *bp;
David Howells45222b92007-05-10 22:22:20 -07001604
David Howells30062bd2018-10-20 00:57:58 +01001605 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1606 return yfs_fs_get_volume_status(fc, vs);
1607
David Howells45222b92007-05-10 22:22:20 -07001608 _enter("");
1609
David Howellsffba7182019-05-09 22:22:50 +01001610 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4,
1611 max(12 * 4, AFSOPAQUEMAX + 1));
1612 if (!call)
David Howells45222b92007-05-10 22:22:20 -07001613 return -ENOMEM;
1614
David Howellsd2ddc772017-11-02 15:27:50 +00001615 call->key = fc->key;
David Howellsffba7182019-05-09 22:22:50 +01001616 call->out_volstatus = vs;
David Howells45222b92007-05-10 22:22:20 -07001617
1618 /* marshall the parameters */
1619 bp = call->request;
1620 bp[0] = htonl(FSGETVOLUMESTATUS);
1621 bp[1] = htonl(vnode->fid.vid);
1622
David Howellsd2ddc772017-11-02 15:27:50 +00001623 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001624 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001625 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001626 afs_make_call(&fc->ac, call, GFP_NOFS);
1627 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells45222b92007-05-10 22:22:20 -07001628}
David Howellse8d6c552007-07-15 23:40:12 -07001629
1630/*
1631 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1632 */
David Howellsd0016482016-08-30 20:42:14 +01001633static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
David Howellse8d6c552007-07-15 23:40:12 -07001634{
1635 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001636 int ret;
David Howellse8d6c552007-07-15 23:40:12 -07001637
David Howellsd0016482016-08-30 20:42:14 +01001638 _enter("{%u}", call->unmarshall);
David Howellse8d6c552007-07-15 23:40:12 -07001639
David Howellsd0016482016-08-30 20:42:14 +01001640 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001641 if (ret < 0)
1642 return ret;
David Howellse8d6c552007-07-15 23:40:12 -07001643
1644 /* unmarshall the reply once we've received all of it */
1645 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +01001646 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howellse8d6c552007-07-15 23:40:12 -07001647
1648 _leave(" = 0 [done]");
1649 return 0;
1650}
1651
1652/*
1653 * FS.SetLock operation type
1654 */
1655static const struct afs_call_type afs_RXFSSetLock = {
1656 .name = "FS.SetLock",
David Howells025db802017-11-02 15:27:51 +00001657 .op = afs_FS_SetLock,
David Howellse8d6c552007-07-15 23:40:12 -07001658 .deliver = afs_deliver_fs_xxxx_lock,
David Howellsa690f602019-04-25 14:26:50 +01001659 .done = afs_lock_op_done,
David Howellse8d6c552007-07-15 23:40:12 -07001660 .destructor = afs_flat_call_destructor,
1661};
1662
1663/*
1664 * FS.ExtendLock operation type
1665 */
1666static const struct afs_call_type afs_RXFSExtendLock = {
1667 .name = "FS.ExtendLock",
David Howells025db802017-11-02 15:27:51 +00001668 .op = afs_FS_ExtendLock,
David Howellse8d6c552007-07-15 23:40:12 -07001669 .deliver = afs_deliver_fs_xxxx_lock,
David Howellsa690f602019-04-25 14:26:50 +01001670 .done = afs_lock_op_done,
David Howellse8d6c552007-07-15 23:40:12 -07001671 .destructor = afs_flat_call_destructor,
1672};
1673
1674/*
1675 * FS.ReleaseLock operation type
1676 */
1677static const struct afs_call_type afs_RXFSReleaseLock = {
1678 .name = "FS.ReleaseLock",
David Howells025db802017-11-02 15:27:51 +00001679 .op = afs_FS_ReleaseLock,
David Howellse8d6c552007-07-15 23:40:12 -07001680 .deliver = afs_deliver_fs_xxxx_lock,
David Howellse8d6c552007-07-15 23:40:12 -07001681 .destructor = afs_flat_call_destructor,
1682};
1683
1684/*
David Howellsd2ddc772017-11-02 15:27:50 +00001685 * Set a lock on a file
David Howellse8d6c552007-07-15 23:40:12 -07001686 */
David Howellsa58823a2019-05-09 15:16:10 +01001687int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type,
1688 struct afs_status_cb *scb)
David Howellse8d6c552007-07-15 23:40:12 -07001689{
David Howellsd2ddc772017-11-02 15:27:50 +00001690 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001691 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001692 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001693 __be32 *bp;
1694
David Howells30062bd2018-10-20 00:57:58 +01001695 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001696 return yfs_fs_set_lock(fc, type, scb);
David Howells30062bd2018-10-20 00:57:58 +01001697
David Howellse8d6c552007-07-15 23:40:12 -07001698 _enter("");
1699
David Howellsf044c882017-11-02 15:27:45 +00001700 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001701 if (!call)
1702 return -ENOMEM;
1703
David Howellsd2ddc772017-11-02 15:27:50 +00001704 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001705 call->lvnode = vnode;
1706 call->out_scb = scb;
David Howellse8d6c552007-07-15 23:40:12 -07001707
1708 /* marshall the parameters */
1709 bp = call->request;
1710 *bp++ = htonl(FSSETLOCK);
1711 *bp++ = htonl(vnode->fid.vid);
1712 *bp++ = htonl(vnode->fid.vnode);
1713 *bp++ = htonl(vnode->fid.unique);
1714 *bp++ = htonl(type);
1715
David Howellsd2ddc772017-11-02 15:27:50 +00001716 afs_use_fs_server(call, fc->cbi);
David Howells6c6c1d62019-04-25 14:26:52 +01001717 trace_afs_make_fs_calli(call, &vnode->fid, type);
David Howells20b83912019-05-08 16:16:31 +01001718 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001719 afs_make_call(&fc->ac, call, GFP_NOFS);
1720 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellse8d6c552007-07-15 23:40:12 -07001721}
1722
1723/*
1724 * extend a lock on a file
1725 */
David Howellsa58823a2019-05-09 15:16:10 +01001726int afs_fs_extend_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
David Howellse8d6c552007-07-15 23:40:12 -07001727{
David Howellsd2ddc772017-11-02 15:27:50 +00001728 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001729 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001730 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001731 __be32 *bp;
1732
David Howells30062bd2018-10-20 00:57:58 +01001733 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001734 return yfs_fs_extend_lock(fc, scb);
David Howells30062bd2018-10-20 00:57:58 +01001735
David Howellse8d6c552007-07-15 23:40:12 -07001736 _enter("");
1737
David Howellsf044c882017-11-02 15:27:45 +00001738 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001739 if (!call)
1740 return -ENOMEM;
1741
David Howellsd2ddc772017-11-02 15:27:50 +00001742 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001743 call->lvnode = vnode;
1744 call->out_scb = scb;
David Howellse8d6c552007-07-15 23:40:12 -07001745
1746 /* marshall the parameters */
1747 bp = call->request;
1748 *bp++ = htonl(FSEXTENDLOCK);
1749 *bp++ = htonl(vnode->fid.vid);
1750 *bp++ = htonl(vnode->fid.vnode);
1751 *bp++ = htonl(vnode->fid.unique);
1752
David Howellsd2ddc772017-11-02 15:27:50 +00001753 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001754 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001755 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001756 afs_make_call(&fc->ac, call, GFP_NOFS);
1757 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellse8d6c552007-07-15 23:40:12 -07001758}
1759
1760/*
1761 * release a lock on a file
1762 */
David Howellsa58823a2019-05-09 15:16:10 +01001763int afs_fs_release_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
David Howellse8d6c552007-07-15 23:40:12 -07001764{
David Howellsd2ddc772017-11-02 15:27:50 +00001765 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001766 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001767 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001768 __be32 *bp;
1769
David Howells30062bd2018-10-20 00:57:58 +01001770 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001771 return yfs_fs_release_lock(fc, scb);
David Howells30062bd2018-10-20 00:57:58 +01001772
David Howellse8d6c552007-07-15 23:40:12 -07001773 _enter("");
1774
David Howellsf044c882017-11-02 15:27:45 +00001775 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001776 if (!call)
1777 return -ENOMEM;
1778
David Howellsd2ddc772017-11-02 15:27:50 +00001779 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001780 call->lvnode = vnode;
1781 call->out_scb = scb;
David Howellse8d6c552007-07-15 23:40:12 -07001782
1783 /* marshall the parameters */
1784 bp = call->request;
1785 *bp++ = htonl(FSRELEASELOCK);
1786 *bp++ = htonl(vnode->fid.vid);
1787 *bp++ = htonl(vnode->fid.vnode);
1788 *bp++ = htonl(vnode->fid.unique);
1789
David Howellsd2ddc772017-11-02 15:27:50 +00001790 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001791 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001792 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001793 afs_make_call(&fc->ac, call, GFP_NOFS);
1794 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsc435ee32017-11-02 15:27:49 +00001795}
1796
1797/*
1798 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1799 */
1800static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1801{
1802 return afs_transfer_reply(call);
1803}
1804
1805/*
1806 * FS.GiveUpAllCallBacks operation type
1807 */
1808static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1809 .name = "FS.GiveUpAllCallBacks",
David Howells025db802017-11-02 15:27:51 +00001810 .op = afs_FS_GiveUpAllCallBacks,
David Howellsc435ee32017-11-02 15:27:49 +00001811 .deliver = afs_deliver_fs_give_up_all_callbacks,
1812 .destructor = afs_flat_call_destructor,
1813};
1814
1815/*
1816 * Flush all the callbacks we have on a server.
1817 */
David Howellsd2ddc772017-11-02 15:27:50 +00001818int afs_fs_give_up_all_callbacks(struct afs_net *net,
1819 struct afs_server *server,
David Howells8b2a4642017-11-02 15:27:50 +00001820 struct afs_addr_cursor *ac,
David Howellsd2ddc772017-11-02 15:27:50 +00001821 struct key *key)
David Howellsc435ee32017-11-02 15:27:49 +00001822{
1823 struct afs_call *call;
1824 __be32 *bp;
1825
1826 _enter("");
1827
David Howellsd2ddc772017-11-02 15:27:50 +00001828 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
David Howellsc435ee32017-11-02 15:27:49 +00001829 if (!call)
1830 return -ENOMEM;
1831
1832 call->key = key;
1833
1834 /* marshall the parameters */
1835 bp = call->request;
1836 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1837
1838 /* Can't take a ref on server */
David Howells0b9bf382019-04-25 14:26:50 +01001839 afs_make_call(ac, call, GFP_NOFS);
1840 return afs_wait_for_call_to_complete(call, ac);
David Howellsd2ddc772017-11-02 15:27:50 +00001841}
1842
1843/*
1844 * Deliver reply data to an FS.GetCapabilities operation.
1845 */
1846static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1847{
1848 u32 count;
1849 int ret;
1850
David Howells12bdcf32018-10-20 00:57:56 +01001851 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
David Howellsd2ddc772017-11-02 15:27:50 +00001852
David Howellsd2ddc772017-11-02 15:27:50 +00001853 switch (call->unmarshall) {
1854 case 0:
David Howells12bdcf32018-10-20 00:57:56 +01001855 afs_extract_to_tmp(call);
David Howellsd2ddc772017-11-02 15:27:50 +00001856 call->unmarshall++;
1857
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06001858 /* Fall through - and extract the capabilities word count */
David Howellsd2ddc772017-11-02 15:27:50 +00001859 case 1:
David Howells12bdcf32018-10-20 00:57:56 +01001860 ret = afs_extract_data(call, true);
David Howellsd2ddc772017-11-02 15:27:50 +00001861 if (ret < 0)
1862 return ret;
1863
1864 count = ntohl(call->tmp);
1865
1866 call->count = count;
1867 call->count2 = count;
David Howells12bdcf32018-10-20 00:57:56 +01001868 iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
David Howellsd2ddc772017-11-02 15:27:50 +00001869 call->unmarshall++;
1870
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06001871 /* Fall through - and extract capabilities words */
David Howellsd2ddc772017-11-02 15:27:50 +00001872 case 2:
David Howells12bdcf32018-10-20 00:57:56 +01001873 ret = afs_extract_data(call, false);
David Howellsd2ddc772017-11-02 15:27:50 +00001874 if (ret < 0)
1875 return ret;
1876
1877 /* TODO: Examine capabilities */
1878
David Howellsd2ddc772017-11-02 15:27:50 +00001879 call->unmarshall++;
1880 break;
1881 }
1882
1883 _leave(" = 0 [done]");
1884 return 0;
1885}
1886
1887/*
1888 * FS.GetCapabilities operation type
1889 */
1890static const struct afs_call_type afs_RXFSGetCapabilities = {
1891 .name = "FS.GetCapabilities",
David Howells025db802017-11-02 15:27:51 +00001892 .op = afs_FS_GetCapabilities,
David Howellsd2ddc772017-11-02 15:27:50 +00001893 .deliver = afs_deliver_fs_get_capabilities,
David Howells3bf0fb62018-10-20 00:57:59 +01001894 .done = afs_fileserver_probe_result,
David Howellsffba7182019-05-09 22:22:50 +01001895 .destructor = afs_flat_call_destructor,
David Howellsd2ddc772017-11-02 15:27:50 +00001896};
1897
1898/*
1899 * Probe a fileserver for the capabilities that it supports. This can
1900 * return up to 196 words.
1901 */
David Howells0b9bf382019-04-25 14:26:50 +01001902struct afs_call *afs_fs_get_capabilities(struct afs_net *net,
1903 struct afs_server *server,
1904 struct afs_addr_cursor *ac,
1905 struct key *key,
1906 unsigned int server_index)
David Howellsd2ddc772017-11-02 15:27:50 +00001907{
1908 struct afs_call *call;
1909 __be32 *bp;
1910
1911 _enter("");
1912
1913 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1914 if (!call)
David Howells0b9bf382019-04-25 14:26:50 +01001915 return ERR_PTR(-ENOMEM);
David Howellsd2ddc772017-11-02 15:27:50 +00001916
1917 call->key = key;
David Howellsffba7182019-05-09 22:22:50 +01001918 call->server = afs_get_server(server);
1919 call->server_index = server_index;
David Howells30062bd2018-10-20 00:57:58 +01001920 call->upgrade = true;
David Howells0b9bf382019-04-25 14:26:50 +01001921 call->async = true;
David Howells94f699c2019-05-16 13:21:59 +01001922 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
David Howellsd2ddc772017-11-02 15:27:50 +00001923
1924 /* marshall the parameters */
1925 bp = call->request;
1926 *bp++ = htonl(FSGETCAPABILITIES);
1927
1928 /* Can't take a ref on server */
David Howells025db802017-11-02 15:27:51 +00001929 trace_afs_make_fs_call(call, NULL);
David Howells0b9bf382019-04-25 14:26:50 +01001930 afs_make_call(ac, call, GFP_NOFS);
1931 return call;
David Howellse8d6c552007-07-15 23:40:12 -07001932}
David Howells5cf9dd52018-04-09 21:12:31 +01001933
1934/*
1935 * Deliver reply data to an FS.FetchStatus with no vnode.
1936 */
1937static int afs_deliver_fs_fetch_status(struct afs_call *call)
1938{
David Howells5cf9dd52018-04-09 21:12:31 +01001939 const __be32 *bp;
1940 int ret;
1941
1942 ret = afs_transfer_reply(call);
1943 if (ret < 0)
1944 return ret;
1945
David Howells5cf9dd52018-04-09 21:12:31 +01001946 /* unmarshall the reply once we've received all of it */
1947 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01001948 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +01001949 if (ret < 0)
1950 return ret;
David Howellsa58823a2019-05-09 15:16:10 +01001951 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
1952 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells5cf9dd52018-04-09 21:12:31 +01001953
1954 _leave(" = 0 [done]");
1955 return 0;
1956}
1957
1958/*
1959 * FS.FetchStatus operation type
1960 */
1961static const struct afs_call_type afs_RXFSFetchStatus = {
1962 .name = "FS.FetchStatus",
1963 .op = afs_FS_FetchStatus,
1964 .deliver = afs_deliver_fs_fetch_status,
1965 .destructor = afs_flat_call_destructor,
1966};
1967
1968/*
1969 * Fetch the status information for a fid without needing a vnode handle.
1970 */
1971int afs_fs_fetch_status(struct afs_fs_cursor *fc,
1972 struct afs_net *net,
1973 struct afs_fid *fid,
David Howellsa58823a2019-05-09 15:16:10 +01001974 struct afs_status_cb *scb,
David Howells5cf9dd52018-04-09 21:12:31 +01001975 struct afs_volsync *volsync)
1976{
1977 struct afs_call *call;
1978 __be32 *bp;
1979
David Howells30062bd2018-10-20 00:57:58 +01001980 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001981 return yfs_fs_fetch_status(fc, net, fid, scb, volsync);
David Howells30062bd2018-10-20 00:57:58 +01001982
David Howells3b6492d2018-10-20 00:57:57 +01001983 _enter(",%x,{%llx:%llu},,",
David Howells5cf9dd52018-04-09 21:12:31 +01001984 key_serial(fc->key), fid->vid, fid->vnode);
1985
1986 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
1987 if (!call) {
1988 fc->ac.error = -ENOMEM;
1989 return -ENOMEM;
1990 }
1991
1992 call->key = fc->key;
David Howellsffba7182019-05-09 22:22:50 +01001993 call->out_fid = fid;
David Howellsa58823a2019-05-09 15:16:10 +01001994 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +01001995 call->out_volsync = volsync;
David Howells5cf9dd52018-04-09 21:12:31 +01001996
1997 /* marshall the parameters */
1998 bp = call->request;
1999 bp[0] = htonl(FSFETCHSTATUS);
2000 bp[1] = htonl(fid->vid);
2001 bp[2] = htonl(fid->vnode);
2002 bp[3] = htonl(fid->unique);
2003
David Howells5cf9dd52018-04-09 21:12:31 +01002004 afs_use_fs_server(call, fc->cbi);
2005 trace_afs_make_fs_call(call, fid);
David Howells20b83912019-05-08 16:16:31 +01002006 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01002007 afs_make_call(&fc->ac, call, GFP_NOFS);
2008 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells5cf9dd52018-04-09 21:12:31 +01002009}
2010
2011/*
2012 * Deliver reply data to an FS.InlineBulkStatus call
2013 */
2014static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2015{
David Howells87182752019-05-09 16:17:05 +01002016 struct afs_status_cb *scb;
David Howells5cf9dd52018-04-09 21:12:31 +01002017 const __be32 *bp;
2018 u32 tmp;
2019 int ret;
2020
2021 _enter("{%u}", call->unmarshall);
2022
2023 switch (call->unmarshall) {
2024 case 0:
David Howells12bdcf32018-10-20 00:57:56 +01002025 afs_extract_to_tmp(call);
David Howells5cf9dd52018-04-09 21:12:31 +01002026 call->unmarshall++;
2027
2028 /* Extract the file status count and array in two steps */
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002029 /* Fall through */
David Howells5cf9dd52018-04-09 21:12:31 +01002030 case 1:
2031 _debug("extract status count");
David Howells12bdcf32018-10-20 00:57:56 +01002032 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002033 if (ret < 0)
2034 return ret;
2035
2036 tmp = ntohl(call->tmp);
2037 _debug("status count: %u/%u", tmp, call->count2);
2038 if (tmp != call->count2)
David Howells160cb952018-10-20 00:57:56 +01002039 return afs_protocol_error(call, -EBADMSG,
2040 afs_eproto_ibulkst_count);
David Howells5cf9dd52018-04-09 21:12:31 +01002041
2042 call->count = 0;
2043 call->unmarshall++;
2044 more_counts:
David Howells12bdcf32018-10-20 00:57:56 +01002045 afs_extract_to_buf(call, 21 * sizeof(__be32));
David Howells5cf9dd52018-04-09 21:12:31 +01002046
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002047 /* Fall through */
David Howells5cf9dd52018-04-09 21:12:31 +01002048 case 2:
2049 _debug("extract status array %u", call->count);
David Howells12bdcf32018-10-20 00:57:56 +01002050 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002051 if (ret < 0)
2052 return ret;
2053
2054 bp = call->buffer;
David Howells87182752019-05-09 16:17:05 +01002055 scb = &call->out_scb[call->count];
David Howellsa58823a2019-05-09 15:16:10 +01002056 ret = xdr_decode_AFSFetchStatus(&bp, call, scb);
David Howells160cb952018-10-20 00:57:56 +01002057 if (ret < 0)
2058 return ret;
David Howells5cf9dd52018-04-09 21:12:31 +01002059
2060 call->count++;
2061 if (call->count < call->count2)
2062 goto more_counts;
2063
2064 call->count = 0;
2065 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01002066 afs_extract_to_tmp(call);
David Howells5cf9dd52018-04-09 21:12:31 +01002067
2068 /* Extract the callback count and array in two steps */
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002069 /* Fall through */
David Howells5cf9dd52018-04-09 21:12:31 +01002070 case 3:
2071 _debug("extract CB count");
David Howells12bdcf32018-10-20 00:57:56 +01002072 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002073 if (ret < 0)
2074 return ret;
2075
2076 tmp = ntohl(call->tmp);
2077 _debug("CB count: %u", tmp);
2078 if (tmp != call->count2)
David Howells160cb952018-10-20 00:57:56 +01002079 return afs_protocol_error(call, -EBADMSG,
2080 afs_eproto_ibulkst_cb_count);
David Howells5cf9dd52018-04-09 21:12:31 +01002081 call->count = 0;
2082 call->unmarshall++;
2083 more_cbs:
David Howells12bdcf32018-10-20 00:57:56 +01002084 afs_extract_to_buf(call, 3 * sizeof(__be32));
David Howells5cf9dd52018-04-09 21:12:31 +01002085
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002086 /* Fall through */
David Howells5cf9dd52018-04-09 21:12:31 +01002087 case 4:
2088 _debug("extract CB array");
David Howells12bdcf32018-10-20 00:57:56 +01002089 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002090 if (ret < 0)
2091 return ret;
2092
2093 _debug("unmarshall CB array");
2094 bp = call->buffer;
David Howells87182752019-05-09 16:17:05 +01002095 scb = &call->out_scb[call->count];
David Howellsa58823a2019-05-09 15:16:10 +01002096 xdr_decode_AFSCallBack(&bp, call, scb);
David Howells5cf9dd52018-04-09 21:12:31 +01002097 call->count++;
2098 if (call->count < call->count2)
2099 goto more_cbs;
2100
David Howells12bdcf32018-10-20 00:57:56 +01002101 afs_extract_to_buf(call, 6 * sizeof(__be32));
David Howells5cf9dd52018-04-09 21:12:31 +01002102 call->unmarshall++;
2103
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002104 /* Fall through */
David Howells5cf9dd52018-04-09 21:12:31 +01002105 case 5:
David Howells12bdcf32018-10-20 00:57:56 +01002106 ret = afs_extract_data(call, false);
David Howells5cf9dd52018-04-09 21:12:31 +01002107 if (ret < 0)
2108 return ret;
2109
2110 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +01002111 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells5cf9dd52018-04-09 21:12:31 +01002112
David Howells5cf9dd52018-04-09 21:12:31 +01002113 call->unmarshall++;
2114
2115 case 6:
2116 break;
2117 }
2118
2119 _leave(" = 0 [done]");
2120 return 0;
2121}
2122
2123/*
2124 * FS.InlineBulkStatus operation type
2125 */
2126static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2127 .name = "FS.InlineBulkStatus",
2128 .op = afs_FS_InlineBulkStatus,
2129 .deliver = afs_deliver_fs_inline_bulk_status,
2130 .destructor = afs_flat_call_destructor,
2131};
2132
2133/*
2134 * Fetch the status information for up to 50 files
2135 */
2136int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2137 struct afs_net *net,
2138 struct afs_fid *fids,
David Howells87182752019-05-09 16:17:05 +01002139 struct afs_status_cb *statuses,
David Howells5cf9dd52018-04-09 21:12:31 +01002140 unsigned int nr_fids,
2141 struct afs_volsync *volsync)
2142{
2143 struct afs_call *call;
2144 __be32 *bp;
2145 int i;
2146
David Howells30062bd2018-10-20 00:57:58 +01002147 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howells87182752019-05-09 16:17:05 +01002148 return yfs_fs_inline_bulk_status(fc, net, fids, statuses,
David Howells30062bd2018-10-20 00:57:58 +01002149 nr_fids, volsync);
2150
David Howells3b6492d2018-10-20 00:57:57 +01002151 _enter(",%x,{%llx:%llu},%u",
David Howells5cf9dd52018-04-09 21:12:31 +01002152 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2153
2154 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2155 (2 + nr_fids * 3) * 4,
2156 21 * 4);
2157 if (!call) {
2158 fc->ac.error = -ENOMEM;
2159 return -ENOMEM;
2160 }
2161
2162 call->key = fc->key;
David Howells87182752019-05-09 16:17:05 +01002163 call->out_scb = statuses;
David Howellsffba7182019-05-09 22:22:50 +01002164 call->out_volsync = volsync;
David Howells5cf9dd52018-04-09 21:12:31 +01002165 call->count2 = nr_fids;
2166
2167 /* marshall the parameters */
2168 bp = call->request;
2169 *bp++ = htonl(FSINLINEBULKSTATUS);
2170 *bp++ = htonl(nr_fids);
2171 for (i = 0; i < nr_fids; i++) {
2172 *bp++ = htonl(fids[i].vid);
2173 *bp++ = htonl(fids[i].vnode);
2174 *bp++ = htonl(fids[i].unique);
2175 }
2176
David Howells5cf9dd52018-04-09 21:12:31 +01002177 afs_use_fs_server(call, fc->cbi);
2178 trace_afs_make_fs_call(call, &fids[0]);
David Howells20b83912019-05-08 16:16:31 +01002179 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01002180 afs_make_call(&fc->ac, call, GFP_NOFS);
2181 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells5cf9dd52018-04-09 21:12:31 +01002182}
David Howells260f0822019-04-25 14:26:52 +01002183
2184/*
2185 * deliver reply data to an FS.FetchACL
2186 */
2187static int afs_deliver_fs_fetch_acl(struct afs_call *call)
2188{
David Howells260f0822019-04-25 14:26:52 +01002189 struct afs_acl *acl;
2190 const __be32 *bp;
2191 unsigned int size;
2192 int ret;
2193
2194 _enter("{%u}", call->unmarshall);
2195
2196 switch (call->unmarshall) {
2197 case 0:
2198 afs_extract_to_tmp(call);
2199 call->unmarshall++;
2200
2201 /* extract the returned data length */
2202 case 1:
2203 ret = afs_extract_data(call, true);
2204 if (ret < 0)
2205 return ret;
2206
2207 size = call->count2 = ntohl(call->tmp);
2208 size = round_up(size, 4);
2209
2210 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2211 if (!acl)
2212 return -ENOMEM;
David Howellsffba7182019-05-09 22:22:50 +01002213 call->ret_acl = acl;
David Howells260f0822019-04-25 14:26:52 +01002214 acl->size = call->count2;
2215 afs_extract_begin(call, acl->data, size);
2216 call->unmarshall++;
2217
2218 /* extract the returned data */
2219 case 2:
2220 ret = afs_extract_data(call, true);
2221 if (ret < 0)
2222 return ret;
2223
2224 afs_extract_to_buf(call, (21 + 6) * 4);
2225 call->unmarshall++;
2226
2227 /* extract the metadata */
2228 case 3:
2229 ret = afs_extract_data(call, false);
2230 if (ret < 0)
2231 return ret;
2232
2233 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01002234 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells260f0822019-04-25 14:26:52 +01002235 if (ret < 0)
2236 return ret;
David Howellsffba7182019-05-09 22:22:50 +01002237 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260f0822019-04-25 14:26:52 +01002238
2239 call->unmarshall++;
2240
2241 case 4:
2242 break;
2243 }
2244
2245 _leave(" = 0 [done]");
2246 return 0;
2247}
2248
2249static void afs_destroy_fs_fetch_acl(struct afs_call *call)
2250{
David Howellsffba7182019-05-09 22:22:50 +01002251 kfree(call->ret_acl);
David Howells260f0822019-04-25 14:26:52 +01002252 afs_flat_call_destructor(call);
2253}
2254
2255/*
2256 * FS.FetchACL operation type
2257 */
2258static const struct afs_call_type afs_RXFSFetchACL = {
2259 .name = "FS.FetchACL",
2260 .op = afs_FS_FetchACL,
2261 .deliver = afs_deliver_fs_fetch_acl,
2262 .destructor = afs_destroy_fs_fetch_acl,
2263};
2264
2265/*
2266 * Fetch the ACL for a file.
2267 */
David Howellsa58823a2019-05-09 15:16:10 +01002268struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc,
2269 struct afs_status_cb *scb)
David Howells260f0822019-04-25 14:26:52 +01002270{
2271 struct afs_vnode *vnode = fc->vnode;
2272 struct afs_call *call;
2273 struct afs_net *net = afs_v2net(vnode);
2274 __be32 *bp;
2275
2276 _enter(",%x,{%llx:%llu},,",
2277 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2278
2279 call = afs_alloc_flat_call(net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2280 if (!call) {
2281 fc->ac.error = -ENOMEM;
2282 return ERR_PTR(-ENOMEM);
2283 }
2284
2285 call->key = fc->key;
David Howellsffba7182019-05-09 22:22:50 +01002286 call->ret_acl = NULL;
David Howellsa58823a2019-05-09 15:16:10 +01002287 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +01002288 call->out_volsync = NULL;
David Howells260f0822019-04-25 14:26:52 +01002289
2290 /* marshall the parameters */
2291 bp = call->request;
2292 bp[0] = htonl(FSFETCHACL);
2293 bp[1] = htonl(vnode->fid.vid);
2294 bp[2] = htonl(vnode->fid.vnode);
2295 bp[3] = htonl(vnode->fid.unique);
2296
David Howells260f0822019-04-25 14:26:52 +01002297 afs_use_fs_server(call, fc->cbi);
2298 trace_afs_make_fs_call(call, &vnode->fid);
2299 afs_make_call(&fc->ac, call, GFP_KERNEL);
2300 return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2301}
Joe Gorseb10494a2019-04-25 14:26:52 +01002302
2303/*
David Howellsffba7182019-05-09 22:22:50 +01002304 * Deliver reply data to any operation that returns file status and volume
2305 * sync.
2306 */
2307static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
2308{
David Howellsffba7182019-05-09 22:22:50 +01002309 const __be32 *bp;
2310 int ret;
2311
David Howellsffba7182019-05-09 22:22:50 +01002312 ret = afs_transfer_reply(call);
2313 if (ret < 0)
2314 return ret;
2315
David Howellsffba7182019-05-09 22:22:50 +01002316 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01002317 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howellsffba7182019-05-09 22:22:50 +01002318 if (ret < 0)
2319 return ret;
2320 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2321
2322 _leave(" = 0 [done]");
2323 return 0;
2324}
2325
2326/*
Joe Gorseb10494a2019-04-25 14:26:52 +01002327 * FS.StoreACL operation type
2328 */
2329static const struct afs_call_type afs_RXFSStoreACL = {
2330 .name = "FS.StoreACL",
2331 .op = afs_FS_StoreACL,
David Howellsffba7182019-05-09 22:22:50 +01002332 .deliver = afs_deliver_fs_file_status_and_vol,
Joe Gorseb10494a2019-04-25 14:26:52 +01002333 .destructor = afs_flat_call_destructor,
2334};
2335
2336/*
2337 * Fetch the ACL for a file.
2338 */
David Howellsa58823a2019-05-09 15:16:10 +01002339int afs_fs_store_acl(struct afs_fs_cursor *fc, const struct afs_acl *acl,
2340 struct afs_status_cb *scb)
Joe Gorseb10494a2019-04-25 14:26:52 +01002341{
2342 struct afs_vnode *vnode = fc->vnode;
2343 struct afs_call *call;
2344 struct afs_net *net = afs_v2net(vnode);
2345 size_t size;
2346 __be32 *bp;
2347
2348 _enter(",%x,{%llx:%llu},,",
2349 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2350
2351 size = round_up(acl->size, 4);
2352 call = afs_alloc_flat_call(net, &afs_RXFSStoreACL,
2353 5 * 4 + size, (21 + 6) * 4);
2354 if (!call) {
2355 fc->ac.error = -ENOMEM;
2356 return -ENOMEM;
2357 }
2358
2359 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01002360 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +01002361 call->out_volsync = NULL;
Joe Gorseb10494a2019-04-25 14:26:52 +01002362
2363 /* marshall the parameters */
2364 bp = call->request;
2365 bp[0] = htonl(FSSTOREACL);
2366 bp[1] = htonl(vnode->fid.vid);
2367 bp[2] = htonl(vnode->fid.vnode);
2368 bp[3] = htonl(vnode->fid.unique);
2369 bp[4] = htonl(acl->size);
2370 memcpy(&bp[5], acl->data, acl->size);
2371 if (acl->size != size)
2372 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2373
2374 trace_afs_make_fs_call(call, &vnode->fid);
2375 afs_make_call(&fc->ac, call, GFP_KERNEL);
2376 return afs_wait_for_call_to_complete(call, &fc->ac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377}