blob: fdc7d675b4b0cc7c4c3af854fba4cbd11bd6961c [file] [log] [blame]
Thomas Gleixnerb4d0d232019-05-20 19:08:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells30062bd2018-10-20 00:57:58 +01002/* YFS File Server client stubs
3 *
4 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
David Howells30062bd2018-10-20 00:57:58 +01006 */
7
8#include <linux/init.h>
9#include <linux/slab.h>
10#include <linux/sched.h>
11#include <linux/circ_buf.h>
12#include <linux/iversion.h>
13#include "internal.h"
14#include "afs_fs.h"
15#include "xdr_fs.h"
16#include "protocol_yfs.h"
17
David Howells30062bd2018-10-20 00:57:58 +010018#define xdr_size(x) (sizeof(*x) / sizeof(__be32))
19
20static void xdr_decode_YFSFid(const __be32 **_bp, struct afs_fid *fid)
21{
22 const struct yfs_xdr_YFSFid *x = (const void *)*_bp;
23
24 fid->vid = xdr_to_u64(x->volume);
25 fid->vnode = xdr_to_u64(x->vnode.lo);
26 fid->vnode_hi = ntohl(x->vnode.hi);
27 fid->unique = ntohl(x->vnode.unique);
28 *_bp += xdr_size(x);
29}
30
31static __be32 *xdr_encode_u32(__be32 *bp, u32 n)
32{
33 *bp++ = htonl(n);
34 return bp;
35}
36
37static __be32 *xdr_encode_u64(__be32 *bp, u64 n)
38{
39 struct yfs_xdr_u64 *x = (void *)bp;
40
41 *x = u64_to_xdr(n);
42 return bp + xdr_size(x);
43}
44
45static __be32 *xdr_encode_YFSFid(__be32 *bp, struct afs_fid *fid)
46{
47 struct yfs_xdr_YFSFid *x = (void *)bp;
48
49 x->volume = u64_to_xdr(fid->vid);
50 x->vnode.lo = u64_to_xdr(fid->vnode);
51 x->vnode.hi = htonl(fid->vnode_hi);
52 x->vnode.unique = htonl(fid->unique);
53 return bp + xdr_size(x);
54}
55
56static size_t xdr_strlen(unsigned int len)
57{
58 return sizeof(__be32) + round_up(len, sizeof(__be32));
59}
60
61static __be32 *xdr_encode_string(__be32 *bp, const char *p, unsigned int len)
62{
63 bp = xdr_encode_u32(bp, len);
64 bp = memcpy(bp, p, len);
65 if (len & 3) {
66 unsigned int pad = 4 - (len & 3);
67
68 memset((u8 *)bp + len, 0, pad);
69 len += pad;
70 }
71
72 return bp + len / sizeof(__be32);
73}
74
David Howellse49c7b22020-04-10 20:51:51 +010075static __be32 *xdr_encode_name(__be32 *bp, const struct qstr *p)
76{
77 return xdr_encode_string(bp, p->name, p->len);
78}
79
David Howells30062bd2018-10-20 00:57:58 +010080static s64 linux_to_yfs_time(const struct timespec64 *t)
81{
82 /* Convert to 100ns intervals. */
83 return (u64)t->tv_sec * 10000000 + t->tv_nsec/100;
84}
85
Marc Dionne52af7102021-10-20 09:51:43 -030086static __be32 *xdr_encode_YFSStoreStatus(__be32 *bp, mode_t *mode,
87 const struct timespec64 *t)
David Howells30062bd2018-10-20 00:57:58 +010088{
89 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
Marc Dionne52af7102021-10-20 09:51:43 -030090 mode_t masked_mode = mode ? *mode & S_IALLUGO : 0;
David Howells30062bd2018-10-20 00:57:58 +010091 s64 mtime = linux_to_yfs_time(t);
Marc Dionne52af7102021-10-20 09:51:43 -030092 u32 mask = AFS_SET_MTIME;
David Howells30062bd2018-10-20 00:57:58 +010093
Marc Dionne52af7102021-10-20 09:51:43 -030094 mask |= mode ? AFS_SET_MODE : 0;
95
96 x->mask = htonl(mask);
97 x->mode = htonl(masked_mode);
David Howells30062bd2018-10-20 00:57:58 +010098 x->mtime_client = u64_to_xdr(mtime);
99 x->owner = u64_to_xdr(0);
100 x->group = u64_to_xdr(0);
101 return bp + xdr_size(x);
102}
103
104/*
105 * Convert a signed 100ns-resolution 64-bit time into a timespec.
106 */
107static struct timespec64 yfs_time_to_linux(s64 t)
108{
109 struct timespec64 ts;
110 u64 abs_t;
111
112 /*
113 * Unfortunately can not use normal 64 bit division on 32 bit arch, but
114 * the alternative, do_div, does not work with negative numbers so have
115 * to special case them
116 */
117 if (t < 0) {
118 abs_t = -t;
119 ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100);
120 ts.tv_nsec = -ts.tv_nsec;
121 ts.tv_sec = -abs_t;
122 } else {
123 abs_t = t;
124 ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100;
125 ts.tv_sec = abs_t;
126 }
127
128 return ts;
129}
130
131static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr)
132{
133 s64 t = xdr_to_u64(xdr);
134
135 return yfs_time_to_linux(t);
136}
137
138static void yfs_check_req(struct afs_call *call, __be32 *bp)
139{
140 size_t len = (void *)bp - call->request;
141
142 if (len > call->request_size)
143 pr_err("kAFS: %s: Request buffer overflow (%zu>%u)\n",
144 call->type->name, len, call->request_size);
145 else if (len < call->request_size)
Kefeng Wanga4e530a2019-10-18 11:18:40 +0800146 pr_warn("kAFS: %s: Request buffer underflow (%zu<%u)\n",
147 call->type->name, len, call->request_size);
David Howells30062bd2018-10-20 00:57:58 +0100148}
149
150/*
151 * Dump a bad file status record.
152 */
153static void xdr_dump_bad(const __be32 *bp)
154{
155 __be32 x[4];
156 int i;
157
158 pr_notice("YFS XDR: Bad status record\n");
David Howells3efe55b2020-04-01 23:32:12 +0100159 for (i = 0; i < 6 * 4 * 4; i += 16) {
David Howells30062bd2018-10-20 00:57:58 +0100160 memcpy(x, bp, 16);
161 bp += 4;
162 pr_notice("%03x: %08x %08x %08x %08x\n",
163 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
164 }
165
David Howells3efe55b2020-04-01 23:32:12 +0100166 memcpy(x, bp, 8);
167 pr_notice("0x60: %08x %08x\n", ntohl(x[0]), ntohl(x[1]));
David Howells30062bd2018-10-20 00:57:58 +0100168}
169
170/*
171 * Decode a YFSFetchStatus block
172 */
David Howells38355ee2020-04-08 16:13:20 +0100173static void xdr_decode_YFSFetchStatus(const __be32 **_bp,
174 struct afs_call *call,
175 struct afs_status_cb *scb)
David Howells30062bd2018-10-20 00:57:58 +0100176{
177 const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
David Howellsa58823a2019-05-09 15:16:10 +0100178 struct afs_file_status *status = &scb->status;
David Howells30062bd2018-10-20 00:57:58 +0100179 u32 type;
David Howells30062bd2018-10-20 00:57:58 +0100180
181 status->abort_code = ntohl(xdr->abort_code);
182 if (status->abort_code != 0) {
David Howellsa58823a2019-05-09 15:16:10 +0100183 if (status->abort_code == VNOVNODE)
David Howells30062bd2018-10-20 00:57:58 +0100184 status->nlink = 0;
David Howellsa38a7552019-05-14 12:29:11 +0100185 scb->have_error = true;
David Howells38355ee2020-04-08 16:13:20 +0100186 goto advance;
David Howells30062bd2018-10-20 00:57:58 +0100187 }
188
189 type = ntohl(xdr->type);
190 switch (type) {
191 case AFS_FTYPE_FILE:
192 case AFS_FTYPE_DIR:
193 case AFS_FTYPE_SYMLINK:
David Howells30062bd2018-10-20 00:57:58 +0100194 status->type = type;
195 break;
196 default:
197 goto bad;
198 }
199
David Howellsa58823a2019-05-09 15:16:10 +0100200 status->nlink = ntohl(xdr->nlink);
201 status->author = xdr_to_u64(xdr->author);
202 status->owner = xdr_to_u64(xdr->owner);
203 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
204 status->anon_access = ntohl(xdr->anon_access);
205 status->mode = ntohl(xdr->mode) & S_IALLUGO;
206 status->group = xdr_to_u64(xdr->group);
207 status->lock_count = ntohl(xdr->lock_count);
David Howells30062bd2018-10-20 00:57:58 +0100208
David Howellsa58823a2019-05-09 15:16:10 +0100209 status->mtime_client = xdr_to_time(xdr->mtime_client);
210 status->mtime_server = xdr_to_time(xdr->mtime_server);
211 status->size = xdr_to_u64(xdr->size);
212 status->data_version = xdr_to_u64(xdr->data_version);
David Howellsa38a7552019-05-14 12:29:11 +0100213 scb->have_status = true;
David Howellsc72057b2020-04-08 16:13:20 +0100214advance:
David Howells30062bd2018-10-20 00:57:58 +0100215 *_bp += xdr_size(xdr);
David Howells38355ee2020-04-08 16:13:20 +0100216 return;
David Howells30062bd2018-10-20 00:57:58 +0100217
218bad:
219 xdr_dump_bad(*_bp);
David Howells7126ead2020-04-08 16:49:08 +0100220 afs_protocol_error(call, afs_eproto_bad_status);
David Howellsc72057b2020-04-08 16:13:20 +0100221 goto advance;
David Howells30062bd2018-10-20 00:57:58 +0100222}
223
224/*
David Howellsa58823a2019-05-09 15:16:10 +0100225 * Decode a YFSCallBack block
David Howells30062bd2018-10-20 00:57:58 +0100226 */
David Howellsa58823a2019-05-09 15:16:10 +0100227static void xdr_decode_YFSCallBack(const __be32 **_bp,
228 struct afs_call *call,
229 struct afs_status_cb *scb)
David Howells78107052019-05-09 17:56:53 +0100230{
231 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
David Howellsa58823a2019-05-09 15:16:10 +0100232 struct afs_callback *cb = &scb->callback;
David Howells78107052019-05-09 17:56:53 +0100233 ktime_t cb_expiry;
234
235 cb_expiry = call->reply_time;
236 cb_expiry = ktime_add(cb_expiry, xdr_to_u64(x->expiration_time) * 100);
237 cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
David Howellsa58823a2019-05-09 15:16:10 +0100238 scb->have_cb = true;
David Howells78107052019-05-09 17:56:53 +0100239 *_bp += xdr_size(x);
240}
241
David Howells30062bd2018-10-20 00:57:58 +0100242/*
David Howells30062bd2018-10-20 00:57:58 +0100243 * Decode a YFSVolSync block
244 */
245static void xdr_decode_YFSVolSync(const __be32 **_bp,
246 struct afs_volsync *volsync)
247{
248 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
249 u64 creation;
250
251 if (volsync) {
252 creation = xdr_to_u64(x->vol_creation_date);
253 do_div(creation, 10 * 1000 * 1000);
254 volsync->creation = creation;
255 }
256
257 *_bp += xdr_size(x);
258}
259
260/*
261 * Encode the requested attributes into a YFSStoreStatus block
262 */
263static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
264{
265 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
266 s64 mtime = 0, owner = 0, group = 0;
267 u32 mask = 0, mode = 0;
268
269 mask = 0;
270 if (attr->ia_valid & ATTR_MTIME) {
271 mask |= AFS_SET_MTIME;
272 mtime = linux_to_yfs_time(&attr->ia_mtime);
273 }
274
275 if (attr->ia_valid & ATTR_UID) {
276 mask |= AFS_SET_OWNER;
277 owner = from_kuid(&init_user_ns, attr->ia_uid);
278 }
279
280 if (attr->ia_valid & ATTR_GID) {
281 mask |= AFS_SET_GROUP;
282 group = from_kgid(&init_user_ns, attr->ia_gid);
283 }
284
285 if (attr->ia_valid & ATTR_MODE) {
286 mask |= AFS_SET_MODE;
287 mode = attr->ia_mode & S_IALLUGO;
288 }
289
290 x->mask = htonl(mask);
291 x->mode = htonl(mode);
292 x->mtime_client = u64_to_xdr(mtime);
293 x->owner = u64_to_xdr(owner);
294 x->group = u64_to_xdr(group);
295 return bp + xdr_size(x);
296}
297
298/*
299 * Decode a YFSFetchVolumeStatus block.
300 */
301static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
302 struct afs_volume_status *vs)
303{
304 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
305 u32 flags;
306
307 vs->vid = xdr_to_u64(x->vid);
308 vs->parent_id = xdr_to_u64(x->parent_id);
309 flags = ntohl(x->flags);
310 vs->online = flags & yfs_FVSOnline;
311 vs->in_service = flags & yfs_FVSInservice;
312 vs->blessed = flags & yfs_FVSBlessed;
313 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
314 vs->type = ntohl(x->type);
315 vs->min_quota = 0;
316 vs->max_quota = xdr_to_u64(x->max_quota);
317 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
318 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
319 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
320 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
321 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
322 *_bp += sizeof(*x) / sizeof(__be32);
323}
324
325/*
David Howellsa58823a2019-05-09 15:16:10 +0100326 * Deliver reply data to operations that just return a file status and a volume
327 * sync record.
328 */
329static int yfs_deliver_status_and_volsync(struct afs_call *call)
330{
David Howellse49c7b22020-04-10 20:51:51 +0100331 struct afs_operation *op = call->op;
David Howellsa58823a2019-05-09 15:16:10 +0100332 const __be32 *bp;
333 int ret;
334
335 ret = afs_transfer_reply(call);
336 if (ret < 0)
337 return ret;
338
339 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100340 xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
341 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100342
343 _leave(" = 0 [done]");
344 return 0;
345}
346
347/*
David Howells30062bd2018-10-20 00:57:58 +0100348 * Deliver reply data to an YFS.FetchData64.
349 */
350static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
351{
David Howellse49c7b22020-04-10 20:51:51 +0100352 struct afs_operation *op = call->op;
353 struct afs_vnode_param *vp = &op->file[0];
354 struct afs_read *req = op->fetch.req;
David Howells30062bd2018-10-20 00:57:58 +0100355 const __be32 *bp;
David Howells30062bd2018-10-20 00:57:58 +0100356 int ret;
357
David Howellsf105da12020-02-06 14:22:28 +0000358 _enter("{%u,%zu, %zu/%llu}",
359 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
360 req->actual_len);
David Howells30062bd2018-10-20 00:57:58 +0100361
362 switch (call->unmarshall) {
363 case 0:
364 req->actual_len = 0;
David Howells30062bd2018-10-20 00:57:58 +0100365 afs_extract_to_tmp64(call);
366 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500367 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +0100368
David Howellsc4508462020-02-06 14:22:28 +0000369 /* Extract the returned data length into ->actual_len. This
370 * may indicate more or less data than was requested will be
371 * returned.
372 */
David Howells30062bd2018-10-20 00:57:58 +0100373 case 1:
374 _debug("extract data length");
375 ret = afs_extract_data(call, true);
376 if (ret < 0)
377 return ret;
378
379 req->actual_len = be64_to_cpu(call->tmp64);
380 _debug("DATA length: %llu", req->actual_len);
David Howellsc4508462020-02-06 14:22:28 +0000381
382 if (req->actual_len == 0)
David Howells30062bd2018-10-20 00:57:58 +0100383 goto no_more_data;
384
David Howellsc4508462020-02-06 14:22:28 +0000385 call->iter = req->iter;
386 call->iov_len = min(req->actual_len, req->len);
David Howells30062bd2018-10-20 00:57:58 +0100387 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500388 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +0100389
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -0500390 /* extract the returned data */
David Howells30062bd2018-10-20 00:57:58 +0100391 case 2:
392 _debug("extract data %zu/%llu",
David Howellsc4508462020-02-06 14:22:28 +0000393 iov_iter_count(call->iter), req->actual_len);
David Howells30062bd2018-10-20 00:57:58 +0100394
395 ret = afs_extract_data(call, true);
396 if (ret < 0)
397 return ret;
David Howells30062bd2018-10-20 00:57:58 +0100398
David Howellsc4508462020-02-06 14:22:28 +0000399 call->iter = &call->def_iter;
David Howells30062bd2018-10-20 00:57:58 +0100400 if (req->actual_len <= req->len)
401 goto no_more_data;
402
403 /* Discard any excess data the server gave us */
David Howells23a28912019-08-20 09:22:38 +0100404 afs_extract_discard(call, req->actual_len - req->len);
David Howells30062bd2018-10-20 00:57:58 +0100405 call->unmarshall = 3;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500406 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -0500407
David Howells30062bd2018-10-20 00:57:58 +0100408 case 3:
409 _debug("extract discard %zu/%llu",
David Howellsfc276122019-11-21 09:12:17 +0000410 iov_iter_count(call->iter), req->actual_len - req->len);
David Howells30062bd2018-10-20 00:57:58 +0100411
412 ret = afs_extract_data(call, true);
413 if (ret < 0)
414 return ret;
415
416 no_more_data:
417 call->unmarshall = 4;
418 afs_extract_to_buf(call,
419 sizeof(struct yfs_xdr_YFSFetchStatus) +
420 sizeof(struct yfs_xdr_YFSCallBack) +
421 sizeof(struct yfs_xdr_YFSVolSync));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500422 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +0100423
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -0500424 /* extract the metadata */
David Howells30062bd2018-10-20 00:57:58 +0100425 case 4:
426 ret = afs_extract_data(call, false);
427 if (ret < 0)
428 return ret;
429
430 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100431 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
432 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
433 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100434
David Howellse49c7b22020-04-10 20:51:51 +0100435 req->data_version = vp->scb.status.data_version;
436 req->file_size = vp->scb.status.size;
David Howellsa58823a2019-05-09 15:16:10 +0100437
David Howells30062bd2018-10-20 00:57:58 +0100438 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500439 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -0500440
David Howells30062bd2018-10-20 00:57:58 +0100441 case 5:
442 break;
443 }
444
David Howells30062bd2018-10-20 00:57:58 +0100445 _leave(" = 0 [done]");
446 return 0;
447}
448
David Howells30062bd2018-10-20 00:57:58 +0100449/*
450 * YFS.FetchData64 operation type
451 */
452static const struct afs_call_type yfs_RXYFSFetchData64 = {
453 .name = "YFS.FetchData64",
454 .op = yfs_FS_FetchData64,
455 .deliver = yfs_deliver_fs_fetch_data64,
David Howellse49c7b22020-04-10 20:51:51 +0100456 .destructor = afs_flat_call_destructor,
David Howells30062bd2018-10-20 00:57:58 +0100457};
458
459/*
460 * Fetch data from a file.
461 */
David Howellse49c7b22020-04-10 20:51:51 +0100462void yfs_fs_fetch_data(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100463{
David Howellse49c7b22020-04-10 20:51:51 +0100464 struct afs_vnode_param *vp = &op->file[0];
465 struct afs_read *req = op->fetch.req;
David Howells30062bd2018-10-20 00:57:58 +0100466 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100467 __be32 *bp;
468
469 _enter(",%x,{%llx:%llu},%llx,%llx",
David Howellse49c7b22020-04-10 20:51:51 +0100470 key_serial(op->key), vp->fid.vid, vp->fid.vnode,
David Howells30062bd2018-10-20 00:57:58 +0100471 req->pos, req->len);
472
David Howellse49c7b22020-04-10 20:51:51 +0100473 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
David Howells30062bd2018-10-20 00:57:58 +0100474 sizeof(__be32) * 2 +
475 sizeof(struct yfs_xdr_YFSFid) +
476 sizeof(struct yfs_xdr_u64) * 2,
477 sizeof(struct yfs_xdr_YFSFetchStatus) +
478 sizeof(struct yfs_xdr_YFSCallBack) +
479 sizeof(struct yfs_xdr_YFSVolSync));
480 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100481 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100482
David Howellsc4508462020-02-06 14:22:28 +0000483 req->call_debug_id = call->debug_id;
484
David Howells30062bd2018-10-20 00:57:58 +0100485 /* marshall the parameters */
486 bp = call->request;
487 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
488 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100489 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +0100490 bp = xdr_encode_u64(bp, req->pos);
491 bp = xdr_encode_u64(bp, req->len);
492 yfs_check_req(call, bp);
493
David Howellse49c7b22020-04-10 20:51:51 +0100494 trace_afs_make_fs_call(call, &vp->fid);
495 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100496}
497
498/*
499 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
500 */
501static int yfs_deliver_fs_create_vnode(struct afs_call *call)
502{
David Howellse49c7b22020-04-10 20:51:51 +0100503 struct afs_operation *op = call->op;
504 struct afs_vnode_param *dvp = &op->file[0];
505 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100506 const __be32 *bp;
507 int ret;
508
509 _enter("{%u}", call->unmarshall);
510
511 ret = afs_transfer_reply(call);
512 if (ret < 0)
513 return ret;
514
515 /* unmarshall the reply once we've received all of it */
516 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100517 xdr_decode_YFSFid(&bp, &op->file[1].fid);
518 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
519 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
520 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
521 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100522
523 _leave(" = 0 [done]");
524 return 0;
525}
526
527/*
528 * FS.CreateFile and FS.MakeDir operation type
529 */
530static const struct afs_call_type afs_RXFSCreateFile = {
531 .name = "YFS.CreateFile",
532 .op = yfs_FS_CreateFile,
533 .deliver = yfs_deliver_fs_create_vnode,
534 .destructor = afs_flat_call_destructor,
535};
536
537/*
538 * Create a file.
539 */
David Howellse49c7b22020-04-10 20:51:51 +0100540void yfs_fs_create_file(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100541{
David Howellse49c7b22020-04-10 20:51:51 +0100542 const struct qstr *name = &op->dentry->d_name;
543 struct afs_vnode_param *dvp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +0100544 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +0100545 size_t reqsz, rplsz;
David Howells30062bd2018-10-20 00:57:58 +0100546 __be32 *bp;
547
548 _enter("");
549
David Howells30062bd2018-10-20 00:57:58 +0100550 reqsz = (sizeof(__be32) +
551 sizeof(__be32) +
552 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +0100553 xdr_strlen(name->len) +
David Howells30062bd2018-10-20 00:57:58 +0100554 sizeof(struct yfs_xdr_YFSStoreStatus) +
555 sizeof(__be32));
556 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
557 sizeof(struct yfs_xdr_YFSFetchStatus) +
558 sizeof(struct yfs_xdr_YFSFetchStatus) +
559 sizeof(struct yfs_xdr_YFSCallBack) +
560 sizeof(struct yfs_xdr_YFSVolSync));
561
David Howellse49c7b22020-04-10 20:51:51 +0100562 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
David Howells30062bd2018-10-20 00:57:58 +0100563 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100564 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100565
566 /* marshall the parameters */
567 bp = call->request;
568 bp = xdr_encode_u32(bp, YFSCREATEFILE);
569 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100570 bp = xdr_encode_YFSFid(bp, &dvp->fid);
571 bp = xdr_encode_name(bp, name);
Marc Dionne52af7102021-10-20 09:51:43 -0300572 bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
Marc Dionne5edc22c2019-01-09 17:23:54 +0000573 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
David Howells30062bd2018-10-20 00:57:58 +0100574 yfs_check_req(call, bp);
575
David Howellse49c7b22020-04-10 20:51:51 +0100576 trace_afs_make_fs_call1(call, &dvp->fid, name);
577 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100578}
579
580static const struct afs_call_type yfs_RXFSMakeDir = {
581 .name = "YFS.MakeDir",
582 .op = yfs_FS_MakeDir,
583 .deliver = yfs_deliver_fs_create_vnode,
584 .destructor = afs_flat_call_destructor,
585};
586
587/*
588 * Make a directory.
589 */
David Howellse49c7b22020-04-10 20:51:51 +0100590void yfs_fs_make_dir(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100591{
David Howellse49c7b22020-04-10 20:51:51 +0100592 const struct qstr *name = &op->dentry->d_name;
593 struct afs_vnode_param *dvp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +0100594 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +0100595 size_t reqsz, rplsz;
David Howells30062bd2018-10-20 00:57:58 +0100596 __be32 *bp;
597
598 _enter("");
599
David Howells30062bd2018-10-20 00:57:58 +0100600 reqsz = (sizeof(__be32) +
601 sizeof(struct yfs_xdr_RPCFlags) +
602 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +0100603 xdr_strlen(name->len) +
David Howells30062bd2018-10-20 00:57:58 +0100604 sizeof(struct yfs_xdr_YFSStoreStatus));
605 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
606 sizeof(struct yfs_xdr_YFSFetchStatus) +
607 sizeof(struct yfs_xdr_YFSFetchStatus) +
608 sizeof(struct yfs_xdr_YFSCallBack) +
609 sizeof(struct yfs_xdr_YFSVolSync));
610
David Howellse49c7b22020-04-10 20:51:51 +0100611 call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
David Howells30062bd2018-10-20 00:57:58 +0100612 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100613 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100614
615 /* marshall the parameters */
616 bp = call->request;
617 bp = xdr_encode_u32(bp, YFSMAKEDIR);
618 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100619 bp = xdr_encode_YFSFid(bp, &dvp->fid);
620 bp = xdr_encode_name(bp, name);
Marc Dionne52af7102021-10-20 09:51:43 -0300621 bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
David Howells30062bd2018-10-20 00:57:58 +0100622 yfs_check_req(call, bp);
623
David Howellse49c7b22020-04-10 20:51:51 +0100624 trace_afs_make_fs_call1(call, &dvp->fid, name);
625 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100626}
627
628/*
629 * Deliver reply data to a YFS.RemoveFile2 operation.
630 */
631static int yfs_deliver_fs_remove_file2(struct afs_call *call)
632{
David Howellse49c7b22020-04-10 20:51:51 +0100633 struct afs_operation *op = call->op;
634 struct afs_vnode_param *dvp = &op->file[0];
635 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100636 struct afs_fid fid;
637 const __be32 *bp;
638 int ret;
639
640 _enter("{%u}", call->unmarshall);
641
642 ret = afs_transfer_reply(call);
643 if (ret < 0)
644 return ret;
645
David Howells30062bd2018-10-20 00:57:58 +0100646 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100647 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
David Howells30062bd2018-10-20 00:57:58 +0100648 xdr_decode_YFSFid(&bp, &fid);
David Howellse49c7b22020-04-10 20:51:51 +0100649 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
David Howells30062bd2018-10-20 00:57:58 +0100650 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
651
David Howellse49c7b22020-04-10 20:51:51 +0100652 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100653 return 0;
654}
655
David Howellse49c7b22020-04-10 20:51:51 +0100656static void yfs_done_fs_remove_file2(struct afs_call *call)
657{
658 if (call->error == -ECONNABORTED &&
659 call->abort_code == RX_INVALID_OPERATION) {
660 set_bit(AFS_SERVER_FL_NO_RM2, &call->server->flags);
661 call->op->flags |= AFS_OPERATION_DOWNGRADE;
662 }
663}
664
David Howells30062bd2018-10-20 00:57:58 +0100665/*
666 * YFS.RemoveFile2 operation type.
667 */
668static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
669 .name = "YFS.RemoveFile2",
670 .op = yfs_FS_RemoveFile2,
671 .deliver = yfs_deliver_fs_remove_file2,
David Howellse49c7b22020-04-10 20:51:51 +0100672 .done = yfs_done_fs_remove_file2,
David Howells30062bd2018-10-20 00:57:58 +0100673 .destructor = afs_flat_call_destructor,
674};
675
676/*
677 * Remove a file and retrieve new file status.
678 */
David Howellse49c7b22020-04-10 20:51:51 +0100679void yfs_fs_remove_file2(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100680{
David Howellse49c7b22020-04-10 20:51:51 +0100681 struct afs_vnode_param *dvp = &op->file[0];
682 const struct qstr *name = &op->dentry->d_name;
David Howells30062bd2018-10-20 00:57:58 +0100683 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100684 __be32 *bp;
685
686 _enter("");
687
David Howellse49c7b22020-04-10 20:51:51 +0100688 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
David Howells30062bd2018-10-20 00:57:58 +0100689 sizeof(__be32) +
690 sizeof(struct yfs_xdr_RPCFlags) +
691 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +0100692 xdr_strlen(name->len),
David Howells30062bd2018-10-20 00:57:58 +0100693 sizeof(struct yfs_xdr_YFSFetchStatus) +
694 sizeof(struct yfs_xdr_YFSFid) +
695 sizeof(struct yfs_xdr_YFSFetchStatus) +
696 sizeof(struct yfs_xdr_YFSVolSync));
697 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100698 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100699
700 /* marshall the parameters */
701 bp = call->request;
702 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
703 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100704 bp = xdr_encode_YFSFid(bp, &dvp->fid);
705 bp = xdr_encode_name(bp, name);
David Howells30062bd2018-10-20 00:57:58 +0100706 yfs_check_req(call, bp);
707
David Howellse49c7b22020-04-10 20:51:51 +0100708 trace_afs_make_fs_call1(call, &dvp->fid, name);
709 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100710}
711
712/*
713 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
714 */
715static int yfs_deliver_fs_remove(struct afs_call *call)
716{
David Howellse49c7b22020-04-10 20:51:51 +0100717 struct afs_operation *op = call->op;
718 struct afs_vnode_param *dvp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +0100719 const __be32 *bp;
720 int ret;
721
722 _enter("{%u}", call->unmarshall);
723
724 ret = afs_transfer_reply(call);
725 if (ret < 0)
726 return ret;
727
David Howells30062bd2018-10-20 00:57:58 +0100728 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100729 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
730 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100731 return 0;
732}
733
734/*
735 * FS.RemoveDir and FS.RemoveFile operation types.
736 */
737static const struct afs_call_type yfs_RXYFSRemoveFile = {
738 .name = "YFS.RemoveFile",
739 .op = yfs_FS_RemoveFile,
740 .deliver = yfs_deliver_fs_remove,
741 .destructor = afs_flat_call_destructor,
742};
743
David Howellse49c7b22020-04-10 20:51:51 +0100744/*
745 * Remove a file.
746 */
747void yfs_fs_remove_file(struct afs_operation *op)
748{
749 const struct qstr *name = &op->dentry->d_name;
750 struct afs_vnode_param *dvp = &op->file[0];
751 struct afs_call *call;
752 __be32 *bp;
753
754 _enter("");
755
David Howells20325962020-04-30 01:03:49 +0100756 if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
David Howellse49c7b22020-04-10 20:51:51 +0100757 return yfs_fs_remove_file2(op);
758
759 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
760 sizeof(__be32) +
761 sizeof(struct yfs_xdr_RPCFlags) +
762 sizeof(struct yfs_xdr_YFSFid) +
763 xdr_strlen(name->len),
764 sizeof(struct yfs_xdr_YFSFetchStatus) +
765 sizeof(struct yfs_xdr_YFSVolSync));
766 if (!call)
767 return afs_op_nomem(op);
768
769 /* marshall the parameters */
770 bp = call->request;
771 bp = xdr_encode_u32(bp, YFSREMOVEFILE);
772 bp = xdr_encode_u32(bp, 0); /* RPC flags */
773 bp = xdr_encode_YFSFid(bp, &dvp->fid);
774 bp = xdr_encode_name(bp, name);
775 yfs_check_req(call, bp);
776
777 trace_afs_make_fs_call1(call, &dvp->fid, name);
778 afs_make_op_call(op, call, GFP_NOFS);
779}
780
David Howells30062bd2018-10-20 00:57:58 +0100781static const struct afs_call_type yfs_RXYFSRemoveDir = {
782 .name = "YFS.RemoveDir",
783 .op = yfs_FS_RemoveDir,
784 .deliver = yfs_deliver_fs_remove,
785 .destructor = afs_flat_call_destructor,
786};
787
788/*
David Howellse49c7b22020-04-10 20:51:51 +0100789 * Remove a directory.
David Howells30062bd2018-10-20 00:57:58 +0100790 */
David Howellse49c7b22020-04-10 20:51:51 +0100791void yfs_fs_remove_dir(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100792{
David Howellse49c7b22020-04-10 20:51:51 +0100793 const struct qstr *name = &op->dentry->d_name;
794 struct afs_vnode_param *dvp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +0100795 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100796 __be32 *bp;
797
798 _enter("");
799
David Howellse49c7b22020-04-10 20:51:51 +0100800 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
801 sizeof(__be32) +
802 sizeof(struct yfs_xdr_RPCFlags) +
803 sizeof(struct yfs_xdr_YFSFid) +
804 xdr_strlen(name->len),
805 sizeof(struct yfs_xdr_YFSFetchStatus) +
806 sizeof(struct yfs_xdr_YFSVolSync));
David Howells30062bd2018-10-20 00:57:58 +0100807 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100808 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100809
810 /* marshall the parameters */
811 bp = call->request;
David Howellse49c7b22020-04-10 20:51:51 +0100812 bp = xdr_encode_u32(bp, YFSREMOVEDIR);
David Howells30062bd2018-10-20 00:57:58 +0100813 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100814 bp = xdr_encode_YFSFid(bp, &dvp->fid);
815 bp = xdr_encode_name(bp, name);
David Howells30062bd2018-10-20 00:57:58 +0100816 yfs_check_req(call, bp);
817
David Howellse49c7b22020-04-10 20:51:51 +0100818 trace_afs_make_fs_call1(call, &dvp->fid, name);
819 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100820}
821
822/*
823 * Deliver reply data to a YFS.Link operation.
824 */
825static int yfs_deliver_fs_link(struct afs_call *call)
826{
David Howellse49c7b22020-04-10 20:51:51 +0100827 struct afs_operation *op = call->op;
828 struct afs_vnode_param *dvp = &op->file[0];
829 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100830 const __be32 *bp;
831 int ret;
832
833 _enter("{%u}", call->unmarshall);
834
835 ret = afs_transfer_reply(call);
836 if (ret < 0)
837 return ret;
838
David Howells30062bd2018-10-20 00:57:58 +0100839 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100840 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
841 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
842 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100843 _leave(" = 0 [done]");
844 return 0;
845}
846
847/*
848 * YFS.Link operation type.
849 */
850static const struct afs_call_type yfs_RXYFSLink = {
851 .name = "YFS.Link",
852 .op = yfs_FS_Link,
853 .deliver = yfs_deliver_fs_link,
854 .destructor = afs_flat_call_destructor,
855};
856
857/*
858 * Make a hard link.
859 */
David Howellse49c7b22020-04-10 20:51:51 +0100860void yfs_fs_link(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100861{
David Howellse49c7b22020-04-10 20:51:51 +0100862 const struct qstr *name = &op->dentry->d_name;
863 struct afs_vnode_param *dvp = &op->file[0];
864 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100865 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100866 __be32 *bp;
867
868 _enter("");
869
David Howellse49c7b22020-04-10 20:51:51 +0100870 call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
David Howells30062bd2018-10-20 00:57:58 +0100871 sizeof(__be32) +
872 sizeof(struct yfs_xdr_RPCFlags) +
873 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +0100874 xdr_strlen(name->len) +
David Howells30062bd2018-10-20 00:57:58 +0100875 sizeof(struct yfs_xdr_YFSFid),
876 sizeof(struct yfs_xdr_YFSFetchStatus) +
877 sizeof(struct yfs_xdr_YFSFetchStatus) +
878 sizeof(struct yfs_xdr_YFSVolSync));
879 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100880 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100881
882 /* marshall the parameters */
883 bp = call->request;
884 bp = xdr_encode_u32(bp, YFSLINK);
885 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100886 bp = xdr_encode_YFSFid(bp, &dvp->fid);
887 bp = xdr_encode_name(bp, name);
888 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +0100889 yfs_check_req(call, bp);
890
David Howellse49c7b22020-04-10 20:51:51 +0100891 trace_afs_make_fs_call1(call, &vp->fid, name);
892 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100893}
894
895/*
896 * Deliver reply data to a YFS.Symlink operation.
897 */
898static int yfs_deliver_fs_symlink(struct afs_call *call)
899{
David Howellse49c7b22020-04-10 20:51:51 +0100900 struct afs_operation *op = call->op;
901 struct afs_vnode_param *dvp = &op->file[0];
902 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100903 const __be32 *bp;
904 int ret;
905
906 _enter("{%u}", call->unmarshall);
907
908 ret = afs_transfer_reply(call);
909 if (ret < 0)
910 return ret;
911
912 /* unmarshall the reply once we've received all of it */
913 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100914 xdr_decode_YFSFid(&bp, &vp->fid);
915 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
916 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
917 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100918
919 _leave(" = 0 [done]");
920 return 0;
921}
922
923/*
924 * YFS.Symlink operation type
925 */
926static const struct afs_call_type yfs_RXYFSSymlink = {
927 .name = "YFS.Symlink",
928 .op = yfs_FS_Symlink,
929 .deliver = yfs_deliver_fs_symlink,
930 .destructor = afs_flat_call_destructor,
931};
932
933/*
934 * Create a symbolic link.
935 */
David Howellse49c7b22020-04-10 20:51:51 +0100936void yfs_fs_symlink(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100937{
David Howellse49c7b22020-04-10 20:51:51 +0100938 const struct qstr *name = &op->dentry->d_name;
939 struct afs_vnode_param *dvp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +0100940 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +0100941 size_t contents_sz;
Marc Dionne52af7102021-10-20 09:51:43 -0300942 mode_t mode = 0777;
David Howells30062bd2018-10-20 00:57:58 +0100943 __be32 *bp;
944
945 _enter("");
946
David Howellse49c7b22020-04-10 20:51:51 +0100947 contents_sz = strlen(op->create.symlink);
948 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
David Howells30062bd2018-10-20 00:57:58 +0100949 sizeof(__be32) +
950 sizeof(struct yfs_xdr_RPCFlags) +
951 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +0100952 xdr_strlen(name->len) +
David Howells30062bd2018-10-20 00:57:58 +0100953 xdr_strlen(contents_sz) +
954 sizeof(struct yfs_xdr_YFSStoreStatus),
955 sizeof(struct yfs_xdr_YFSFid) +
956 sizeof(struct yfs_xdr_YFSFetchStatus) +
957 sizeof(struct yfs_xdr_YFSFetchStatus) +
958 sizeof(struct yfs_xdr_YFSVolSync));
959 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100960 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100961
962 /* marshall the parameters */
963 bp = call->request;
964 bp = xdr_encode_u32(bp, YFSSYMLINK);
965 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100966 bp = xdr_encode_YFSFid(bp, &dvp->fid);
967 bp = xdr_encode_name(bp, name);
968 bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
Marc Dionne52af7102021-10-20 09:51:43 -0300969 bp = xdr_encode_YFSStoreStatus(bp, &mode, &op->mtime);
David Howells30062bd2018-10-20 00:57:58 +0100970 yfs_check_req(call, bp);
971
David Howellse49c7b22020-04-10 20:51:51 +0100972 trace_afs_make_fs_call1(call, &dvp->fid, name);
973 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100974}
975
976/*
977 * Deliver reply data to a YFS.Rename operation.
978 */
979static int yfs_deliver_fs_rename(struct afs_call *call)
980{
David Howellse49c7b22020-04-10 20:51:51 +0100981 struct afs_operation *op = call->op;
982 struct afs_vnode_param *orig_dvp = &op->file[0];
983 struct afs_vnode_param *new_dvp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100984 const __be32 *bp;
985 int ret;
986
987 _enter("{%u}", call->unmarshall);
988
989 ret = afs_transfer_reply(call);
990 if (ret < 0)
991 return ret;
992
David Howells30062bd2018-10-20 00:57:58 +0100993 bp = call->buffer;
David Howells38355ee2020-04-08 16:13:20 +0100994 /* If the two dirs are the same, we have two copies of the same status
995 * report, so we just decode it twice.
996 */
David Howellse49c7b22020-04-10 20:51:51 +0100997 xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
998 xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
999 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +01001000 _leave(" = 0 [done]");
1001 return 0;
1002}
1003
1004/*
1005 * YFS.Rename operation type
1006 */
1007static const struct afs_call_type yfs_RXYFSRename = {
1008 .name = "FS.Rename",
1009 .op = yfs_FS_Rename,
1010 .deliver = yfs_deliver_fs_rename,
1011 .destructor = afs_flat_call_destructor,
1012};
1013
1014/*
1015 * Rename a file or directory.
1016 */
David Howellse49c7b22020-04-10 20:51:51 +01001017void yfs_fs_rename(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001018{
David Howellse49c7b22020-04-10 20:51:51 +01001019 struct afs_vnode_param *orig_dvp = &op->file[0];
1020 struct afs_vnode_param *new_dvp = &op->file[1];
1021 const struct qstr *orig_name = &op->dentry->d_name;
1022 const struct qstr *new_name = &op->dentry_2->d_name;
David Howells30062bd2018-10-20 00:57:58 +01001023 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001024 __be32 *bp;
1025
1026 _enter("");
1027
David Howellse49c7b22020-04-10 20:51:51 +01001028 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
David Howells30062bd2018-10-20 00:57:58 +01001029 sizeof(__be32) +
1030 sizeof(struct yfs_xdr_RPCFlags) +
1031 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +01001032 xdr_strlen(orig_name->len) +
David Howells30062bd2018-10-20 00:57:58 +01001033 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +01001034 xdr_strlen(new_name->len),
David Howells30062bd2018-10-20 00:57:58 +01001035 sizeof(struct yfs_xdr_YFSFetchStatus) +
1036 sizeof(struct yfs_xdr_YFSFetchStatus) +
1037 sizeof(struct yfs_xdr_YFSVolSync));
1038 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001039 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001040
1041 /* marshall the parameters */
1042 bp = call->request;
1043 bp = xdr_encode_u32(bp, YFSRENAME);
1044 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001045 bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
1046 bp = xdr_encode_name(bp, orig_name);
1047 bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
1048 bp = xdr_encode_name(bp, new_name);
David Howells30062bd2018-10-20 00:57:58 +01001049 yfs_check_req(call, bp);
1050
David Howellse49c7b22020-04-10 20:51:51 +01001051 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1052 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001053}
1054
1055/*
David Howells30062bd2018-10-20 00:57:58 +01001056 * YFS.StoreData64 operation type.
1057 */
1058static const struct afs_call_type yfs_RXYFSStoreData64 = {
1059 .name = "YFS.StoreData64",
1060 .op = yfs_FS_StoreData64,
David Howellsa58823a2019-05-09 15:16:10 +01001061 .deliver = yfs_deliver_status_and_volsync,
David Howells30062bd2018-10-20 00:57:58 +01001062 .destructor = afs_flat_call_destructor,
1063};
1064
1065/*
1066 * Store a set of pages to a large file.
1067 */
David Howellse49c7b22020-04-10 20:51:51 +01001068void yfs_fs_store_data(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001069{
David Howellse49c7b22020-04-10 20:51:51 +01001070 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001071 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001072 __be32 *bp;
1073
1074 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001075 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells30062bd2018-10-20 00:57:58 +01001076
David Howells30062bd2018-10-20 00:57:58 +01001077 _debug("size %llx, at %llx, i_size %llx",
David Howellsbd80d8a2020-02-06 14:22:28 +00001078 (unsigned long long)op->store.size,
1079 (unsigned long long)op->store.pos,
1080 (unsigned long long)op->store.i_size);
David Howells30062bd2018-10-20 00:57:58 +01001081
David Howellse49c7b22020-04-10 20:51:51 +01001082 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
David Howells30062bd2018-10-20 00:57:58 +01001083 sizeof(__be32) +
1084 sizeof(__be32) +
1085 sizeof(struct yfs_xdr_YFSFid) +
1086 sizeof(struct yfs_xdr_YFSStoreStatus) +
1087 sizeof(struct yfs_xdr_u64) * 3,
1088 sizeof(struct yfs_xdr_YFSFetchStatus) +
1089 sizeof(struct yfs_xdr_YFSVolSync));
1090 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001091 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001092
David Howellsbd80d8a2020-02-06 14:22:28 +00001093 call->write_iter = op->store.write_iter;
David Howells30062bd2018-10-20 00:57:58 +01001094
1095 /* marshall the parameters */
1096 bp = call->request;
1097 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1098 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001099 bp = xdr_encode_YFSFid(bp, &vp->fid);
Marc Dionne52af7102021-10-20 09:51:43 -03001100 bp = xdr_encode_YFSStoreStatus(bp, NULL, &op->mtime);
David Howellsbd80d8a2020-02-06 14:22:28 +00001101 bp = xdr_encode_u64(bp, op->store.pos);
1102 bp = xdr_encode_u64(bp, op->store.size);
1103 bp = xdr_encode_u64(bp, op->store.i_size);
David Howells30062bd2018-10-20 00:57:58 +01001104 yfs_check_req(call, bp);
1105
David Howellse49c7b22020-04-10 20:51:51 +01001106 trace_afs_make_fs_call(call, &vp->fid);
1107 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001108}
1109
1110/*
David Howells30062bd2018-10-20 00:57:58 +01001111 * YFS.StoreStatus operation type
1112 */
1113static const struct afs_call_type yfs_RXYFSStoreStatus = {
1114 .name = "YFS.StoreStatus",
1115 .op = yfs_FS_StoreStatus,
David Howellsa58823a2019-05-09 15:16:10 +01001116 .deliver = yfs_deliver_status_and_volsync,
David Howells30062bd2018-10-20 00:57:58 +01001117 .destructor = afs_flat_call_destructor,
1118};
1119
1120static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1121 .name = "YFS.StoreData64",
1122 .op = yfs_FS_StoreData64,
David Howellsa58823a2019-05-09 15:16:10 +01001123 .deliver = yfs_deliver_status_and_volsync,
David Howells30062bd2018-10-20 00:57:58 +01001124 .destructor = afs_flat_call_destructor,
1125};
1126
1127/*
1128 * Set the attributes on a file, using YFS.StoreData64 rather than
1129 * YFS.StoreStatus so as to alter the file size also.
1130 */
David Howellse49c7b22020-04-10 20:51:51 +01001131static void yfs_fs_setattr_size(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001132{
David Howellse49c7b22020-04-10 20:51:51 +01001133 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001134 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +01001135 struct iattr *attr = op->setattr.attr;
David Howells30062bd2018-10-20 00:57:58 +01001136 __be32 *bp;
1137
1138 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001139 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells30062bd2018-10-20 00:57:58 +01001140
David Howellse49c7b22020-04-10 20:51:51 +01001141 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
David Howells30062bd2018-10-20 00:57:58 +01001142 sizeof(__be32) * 2 +
1143 sizeof(struct yfs_xdr_YFSFid) +
1144 sizeof(struct yfs_xdr_YFSStoreStatus) +
1145 sizeof(struct yfs_xdr_u64) * 3,
1146 sizeof(struct yfs_xdr_YFSFetchStatus) +
1147 sizeof(struct yfs_xdr_YFSVolSync));
1148 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001149 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001150
1151 /* marshall the parameters */
1152 bp = call->request;
1153 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1154 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001155 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +01001156 bp = xdr_encode_YFS_StoreStatus(bp, attr);
David Howells8c7ae382019-03-27 22:48:02 +00001157 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
David Howells30062bd2018-10-20 00:57:58 +01001158 bp = xdr_encode_u64(bp, 0); /* size of write */
1159 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1160 yfs_check_req(call, bp);
1161
David Howellse49c7b22020-04-10 20:51:51 +01001162 trace_afs_make_fs_call(call, &vp->fid);
1163 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001164}
1165
1166/*
1167 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1168 * file size, and YFS.StoreStatus otherwise.
1169 */
David Howellse49c7b22020-04-10 20:51:51 +01001170void yfs_fs_setattr(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001171{
David Howellse49c7b22020-04-10 20:51:51 +01001172 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001173 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +01001174 struct iattr *attr = op->setattr.attr;
David Howells30062bd2018-10-20 00:57:58 +01001175 __be32 *bp;
1176
1177 if (attr->ia_valid & ATTR_SIZE)
David Howellse49c7b22020-04-10 20:51:51 +01001178 return yfs_fs_setattr_size(op);
David Howells30062bd2018-10-20 00:57:58 +01001179
1180 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001181 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells30062bd2018-10-20 00:57:58 +01001182
David Howellse49c7b22020-04-10 20:51:51 +01001183 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
David Howells30062bd2018-10-20 00:57:58 +01001184 sizeof(__be32) * 2 +
1185 sizeof(struct yfs_xdr_YFSFid) +
1186 sizeof(struct yfs_xdr_YFSStoreStatus),
1187 sizeof(struct yfs_xdr_YFSFetchStatus) +
1188 sizeof(struct yfs_xdr_YFSVolSync));
1189 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001190 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001191
1192 /* marshall the parameters */
1193 bp = call->request;
1194 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1195 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001196 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +01001197 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1198 yfs_check_req(call, bp);
1199
David Howellse49c7b22020-04-10 20:51:51 +01001200 trace_afs_make_fs_call(call, &vp->fid);
1201 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001202}
1203
1204/*
1205 * Deliver reply data to a YFS.GetVolumeStatus operation.
1206 */
1207static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1208{
David Howellse49c7b22020-04-10 20:51:51 +01001209 struct afs_operation *op = call->op;
David Howells30062bd2018-10-20 00:57:58 +01001210 const __be32 *bp;
1211 char *p;
1212 u32 size;
1213 int ret;
1214
1215 _enter("{%u}", call->unmarshall);
1216
1217 switch (call->unmarshall) {
1218 case 0:
1219 call->unmarshall++;
1220 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001221 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001222
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001223 /* extract the returned status record */
David Howells30062bd2018-10-20 00:57:58 +01001224 case 1:
1225 _debug("extract status");
1226 ret = afs_extract_data(call, true);
1227 if (ret < 0)
1228 return ret;
1229
1230 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +01001231 xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
David Howells30062bd2018-10-20 00:57:58 +01001232 call->unmarshall++;
1233 afs_extract_to_tmp(call);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001234 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001235
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001236 /* extract the volume name length */
David Howells30062bd2018-10-20 00:57:58 +01001237 case 2:
1238 ret = afs_extract_data(call, true);
1239 if (ret < 0)
1240 return ret;
1241
1242 call->count = ntohl(call->tmp);
1243 _debug("volname length: %u", call->count);
1244 if (call->count >= AFSNAMEMAX)
David Howells7126ead2020-04-08 16:49:08 +01001245 return afs_protocol_error(call, afs_eproto_volname_len);
David Howells30062bd2018-10-20 00:57:58 +01001246 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001247 afs_extract_to_buf(call, size);
David Howells30062bd2018-10-20 00:57:58 +01001248 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001249 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001250
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001251 /* extract the volume name */
David Howells30062bd2018-10-20 00:57:58 +01001252 case 3:
1253 _debug("extract volname");
1254 ret = afs_extract_data(call, true);
1255 if (ret < 0)
1256 return ret;
1257
David Howellsffba7182019-05-09 22:22:50 +01001258 p = call->buffer;
David Howells30062bd2018-10-20 00:57:58 +01001259 p[call->count] = 0;
1260 _debug("volname '%s'", p);
1261 afs_extract_to_tmp(call);
1262 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001263 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001264
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001265 /* extract the offline message length */
David Howells30062bd2018-10-20 00:57:58 +01001266 case 4:
1267 ret = afs_extract_data(call, true);
1268 if (ret < 0)
1269 return ret;
1270
1271 call->count = ntohl(call->tmp);
1272 _debug("offline msg length: %u", call->count);
1273 if (call->count >= AFSNAMEMAX)
David Howells7126ead2020-04-08 16:49:08 +01001274 return afs_protocol_error(call, afs_eproto_offline_msg_len);
David Howells30062bd2018-10-20 00:57:58 +01001275 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001276 afs_extract_to_buf(call, size);
David Howells30062bd2018-10-20 00:57:58 +01001277 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001278 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001279
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001280 /* extract the offline message */
David Howells30062bd2018-10-20 00:57:58 +01001281 case 5:
1282 _debug("extract offline");
1283 ret = afs_extract_data(call, true);
1284 if (ret < 0)
1285 return ret;
1286
David Howellsffba7182019-05-09 22:22:50 +01001287 p = call->buffer;
David Howells30062bd2018-10-20 00:57:58 +01001288 p[call->count] = 0;
1289 _debug("offline '%s'", p);
1290
1291 afs_extract_to_tmp(call);
1292 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001293 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001294
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001295 /* extract the message of the day length */
David Howells30062bd2018-10-20 00:57:58 +01001296 case 6:
1297 ret = afs_extract_data(call, true);
1298 if (ret < 0)
1299 return ret;
1300
1301 call->count = ntohl(call->tmp);
1302 _debug("motd length: %u", call->count);
1303 if (call->count >= AFSNAMEMAX)
David Howells7126ead2020-04-08 16:49:08 +01001304 return afs_protocol_error(call, afs_eproto_motd_len);
David Howells30062bd2018-10-20 00:57:58 +01001305 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001306 afs_extract_to_buf(call, size);
David Howells30062bd2018-10-20 00:57:58 +01001307 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001308 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001309
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001310 /* extract the message of the day */
David Howells30062bd2018-10-20 00:57:58 +01001311 case 7:
1312 _debug("extract motd");
1313 ret = afs_extract_data(call, false);
1314 if (ret < 0)
1315 return ret;
1316
David Howellsffba7182019-05-09 22:22:50 +01001317 p = call->buffer;
David Howells30062bd2018-10-20 00:57:58 +01001318 p[call->count] = 0;
1319 _debug("motd '%s'", p);
1320
1321 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001322 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001323
David Howells30062bd2018-10-20 00:57:58 +01001324 case 8:
1325 break;
1326 }
1327
1328 _leave(" = 0 [done]");
1329 return 0;
1330}
1331
1332/*
David Howells30062bd2018-10-20 00:57:58 +01001333 * YFS.GetVolumeStatus operation type
1334 */
1335static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1336 .name = "YFS.GetVolumeStatus",
1337 .op = yfs_FS_GetVolumeStatus,
1338 .deliver = yfs_deliver_fs_get_volume_status,
David Howellsffba7182019-05-09 22:22:50 +01001339 .destructor = afs_flat_call_destructor,
David Howells30062bd2018-10-20 00:57:58 +01001340};
1341
1342/*
1343 * fetch the status of a volume
1344 */
David Howellse49c7b22020-04-10 20:51:51 +01001345void yfs_fs_get_volume_status(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001346{
David Howellse49c7b22020-04-10 20:51:51 +01001347 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001348 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001349 __be32 *bp;
David Howells30062bd2018-10-20 00:57:58 +01001350
1351 _enter("");
1352
David Howellse49c7b22020-04-10 20:51:51 +01001353 call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
David Howells30062bd2018-10-20 00:57:58 +01001354 sizeof(__be32) * 2 +
1355 sizeof(struct yfs_xdr_u64),
David Howellsffba7182019-05-09 22:22:50 +01001356 max_t(size_t,
1357 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1358 sizeof(__be32),
1359 AFSOPAQUEMAX + 1));
1360 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001361 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001362
1363 /* marshall the parameters */
1364 bp = call->request;
1365 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1366 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001367 bp = xdr_encode_u64(bp, vp->fid.vid);
David Howells30062bd2018-10-20 00:57:58 +01001368 yfs_check_req(call, bp);
1369
David Howellse49c7b22020-04-10 20:51:51 +01001370 trace_afs_make_fs_call(call, &vp->fid);
1371 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001372}
1373
1374/*
David Howells30062bd2018-10-20 00:57:58 +01001375 * YFS.SetLock operation type
1376 */
1377static const struct afs_call_type yfs_RXYFSSetLock = {
1378 .name = "YFS.SetLock",
1379 .op = yfs_FS_SetLock,
David Howellsf5e45462019-05-01 14:05:27 +01001380 .deliver = yfs_deliver_status_and_volsync,
David Howellsa690f602019-04-25 14:26:50 +01001381 .done = afs_lock_op_done,
David Howells30062bd2018-10-20 00:57:58 +01001382 .destructor = afs_flat_call_destructor,
1383};
1384
1385/*
1386 * YFS.ExtendLock operation type
1387 */
1388static const struct afs_call_type yfs_RXYFSExtendLock = {
1389 .name = "YFS.ExtendLock",
1390 .op = yfs_FS_ExtendLock,
David Howellsf5e45462019-05-01 14:05:27 +01001391 .deliver = yfs_deliver_status_and_volsync,
David Howellsa690f602019-04-25 14:26:50 +01001392 .done = afs_lock_op_done,
David Howells30062bd2018-10-20 00:57:58 +01001393 .destructor = afs_flat_call_destructor,
1394};
1395
1396/*
1397 * YFS.ReleaseLock operation type
1398 */
1399static const struct afs_call_type yfs_RXYFSReleaseLock = {
1400 .name = "YFS.ReleaseLock",
1401 .op = yfs_FS_ReleaseLock,
David Howellsf5e45462019-05-01 14:05:27 +01001402 .deliver = yfs_deliver_status_and_volsync,
David Howells30062bd2018-10-20 00:57:58 +01001403 .destructor = afs_flat_call_destructor,
1404};
1405
1406/*
1407 * Set a lock on a file
1408 */
David Howellse49c7b22020-04-10 20:51:51 +01001409void yfs_fs_set_lock(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001410{
David Howellse49c7b22020-04-10 20:51:51 +01001411 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001412 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001413 __be32 *bp;
1414
1415 _enter("");
1416
David Howellse49c7b22020-04-10 20:51:51 +01001417 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
David Howells30062bd2018-10-20 00:57:58 +01001418 sizeof(__be32) * 2 +
1419 sizeof(struct yfs_xdr_YFSFid) +
1420 sizeof(__be32),
1421 sizeof(struct yfs_xdr_YFSFetchStatus) +
1422 sizeof(struct yfs_xdr_YFSVolSync));
1423 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001424 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001425
1426 /* marshall the parameters */
1427 bp = call->request;
1428 bp = xdr_encode_u32(bp, YFSSETLOCK);
1429 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001430 bp = xdr_encode_YFSFid(bp, &vp->fid);
1431 bp = xdr_encode_u32(bp, op->lock.type);
David Howells30062bd2018-10-20 00:57:58 +01001432 yfs_check_req(call, bp);
1433
David Howellse49c7b22020-04-10 20:51:51 +01001434 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1435 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001436}
1437
1438/*
1439 * extend a lock on a file
1440 */
David Howellse49c7b22020-04-10 20:51:51 +01001441void yfs_fs_extend_lock(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001442{
David Howellse49c7b22020-04-10 20:51:51 +01001443 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001444 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001445 __be32 *bp;
1446
1447 _enter("");
1448
David Howellse49c7b22020-04-10 20:51:51 +01001449 call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
David Howells30062bd2018-10-20 00:57:58 +01001450 sizeof(__be32) * 2 +
1451 sizeof(struct yfs_xdr_YFSFid),
1452 sizeof(struct yfs_xdr_YFSFetchStatus) +
1453 sizeof(struct yfs_xdr_YFSVolSync));
1454 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001455 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001456
1457 /* marshall the parameters */
1458 bp = call->request;
1459 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1460 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001461 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +01001462 yfs_check_req(call, bp);
1463
David Howellse49c7b22020-04-10 20:51:51 +01001464 trace_afs_make_fs_call(call, &vp->fid);
1465 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001466}
1467
1468/*
1469 * release a lock on a file
1470 */
David Howellse49c7b22020-04-10 20:51:51 +01001471void yfs_fs_release_lock(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001472{
David Howellse49c7b22020-04-10 20:51:51 +01001473 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001474 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001475 __be32 *bp;
1476
1477 _enter("");
1478
David Howellse49c7b22020-04-10 20:51:51 +01001479 call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
David Howells30062bd2018-10-20 00:57:58 +01001480 sizeof(__be32) * 2 +
1481 sizeof(struct yfs_xdr_YFSFid),
1482 sizeof(struct yfs_xdr_YFSFetchStatus) +
1483 sizeof(struct yfs_xdr_YFSVolSync));
1484 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001485 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001486
1487 /* marshall the parameters */
1488 bp = call->request;
1489 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1490 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001491 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +01001492 yfs_check_req(call, bp);
1493
David Howellse49c7b22020-04-10 20:51:51 +01001494 trace_afs_make_fs_call(call, &vp->fid);
1495 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001496}
1497
1498/*
David Howells9bd87ec2020-06-16 00:23:12 +01001499 * Deliver a reply to YFS.FetchStatus
1500 */
1501static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1502{
1503 struct afs_operation *op = call->op;
1504 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1505 const __be32 *bp;
1506 int ret;
1507
1508 ret = afs_transfer_reply(call);
1509 if (ret < 0)
1510 return ret;
1511
1512 /* unmarshall the reply once we've received all of it */
1513 bp = call->buffer;
1514 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1515 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
1516 xdr_decode_YFSVolSync(&bp, &op->volsync);
1517
1518 _leave(" = 0 [done]");
1519 return 0;
1520}
1521
1522/*
David Howells30062bd2018-10-20 00:57:58 +01001523 * YFS.FetchStatus operation type
1524 */
1525static const struct afs_call_type yfs_RXYFSFetchStatus = {
1526 .name = "YFS.FetchStatus",
1527 .op = yfs_FS_FetchStatus,
David Howells9bd87ec2020-06-16 00:23:12 +01001528 .deliver = yfs_deliver_fs_fetch_status,
David Howells30062bd2018-10-20 00:57:58 +01001529 .destructor = afs_flat_call_destructor,
1530};
1531
1532/*
1533 * Fetch the status information for a fid without needing a vnode handle.
1534 */
David Howellse49c7b22020-04-10 20:51:51 +01001535void yfs_fs_fetch_status(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001536{
David Howells9bd87ec2020-06-16 00:23:12 +01001537 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
David Howells30062bd2018-10-20 00:57:58 +01001538 struct afs_call *call;
1539 __be32 *bp;
1540
1541 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001542 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells30062bd2018-10-20 00:57:58 +01001543
David Howellse49c7b22020-04-10 20:51:51 +01001544 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
David Howells30062bd2018-10-20 00:57:58 +01001545 sizeof(__be32) * 2 +
1546 sizeof(struct yfs_xdr_YFSFid),
1547 sizeof(struct yfs_xdr_YFSFetchStatus) +
1548 sizeof(struct yfs_xdr_YFSCallBack) +
1549 sizeof(struct yfs_xdr_YFSVolSync));
David Howellse49c7b22020-04-10 20:51:51 +01001550 if (!call)
1551 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001552
1553 /* marshall the parameters */
1554 bp = call->request;
1555 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
1556 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001557 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +01001558 yfs_check_req(call, bp);
1559
David Howellse49c7b22020-04-10 20:51:51 +01001560 trace_afs_make_fs_call(call, &vp->fid);
1561 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001562}
1563
1564/*
1565 * Deliver reply data to an YFS.InlineBulkStatus call
1566 */
1567static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
1568{
David Howellse49c7b22020-04-10 20:51:51 +01001569 struct afs_operation *op = call->op;
David Howells87182752019-05-09 16:17:05 +01001570 struct afs_status_cb *scb;
David Howells30062bd2018-10-20 00:57:58 +01001571 const __be32 *bp;
1572 u32 tmp;
1573 int ret;
1574
1575 _enter("{%u}", call->unmarshall);
1576
1577 switch (call->unmarshall) {
1578 case 0:
1579 afs_extract_to_tmp(call);
1580 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001581 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001582
1583 /* Extract the file status count and array in two steps */
1584 case 1:
1585 _debug("extract status count");
1586 ret = afs_extract_data(call, true);
1587 if (ret < 0)
1588 return ret;
1589
1590 tmp = ntohl(call->tmp);
David Howellse49c7b22020-04-10 20:51:51 +01001591 _debug("status count: %u/%u", tmp, op->nr_files);
1592 if (tmp != op->nr_files)
David Howells7126ead2020-04-08 16:49:08 +01001593 return afs_protocol_error(call, afs_eproto_ibulkst_count);
David Howells30062bd2018-10-20 00:57:58 +01001594
1595 call->count = 0;
1596 call->unmarshall++;
1597 more_counts:
1598 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001599 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001600
David Howells30062bd2018-10-20 00:57:58 +01001601 case 2:
1602 _debug("extract status array %u", call->count);
1603 ret = afs_extract_data(call, true);
1604 if (ret < 0)
1605 return ret;
1606
David Howellse49c7b22020-04-10 20:51:51 +01001607 switch (call->count) {
1608 case 0:
1609 scb = &op->file[0].scb;
1610 break;
1611 case 1:
1612 scb = &op->file[1].scb;
1613 break;
1614 default:
1615 scb = &op->more_files[call->count - 2].scb;
1616 break;
1617 }
1618
David Howells30062bd2018-10-20 00:57:58 +01001619 bp = call->buffer;
David Howells38355ee2020-04-08 16:13:20 +01001620 xdr_decode_YFSFetchStatus(&bp, call, scb);
David Howells30062bd2018-10-20 00:57:58 +01001621
1622 call->count++;
David Howellse49c7b22020-04-10 20:51:51 +01001623 if (call->count < op->nr_files)
David Howells30062bd2018-10-20 00:57:58 +01001624 goto more_counts;
1625
1626 call->count = 0;
1627 call->unmarshall++;
1628 afs_extract_to_tmp(call);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001629 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001630
1631 /* Extract the callback count and array in two steps */
1632 case 3:
1633 _debug("extract CB count");
1634 ret = afs_extract_data(call, true);
1635 if (ret < 0)
1636 return ret;
1637
1638 tmp = ntohl(call->tmp);
1639 _debug("CB count: %u", tmp);
David Howellse49c7b22020-04-10 20:51:51 +01001640 if (tmp != op->nr_files)
David Howells7126ead2020-04-08 16:49:08 +01001641 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
David Howells30062bd2018-10-20 00:57:58 +01001642 call->count = 0;
1643 call->unmarshall++;
1644 more_cbs:
1645 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001646 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001647
David Howells30062bd2018-10-20 00:57:58 +01001648 case 4:
1649 _debug("extract CB array");
1650 ret = afs_extract_data(call, true);
1651 if (ret < 0)
1652 return ret;
1653
1654 _debug("unmarshall CB array");
David Howellse49c7b22020-04-10 20:51:51 +01001655 switch (call->count) {
1656 case 0:
1657 scb = &op->file[0].scb;
1658 break;
1659 case 1:
1660 scb = &op->file[1].scb;
1661 break;
1662 default:
1663 scb = &op->more_files[call->count - 2].scb;
1664 break;
1665 }
1666
David Howells30062bd2018-10-20 00:57:58 +01001667 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01001668 xdr_decode_YFSCallBack(&bp, call, scb);
David Howells30062bd2018-10-20 00:57:58 +01001669 call->count++;
David Howellse49c7b22020-04-10 20:51:51 +01001670 if (call->count < op->nr_files)
David Howells30062bd2018-10-20 00:57:58 +01001671 goto more_cbs;
1672
1673 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
1674 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001675 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001676
David Howells30062bd2018-10-20 00:57:58 +01001677 case 5:
1678 ret = afs_extract_data(call, false);
1679 if (ret < 0)
1680 return ret;
1681
1682 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +01001683 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +01001684
1685 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001686 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001687
David Howells30062bd2018-10-20 00:57:58 +01001688 case 6:
1689 break;
1690 }
1691
1692 _leave(" = 0 [done]");
1693 return 0;
1694}
1695
1696/*
1697 * FS.InlineBulkStatus operation type
1698 */
1699static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
1700 .name = "YFS.InlineBulkStatus",
1701 .op = yfs_FS_InlineBulkStatus,
1702 .deliver = yfs_deliver_fs_inline_bulk_status,
1703 .destructor = afs_flat_call_destructor,
1704};
1705
1706/*
1707 * Fetch the status information for up to 1024 files
1708 */
David Howellse49c7b22020-04-10 20:51:51 +01001709void yfs_fs_inline_bulk_status(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001710{
David Howellse49c7b22020-04-10 20:51:51 +01001711 struct afs_vnode_param *dvp = &op->file[0];
1712 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +01001713 struct afs_call *call;
1714 __be32 *bp;
1715 int i;
1716
1717 _enter(",%x,{%llx:%llu},%u",
David Howellse49c7b22020-04-10 20:51:51 +01001718 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
David Howells30062bd2018-10-20 00:57:58 +01001719
David Howellse49c7b22020-04-10 20:51:51 +01001720 call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
David Howells30062bd2018-10-20 00:57:58 +01001721 sizeof(__be32) +
1722 sizeof(__be32) +
1723 sizeof(__be32) +
David Howellse49c7b22020-04-10 20:51:51 +01001724 sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
David Howells30062bd2018-10-20 00:57:58 +01001725 sizeof(struct yfs_xdr_YFSFetchStatus));
David Howellse49c7b22020-04-10 20:51:51 +01001726 if (!call)
1727 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001728
1729 /* marshall the parameters */
1730 bp = call->request;
1731 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
1732 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
David Howellse49c7b22020-04-10 20:51:51 +01001733 bp = xdr_encode_u32(bp, op->nr_files);
1734 bp = xdr_encode_YFSFid(bp, &dvp->fid);
1735 bp = xdr_encode_YFSFid(bp, &vp->fid);
1736 for (i = 0; i < op->nr_files - 2; i++)
1737 bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
David Howells30062bd2018-10-20 00:57:58 +01001738 yfs_check_req(call, bp);
1739
David Howellse49c7b22020-04-10 20:51:51 +01001740 trace_afs_make_fs_call(call, &vp->fid);
1741 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001742}
David Howellsae465782019-04-30 18:30:21 +01001743
1744/*
1745 * Deliver reply data to an YFS.FetchOpaqueACL.
1746 */
1747static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
1748{
David Howellse49c7b22020-04-10 20:51:51 +01001749 struct afs_operation *op = call->op;
1750 struct afs_vnode_param *vp = &op->file[0];
1751 struct yfs_acl *yacl = op->yacl;
David Howellsae465782019-04-30 18:30:21 +01001752 struct afs_acl *acl;
1753 const __be32 *bp;
1754 unsigned int size;
1755 int ret;
1756
1757 _enter("{%u}", call->unmarshall);
1758
1759 switch (call->unmarshall) {
1760 case 0:
1761 afs_extract_to_tmp(call);
1762 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001763 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001764
1765 /* Extract the file ACL length */
1766 case 1:
1767 ret = afs_extract_data(call, true);
1768 if (ret < 0)
1769 return ret;
1770
1771 size = call->count2 = ntohl(call->tmp);
1772 size = round_up(size, 4);
1773
1774 if (yacl->flags & YFS_ACL_WANT_ACL) {
1775 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1776 if (!acl)
1777 return -ENOMEM;
1778 yacl->acl = acl;
1779 acl->size = call->count2;
1780 afs_extract_begin(call, acl->data, size);
1781 } else {
David Howells23a28912019-08-20 09:22:38 +01001782 afs_extract_discard(call, size);
David Howellsae465782019-04-30 18:30:21 +01001783 }
1784 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001785 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001786
1787 /* Extract the file ACL */
1788 case 2:
1789 ret = afs_extract_data(call, true);
1790 if (ret < 0)
1791 return ret;
1792
1793 afs_extract_to_tmp(call);
1794 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001795 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001796
1797 /* Extract the volume ACL length */
1798 case 3:
1799 ret = afs_extract_data(call, true);
1800 if (ret < 0)
1801 return ret;
1802
1803 size = call->count2 = ntohl(call->tmp);
1804 size = round_up(size, 4);
1805
1806 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
1807 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1808 if (!acl)
1809 return -ENOMEM;
1810 yacl->vol_acl = acl;
1811 acl->size = call->count2;
1812 afs_extract_begin(call, acl->data, size);
1813 } else {
David Howells23a28912019-08-20 09:22:38 +01001814 afs_extract_discard(call, size);
David Howellsae465782019-04-30 18:30:21 +01001815 }
1816 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001817 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001818
1819 /* Extract the volume ACL */
1820 case 4:
1821 ret = afs_extract_data(call, true);
1822 if (ret < 0)
1823 return ret;
1824
1825 afs_extract_to_buf(call,
1826 sizeof(__be32) * 2 +
1827 sizeof(struct yfs_xdr_YFSFetchStatus) +
1828 sizeof(struct yfs_xdr_YFSVolSync));
1829 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001830 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001831
1832 /* extract the metadata */
1833 case 5:
1834 ret = afs_extract_data(call, false);
1835 if (ret < 0)
1836 return ret;
1837
1838 bp = call->buffer;
1839 yacl->inherit_flag = ntohl(*bp++);
1840 yacl->num_cleaned = ntohl(*bp++);
David Howellse49c7b22020-04-10 20:51:51 +01001841 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1842 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howellsae465782019-04-30 18:30:21 +01001843
1844 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001845 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001846
1847 case 6:
1848 break;
1849 }
1850
1851 _leave(" = 0 [done]");
1852 return 0;
1853}
1854
1855void yfs_free_opaque_acl(struct yfs_acl *yacl)
1856{
1857 if (yacl) {
1858 kfree(yacl->acl);
1859 kfree(yacl->vol_acl);
1860 kfree(yacl);
1861 }
1862}
1863
David Howellsae465782019-04-30 18:30:21 +01001864/*
1865 * YFS.FetchOpaqueACL operation type
1866 */
1867static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
1868 .name = "YFS.FetchOpaqueACL",
1869 .op = yfs_FS_FetchOpaqueACL,
1870 .deliver = yfs_deliver_fs_fetch_opaque_acl,
David Howells773e0c42019-05-12 08:31:23 +01001871 .destructor = afs_flat_call_destructor,
David Howellsae465782019-04-30 18:30:21 +01001872};
1873
1874/*
1875 * Fetch the YFS advanced ACLs for a file.
1876 */
David Howellse49c7b22020-04-10 20:51:51 +01001877void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
David Howellsae465782019-04-30 18:30:21 +01001878{
David Howellse49c7b22020-04-10 20:51:51 +01001879 struct afs_vnode_param *vp = &op->file[0];
David Howellsae465782019-04-30 18:30:21 +01001880 struct afs_call *call;
David Howellsae465782019-04-30 18:30:21 +01001881 __be32 *bp;
1882
1883 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001884 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howellsae465782019-04-30 18:30:21 +01001885
David Howellse49c7b22020-04-10 20:51:51 +01001886 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
David Howellsae465782019-04-30 18:30:21 +01001887 sizeof(__be32) * 2 +
1888 sizeof(struct yfs_xdr_YFSFid),
1889 sizeof(__be32) * 2 +
1890 sizeof(struct yfs_xdr_YFSFetchStatus) +
1891 sizeof(struct yfs_xdr_YFSVolSync));
David Howellse49c7b22020-04-10 20:51:51 +01001892 if (!call)
1893 return afs_op_nomem(op);
David Howellsae465782019-04-30 18:30:21 +01001894
1895 /* marshall the parameters */
1896 bp = call->request;
1897 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
1898 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001899 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howellsae465782019-04-30 18:30:21 +01001900 yfs_check_req(call, bp);
1901
David Howellse49c7b22020-04-10 20:51:51 +01001902 trace_afs_make_fs_call(call, &vp->fid);
1903 afs_make_op_call(op, call, GFP_KERNEL);
David Howellsae465782019-04-30 18:30:21 +01001904}
David Howellsf5e45462019-05-01 14:05:27 +01001905
1906/*
1907 * YFS.StoreOpaqueACL2 operation type
1908 */
1909static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
1910 .name = "YFS.StoreOpaqueACL2",
1911 .op = yfs_FS_StoreOpaqueACL2,
1912 .deliver = yfs_deliver_status_and_volsync,
1913 .destructor = afs_flat_call_destructor,
1914};
1915
1916/*
1917 * Fetch the YFS ACL for a file.
1918 */
David Howellse49c7b22020-04-10 20:51:51 +01001919void yfs_fs_store_opaque_acl2(struct afs_operation *op)
David Howellsf5e45462019-05-01 14:05:27 +01001920{
David Howellse49c7b22020-04-10 20:51:51 +01001921 struct afs_vnode_param *vp = &op->file[0];
David Howellsf5e45462019-05-01 14:05:27 +01001922 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +01001923 struct afs_acl *acl = op->acl;
David Howellsf5e45462019-05-01 14:05:27 +01001924 size_t size;
1925 __be32 *bp;
1926
1927 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001928 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howellsf5e45462019-05-01 14:05:27 +01001929
1930 size = round_up(acl->size, 4);
David Howellse49c7b22020-04-10 20:51:51 +01001931 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
David Howellsf5e45462019-05-01 14:05:27 +01001932 sizeof(__be32) * 2 +
1933 sizeof(struct yfs_xdr_YFSFid) +
1934 sizeof(__be32) + size,
1935 sizeof(struct yfs_xdr_YFSFetchStatus) +
1936 sizeof(struct yfs_xdr_YFSVolSync));
David Howellse49c7b22020-04-10 20:51:51 +01001937 if (!call)
1938 return afs_op_nomem(op);
David Howellsf5e45462019-05-01 14:05:27 +01001939
1940 /* marshall the parameters */
1941 bp = call->request;
1942 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
1943 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001944 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howellsf5e45462019-05-01 14:05:27 +01001945 bp = xdr_encode_u32(bp, acl->size);
1946 memcpy(bp, acl->data, acl->size);
1947 if (acl->size != size)
1948 memset((void *)bp + acl->size, 0, size - acl->size);
David Howellsc80afa12020-11-03 16:32:58 +00001949 bp += size / sizeof(__be32);
David Howellsf5e45462019-05-01 14:05:27 +01001950 yfs_check_req(call, bp);
1951
David Howellse49c7b22020-04-10 20:51:51 +01001952 trace_afs_make_fs_call(call, &vp->fid);
1953 afs_make_op_call(op, call, GFP_KERNEL);
David Howells30062bd2018-10-20 00:57:58 +01001954}