blob: 1d95ed9dd86e601f6068ec3bf500ebcc08b9d8e9 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells08e0e7c2007-04-26 15:55:03 -07002/* AFS File Server client stubs
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
David Howells08e0e7c2007-04-26 15:55:03 -07004 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Written by David Howells (dhowells@redhat.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/sched.h>
David Howells08e0e7c2007-04-26 15:55:03 -070011#include <linux/circ_buf.h>
Jeff Laytona01179e2017-12-11 06:35:11 -050012#include <linux/iversion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070014#include "afs_fs.h"
David Howellsdd9fbcb2018-04-06 14:17:24 +010015#include "xdr_fs.h"
David Howellsc435ee32017-11-02 15:27:49 +000016
David Howells6db3ac32017-03-16 16:27:44 +000017/*
David Howells260a9802007-04-26 15:59:35 -070018 * decode an AFSFid block
19 */
20static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
21{
22 const __be32 *bp = *_bp;
23
24 fid->vid = ntohl(*bp++);
25 fid->vnode = ntohl(*bp++);
26 fid->unique = ntohl(*bp++);
27 *_bp = bp;
28}
29
30/*
David Howells888b3382018-04-06 14:17:24 +010031 * Dump a bad file status record.
32 */
33static void xdr_dump_bad(const __be32 *bp)
34{
35 __be32 x[4];
36 int i;
37
38 pr_notice("AFS XDR: Bad status record\n");
39 for (i = 0; i < 5 * 4 * 4; i += 16) {
40 memcpy(x, bp, 16);
41 bp += 4;
42 pr_notice("%03x: %08x %08x %08x %08x\n",
43 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
44 }
45
46 memcpy(x, bp, 4);
47 pr_notice("0x50: %08x\n", ntohl(x[0]));
48}
49
50/*
David Howellsdd9fbcb2018-04-06 14:17:24 +010051 * decode an AFSFetchStatus block
52 */
David Howells38355ee2020-04-08 16:13:20 +010053static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
54 struct afs_call *call,
55 struct afs_status_cb *scb)
David Howellsdd9fbcb2018-04-06 14:17:24 +010056{
57 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
David Howellsa58823a2019-05-09 15:16:10 +010058 struct afs_file_status *status = &scb->status;
David Howells684b0f62018-05-10 21:51:47 +010059 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
David Howellsdd9fbcb2018-04-06 14:17:24 +010060 u64 data_version, size;
61 u32 type, abort_code;
David Howellsdd9fbcb2018-04-06 14:17:24 +010062
David Howells684b0f62018-05-10 21:51:47 +010063 abort_code = ntohl(xdr->abort_code);
64
David Howellsdd9fbcb2018-04-06 14:17:24 +010065 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
David Howells684b0f62018-05-10 21:51:47 +010066 if (xdr->if_version == htonl(0) &&
67 abort_code != 0 &&
68 inline_error) {
69 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
70 * whereby it doesn't set the interface version in the error
71 * case.
72 */
73 status->abort_code = abort_code;
David Howellsa38a7552019-05-14 12:29:11 +010074 scb->have_error = true;
David Howells38355ee2020-04-08 16:13:20 +010075 goto advance;
David Howells684b0f62018-05-10 21:51:47 +010076 }
77
David Howellsdd9fbcb2018-04-06 14:17:24 +010078 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
79 goto bad;
80 }
81
David Howells684b0f62018-05-10 21:51:47 +010082 if (abort_code != 0 && inline_error) {
83 status->abort_code = abort_code;
David Howells3e0d9892020-04-08 17:32:10 +010084 scb->have_error = true;
David Howells38355ee2020-04-08 16:13:20 +010085 goto advance;
David Howells684b0f62018-05-10 21:51:47 +010086 }
87
David Howellsdd9fbcb2018-04-06 14:17:24 +010088 type = ntohl(xdr->type);
David Howellsdd9fbcb2018-04-06 14:17:24 +010089 switch (type) {
90 case AFS_FTYPE_FILE:
91 case AFS_FTYPE_DIR:
92 case AFS_FTYPE_SYMLINK:
David Howellsdd9fbcb2018-04-06 14:17:24 +010093 status->type = type;
94 break;
David Howellsdd9fbcb2018-04-06 14:17:24 +010095 default:
96 goto bad;
97 }
98
David Howellsa58823a2019-05-09 15:16:10 +010099 status->nlink = ntohl(xdr->nlink);
100 status->author = ntohl(xdr->author);
101 status->owner = ntohl(xdr->owner);
102 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
103 status->anon_access = ntohl(xdr->anon_access);
104 status->mode = ntohl(xdr->mode) & S_IALLUGO;
105 status->group = ntohl(xdr->group);
106 status->lock_count = ntohl(xdr->lock_count);
David Howellsdd9fbcb2018-04-06 14:17:24 +0100107
David Howellsd4936802018-10-20 00:57:58 +0100108 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
109 status->mtime_client.tv_nsec = 0;
110 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
111 status->mtime_server.tv_nsec = 0;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100112
113 size = (u64)ntohl(xdr->size_lo);
114 size |= (u64)ntohl(xdr->size_hi) << 32;
David Howells63a46812018-04-06 14:17:25 +0100115 status->size = size;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100116
117 data_version = (u64)ntohl(xdr->data_version_lo);
118 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
David Howellsa58823a2019-05-09 15:16:10 +0100119 status->data_version = data_version;
David Howellsa38a7552019-05-14 12:29:11 +0100120 scb->have_status = true;
David Howellsc72057b2020-04-08 16:13:20 +0100121advance:
David Howellsdd9fbcb2018-04-06 14:17:24 +0100122 *_bp = (const void *)*_bp + sizeof(*xdr);
David Howells38355ee2020-04-08 16:13:20 +0100123 return;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100124
125bad:
126 xdr_dump_bad(*_bp);
David Howells7126ead2020-04-08 16:49:08 +0100127 afs_protocol_error(call, afs_eproto_bad_status);
David Howellsc72057b2020-04-08 16:13:20 +0100128 goto advance;
David Howellsc875c762018-05-23 11:32:06 +0100129}
130
David Howells78107052019-05-09 17:56:53 +0100131static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
132{
133 return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
134}
135
David Howellsa58823a2019-05-09 15:16:10 +0100136static void xdr_decode_AFSCallBack(const __be32 **_bp,
137 struct afs_call *call,
138 struct afs_status_cb *scb)
David Howells78107052019-05-09 17:56:53 +0100139{
David Howellsa58823a2019-05-09 15:16:10 +0100140 struct afs_callback *cb = &scb->callback;
David Howells78107052019-05-09 17:56:53 +0100141 const __be32 *bp = *_bp;
142
David Howells7c712452019-05-14 15:35:44 +0100143 bp++; /* version */
David Howells78107052019-05-09 17:56:53 +0100144 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
David Howells7c712452019-05-14 15:35:44 +0100145 bp++; /* type */
David Howellsa58823a2019-05-09 15:16:10 +0100146 scb->have_cb = true;
David Howells78107052019-05-09 17:56:53 +0100147 *_bp = bp;
148}
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150/*
David Howells08e0e7c2007-04-26 15:55:03 -0700151 * decode an AFSVolSync block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 */
David Howells08e0e7c2007-04-26 15:55:03 -0700153static void xdr_decode_AFSVolSync(const __be32 **_bp,
154 struct afs_volsync *volsync)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
David Howells08e0e7c2007-04-26 15:55:03 -0700156 const __be32 *bp = *_bp;
David Howells30062bd2018-10-20 00:57:58 +0100157 u32 creation;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
David Howells30062bd2018-10-20 00:57:58 +0100159 creation = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700160 bp++; /* spare2 */
161 bp++; /* spare3 */
162 bp++; /* spare4 */
163 bp++; /* spare5 */
164 bp++; /* spare6 */
165 *_bp = bp;
David Howells30062bd2018-10-20 00:57:58 +0100166
167 if (volsync)
168 volsync->creation = creation;
David Howellsec268152007-04-26 15:49:28 -0700169}
David Howells08e0e7c2007-04-26 15:55:03 -0700170
171/*
David Howells31143d52007-05-09 02:33:46 -0700172 * encode the requested attributes into an AFSStoreStatus block
173 */
174static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
175{
176 __be32 *bp = *_bp;
177 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
178
179 mask = 0;
180 if (attr->ia_valid & ATTR_MTIME) {
181 mask |= AFS_SET_MTIME;
182 mtime = attr->ia_mtime.tv_sec;
183 }
184
185 if (attr->ia_valid & ATTR_UID) {
186 mask |= AFS_SET_OWNER;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800187 owner = from_kuid(&init_user_ns, attr->ia_uid);
David Howells31143d52007-05-09 02:33:46 -0700188 }
189
190 if (attr->ia_valid & ATTR_GID) {
191 mask |= AFS_SET_GROUP;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800192 group = from_kgid(&init_user_ns, attr->ia_gid);
David Howells31143d52007-05-09 02:33:46 -0700193 }
194
195 if (attr->ia_valid & ATTR_MODE) {
196 mask |= AFS_SET_MODE;
197 mode = attr->ia_mode & S_IALLUGO;
198 }
199
200 *bp++ = htonl(mask);
201 *bp++ = htonl(mtime);
202 *bp++ = htonl(owner);
203 *bp++ = htonl(group);
204 *bp++ = htonl(mode);
205 *bp++ = 0; /* segment size */
206 *_bp = bp;
207}
208
209/*
David Howells45222b92007-05-10 22:22:20 -0700210 * decode an AFSFetchVolumeStatus block
211 */
212static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
213 struct afs_volume_status *vs)
214{
215 const __be32 *bp = *_bp;
216
217 vs->vid = ntohl(*bp++);
218 vs->parent_id = ntohl(*bp++);
219 vs->online = ntohl(*bp++);
220 vs->in_service = ntohl(*bp++);
221 vs->blessed = ntohl(*bp++);
222 vs->needs_salvage = ntohl(*bp++);
223 vs->type = ntohl(*bp++);
224 vs->min_quota = ntohl(*bp++);
225 vs->max_quota = ntohl(*bp++);
226 vs->blocks_in_use = ntohl(*bp++);
227 vs->part_blocks_avail = ntohl(*bp++);
228 vs->part_max_blocks = ntohl(*bp++);
David Howells30062bd2018-10-20 00:57:58 +0100229 vs->vol_copy_date = 0;
230 vs->vol_backup_date = 0;
David Howells45222b92007-05-10 22:22:20 -0700231 *_bp = bp;
232}
233
234/*
David Howells08e0e7c2007-04-26 15:55:03 -0700235 * deliver reply data to an FS.FetchStatus
236 */
David Howellse49c7b22020-04-10 20:51:51 +0100237static int afs_deliver_fs_fetch_status(struct afs_call *call)
David Howells08e0e7c2007-04-26 15:55:03 -0700238{
David Howellse49c7b22020-04-10 20:51:51 +0100239 struct afs_operation *op = call->op;
240 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
David Howells08e0e7c2007-04-26 15:55:03 -0700241 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100242 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700243
David Howellsd0016482016-08-30 20:42:14 +0100244 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100245 if (ret < 0)
246 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700247
248 /* unmarshall the reply once we've received all of it */
249 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100250 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
251 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
252 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howells08e0e7c2007-04-26 15:55:03 -0700253
254 _leave(" = 0 [done]");
255 return 0;
256}
257
258/*
259 * FS.FetchStatus operation type
260 */
David Howellse49c7b22020-04-10 20:51:51 +0100261static const struct afs_call_type afs_RXFSFetchStatus = {
262 .name = "FS.FetchStatus",
David Howells025db802017-11-02 15:27:51 +0000263 .op = afs_FS_FetchStatus,
David Howellse49c7b22020-04-10 20:51:51 +0100264 .deliver = afs_deliver_fs_fetch_status,
David Howells08e0e7c2007-04-26 15:55:03 -0700265 .destructor = afs_flat_call_destructor,
266};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268/*
269 * fetch the status information for a file
270 */
David Howellse49c7b22020-04-10 20:51:51 +0100271void afs_fs_fetch_status(struct afs_operation *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
David Howellse49c7b22020-04-10 20:51:51 +0100273 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
David Howells08e0e7c2007-04-26 15:55:03 -0700274 struct afs_call *call;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 __be32 *bp;
276
David Howells3b6492d2018-10-20 00:57:57 +0100277 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +0100278 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
David Howellse49c7b22020-04-10 20:51:51 +0100280 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchStatus,
David Howells5cf9dd52018-04-09 21:12:31 +0100281 16, (21 + 3 + 6) * 4);
David Howellse49c7b22020-04-10 20:51:51 +0100282 if (!call)
283 return afs_op_nomem(op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700286 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 bp[0] = htonl(FSFETCHSTATUS);
David Howellse49c7b22020-04-10 20:51:51 +0100288 bp[1] = htonl(vp->fid.vid);
289 bp[2] = htonl(vp->fid.vnode);
290 bp[3] = htonl(vp->fid.unique);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
David Howellse49c7b22020-04-10 20:51:51 +0100292 trace_afs_make_fs_call(call, &vp->fid);
293 afs_make_op_call(op, call, GFP_NOFS);
David Howellsec268152007-04-26 15:49:28 -0700294}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296/*
David Howells08e0e7c2007-04-26 15:55:03 -0700297 * deliver reply data to an FS.FetchData
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 */
David Howellsd0016482016-08-30 20:42:14 +0100299static int afs_deliver_fs_fetch_data(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
David Howellse49c7b22020-04-10 20:51:51 +0100301 struct afs_operation *op = call->op;
302 struct afs_vnode_param *vp = &op->file[0];
303 struct afs_read *req = op->fetch.req;
David Howells08e0e7c2007-04-26 15:55:03 -0700304 const __be32 *bp;
David Howells196ee9c2017-01-05 10:38:34 +0000305 unsigned int size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700307
David Howells12bdcf32018-10-20 00:57:56 +0100308 _enter("{%u,%zu/%llu}",
David Howellsfc276122019-11-21 09:12:17 +0000309 call->unmarshall, iov_iter_count(call->iter), req->actual_len);
David Howells08e0e7c2007-04-26 15:55:03 -0700310
311 switch (call->unmarshall) {
312 case 0:
David Howells196ee9c2017-01-05 10:38:34 +0000313 req->actual_len = 0;
David Howells12bdcf32018-10-20 00:57:56 +0100314 req->index = 0;
315 req->offset = req->pos & (PAGE_SIZE - 1);
David Howells08e0e7c2007-04-26 15:55:03 -0700316 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +0100317 if (call->operation_ID == FSFETCHDATA64) {
318 afs_extract_to_tmp64(call);
319 } else {
320 call->tmp_u = htonl(0);
321 afs_extract_to_tmp(call);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700322 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500323 fallthrough;
David Howells08e0e7c2007-04-26 15:55:03 -0700324
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500325 /* extract the returned data length */
David Howells12bdcf32018-10-20 00:57:56 +0100326 case 1:
David Howells08e0e7c2007-04-26 15:55:03 -0700327 _debug("extract data length");
David Howells12bdcf32018-10-20 00:57:56 +0100328 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100329 if (ret < 0)
330 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700331
David Howells12bdcf32018-10-20 00:57:56 +0100332 req->actual_len = be64_to_cpu(call->tmp64);
David Howells196ee9c2017-01-05 10:38:34 +0000333 _debug("DATA length: %llu", req->actual_len);
David Howells12bdcf32018-10-20 00:57:56 +0100334 req->remain = min(req->len, req->actual_len);
335 if (req->remain == 0)
David Howells196ee9c2017-01-05 10:38:34 +0000336 goto no_more_data;
David Howells12bdcf32018-10-20 00:57:56 +0100337
David Howells08e0e7c2007-04-26 15:55:03 -0700338 call->unmarshall++;
339
David Howells196ee9c2017-01-05 10:38:34 +0000340 begin_page:
David Howells6db3ac32017-03-16 16:27:44 +0000341 ASSERTCMP(req->index, <, req->nr_pages);
David Howells12bdcf32018-10-20 00:57:56 +0100342 if (req->remain > PAGE_SIZE - req->offset)
343 size = PAGE_SIZE - req->offset;
David Howells196ee9c2017-01-05 10:38:34 +0000344 else
345 size = req->remain;
David Howells12bdcf32018-10-20 00:57:56 +0100346 call->bvec[0].bv_len = size;
347 call->bvec[0].bv_offset = req->offset;
348 call->bvec[0].bv_page = req->pages[req->index];
David Howellsfc276122019-11-21 09:12:17 +0000349 iov_iter_bvec(&call->def_iter, READ, call->bvec, 1, size);
David Howells12bdcf32018-10-20 00:57:56 +0100350 ASSERTCMP(size, <=, PAGE_SIZE);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500351 fallthrough;
David Howells196ee9c2017-01-05 10:38:34 +0000352
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500353 /* extract the returned data */
David Howells12bdcf32018-10-20 00:57:56 +0100354 case 2:
355 _debug("extract data %zu/%llu",
David Howellsfc276122019-11-21 09:12:17 +0000356 iov_iter_count(call->iter), req->remain);
David Howells196ee9c2017-01-05 10:38:34 +0000357
David Howells12bdcf32018-10-20 00:57:56 +0100358 ret = afs_extract_data(call, true);
David Howells196ee9c2017-01-05 10:38:34 +0000359 if (ret < 0)
360 return ret;
David Howells12bdcf32018-10-20 00:57:56 +0100361 req->remain -= call->bvec[0].bv_len;
362 req->offset += call->bvec[0].bv_len;
363 ASSERTCMP(req->offset, <=, PAGE_SIZE);
364 if (req->offset == PAGE_SIZE) {
365 req->offset = 0;
David Howells29f06982017-03-16 16:27:46 +0000366 req->index++;
David Howells12bdcf32018-10-20 00:57:56 +0100367 if (req->remain > 0)
David Howells196ee9c2017-01-05 10:38:34 +0000368 goto begin_page;
David Howells08e0e7c2007-04-26 15:55:03 -0700369 }
David Howells12bdcf32018-10-20 00:57:56 +0100370
371 ASSERTCMP(req->remain, ==, 0);
372 if (req->actual_len <= req->len)
373 goto no_more_data;
David Howells6db3ac32017-03-16 16:27:44 +0000374
375 /* Discard any excess data the server gave us */
David Howells23a28912019-08-20 09:22:38 +0100376 afs_extract_discard(call, req->actual_len - req->len);
David Howells12bdcf32018-10-20 00:57:56 +0100377 call->unmarshall = 3;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500378 fallthrough;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500379
David Howells12bdcf32018-10-20 00:57:56 +0100380 case 3:
381 _debug("extract discard %zu/%llu",
David Howellsfc276122019-11-21 09:12:17 +0000382 iov_iter_count(call->iter), req->actual_len - req->len);
David Howells6db3ac32017-03-16 16:27:44 +0000383
David Howells12bdcf32018-10-20 00:57:56 +0100384 ret = afs_extract_data(call, true);
David Howells6db3ac32017-03-16 16:27:44 +0000385 if (ret < 0)
386 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700387
David Howells196ee9c2017-01-05 10:38:34 +0000388 no_more_data:
David Howells12bdcf32018-10-20 00:57:56 +0100389 call->unmarshall = 4;
390 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500391 fallthrough;
David Howells08e0e7c2007-04-26 15:55:03 -0700392
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500393 /* extract the metadata */
David Howells12bdcf32018-10-20 00:57:56 +0100394 case 4:
395 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100396 if (ret < 0)
397 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700398
399 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100400 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
401 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
402 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howells08e0e7c2007-04-26 15:55:03 -0700403
David Howellse49c7b22020-04-10 20:51:51 +0100404 req->data_version = vp->scb.status.data_version;
405 req->file_size = vp->scb.status.size;
David Howellsa58823a2019-05-09 15:16:10 +0100406
David Howells08e0e7c2007-04-26 15:55:03 -0700407 call->unmarshall++;
408
David Howells12bdcf32018-10-20 00:57:56 +0100409 case 5:
David Howells08e0e7c2007-04-26 15:55:03 -0700410 break;
411 }
412
David Howells6db3ac32017-03-16 16:27:44 +0000413 for (; req->index < req->nr_pages; req->index++) {
David Howells12bdcf32018-10-20 00:57:56 +0100414 if (req->offset < PAGE_SIZE)
David Howells6db3ac32017-03-16 16:27:44 +0000415 zero_user_segment(req->pages[req->index],
David Howells12bdcf32018-10-20 00:57:56 +0100416 req->offset, PAGE_SIZE);
David Howells12bdcf32018-10-20 00:57:56 +0100417 req->offset = 0;
David Howells416351f2007-05-09 02:33:45 -0700418 }
419
David Howells9d1be4f2020-05-17 21:21:05 +0100420 if (req->page_done)
421 for (req->index = 0; req->index < req->nr_pages; req->index++)
422 req->page_done(req);
423
David Howells08e0e7c2007-04-26 15:55:03 -0700424 _leave(" = 0 [done]");
425 return 0;
426}
427
428/*
429 * FS.FetchData operation type
430 */
431static const struct afs_call_type afs_RXFSFetchData = {
David Howells00d3b7a2007-04-26 15:57:07 -0700432 .name = "FS.FetchData",
David Howells025db802017-11-02 15:27:51 +0000433 .op = afs_FS_FetchData,
David Howells08e0e7c2007-04-26 15:55:03 -0700434 .deliver = afs_deliver_fs_fetch_data,
David Howellse49c7b22020-04-10 20:51:51 +0100435 .destructor = afs_flat_call_destructor,
David Howells08e0e7c2007-04-26 15:55:03 -0700436};
437
David Howellsb9b1f8d2007-05-10 03:15:21 -0700438static const struct afs_call_type afs_RXFSFetchData64 = {
439 .name = "FS.FetchData64",
David Howells025db802017-11-02 15:27:51 +0000440 .op = afs_FS_FetchData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -0700441 .deliver = afs_deliver_fs_fetch_data,
David Howellse49c7b22020-04-10 20:51:51 +0100442 .destructor = afs_flat_call_destructor,
David Howellsb9b1f8d2007-05-10 03:15:21 -0700443};
444
445/*
446 * fetch data from a very large file
447 */
David Howellse49c7b22020-04-10 20:51:51 +0100448static void afs_fs_fetch_data64(struct afs_operation *op)
David Howellsb9b1f8d2007-05-10 03:15:21 -0700449{
David Howellse49c7b22020-04-10 20:51:51 +0100450 struct afs_vnode_param *vp = &op->file[0];
451 struct afs_read *req = op->fetch.req;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700452 struct afs_call *call;
453 __be32 *bp;
454
455 _enter("");
456
David Howellse49c7b22020-04-10 20:51:51 +0100457 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700458 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100459 return afs_op_nomem(op);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700460
461 /* marshall the parameters */
462 bp = call->request;
463 bp[0] = htonl(FSFETCHDATA64);
David Howellse49c7b22020-04-10 20:51:51 +0100464 bp[1] = htonl(vp->fid.vid);
465 bp[2] = htonl(vp->fid.vnode);
466 bp[3] = htonl(vp->fid.unique);
David Howells196ee9c2017-01-05 10:38:34 +0000467 bp[4] = htonl(upper_32_bits(req->pos));
468 bp[5] = htonl(lower_32_bits(req->pos));
David Howellsb9b1f8d2007-05-10 03:15:21 -0700469 bp[6] = 0;
David Howells196ee9c2017-01-05 10:38:34 +0000470 bp[7] = htonl(lower_32_bits(req->len));
David Howellsb9b1f8d2007-05-10 03:15:21 -0700471
David Howellse49c7b22020-04-10 20:51:51 +0100472 trace_afs_make_fs_call(call, &vp->fid);
473 afs_make_op_call(op, call, GFP_NOFS);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700474}
475
David Howells08e0e7c2007-04-26 15:55:03 -0700476/*
477 * fetch data from a file
478 */
David Howellse49c7b22020-04-10 20:51:51 +0100479void afs_fs_fetch_data(struct afs_operation *op)
David Howells08e0e7c2007-04-26 15:55:03 -0700480{
David Howellse49c7b22020-04-10 20:51:51 +0100481 struct afs_vnode_param *vp = &op->file[0];
David Howells08e0e7c2007-04-26 15:55:03 -0700482 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +0100483 struct afs_read *req = op->fetch.req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 __be32 *bp;
485
David Howells196ee9c2017-01-05 10:38:34 +0000486 if (upper_32_bits(req->pos) ||
487 upper_32_bits(req->len) ||
488 upper_32_bits(req->pos + req->len))
David Howellse49c7b22020-04-10 20:51:51 +0100489 return afs_fs_fetch_data64(op);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700490
David Howells08e0e7c2007-04-26 15:55:03 -0700491 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
David Howellse49c7b22020-04-10 20:51:51 +0100493 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700494 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100495 return afs_op_nomem(op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700498 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 bp[0] = htonl(FSFETCHDATA);
David Howellse49c7b22020-04-10 20:51:51 +0100500 bp[1] = htonl(vp->fid.vid);
501 bp[2] = htonl(vp->fid.vnode);
502 bp[3] = htonl(vp->fid.unique);
David Howells196ee9c2017-01-05 10:38:34 +0000503 bp[4] = htonl(lower_32_bits(req->pos));
504 bp[5] = htonl(lower_32_bits(req->len));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
David Howellse49c7b22020-04-10 20:51:51 +0100506 trace_afs_make_fs_call(call, &vp->fid);
507 afs_make_op_call(op, call, GFP_NOFS);
David Howellsec268152007-04-26 15:49:28 -0700508}
David Howells260a9802007-04-26 15:59:35 -0700509
510/*
511 * deliver reply data to an FS.CreateFile or an FS.MakeDir
512 */
David Howellsd0016482016-08-30 20:42:14 +0100513static int afs_deliver_fs_create_vnode(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700514{
David Howellse49c7b22020-04-10 20:51:51 +0100515 struct afs_operation *op = call->op;
516 struct afs_vnode_param *dvp = &op->file[0];
517 struct afs_vnode_param *vp = &op->file[1];
David Howells260a9802007-04-26 15:59:35 -0700518 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100519 int ret;
David Howells260a9802007-04-26 15:59:35 -0700520
David Howellsd0016482016-08-30 20:42:14 +0100521 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100522 if (ret < 0)
523 return ret;
David Howells260a9802007-04-26 15:59:35 -0700524
525 /* unmarshall the reply once we've received all of it */
526 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100527 xdr_decode_AFSFid(&bp, &op->file[1].fid);
528 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
529 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
530 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
531 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howells260a9802007-04-26 15:59:35 -0700532
533 _leave(" = 0 [done]");
534 return 0;
535}
536
537/*
538 * FS.CreateFile and FS.MakeDir operation type
539 */
David Howells025db802017-11-02 15:27:51 +0000540static const struct afs_call_type afs_RXFSCreateFile = {
541 .name = "FS.CreateFile",
542 .op = afs_FS_CreateFile,
543 .deliver = afs_deliver_fs_create_vnode,
544 .destructor = afs_flat_call_destructor,
545};
546
David Howellse49c7b22020-04-10 20:51:51 +0100547/*
548 * Create a file.
549 */
550void afs_fs_create_file(struct afs_operation *op)
551{
552 const struct qstr *name = &op->dentry->d_name;
553 struct afs_vnode_param *dvp = &op->file[0];
554 struct afs_call *call;
555 size_t namesz, reqsz, padsz;
556 __be32 *bp;
557
558 _enter("");
559
560 namesz = name->len;
561 padsz = (4 - (namesz & 3)) & 3;
562 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
563
564 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile,
565 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
566 if (!call)
567 return afs_op_nomem(op);
568
569 /* marshall the parameters */
570 bp = call->request;
571 *bp++ = htonl(FSCREATEFILE);
572 *bp++ = htonl(dvp->fid.vid);
573 *bp++ = htonl(dvp->fid.vnode);
574 *bp++ = htonl(dvp->fid.unique);
575 *bp++ = htonl(namesz);
576 memcpy(bp, name->name, namesz);
577 bp = (void *) bp + namesz;
578 if (padsz > 0) {
579 memset(bp, 0, padsz);
580 bp = (void *) bp + padsz;
581 }
582 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
583 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
584 *bp++ = 0; /* owner */
585 *bp++ = 0; /* group */
586 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
587 *bp++ = 0; /* segment size */
588
589 trace_afs_make_fs_call1(call, &dvp->fid, name);
590 afs_make_op_call(op, call, GFP_NOFS);
591}
592
David Howells025db802017-11-02 15:27:51 +0000593static const struct afs_call_type afs_RXFSMakeDir = {
594 .name = "FS.MakeDir",
595 .op = afs_FS_MakeDir,
David Howells260a9802007-04-26 15:59:35 -0700596 .deliver = afs_deliver_fs_create_vnode,
David Howells260a9802007-04-26 15:59:35 -0700597 .destructor = afs_flat_call_destructor,
598};
599
600/*
David Howellse49c7b22020-04-10 20:51:51 +0100601 * Create a new directory
David Howells260a9802007-04-26 15:59:35 -0700602 */
David Howellse49c7b22020-04-10 20:51:51 +0100603void afs_fs_make_dir(struct afs_operation *op)
David Howells260a9802007-04-26 15:59:35 -0700604{
David Howellse49c7b22020-04-10 20:51:51 +0100605 const struct qstr *name = &op->dentry->d_name;
606 struct afs_vnode_param *dvp = &op->file[0];
David Howells260a9802007-04-26 15:59:35 -0700607 struct afs_call *call;
608 size_t namesz, reqsz, padsz;
609 __be32 *bp;
610
611 _enter("");
612
David Howellse49c7b22020-04-10 20:51:51 +0100613 namesz = name->len;
David Howells260a9802007-04-26 15:59:35 -0700614 padsz = (4 - (namesz & 3)) & 3;
615 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
616
David Howellse49c7b22020-04-10 20:51:51 +0100617 call = afs_alloc_flat_call(op->net, &afs_RXFSMakeDir,
618 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700619 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100620 return afs_op_nomem(op);
David Howells260a9802007-04-26 15:59:35 -0700621
622 /* marshall the parameters */
623 bp = call->request;
David Howellse49c7b22020-04-10 20:51:51 +0100624 *bp++ = htonl(FSMAKEDIR);
625 *bp++ = htonl(dvp->fid.vid);
626 *bp++ = htonl(dvp->fid.vnode);
627 *bp++ = htonl(dvp->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700628 *bp++ = htonl(namesz);
David Howellse49c7b22020-04-10 20:51:51 +0100629 memcpy(bp, name->name, namesz);
David Howells260a9802007-04-26 15:59:35 -0700630 bp = (void *) bp + namesz;
631 if (padsz > 0) {
632 memset(bp, 0, padsz);
633 bp = (void *) bp + padsz;
634 }
Marc Dionneab94f5d2017-03-16 16:27:47 +0000635 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
David Howellse49c7b22020-04-10 20:51:51 +0100636 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
David Howells260a9802007-04-26 15:59:35 -0700637 *bp++ = 0; /* owner */
638 *bp++ = 0; /* group */
David Howellse49c7b22020-04-10 20:51:51 +0100639 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
David Howells260a9802007-04-26 15:59:35 -0700640 *bp++ = 0; /* segment size */
641
David Howellse49c7b22020-04-10 20:51:51 +0100642 trace_afs_make_fs_call1(call, &dvp->fid, name);
643 afs_make_op_call(op, call, GFP_NOFS);
David Howells260a9802007-04-26 15:59:35 -0700644}
645
646/*
David Howellse49c7b22020-04-10 20:51:51 +0100647 * Deliver reply data to any operation that returns status and volume sync.
David Howells260a9802007-04-26 15:59:35 -0700648 */
David Howellse49c7b22020-04-10 20:51:51 +0100649static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700650{
David Howellse49c7b22020-04-10 20:51:51 +0100651 struct afs_operation *op = call->op;
652 struct afs_vnode_param *vp = &op->file[0];
David Howells260a9802007-04-26 15:59:35 -0700653 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100654 int ret;
David Howells260a9802007-04-26 15:59:35 -0700655
David Howellsd0016482016-08-30 20:42:14 +0100656 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100657 if (ret < 0)
658 return ret;
David Howells260a9802007-04-26 15:59:35 -0700659
660 /* unmarshall the reply once we've received all of it */
661 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100662 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
663 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howells260a9802007-04-26 15:59:35 -0700664
665 _leave(" = 0 [done]");
666 return 0;
667}
668
669/*
David Howellse49c7b22020-04-10 20:51:51 +0100670 * FS.RemoveFile operation type
David Howells260a9802007-04-26 15:59:35 -0700671 */
David Howells025db802017-11-02 15:27:51 +0000672static const struct afs_call_type afs_RXFSRemoveFile = {
673 .name = "FS.RemoveFile",
674 .op = afs_FS_RemoveFile,
David Howellse49c7b22020-04-10 20:51:51 +0100675 .deliver = afs_deliver_fs_file_status_and_vol,
David Howells260a9802007-04-26 15:59:35 -0700676 .destructor = afs_flat_call_destructor,
677};
678
679/*
David Howellse49c7b22020-04-10 20:51:51 +0100680 * Remove a file.
David Howells260a9802007-04-26 15:59:35 -0700681 */
David Howellse49c7b22020-04-10 20:51:51 +0100682void afs_fs_remove_file(struct afs_operation *op)
David Howells260a9802007-04-26 15:59:35 -0700683{
David Howellse49c7b22020-04-10 20:51:51 +0100684 const struct qstr *name = &op->dentry->d_name;
685 struct afs_vnode_param *dvp = &op->file[0];
David Howells260a9802007-04-26 15:59:35 -0700686 struct afs_call *call;
687 size_t namesz, reqsz, padsz;
688 __be32 *bp;
689
690 _enter("");
691
David Howellse49c7b22020-04-10 20:51:51 +0100692 namesz = name->len;
David Howells260a9802007-04-26 15:59:35 -0700693 padsz = (4 - (namesz & 3)) & 3;
694 reqsz = (5 * 4) + namesz + padsz;
695
David Howellse49c7b22020-04-10 20:51:51 +0100696 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveFile,
697 reqsz, (21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700698 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100699 return afs_op_nomem(op);
David Howells260a9802007-04-26 15:59:35 -0700700
701 /* marshall the parameters */
702 bp = call->request;
David Howellse49c7b22020-04-10 20:51:51 +0100703 *bp++ = htonl(FSREMOVEFILE);
704 *bp++ = htonl(dvp->fid.vid);
705 *bp++ = htonl(dvp->fid.vnode);
706 *bp++ = htonl(dvp->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700707 *bp++ = htonl(namesz);
David Howellse49c7b22020-04-10 20:51:51 +0100708 memcpy(bp, name->name, namesz);
David Howells260a9802007-04-26 15:59:35 -0700709 bp = (void *) bp + namesz;
710 if (padsz > 0) {
711 memset(bp, 0, padsz);
712 bp = (void *) bp + padsz;
713 }
714
David Howellse49c7b22020-04-10 20:51:51 +0100715 trace_afs_make_fs_call1(call, &dvp->fid, name);
716 afs_make_op_call(op, call, GFP_NOFS);
717}
718
719static const struct afs_call_type afs_RXFSRemoveDir = {
720 .name = "FS.RemoveDir",
721 .op = afs_FS_RemoveDir,
722 .deliver = afs_deliver_fs_file_status_and_vol,
723 .destructor = afs_flat_call_destructor,
724};
725
726/*
727 * Remove a directory.
728 */
729void afs_fs_remove_dir(struct afs_operation *op)
730{
731 const struct qstr *name = &op->dentry->d_name;
732 struct afs_vnode_param *dvp = &op->file[0];
733 struct afs_call *call;
734 size_t namesz, reqsz, padsz;
735 __be32 *bp;
736
737 _enter("");
738
739 namesz = name->len;
740 padsz = (4 - (namesz & 3)) & 3;
741 reqsz = (5 * 4) + namesz + padsz;
742
743 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveDir,
744 reqsz, (21 + 6) * 4);
745 if (!call)
746 return afs_op_nomem(op);
747
748 /* marshall the parameters */
749 bp = call->request;
750 *bp++ = htonl(FSREMOVEDIR);
751 *bp++ = htonl(dvp->fid.vid);
752 *bp++ = htonl(dvp->fid.vnode);
753 *bp++ = htonl(dvp->fid.unique);
754 *bp++ = htonl(namesz);
755 memcpy(bp, name->name, namesz);
756 bp = (void *) bp + namesz;
757 if (padsz > 0) {
758 memset(bp, 0, padsz);
759 bp = (void *) bp + padsz;
760 }
761
762 trace_afs_make_fs_call1(call, &dvp->fid, name);
763 afs_make_op_call(op, call, GFP_NOFS);
David Howells260a9802007-04-26 15:59:35 -0700764}
765
766/*
767 * deliver reply data to an FS.Link
768 */
David Howellsd0016482016-08-30 20:42:14 +0100769static int afs_deliver_fs_link(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700770{
David Howellse49c7b22020-04-10 20:51:51 +0100771 struct afs_operation *op = call->op;
772 struct afs_vnode_param *dvp = &op->file[0];
773 struct afs_vnode_param *vp = &op->file[1];
David Howells260a9802007-04-26 15:59:35 -0700774 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100775 int ret;
David Howells260a9802007-04-26 15:59:35 -0700776
David Howellsd0016482016-08-30 20:42:14 +0100777 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700778
David Howellsd0016482016-08-30 20:42:14 +0100779 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100780 if (ret < 0)
781 return ret;
David Howells260a9802007-04-26 15:59:35 -0700782
783 /* unmarshall the reply once we've received all of it */
784 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100785 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
786 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
787 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howells260a9802007-04-26 15:59:35 -0700788
789 _leave(" = 0 [done]");
790 return 0;
791}
792
793/*
794 * FS.Link operation type
795 */
796static const struct afs_call_type afs_RXFSLink = {
797 .name = "FS.Link",
David Howells025db802017-11-02 15:27:51 +0000798 .op = afs_FS_Link,
David Howells260a9802007-04-26 15:59:35 -0700799 .deliver = afs_deliver_fs_link,
David Howells260a9802007-04-26 15:59:35 -0700800 .destructor = afs_flat_call_destructor,
801};
802
803/*
804 * make a hard link
805 */
David Howellse49c7b22020-04-10 20:51:51 +0100806void afs_fs_link(struct afs_operation *op)
David Howells260a9802007-04-26 15:59:35 -0700807{
David Howellse49c7b22020-04-10 20:51:51 +0100808 const struct qstr *name = &op->dentry->d_name;
809 struct afs_vnode_param *dvp = &op->file[0];
810 struct afs_vnode_param *vp = &op->file[1];
David Howells260a9802007-04-26 15:59:35 -0700811 struct afs_call *call;
812 size_t namesz, reqsz, padsz;
813 __be32 *bp;
814
815 _enter("");
816
David Howellse49c7b22020-04-10 20:51:51 +0100817 namesz = name->len;
David Howells260a9802007-04-26 15:59:35 -0700818 padsz = (4 - (namesz & 3)) & 3;
819 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
820
David Howellse49c7b22020-04-10 20:51:51 +0100821 call = afs_alloc_flat_call(op->net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700822 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100823 return afs_op_nomem(op);
David Howells260a9802007-04-26 15:59:35 -0700824
825 /* marshall the parameters */
826 bp = call->request;
827 *bp++ = htonl(FSLINK);
David Howellse49c7b22020-04-10 20:51:51 +0100828 *bp++ = htonl(dvp->fid.vid);
829 *bp++ = htonl(dvp->fid.vnode);
830 *bp++ = htonl(dvp->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700831 *bp++ = htonl(namesz);
David Howellse49c7b22020-04-10 20:51:51 +0100832 memcpy(bp, name->name, namesz);
David Howells260a9802007-04-26 15:59:35 -0700833 bp = (void *) bp + namesz;
834 if (padsz > 0) {
835 memset(bp, 0, padsz);
836 bp = (void *) bp + padsz;
837 }
David Howellse49c7b22020-04-10 20:51:51 +0100838 *bp++ = htonl(vp->fid.vid);
839 *bp++ = htonl(vp->fid.vnode);
840 *bp++ = htonl(vp->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700841
David Howellse49c7b22020-04-10 20:51:51 +0100842 trace_afs_make_fs_call1(call, &vp->fid, name);
843 afs_make_op_call(op, call, GFP_NOFS);
David Howells260a9802007-04-26 15:59:35 -0700844}
845
846/*
847 * deliver reply data to an FS.Symlink
848 */
David Howellsd0016482016-08-30 20:42:14 +0100849static int afs_deliver_fs_symlink(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700850{
David Howellse49c7b22020-04-10 20:51:51 +0100851 struct afs_operation *op = call->op;
852 struct afs_vnode_param *dvp = &op->file[0];
853 struct afs_vnode_param *vp = &op->file[1];
David Howells260a9802007-04-26 15:59:35 -0700854 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100855 int ret;
David Howells260a9802007-04-26 15:59:35 -0700856
David Howellsd0016482016-08-30 20:42:14 +0100857 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700858
David Howellsd0016482016-08-30 20:42:14 +0100859 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100860 if (ret < 0)
861 return ret;
David Howells260a9802007-04-26 15:59:35 -0700862
863 /* unmarshall the reply once we've received all of it */
864 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100865 xdr_decode_AFSFid(&bp, &vp->fid);
866 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
867 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
868 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howells260a9802007-04-26 15:59:35 -0700869
870 _leave(" = 0 [done]");
871 return 0;
872}
873
874/*
875 * FS.Symlink operation type
876 */
877static const struct afs_call_type afs_RXFSSymlink = {
878 .name = "FS.Symlink",
David Howells025db802017-11-02 15:27:51 +0000879 .op = afs_FS_Symlink,
David Howells260a9802007-04-26 15:59:35 -0700880 .deliver = afs_deliver_fs_symlink,
David Howells260a9802007-04-26 15:59:35 -0700881 .destructor = afs_flat_call_destructor,
882};
883
884/*
885 * create a symbolic link
886 */
David Howellse49c7b22020-04-10 20:51:51 +0100887void afs_fs_symlink(struct afs_operation *op)
David Howells260a9802007-04-26 15:59:35 -0700888{
David Howellse49c7b22020-04-10 20:51:51 +0100889 const struct qstr *name = &op->dentry->d_name;
890 struct afs_vnode_param *dvp = &op->file[0];
David Howells260a9802007-04-26 15:59:35 -0700891 struct afs_call *call;
892 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
893 __be32 *bp;
894
895 _enter("");
896
David Howellse49c7b22020-04-10 20:51:51 +0100897 namesz = name->len;
David Howells260a9802007-04-26 15:59:35 -0700898 padsz = (4 - (namesz & 3)) & 3;
899
David Howellse49c7b22020-04-10 20:51:51 +0100900 c_namesz = strlen(op->create.symlink);
David Howells260a9802007-04-26 15:59:35 -0700901 c_padsz = (4 - (c_namesz & 3)) & 3;
902
903 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
904
David Howellse49c7b22020-04-10 20:51:51 +0100905 call = afs_alloc_flat_call(op->net, &afs_RXFSSymlink, reqsz,
David Howells260a9802007-04-26 15:59:35 -0700906 (3 + 21 + 21 + 6) * 4);
907 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100908 return afs_op_nomem(op);
David Howells260a9802007-04-26 15:59:35 -0700909
910 /* marshall the parameters */
911 bp = call->request;
912 *bp++ = htonl(FSSYMLINK);
David Howellse49c7b22020-04-10 20:51:51 +0100913 *bp++ = htonl(dvp->fid.vid);
914 *bp++ = htonl(dvp->fid.vnode);
915 *bp++ = htonl(dvp->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700916 *bp++ = htonl(namesz);
David Howellse49c7b22020-04-10 20:51:51 +0100917 memcpy(bp, name->name, namesz);
David Howells260a9802007-04-26 15:59:35 -0700918 bp = (void *) bp + namesz;
919 if (padsz > 0) {
920 memset(bp, 0, padsz);
921 bp = (void *) bp + padsz;
922 }
923 *bp++ = htonl(c_namesz);
David Howellse49c7b22020-04-10 20:51:51 +0100924 memcpy(bp, op->create.symlink, c_namesz);
David Howells260a9802007-04-26 15:59:35 -0700925 bp = (void *) bp + c_namesz;
926 if (c_padsz > 0) {
927 memset(bp, 0, c_padsz);
928 bp = (void *) bp + c_padsz;
929 }
Marc Dionneab94f5d2017-03-16 16:27:47 +0000930 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
David Howellse49c7b22020-04-10 20:51:51 +0100931 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
David Howells260a9802007-04-26 15:59:35 -0700932 *bp++ = 0; /* owner */
933 *bp++ = 0; /* group */
934 *bp++ = htonl(S_IRWXUGO); /* unix mode */
935 *bp++ = 0; /* segment size */
936
David Howellse49c7b22020-04-10 20:51:51 +0100937 trace_afs_make_fs_call1(call, &dvp->fid, name);
938 afs_make_op_call(op, call, GFP_NOFS);
David Howells260a9802007-04-26 15:59:35 -0700939}
940
941/*
942 * deliver reply data to an FS.Rename
943 */
David Howellsd0016482016-08-30 20:42:14 +0100944static int afs_deliver_fs_rename(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700945{
David Howellse49c7b22020-04-10 20:51:51 +0100946 struct afs_operation *op = call->op;
947 struct afs_vnode_param *orig_dvp = &op->file[0];
948 struct afs_vnode_param *new_dvp = &op->file[1];
David Howells260a9802007-04-26 15:59:35 -0700949 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100950 int ret;
David Howells260a9802007-04-26 15:59:35 -0700951
David Howellsd0016482016-08-30 20:42:14 +0100952 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100953 if (ret < 0)
954 return ret;
David Howells260a9802007-04-26 15:59:35 -0700955
David Howells38355ee2020-04-08 16:13:20 +0100956 bp = call->buffer;
David Howellsb98f0ec2020-04-08 20:56:20 +0100957 /* If the two dirs are the same, we have two copies of the same status
958 * report, so we just decode it twice.
959 */
David Howellse49c7b22020-04-10 20:51:51 +0100960 xdr_decode_AFSFetchStatus(&bp, call, &orig_dvp->scb);
961 xdr_decode_AFSFetchStatus(&bp, call, &new_dvp->scb);
962 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howells260a9802007-04-26 15:59:35 -0700963
964 _leave(" = 0 [done]");
965 return 0;
966}
967
968/*
969 * FS.Rename operation type
970 */
971static const struct afs_call_type afs_RXFSRename = {
972 .name = "FS.Rename",
David Howells025db802017-11-02 15:27:51 +0000973 .op = afs_FS_Rename,
David Howells260a9802007-04-26 15:59:35 -0700974 .deliver = afs_deliver_fs_rename,
David Howells260a9802007-04-26 15:59:35 -0700975 .destructor = afs_flat_call_destructor,
976};
977
978/*
David Howellsa58823a2019-05-09 15:16:10 +0100979 * Rename/move a file or directory.
David Howells260a9802007-04-26 15:59:35 -0700980 */
David Howellse49c7b22020-04-10 20:51:51 +0100981void afs_fs_rename(struct afs_operation *op)
David Howells260a9802007-04-26 15:59:35 -0700982{
David Howellse49c7b22020-04-10 20:51:51 +0100983 struct afs_vnode_param *orig_dvp = &op->file[0];
984 struct afs_vnode_param *new_dvp = &op->file[1];
985 const struct qstr *orig_name = &op->dentry->d_name;
986 const struct qstr *new_name = &op->dentry_2->d_name;
David Howells260a9802007-04-26 15:59:35 -0700987 struct afs_call *call;
988 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
989 __be32 *bp;
990
991 _enter("");
992
David Howellse49c7b22020-04-10 20:51:51 +0100993 o_namesz = orig_name->len;
David Howells260a9802007-04-26 15:59:35 -0700994 o_padsz = (4 - (o_namesz & 3)) & 3;
995
David Howellse49c7b22020-04-10 20:51:51 +0100996 n_namesz = new_name->len;
David Howells260a9802007-04-26 15:59:35 -0700997 n_padsz = (4 - (n_namesz & 3)) & 3;
998
999 reqsz = (4 * 4) +
1000 4 + o_namesz + o_padsz +
1001 (3 * 4) +
1002 4 + n_namesz + n_padsz;
1003
David Howellse49c7b22020-04-10 20:51:51 +01001004 call = afs_alloc_flat_call(op->net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -07001005 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001006 return afs_op_nomem(op);
David Howells260a9802007-04-26 15:59:35 -07001007
1008 /* marshall the parameters */
1009 bp = call->request;
1010 *bp++ = htonl(FSRENAME);
David Howellse49c7b22020-04-10 20:51:51 +01001011 *bp++ = htonl(orig_dvp->fid.vid);
1012 *bp++ = htonl(orig_dvp->fid.vnode);
1013 *bp++ = htonl(orig_dvp->fid.unique);
David Howells260a9802007-04-26 15:59:35 -07001014 *bp++ = htonl(o_namesz);
David Howellse49c7b22020-04-10 20:51:51 +01001015 memcpy(bp, orig_name->name, o_namesz);
David Howells260a9802007-04-26 15:59:35 -07001016 bp = (void *) bp + o_namesz;
1017 if (o_padsz > 0) {
1018 memset(bp, 0, o_padsz);
1019 bp = (void *) bp + o_padsz;
1020 }
1021
David Howellse49c7b22020-04-10 20:51:51 +01001022 *bp++ = htonl(new_dvp->fid.vid);
1023 *bp++ = htonl(new_dvp->fid.vnode);
1024 *bp++ = htonl(new_dvp->fid.unique);
David Howells260a9802007-04-26 15:59:35 -07001025 *bp++ = htonl(n_namesz);
David Howellse49c7b22020-04-10 20:51:51 +01001026 memcpy(bp, new_name->name, n_namesz);
David Howells260a9802007-04-26 15:59:35 -07001027 bp = (void *) bp + n_namesz;
1028 if (n_padsz > 0) {
1029 memset(bp, 0, n_padsz);
1030 bp = (void *) bp + n_padsz;
1031 }
1032
David Howellse49c7b22020-04-10 20:51:51 +01001033 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1034 afs_make_op_call(op, call, GFP_NOFS);
David Howells260a9802007-04-26 15:59:35 -07001035}
David Howells31143d52007-05-09 02:33:46 -07001036
1037/*
David Howellse49c7b22020-04-10 20:51:51 +01001038 * Deliver reply data to FS.StoreData or FS.StoreStatus
David Howells31143d52007-05-09 02:33:46 -07001039 */
David Howellsd0016482016-08-30 20:42:14 +01001040static int afs_deliver_fs_store_data(struct afs_call *call)
David Howells31143d52007-05-09 02:33:46 -07001041{
David Howellse49c7b22020-04-10 20:51:51 +01001042 struct afs_operation *op = call->op;
1043 struct afs_vnode_param *vp = &op->file[0];
David Howells31143d52007-05-09 02:33:46 -07001044 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001045 int ret;
David Howells31143d52007-05-09 02:33:46 -07001046
David Howellsd0016482016-08-30 20:42:14 +01001047 _enter("");
David Howells31143d52007-05-09 02:33:46 -07001048
David Howellsd0016482016-08-30 20:42:14 +01001049 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001050 if (ret < 0)
1051 return ret;
David Howells31143d52007-05-09 02:33:46 -07001052
1053 /* unmarshall the reply once we've received all of it */
1054 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +01001055 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
1056 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howells31143d52007-05-09 02:33:46 -07001057
David Howells31143d52007-05-09 02:33:46 -07001058 _leave(" = 0 [done]");
1059 return 0;
1060}
1061
1062/*
1063 * FS.StoreData operation type
1064 */
1065static const struct afs_call_type afs_RXFSStoreData = {
1066 .name = "FS.StoreData",
David Howells025db802017-11-02 15:27:51 +00001067 .op = afs_FS_StoreData,
David Howells31143d52007-05-09 02:33:46 -07001068 .deliver = afs_deliver_fs_store_data,
David Howells31143d52007-05-09 02:33:46 -07001069 .destructor = afs_flat_call_destructor,
1070};
1071
David Howellsb9b1f8d2007-05-10 03:15:21 -07001072static const struct afs_call_type afs_RXFSStoreData64 = {
1073 .name = "FS.StoreData64",
David Howells025db802017-11-02 15:27:51 +00001074 .op = afs_FS_StoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001075 .deliver = afs_deliver_fs_store_data,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001076 .destructor = afs_flat_call_destructor,
1077};
1078
1079/*
1080 * store a set of pages to a very large file
1081 */
David Howellse49c7b22020-04-10 20:51:51 +01001082static void afs_fs_store_data64(struct afs_operation *op,
1083 loff_t pos, loff_t size, loff_t i_size)
David Howellsb9b1f8d2007-05-10 03:15:21 -07001084{
David Howellse49c7b22020-04-10 20:51:51 +01001085 struct afs_vnode_param *vp = &op->file[0];
David Howellsb9b1f8d2007-05-10 03:15:21 -07001086 struct afs_call *call;
1087 __be32 *bp;
1088
David Howells3b6492d2018-10-20 00:57:57 +01001089 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001090 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001091
David Howellse49c7b22020-04-10 20:51:51 +01001092 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001093 (4 + 6 + 3 * 2) * 4,
1094 (21 + 6) * 4);
1095 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001096 return afs_op_nomem(op);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001097
David Howellsb9b1f8d2007-05-10 03:15:21 -07001098 call->send_pages = true;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001099
1100 /* marshall the parameters */
1101 bp = call->request;
1102 *bp++ = htonl(FSSTOREDATA64);
David Howellse49c7b22020-04-10 20:51:51 +01001103 *bp++ = htonl(vp->fid.vid);
1104 *bp++ = htonl(vp->fid.vnode);
1105 *bp++ = htonl(vp->fid.unique);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001106
Marc Dionneab94f5d2017-03-16 16:27:47 +00001107 *bp++ = htonl(AFS_SET_MTIME); /* mask */
David Howellse49c7b22020-04-10 20:51:51 +01001108 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
David Howellsb9b1f8d2007-05-10 03:15:21 -07001109 *bp++ = 0; /* owner */
1110 *bp++ = 0; /* group */
1111 *bp++ = 0; /* unix mode */
1112 *bp++ = 0; /* segment size */
1113
David Howellse49c7b22020-04-10 20:51:51 +01001114 *bp++ = htonl(upper_32_bits(pos));
1115 *bp++ = htonl(lower_32_bits(pos));
1116 *bp++ = htonl(upper_32_bits(size));
1117 *bp++ = htonl(lower_32_bits(size));
1118 *bp++ = htonl(upper_32_bits(i_size));
1119 *bp++ = htonl(lower_32_bits(i_size));
David Howellsb9b1f8d2007-05-10 03:15:21 -07001120
David Howellse49c7b22020-04-10 20:51:51 +01001121 trace_afs_make_fs_call(call, &vp->fid);
1122 afs_make_op_call(op, call, GFP_NOFS);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001123}
1124
David Howells31143d52007-05-09 02:33:46 -07001125/*
1126 * store a set of pages
1127 */
David Howellse49c7b22020-04-10 20:51:51 +01001128void afs_fs_store_data(struct afs_operation *op)
David Howells31143d52007-05-09 02:33:46 -07001129{
David Howellse49c7b22020-04-10 20:51:51 +01001130 struct afs_vnode_param *vp = &op->file[0];
David Howells31143d52007-05-09 02:33:46 -07001131 struct afs_call *call;
1132 loff_t size, pos, i_size;
1133 __be32 *bp;
1134
David Howells3b6492d2018-10-20 00:57:57 +01001135 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001136 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001137
David Howellse49c7b22020-04-10 20:51:51 +01001138 size = (loff_t)op->store.last_to - (loff_t)op->store.first_offset;
1139 if (op->store.first != op->store.last)
1140 size += (loff_t)(op->store.last - op->store.first) << PAGE_SHIFT;
1141 pos = (loff_t)op->store.first << PAGE_SHIFT;
1142 pos += op->store.first_offset;
David Howells31143d52007-05-09 02:33:46 -07001143
David Howellse49c7b22020-04-10 20:51:51 +01001144 i_size = i_size_read(&vp->vnode->vfs_inode);
David Howells31143d52007-05-09 02:33:46 -07001145 if (pos + size > i_size)
1146 i_size = size + pos;
1147
1148 _debug("size %llx, at %llx, i_size %llx",
1149 (unsigned long long) size, (unsigned long long) pos,
1150 (unsigned long long) i_size);
1151
David Howellse49c7b22020-04-10 20:51:51 +01001152 if (upper_32_bits(pos) || upper_32_bits(i_size) || upper_32_bits(size) ||
1153 upper_32_bits(pos + size))
1154 return afs_fs_store_data64(op, pos, size, i_size);
David Howells31143d52007-05-09 02:33:46 -07001155
David Howellse49c7b22020-04-10 20:51:51 +01001156 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData,
David Howells31143d52007-05-09 02:33:46 -07001157 (4 + 6 + 3) * 4,
1158 (21 + 6) * 4);
1159 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001160 return afs_op_nomem(op);
David Howells31143d52007-05-09 02:33:46 -07001161
David Howells31143d52007-05-09 02:33:46 -07001162 call->send_pages = true;
David Howells31143d52007-05-09 02:33:46 -07001163
1164 /* marshall the parameters */
1165 bp = call->request;
1166 *bp++ = htonl(FSSTOREDATA);
David Howellse49c7b22020-04-10 20:51:51 +01001167 *bp++ = htonl(vp->fid.vid);
1168 *bp++ = htonl(vp->fid.vnode);
1169 *bp++ = htonl(vp->fid.unique);
David Howells31143d52007-05-09 02:33:46 -07001170
Marc Dionneab94f5d2017-03-16 16:27:47 +00001171 *bp++ = htonl(AFS_SET_MTIME); /* mask */
David Howellse49c7b22020-04-10 20:51:51 +01001172 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
David Howells31143d52007-05-09 02:33:46 -07001173 *bp++ = 0; /* owner */
1174 *bp++ = 0; /* group */
1175 *bp++ = 0; /* unix mode */
1176 *bp++ = 0; /* segment size */
1177
David Howellse49c7b22020-04-10 20:51:51 +01001178 *bp++ = htonl(lower_32_bits(pos));
1179 *bp++ = htonl(lower_32_bits(size));
1180 *bp++ = htonl(lower_32_bits(i_size));
David Howells31143d52007-05-09 02:33:46 -07001181
David Howellse49c7b22020-04-10 20:51:51 +01001182 trace_afs_make_fs_call(call, &vp->fid);
1183 afs_make_op_call(op, call, GFP_NOFS);
David Howells31143d52007-05-09 02:33:46 -07001184}
1185
1186/*
1187 * FS.StoreStatus operation type
1188 */
1189static const struct afs_call_type afs_RXFSStoreStatus = {
1190 .name = "FS.StoreStatus",
David Howells025db802017-11-02 15:27:51 +00001191 .op = afs_FS_StoreStatus,
David Howellse49c7b22020-04-10 20:51:51 +01001192 .deliver = afs_deliver_fs_store_data,
David Howells31143d52007-05-09 02:33:46 -07001193 .destructor = afs_flat_call_destructor,
1194};
1195
1196static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1197 .name = "FS.StoreData",
David Howells025db802017-11-02 15:27:51 +00001198 .op = afs_FS_StoreData,
David Howellse49c7b22020-04-10 20:51:51 +01001199 .deliver = afs_deliver_fs_store_data,
David Howells31143d52007-05-09 02:33:46 -07001200 .destructor = afs_flat_call_destructor,
1201};
1202
David Howellsb9b1f8d2007-05-10 03:15:21 -07001203static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1204 .name = "FS.StoreData64",
David Howells025db802017-11-02 15:27:51 +00001205 .op = afs_FS_StoreData64,
David Howellse49c7b22020-04-10 20:51:51 +01001206 .deliver = afs_deliver_fs_store_data,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001207 .destructor = afs_flat_call_destructor,
1208};
1209
1210/*
1211 * set the attributes on a very large file, using FS.StoreData rather than
1212 * FS.StoreStatus so as to alter the file size also
1213 */
David Howellse49c7b22020-04-10 20:51:51 +01001214static void afs_fs_setattr_size64(struct afs_operation *op)
David Howellsb9b1f8d2007-05-10 03:15:21 -07001215{
David Howellse49c7b22020-04-10 20:51:51 +01001216 struct afs_vnode_param *vp = &op->file[0];
David Howellsb9b1f8d2007-05-10 03:15:21 -07001217 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +01001218 struct iattr *attr = op->setattr.attr;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001219 __be32 *bp;
1220
David Howells3b6492d2018-10-20 00:57:57 +01001221 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001222 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001223
1224 ASSERT(attr->ia_valid & ATTR_SIZE);
1225
David Howellse49c7b22020-04-10 20:51:51 +01001226 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64_as_Status,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001227 (4 + 6 + 3 * 2) * 4,
1228 (21 + 6) * 4);
1229 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001230 return afs_op_nomem(op);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001231
1232 /* marshall the parameters */
1233 bp = call->request;
1234 *bp++ = htonl(FSSTOREDATA64);
David Howellse49c7b22020-04-10 20:51:51 +01001235 *bp++ = htonl(vp->fid.vid);
1236 *bp++ = htonl(vp->fid.vnode);
1237 *bp++ = htonl(vp->fid.unique);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001238
1239 xdr_encode_AFS_StoreStatus(&bp, attr);
1240
David Howellse49c7b22020-04-10 20:51:51 +01001241 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* position of start of write */
1242 *bp++ = htonl(lower_32_bits(attr->ia_size));
1243 *bp++ = 0; /* size of write */
David Howellsb9b1f8d2007-05-10 03:15:21 -07001244 *bp++ = 0;
David Howellse49c7b22020-04-10 20:51:51 +01001245 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* new file length */
1246 *bp++ = htonl(lower_32_bits(attr->ia_size));
David Howellsb9b1f8d2007-05-10 03:15:21 -07001247
David Howellse49c7b22020-04-10 20:51:51 +01001248 trace_afs_make_fs_call(call, &vp->fid);
1249 afs_make_op_call(op, call, GFP_NOFS);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001250}
1251
David Howells31143d52007-05-09 02:33:46 -07001252/*
1253 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1254 * so as to alter the file size also
1255 */
David Howellse49c7b22020-04-10 20:51:51 +01001256static void afs_fs_setattr_size(struct afs_operation *op)
David Howells31143d52007-05-09 02:33:46 -07001257{
David Howellse49c7b22020-04-10 20:51:51 +01001258 struct afs_vnode_param *vp = &op->file[0];
David Howells31143d52007-05-09 02:33:46 -07001259 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +01001260 struct iattr *attr = op->setattr.attr;
David Howells31143d52007-05-09 02:33:46 -07001261 __be32 *bp;
1262
David Howells3b6492d2018-10-20 00:57:57 +01001263 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001264 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001265
1266 ASSERT(attr->ia_valid & ATTR_SIZE);
David Howellse49c7b22020-04-10 20:51:51 +01001267 if (upper_32_bits(attr->ia_size))
1268 return afs_fs_setattr_size64(op);
David Howells31143d52007-05-09 02:33:46 -07001269
David Howellse49c7b22020-04-10 20:51:51 +01001270 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData_as_Status,
David Howells31143d52007-05-09 02:33:46 -07001271 (4 + 6 + 3) * 4,
1272 (21 + 6) * 4);
1273 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001274 return afs_op_nomem(op);
David Howells31143d52007-05-09 02:33:46 -07001275
1276 /* marshall the parameters */
1277 bp = call->request;
1278 *bp++ = htonl(FSSTOREDATA);
David Howellse49c7b22020-04-10 20:51:51 +01001279 *bp++ = htonl(vp->fid.vid);
1280 *bp++ = htonl(vp->fid.vnode);
1281 *bp++ = htonl(vp->fid.unique);
David Howells31143d52007-05-09 02:33:46 -07001282
1283 xdr_encode_AFS_StoreStatus(&bp, attr);
1284
David Howells8c7ae382019-03-27 22:48:02 +00001285 *bp++ = htonl(attr->ia_size); /* position of start of write */
David Howells31143d52007-05-09 02:33:46 -07001286 *bp++ = 0; /* size of write */
1287 *bp++ = htonl(attr->ia_size); /* new file length */
1288
David Howellse49c7b22020-04-10 20:51:51 +01001289 trace_afs_make_fs_call(call, &vp->fid);
1290 afs_make_op_call(op, call, GFP_NOFS);
David Howells31143d52007-05-09 02:33:46 -07001291}
1292
1293/*
1294 * set the attributes on a file, using FS.StoreData if there's a change in file
1295 * size, and FS.StoreStatus otherwise
1296 */
David Howellse49c7b22020-04-10 20:51:51 +01001297void afs_fs_setattr(struct afs_operation *op)
David Howells31143d52007-05-09 02:33:46 -07001298{
David Howellse49c7b22020-04-10 20:51:51 +01001299 struct afs_vnode_param *vp = &op->file[0];
David Howells31143d52007-05-09 02:33:46 -07001300 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +01001301 struct iattr *attr = op->setattr.attr;
David Howells31143d52007-05-09 02:33:46 -07001302 __be32 *bp;
1303
1304 if (attr->ia_valid & ATTR_SIZE)
David Howellse49c7b22020-04-10 20:51:51 +01001305 return afs_fs_setattr_size(op);
David Howells31143d52007-05-09 02:33:46 -07001306
David Howells3b6492d2018-10-20 00:57:57 +01001307 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001308 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001309
David Howellse49c7b22020-04-10 20:51:51 +01001310 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreStatus,
David Howells31143d52007-05-09 02:33:46 -07001311 (4 + 6) * 4,
1312 (21 + 6) * 4);
1313 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001314 return afs_op_nomem(op);
David Howells31143d52007-05-09 02:33:46 -07001315
1316 /* marshall the parameters */
1317 bp = call->request;
1318 *bp++ = htonl(FSSTORESTATUS);
David Howellse49c7b22020-04-10 20:51:51 +01001319 *bp++ = htonl(vp->fid.vid);
1320 *bp++ = htonl(vp->fid.vnode);
1321 *bp++ = htonl(vp->fid.unique);
David Howells31143d52007-05-09 02:33:46 -07001322
David Howellse49c7b22020-04-10 20:51:51 +01001323 xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr);
David Howells31143d52007-05-09 02:33:46 -07001324
David Howellse49c7b22020-04-10 20:51:51 +01001325 trace_afs_make_fs_call(call, &vp->fid);
1326 afs_make_op_call(op, call, GFP_NOFS);
David Howells31143d52007-05-09 02:33:46 -07001327}
David Howells45222b92007-05-10 22:22:20 -07001328
1329/*
1330 * deliver reply data to an FS.GetVolumeStatus
1331 */
David Howellsd0016482016-08-30 20:42:14 +01001332static int afs_deliver_fs_get_volume_status(struct afs_call *call)
David Howells45222b92007-05-10 22:22:20 -07001333{
David Howellse49c7b22020-04-10 20:51:51 +01001334 struct afs_operation *op = call->op;
David Howells45222b92007-05-10 22:22:20 -07001335 const __be32 *bp;
1336 char *p;
David Howells12bdcf32018-10-20 00:57:56 +01001337 u32 size;
David Howells45222b92007-05-10 22:22:20 -07001338 int ret;
1339
David Howellsd0016482016-08-30 20:42:14 +01001340 _enter("{%u}", call->unmarshall);
David Howells45222b92007-05-10 22:22:20 -07001341
1342 switch (call->unmarshall) {
1343 case 0:
David Howells45222b92007-05-10 22:22:20 -07001344 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01001345 afs_extract_to_buf(call, 12 * 4);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001346 fallthrough;
David Howells45222b92007-05-10 22:22:20 -07001347
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001348 /* extract the returned status record */
David Howells45222b92007-05-10 22:22:20 -07001349 case 1:
1350 _debug("extract status");
David Howells12bdcf32018-10-20 00:57:56 +01001351 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001352 if (ret < 0)
1353 return ret;
David Howells45222b92007-05-10 22:22:20 -07001354
1355 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +01001356 xdr_decode_AFSFetchVolumeStatus(&bp, &op->volstatus.vs);
David Howells45222b92007-05-10 22:22:20 -07001357 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01001358 afs_extract_to_tmp(call);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001359 fallthrough;
David Howells45222b92007-05-10 22:22:20 -07001360
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001361 /* extract the volume name length */
David Howells45222b92007-05-10 22:22:20 -07001362 case 2:
David Howells12bdcf32018-10-20 00:57:56 +01001363 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001364 if (ret < 0)
1365 return ret;
David Howells45222b92007-05-10 22:22:20 -07001366
1367 call->count = ntohl(call->tmp);
1368 _debug("volname length: %u", call->count);
1369 if (call->count >= AFSNAMEMAX)
David Howells7126ead2020-04-08 16:49:08 +01001370 return afs_protocol_error(call, afs_eproto_volname_len);
David Howells12bdcf32018-10-20 00:57:56 +01001371 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001372 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001373 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001374 fallthrough;
David Howells45222b92007-05-10 22:22:20 -07001375
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001376 /* extract the volume name */
David Howells45222b92007-05-10 22:22:20 -07001377 case 3:
1378 _debug("extract volname");
David Howells12bdcf32018-10-20 00:57:56 +01001379 ret = afs_extract_data(call, true);
1380 if (ret < 0)
1381 return ret;
David Howells45222b92007-05-10 22:22:20 -07001382
David Howellsffba7182019-05-09 22:22:50 +01001383 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001384 p[call->count] = 0;
1385 _debug("volname '%s'", p);
David Howells12bdcf32018-10-20 00:57:56 +01001386 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001387 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001388 fallthrough;
David Howells45222b92007-05-10 22:22:20 -07001389
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001390 /* extract the offline message length */
David Howells12bdcf32018-10-20 00:57:56 +01001391 case 4:
1392 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001393 if (ret < 0)
1394 return ret;
David Howells45222b92007-05-10 22:22:20 -07001395
1396 call->count = ntohl(call->tmp);
1397 _debug("offline msg length: %u", call->count);
1398 if (call->count >= AFSNAMEMAX)
David Howells7126ead2020-04-08 16:49:08 +01001399 return afs_protocol_error(call, afs_eproto_offline_msg_len);
David Howells12bdcf32018-10-20 00:57:56 +01001400 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001401 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001402 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001403 fallthrough;
David Howells45222b92007-05-10 22:22:20 -07001404
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001405 /* extract the offline message */
David Howells12bdcf32018-10-20 00:57:56 +01001406 case 5:
David Howells45222b92007-05-10 22:22:20 -07001407 _debug("extract offline");
David Howells12bdcf32018-10-20 00:57:56 +01001408 ret = afs_extract_data(call, true);
1409 if (ret < 0)
1410 return ret;
David Howells45222b92007-05-10 22:22:20 -07001411
David Howellsffba7182019-05-09 22:22:50 +01001412 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001413 p[call->count] = 0;
1414 _debug("offline '%s'", p);
1415
David Howells12bdcf32018-10-20 00:57:56 +01001416 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001417 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001418 fallthrough;
David Howells45222b92007-05-10 22:22:20 -07001419
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001420 /* extract the message of the day length */
David Howells12bdcf32018-10-20 00:57:56 +01001421 case 6:
1422 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001423 if (ret < 0)
1424 return ret;
David Howells45222b92007-05-10 22:22:20 -07001425
1426 call->count = ntohl(call->tmp);
1427 _debug("motd length: %u", call->count);
1428 if (call->count >= AFSNAMEMAX)
David Howells7126ead2020-04-08 16:49:08 +01001429 return afs_protocol_error(call, afs_eproto_motd_len);
David Howells12bdcf32018-10-20 00:57:56 +01001430 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001431 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001432 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001433 fallthrough;
David Howells45222b92007-05-10 22:22:20 -07001434
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001435 /* extract the message of the day */
David Howells12bdcf32018-10-20 00:57:56 +01001436 case 7:
David Howells45222b92007-05-10 22:22:20 -07001437 _debug("extract motd");
David Howells12bdcf32018-10-20 00:57:56 +01001438 ret = afs_extract_data(call, false);
1439 if (ret < 0)
1440 return ret;
David Howells45222b92007-05-10 22:22:20 -07001441
David Howellsffba7182019-05-09 22:22:50 +01001442 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001443 p[call->count] = 0;
1444 _debug("motd '%s'", p);
1445
David Howells45222b92007-05-10 22:22:20 -07001446 call->unmarshall++;
1447
David Howells12bdcf32018-10-20 00:57:56 +01001448 case 8:
David Howells45222b92007-05-10 22:22:20 -07001449 break;
1450 }
1451
David Howells45222b92007-05-10 22:22:20 -07001452 _leave(" = 0 [done]");
1453 return 0;
1454}
1455
1456/*
David Howells45222b92007-05-10 22:22:20 -07001457 * FS.GetVolumeStatus operation type
1458 */
1459static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1460 .name = "FS.GetVolumeStatus",
David Howells025db802017-11-02 15:27:51 +00001461 .op = afs_FS_GetVolumeStatus,
David Howells45222b92007-05-10 22:22:20 -07001462 .deliver = afs_deliver_fs_get_volume_status,
David Howellsffba7182019-05-09 22:22:50 +01001463 .destructor = afs_flat_call_destructor,
David Howells45222b92007-05-10 22:22:20 -07001464};
1465
1466/*
1467 * fetch the status of a volume
1468 */
David Howellse49c7b22020-04-10 20:51:51 +01001469void afs_fs_get_volume_status(struct afs_operation *op)
David Howells45222b92007-05-10 22:22:20 -07001470{
David Howellse49c7b22020-04-10 20:51:51 +01001471 struct afs_vnode_param *vp = &op->file[0];
David Howells45222b92007-05-10 22:22:20 -07001472 struct afs_call *call;
1473 __be32 *bp;
David Howells45222b92007-05-10 22:22:20 -07001474
1475 _enter("");
1476
David Howellse49c7b22020-04-10 20:51:51 +01001477 call = afs_alloc_flat_call(op->net, &afs_RXFSGetVolumeStatus, 2 * 4,
David Howellsffba7182019-05-09 22:22:50 +01001478 max(12 * 4, AFSOPAQUEMAX + 1));
1479 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001480 return afs_op_nomem(op);
David Howells45222b92007-05-10 22:22:20 -07001481
1482 /* marshall the parameters */
1483 bp = call->request;
1484 bp[0] = htonl(FSGETVOLUMESTATUS);
David Howellse49c7b22020-04-10 20:51:51 +01001485 bp[1] = htonl(vp->fid.vid);
David Howells45222b92007-05-10 22:22:20 -07001486
David Howellse49c7b22020-04-10 20:51:51 +01001487 trace_afs_make_fs_call(call, &vp->fid);
1488 afs_make_op_call(op, call, GFP_NOFS);
David Howells45222b92007-05-10 22:22:20 -07001489}
David Howellse8d6c552007-07-15 23:40:12 -07001490
1491/*
1492 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1493 */
David Howellsd0016482016-08-30 20:42:14 +01001494static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
David Howellse8d6c552007-07-15 23:40:12 -07001495{
David Howellse49c7b22020-04-10 20:51:51 +01001496 struct afs_operation *op = call->op;
David Howellse8d6c552007-07-15 23:40:12 -07001497 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001498 int ret;
David Howellse8d6c552007-07-15 23:40:12 -07001499
David Howellsd0016482016-08-30 20:42:14 +01001500 _enter("{%u}", call->unmarshall);
David Howellse8d6c552007-07-15 23:40:12 -07001501
David Howellsd0016482016-08-30 20:42:14 +01001502 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001503 if (ret < 0)
1504 return ret;
David Howellse8d6c552007-07-15 23:40:12 -07001505
1506 /* unmarshall the reply once we've received all of it */
1507 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +01001508 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howellse8d6c552007-07-15 23:40:12 -07001509
1510 _leave(" = 0 [done]");
1511 return 0;
1512}
1513
1514/*
1515 * FS.SetLock operation type
1516 */
1517static const struct afs_call_type afs_RXFSSetLock = {
1518 .name = "FS.SetLock",
David Howells025db802017-11-02 15:27:51 +00001519 .op = afs_FS_SetLock,
David Howellse8d6c552007-07-15 23:40:12 -07001520 .deliver = afs_deliver_fs_xxxx_lock,
David Howellsa690f602019-04-25 14:26:50 +01001521 .done = afs_lock_op_done,
David Howellse8d6c552007-07-15 23:40:12 -07001522 .destructor = afs_flat_call_destructor,
1523};
1524
1525/*
1526 * FS.ExtendLock operation type
1527 */
1528static const struct afs_call_type afs_RXFSExtendLock = {
1529 .name = "FS.ExtendLock",
David Howells025db802017-11-02 15:27:51 +00001530 .op = afs_FS_ExtendLock,
David Howellse8d6c552007-07-15 23:40:12 -07001531 .deliver = afs_deliver_fs_xxxx_lock,
David Howellsa690f602019-04-25 14:26:50 +01001532 .done = afs_lock_op_done,
David Howellse8d6c552007-07-15 23:40:12 -07001533 .destructor = afs_flat_call_destructor,
1534};
1535
1536/*
1537 * FS.ReleaseLock operation type
1538 */
1539static const struct afs_call_type afs_RXFSReleaseLock = {
1540 .name = "FS.ReleaseLock",
David Howells025db802017-11-02 15:27:51 +00001541 .op = afs_FS_ReleaseLock,
David Howellse8d6c552007-07-15 23:40:12 -07001542 .deliver = afs_deliver_fs_xxxx_lock,
David Howellse8d6c552007-07-15 23:40:12 -07001543 .destructor = afs_flat_call_destructor,
1544};
1545
1546/*
David Howellsd2ddc772017-11-02 15:27:50 +00001547 * Set a lock on a file
David Howellse8d6c552007-07-15 23:40:12 -07001548 */
David Howellse49c7b22020-04-10 20:51:51 +01001549void afs_fs_set_lock(struct afs_operation *op)
David Howellse8d6c552007-07-15 23:40:12 -07001550{
David Howellse49c7b22020-04-10 20:51:51 +01001551 struct afs_vnode_param *vp = &op->file[0];
David Howellse8d6c552007-07-15 23:40:12 -07001552 struct afs_call *call;
1553 __be32 *bp;
1554
1555 _enter("");
1556
David Howellse49c7b22020-04-10 20:51:51 +01001557 call = afs_alloc_flat_call(op->net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001558 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001559 return afs_op_nomem(op);
David Howellse8d6c552007-07-15 23:40:12 -07001560
1561 /* marshall the parameters */
1562 bp = call->request;
1563 *bp++ = htonl(FSSETLOCK);
David Howellse49c7b22020-04-10 20:51:51 +01001564 *bp++ = htonl(vp->fid.vid);
1565 *bp++ = htonl(vp->fid.vnode);
1566 *bp++ = htonl(vp->fid.unique);
1567 *bp++ = htonl(op->lock.type);
David Howellse8d6c552007-07-15 23:40:12 -07001568
David Howellse49c7b22020-04-10 20:51:51 +01001569 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1570 afs_make_op_call(op, call, GFP_NOFS);
David Howellse8d6c552007-07-15 23:40:12 -07001571}
1572
1573/*
1574 * extend a lock on a file
1575 */
David Howellse49c7b22020-04-10 20:51:51 +01001576void afs_fs_extend_lock(struct afs_operation *op)
David Howellse8d6c552007-07-15 23:40:12 -07001577{
David Howellse49c7b22020-04-10 20:51:51 +01001578 struct afs_vnode_param *vp = &op->file[0];
David Howellse8d6c552007-07-15 23:40:12 -07001579 struct afs_call *call;
1580 __be32 *bp;
1581
1582 _enter("");
1583
David Howellse49c7b22020-04-10 20:51:51 +01001584 call = afs_alloc_flat_call(op->net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001585 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001586 return afs_op_nomem(op);
David Howellse8d6c552007-07-15 23:40:12 -07001587
1588 /* marshall the parameters */
1589 bp = call->request;
1590 *bp++ = htonl(FSEXTENDLOCK);
David Howellse49c7b22020-04-10 20:51:51 +01001591 *bp++ = htonl(vp->fid.vid);
1592 *bp++ = htonl(vp->fid.vnode);
1593 *bp++ = htonl(vp->fid.unique);
David Howellse8d6c552007-07-15 23:40:12 -07001594
David Howellse49c7b22020-04-10 20:51:51 +01001595 trace_afs_make_fs_call(call, &vp->fid);
1596 afs_make_op_call(op, call, GFP_NOFS);
David Howellse8d6c552007-07-15 23:40:12 -07001597}
1598
1599/*
1600 * release a lock on a file
1601 */
David Howellse49c7b22020-04-10 20:51:51 +01001602void afs_fs_release_lock(struct afs_operation *op)
David Howellse8d6c552007-07-15 23:40:12 -07001603{
David Howellse49c7b22020-04-10 20:51:51 +01001604 struct afs_vnode_param *vp = &op->file[0];
David Howellse8d6c552007-07-15 23:40:12 -07001605 struct afs_call *call;
1606 __be32 *bp;
1607
1608 _enter("");
1609
David Howellse49c7b22020-04-10 20:51:51 +01001610 call = afs_alloc_flat_call(op->net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001611 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001612 return afs_op_nomem(op);
David Howellse8d6c552007-07-15 23:40:12 -07001613
1614 /* marshall the parameters */
1615 bp = call->request;
1616 *bp++ = htonl(FSRELEASELOCK);
David Howellse49c7b22020-04-10 20:51:51 +01001617 *bp++ = htonl(vp->fid.vid);
1618 *bp++ = htonl(vp->fid.vnode);
1619 *bp++ = htonl(vp->fid.unique);
David Howellse8d6c552007-07-15 23:40:12 -07001620
David Howellse49c7b22020-04-10 20:51:51 +01001621 trace_afs_make_fs_call(call, &vp->fid);
1622 afs_make_op_call(op, call, GFP_NOFS);
David Howellsc435ee32017-11-02 15:27:49 +00001623}
1624
1625/*
1626 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1627 */
1628static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1629{
1630 return afs_transfer_reply(call);
1631}
1632
1633/*
1634 * FS.GiveUpAllCallBacks operation type
1635 */
1636static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1637 .name = "FS.GiveUpAllCallBacks",
David Howells025db802017-11-02 15:27:51 +00001638 .op = afs_FS_GiveUpAllCallBacks,
David Howellsc435ee32017-11-02 15:27:49 +00001639 .deliver = afs_deliver_fs_give_up_all_callbacks,
1640 .destructor = afs_flat_call_destructor,
1641};
1642
1643/*
1644 * Flush all the callbacks we have on a server.
1645 */
David Howellsd2ddc772017-11-02 15:27:50 +00001646int afs_fs_give_up_all_callbacks(struct afs_net *net,
1647 struct afs_server *server,
David Howells8b2a4642017-11-02 15:27:50 +00001648 struct afs_addr_cursor *ac,
David Howellsd2ddc772017-11-02 15:27:50 +00001649 struct key *key)
David Howellsc435ee32017-11-02 15:27:49 +00001650{
1651 struct afs_call *call;
1652 __be32 *bp;
1653
1654 _enter("");
1655
David Howellsd2ddc772017-11-02 15:27:50 +00001656 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
David Howellsc435ee32017-11-02 15:27:49 +00001657 if (!call)
1658 return -ENOMEM;
1659
1660 call->key = key;
1661
1662 /* marshall the parameters */
1663 bp = call->request;
1664 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1665
David Howells977e5f82020-04-17 17:31:26 +01001666 call->server = afs_use_server(server, afs_server_trace_give_up_cb);
David Howells0b9bf382019-04-25 14:26:50 +01001667 afs_make_call(ac, call, GFP_NOFS);
1668 return afs_wait_for_call_to_complete(call, ac);
David Howellsd2ddc772017-11-02 15:27:50 +00001669}
1670
1671/*
1672 * Deliver reply data to an FS.GetCapabilities operation.
1673 */
1674static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1675{
1676 u32 count;
1677 int ret;
1678
David Howellsfc276122019-11-21 09:12:17 +00001679 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
David Howellsd2ddc772017-11-02 15:27:50 +00001680
David Howellsd2ddc772017-11-02 15:27:50 +00001681 switch (call->unmarshall) {
1682 case 0:
David Howells12bdcf32018-10-20 00:57:56 +01001683 afs_extract_to_tmp(call);
David Howellsd2ddc772017-11-02 15:27:50 +00001684 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001685 fallthrough;
David Howellsd2ddc772017-11-02 15:27:50 +00001686
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001687 /* Extract the capabilities word count */
David Howellsd2ddc772017-11-02 15:27:50 +00001688 case 1:
David Howells12bdcf32018-10-20 00:57:56 +01001689 ret = afs_extract_data(call, true);
David Howellsd2ddc772017-11-02 15:27:50 +00001690 if (ret < 0)
1691 return ret;
1692
1693 count = ntohl(call->tmp);
1694
1695 call->count = count;
1696 call->count2 = count;
David Howells23a28912019-08-20 09:22:38 +01001697 afs_extract_discard(call, count * sizeof(__be32));
David Howellsd2ddc772017-11-02 15:27:50 +00001698 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001699 fallthrough;
David Howellsd2ddc772017-11-02 15:27:50 +00001700
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001701 /* Extract capabilities words */
David Howellsd2ddc772017-11-02 15:27:50 +00001702 case 2:
David Howells12bdcf32018-10-20 00:57:56 +01001703 ret = afs_extract_data(call, false);
David Howellsd2ddc772017-11-02 15:27:50 +00001704 if (ret < 0)
1705 return ret;
1706
1707 /* TODO: Examine capabilities */
1708
David Howellsd2ddc772017-11-02 15:27:50 +00001709 call->unmarshall++;
1710 break;
1711 }
1712
1713 _leave(" = 0 [done]");
1714 return 0;
1715}
1716
1717/*
1718 * FS.GetCapabilities operation type
1719 */
1720static const struct afs_call_type afs_RXFSGetCapabilities = {
1721 .name = "FS.GetCapabilities",
David Howells025db802017-11-02 15:27:51 +00001722 .op = afs_FS_GetCapabilities,
David Howellsd2ddc772017-11-02 15:27:50 +00001723 .deliver = afs_deliver_fs_get_capabilities,
David Howells3bf0fb62018-10-20 00:57:59 +01001724 .done = afs_fileserver_probe_result,
David Howellsffba7182019-05-09 22:22:50 +01001725 .destructor = afs_flat_call_destructor,
David Howellsd2ddc772017-11-02 15:27:50 +00001726};
1727
1728/*
David Howellsf6cbb362020-04-24 15:10:00 +01001729 * Probe a fileserver for the capabilities that it supports. This RPC can
1730 * reply with up to 196 words. The operation is asynchronous and if we managed
1731 * to allocate a call, true is returned the result is delivered through the
1732 * ->done() - otherwise we return false to indicate we didn't even try.
David Howellsd2ddc772017-11-02 15:27:50 +00001733 */
David Howellsf6cbb362020-04-24 15:10:00 +01001734bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
1735 struct afs_addr_cursor *ac, struct key *key)
David Howellsd2ddc772017-11-02 15:27:50 +00001736{
1737 struct afs_call *call;
1738 __be32 *bp;
1739
1740 _enter("");
1741
1742 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1743 if (!call)
David Howellsf6cbb362020-04-24 15:10:00 +01001744 return false;
David Howellsd2ddc772017-11-02 15:27:50 +00001745
1746 call->key = key;
David Howells977e5f82020-04-17 17:31:26 +01001747 call->server = afs_use_server(server, afs_server_trace_get_caps);
David Howells30062bd2018-10-20 00:57:58 +01001748 call->upgrade = true;
David Howells0b9bf382019-04-25 14:26:50 +01001749 call->async = true;
David Howells94f699c2019-05-16 13:21:59 +01001750 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
David Howellsd2ddc772017-11-02 15:27:50 +00001751
1752 /* marshall the parameters */
1753 bp = call->request;
1754 *bp++ = htonl(FSGETCAPABILITIES);
1755
David Howells025db802017-11-02 15:27:51 +00001756 trace_afs_make_fs_call(call, NULL);
David Howells0b9bf382019-04-25 14:26:50 +01001757 afs_make_call(ac, call, GFP_NOFS);
David Howellsf6cbb362020-04-24 15:10:00 +01001758 afs_put_call(call);
1759 return true;
David Howellse8d6c552007-07-15 23:40:12 -07001760}
David Howells5cf9dd52018-04-09 21:12:31 +01001761
1762/*
David Howells5cf9dd52018-04-09 21:12:31 +01001763 * Deliver reply data to an FS.InlineBulkStatus call
1764 */
1765static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
1766{
David Howellse49c7b22020-04-10 20:51:51 +01001767 struct afs_operation *op = call->op;
David Howells87182752019-05-09 16:17:05 +01001768 struct afs_status_cb *scb;
David Howells5cf9dd52018-04-09 21:12:31 +01001769 const __be32 *bp;
1770 u32 tmp;
1771 int ret;
1772
1773 _enter("{%u}", call->unmarshall);
1774
1775 switch (call->unmarshall) {
1776 case 0:
David Howells12bdcf32018-10-20 00:57:56 +01001777 afs_extract_to_tmp(call);
David Howells5cf9dd52018-04-09 21:12:31 +01001778 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001779 fallthrough;
David Howells5cf9dd52018-04-09 21:12:31 +01001780
1781 /* Extract the file status count and array in two steps */
1782 case 1:
1783 _debug("extract status count");
David Howells12bdcf32018-10-20 00:57:56 +01001784 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01001785 if (ret < 0)
1786 return ret;
1787
1788 tmp = ntohl(call->tmp);
David Howellse49c7b22020-04-10 20:51:51 +01001789 _debug("status count: %u/%u", tmp, op->nr_files);
1790 if (tmp != op->nr_files)
David Howells7126ead2020-04-08 16:49:08 +01001791 return afs_protocol_error(call, afs_eproto_ibulkst_count);
David Howells5cf9dd52018-04-09 21:12:31 +01001792
1793 call->count = 0;
1794 call->unmarshall++;
1795 more_counts:
David Howells12bdcf32018-10-20 00:57:56 +01001796 afs_extract_to_buf(call, 21 * sizeof(__be32));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001797 fallthrough;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001798
David Howells5cf9dd52018-04-09 21:12:31 +01001799 case 2:
1800 _debug("extract status array %u", call->count);
David Howells12bdcf32018-10-20 00:57:56 +01001801 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01001802 if (ret < 0)
1803 return ret;
1804
David Howellse49c7b22020-04-10 20:51:51 +01001805 switch (call->count) {
1806 case 0:
1807 scb = &op->file[0].scb;
1808 break;
1809 case 1:
1810 scb = &op->file[1].scb;
1811 break;
1812 default:
1813 scb = &op->more_files[call->count - 2].scb;
1814 break;
1815 }
1816
David Howells5cf9dd52018-04-09 21:12:31 +01001817 bp = call->buffer;
David Howells38355ee2020-04-08 16:13:20 +01001818 xdr_decode_AFSFetchStatus(&bp, call, scb);
David Howellse49c7b22020-04-10 20:51:51 +01001819
David Howells5cf9dd52018-04-09 21:12:31 +01001820 call->count++;
David Howellse49c7b22020-04-10 20:51:51 +01001821 if (call->count < op->nr_files)
David Howells5cf9dd52018-04-09 21:12:31 +01001822 goto more_counts;
1823
1824 call->count = 0;
1825 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01001826 afs_extract_to_tmp(call);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001827 fallthrough;
David Howells5cf9dd52018-04-09 21:12:31 +01001828
1829 /* Extract the callback count and array in two steps */
1830 case 3:
1831 _debug("extract CB count");
David Howells12bdcf32018-10-20 00:57:56 +01001832 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01001833 if (ret < 0)
1834 return ret;
1835
1836 tmp = ntohl(call->tmp);
1837 _debug("CB count: %u", tmp);
David Howellse49c7b22020-04-10 20:51:51 +01001838 if (tmp != op->nr_files)
David Howells7126ead2020-04-08 16:49:08 +01001839 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
David Howells5cf9dd52018-04-09 21:12:31 +01001840 call->count = 0;
1841 call->unmarshall++;
1842 more_cbs:
David Howells12bdcf32018-10-20 00:57:56 +01001843 afs_extract_to_buf(call, 3 * sizeof(__be32));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001844 fallthrough;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001845
David Howells5cf9dd52018-04-09 21:12:31 +01001846 case 4:
1847 _debug("extract CB array");
David Howells12bdcf32018-10-20 00:57:56 +01001848 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01001849 if (ret < 0)
1850 return ret;
1851
1852 _debug("unmarshall CB array");
David Howellse49c7b22020-04-10 20:51:51 +01001853 switch (call->count) {
1854 case 0:
1855 scb = &op->file[0].scb;
1856 break;
1857 case 1:
1858 scb = &op->file[1].scb;
1859 break;
1860 default:
1861 scb = &op->more_files[call->count - 2].scb;
1862 break;
1863 }
1864
David Howells5cf9dd52018-04-09 21:12:31 +01001865 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01001866 xdr_decode_AFSCallBack(&bp, call, scb);
David Howells5cf9dd52018-04-09 21:12:31 +01001867 call->count++;
David Howellse49c7b22020-04-10 20:51:51 +01001868 if (call->count < op->nr_files)
David Howells5cf9dd52018-04-09 21:12:31 +01001869 goto more_cbs;
1870
David Howells12bdcf32018-10-20 00:57:56 +01001871 afs_extract_to_buf(call, 6 * sizeof(__be32));
David Howells5cf9dd52018-04-09 21:12:31 +01001872 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001873 fallthrough;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001874
David Howells5cf9dd52018-04-09 21:12:31 +01001875 case 5:
David Howells12bdcf32018-10-20 00:57:56 +01001876 ret = afs_extract_data(call, false);
David Howells5cf9dd52018-04-09 21:12:31 +01001877 if (ret < 0)
1878 return ret;
1879
1880 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +01001881 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howells5cf9dd52018-04-09 21:12:31 +01001882
David Howells5cf9dd52018-04-09 21:12:31 +01001883 call->unmarshall++;
1884
1885 case 6:
1886 break;
1887 }
1888
1889 _leave(" = 0 [done]");
1890 return 0;
1891}
1892
David Howellse49c7b22020-04-10 20:51:51 +01001893static void afs_done_fs_inline_bulk_status(struct afs_call *call)
1894{
1895 if (call->error == -ECONNABORTED &&
David Howells20325962020-04-30 01:03:49 +01001896 call->abort_code == RX_INVALID_OPERATION) {
David Howellse49c7b22020-04-10 20:51:51 +01001897 set_bit(AFS_SERVER_FL_NO_IBULK, &call->server->flags);
David Howells20325962020-04-30 01:03:49 +01001898 if (call->op)
1899 set_bit(AFS_VOLUME_MAYBE_NO_IBULK, &call->op->volume->flags);
1900 }
David Howellse49c7b22020-04-10 20:51:51 +01001901}
1902
David Howells5cf9dd52018-04-09 21:12:31 +01001903/*
1904 * FS.InlineBulkStatus operation type
1905 */
1906static const struct afs_call_type afs_RXFSInlineBulkStatus = {
1907 .name = "FS.InlineBulkStatus",
1908 .op = afs_FS_InlineBulkStatus,
1909 .deliver = afs_deliver_fs_inline_bulk_status,
David Howellse49c7b22020-04-10 20:51:51 +01001910 .done = afs_done_fs_inline_bulk_status,
David Howells5cf9dd52018-04-09 21:12:31 +01001911 .destructor = afs_flat_call_destructor,
1912};
1913
1914/*
1915 * Fetch the status information for up to 50 files
1916 */
David Howellse49c7b22020-04-10 20:51:51 +01001917void afs_fs_inline_bulk_status(struct afs_operation *op)
David Howells5cf9dd52018-04-09 21:12:31 +01001918{
David Howellse49c7b22020-04-10 20:51:51 +01001919 struct afs_vnode_param *dvp = &op->file[0];
1920 struct afs_vnode_param *vp = &op->file[1];
David Howells5cf9dd52018-04-09 21:12:31 +01001921 struct afs_call *call;
1922 __be32 *bp;
1923 int i;
1924
David Howells20325962020-04-30 01:03:49 +01001925 if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) {
David Howellse49c7b22020-04-10 20:51:51 +01001926 op->error = -ENOTSUPP;
1927 return;
David Howells5cf9dd52018-04-09 21:12:31 +01001928 }
1929
David Howellse49c7b22020-04-10 20:51:51 +01001930 _enter(",%x,{%llx:%llu},%u",
1931 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1932
1933 call = afs_alloc_flat_call(op->net, &afs_RXFSInlineBulkStatus,
1934 (2 + op->nr_files * 3) * 4,
1935 21 * 4);
1936 if (!call)
1937 return afs_op_nomem(op);
David Howells5cf9dd52018-04-09 21:12:31 +01001938
1939 /* marshall the parameters */
1940 bp = call->request;
1941 *bp++ = htonl(FSINLINEBULKSTATUS);
David Howellse49c7b22020-04-10 20:51:51 +01001942 *bp++ = htonl(op->nr_files);
1943 *bp++ = htonl(dvp->fid.vid);
1944 *bp++ = htonl(dvp->fid.vnode);
1945 *bp++ = htonl(dvp->fid.unique);
1946 *bp++ = htonl(vp->fid.vid);
1947 *bp++ = htonl(vp->fid.vnode);
1948 *bp++ = htonl(vp->fid.unique);
1949 for (i = 0; i < op->nr_files - 2; i++) {
1950 *bp++ = htonl(op->more_files[i].fid.vid);
1951 *bp++ = htonl(op->more_files[i].fid.vnode);
1952 *bp++ = htonl(op->more_files[i].fid.unique);
David Howells5cf9dd52018-04-09 21:12:31 +01001953 }
1954
David Howellse49c7b22020-04-10 20:51:51 +01001955 trace_afs_make_fs_call(call, &vp->fid);
1956 afs_make_op_call(op, call, GFP_NOFS);
David Howells5cf9dd52018-04-09 21:12:31 +01001957}
David Howells260f0822019-04-25 14:26:52 +01001958
1959/*
1960 * deliver reply data to an FS.FetchACL
1961 */
1962static int afs_deliver_fs_fetch_acl(struct afs_call *call)
1963{
David Howellse49c7b22020-04-10 20:51:51 +01001964 struct afs_operation *op = call->op;
1965 struct afs_vnode_param *vp = &op->file[0];
David Howells260f0822019-04-25 14:26:52 +01001966 struct afs_acl *acl;
1967 const __be32 *bp;
1968 unsigned int size;
1969 int ret;
1970
1971 _enter("{%u}", call->unmarshall);
1972
1973 switch (call->unmarshall) {
1974 case 0:
1975 afs_extract_to_tmp(call);
1976 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001977 fallthrough;
David Howells260f0822019-04-25 14:26:52 +01001978
1979 /* extract the returned data length */
1980 case 1:
1981 ret = afs_extract_data(call, true);
1982 if (ret < 0)
1983 return ret;
1984
1985 size = call->count2 = ntohl(call->tmp);
1986 size = round_up(size, 4);
1987
1988 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1989 if (!acl)
1990 return -ENOMEM;
David Howellse49c7b22020-04-10 20:51:51 +01001991 op->acl = acl;
David Howells260f0822019-04-25 14:26:52 +01001992 acl->size = call->count2;
1993 afs_extract_begin(call, acl->data, size);
1994 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001995 fallthrough;
David Howells260f0822019-04-25 14:26:52 +01001996
1997 /* extract the returned data */
1998 case 2:
1999 ret = afs_extract_data(call, true);
2000 if (ret < 0)
2001 return ret;
2002
2003 afs_extract_to_buf(call, (21 + 6) * 4);
2004 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002005 fallthrough;
David Howells260f0822019-04-25 14:26:52 +01002006
2007 /* extract the metadata */
2008 case 3:
2009 ret = afs_extract_data(call, false);
2010 if (ret < 0)
2011 return ret;
2012
2013 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +01002014 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
2015 xdr_decode_AFSVolSync(&bp, &op->volsync);
David Howells260f0822019-04-25 14:26:52 +01002016
2017 call->unmarshall++;
2018
2019 case 4:
2020 break;
2021 }
2022
2023 _leave(" = 0 [done]");
2024 return 0;
2025}
2026
David Howells260f0822019-04-25 14:26:52 +01002027/*
2028 * FS.FetchACL operation type
2029 */
2030static const struct afs_call_type afs_RXFSFetchACL = {
2031 .name = "FS.FetchACL",
2032 .op = afs_FS_FetchACL,
2033 .deliver = afs_deliver_fs_fetch_acl,
David Howells260f0822019-04-25 14:26:52 +01002034};
2035
2036/*
2037 * Fetch the ACL for a file.
2038 */
David Howellse49c7b22020-04-10 20:51:51 +01002039void afs_fs_fetch_acl(struct afs_operation *op)
David Howells260f0822019-04-25 14:26:52 +01002040{
David Howellse49c7b22020-04-10 20:51:51 +01002041 struct afs_vnode_param *vp = &op->file[0];
David Howells260f0822019-04-25 14:26:52 +01002042 struct afs_call *call;
David Howells260f0822019-04-25 14:26:52 +01002043 __be32 *bp;
2044
2045 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01002046 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells260f0822019-04-25 14:26:52 +01002047
David Howellse49c7b22020-04-10 20:51:51 +01002048 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2049 if (!call)
2050 return afs_op_nomem(op);
David Howells260f0822019-04-25 14:26:52 +01002051
2052 /* marshall the parameters */
2053 bp = call->request;
2054 bp[0] = htonl(FSFETCHACL);
David Howellse49c7b22020-04-10 20:51:51 +01002055 bp[1] = htonl(vp->fid.vid);
2056 bp[2] = htonl(vp->fid.vnode);
2057 bp[3] = htonl(vp->fid.unique);
David Howells260f0822019-04-25 14:26:52 +01002058
David Howellse49c7b22020-04-10 20:51:51 +01002059 trace_afs_make_fs_call(call, &vp->fid);
2060 afs_make_op_call(op, call, GFP_KERNEL);
David Howellsffba7182019-05-09 22:22:50 +01002061}
2062
2063/*
Joe Gorseb10494a2019-04-25 14:26:52 +01002064 * FS.StoreACL operation type
2065 */
2066static const struct afs_call_type afs_RXFSStoreACL = {
2067 .name = "FS.StoreACL",
2068 .op = afs_FS_StoreACL,
David Howellsffba7182019-05-09 22:22:50 +01002069 .deliver = afs_deliver_fs_file_status_and_vol,
Joe Gorseb10494a2019-04-25 14:26:52 +01002070 .destructor = afs_flat_call_destructor,
2071};
2072
2073/*
2074 * Fetch the ACL for a file.
2075 */
David Howellse49c7b22020-04-10 20:51:51 +01002076void afs_fs_store_acl(struct afs_operation *op)
Joe Gorseb10494a2019-04-25 14:26:52 +01002077{
David Howellse49c7b22020-04-10 20:51:51 +01002078 struct afs_vnode_param *vp = &op->file[0];
Joe Gorseb10494a2019-04-25 14:26:52 +01002079 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +01002080 const struct afs_acl *acl = op->acl;
Joe Gorseb10494a2019-04-25 14:26:52 +01002081 size_t size;
2082 __be32 *bp;
2083
2084 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01002085 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
Joe Gorseb10494a2019-04-25 14:26:52 +01002086
2087 size = round_up(acl->size, 4);
David Howellse49c7b22020-04-10 20:51:51 +01002088 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreACL,
Joe Gorseb10494a2019-04-25 14:26:52 +01002089 5 * 4 + size, (21 + 6) * 4);
David Howellse49c7b22020-04-10 20:51:51 +01002090 if (!call)
2091 return afs_op_nomem(op);
Joe Gorseb10494a2019-04-25 14:26:52 +01002092
2093 /* marshall the parameters */
2094 bp = call->request;
2095 bp[0] = htonl(FSSTOREACL);
David Howellse49c7b22020-04-10 20:51:51 +01002096 bp[1] = htonl(vp->fid.vid);
2097 bp[2] = htonl(vp->fid.vnode);
2098 bp[3] = htonl(vp->fid.unique);
Joe Gorseb10494a2019-04-25 14:26:52 +01002099 bp[4] = htonl(acl->size);
2100 memcpy(&bp[5], acl->data, acl->size);
2101 if (acl->size != size)
2102 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2103
David Howellse49c7b22020-04-10 20:51:51 +01002104 trace_afs_make_fs_call(call, &vp->fid);
2105 afs_make_op_call(op, call, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}