blob: bd787e71a657f9b683922eeb7cd2ac5b655eb620 [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 ([email protected])
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
86static __be32 *xdr_encode_YFSStoreStatus_mode(__be32 *bp, mode_t mode)
87{
88 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
89
90 x->mask = htonl(AFS_SET_MODE);
91 x->mode = htonl(mode & S_IALLUGO);
92 x->mtime_client = u64_to_xdr(0);
93 x->owner = u64_to_xdr(0);
94 x->group = u64_to_xdr(0);
95 return bp + xdr_size(x);
96}
97
98static __be32 *xdr_encode_YFSStoreStatus_mtime(__be32 *bp, const struct timespec64 *t)
99{
100 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
101 s64 mtime = linux_to_yfs_time(t);
102
103 x->mask = htonl(AFS_SET_MTIME);
104 x->mode = htonl(0);
105 x->mtime_client = u64_to_xdr(mtime);
106 x->owner = u64_to_xdr(0);
107 x->group = u64_to_xdr(0);
108 return bp + xdr_size(x);
109}
110
111/*
112 * Convert a signed 100ns-resolution 64-bit time into a timespec.
113 */
114static struct timespec64 yfs_time_to_linux(s64 t)
115{
116 struct timespec64 ts;
117 u64 abs_t;
118
119 /*
120 * Unfortunately can not use normal 64 bit division on 32 bit arch, but
121 * the alternative, do_div, does not work with negative numbers so have
122 * to special case them
123 */
124 if (t < 0) {
125 abs_t = -t;
126 ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100);
127 ts.tv_nsec = -ts.tv_nsec;
128 ts.tv_sec = -abs_t;
129 } else {
130 abs_t = t;
131 ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100;
132 ts.tv_sec = abs_t;
133 }
134
135 return ts;
136}
137
138static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr)
139{
140 s64 t = xdr_to_u64(xdr);
141
142 return yfs_time_to_linux(t);
143}
144
145static void yfs_check_req(struct afs_call *call, __be32 *bp)
146{
147 size_t len = (void *)bp - call->request;
148
149 if (len > call->request_size)
150 pr_err("kAFS: %s: Request buffer overflow (%zu>%u)\n",
151 call->type->name, len, call->request_size);
152 else if (len < call->request_size)
Kefeng Wanga4e530a2019-10-18 11:18:40 +0800153 pr_warn("kAFS: %s: Request buffer underflow (%zu<%u)\n",
154 call->type->name, len, call->request_size);
David Howells30062bd2018-10-20 00:57:58 +0100155}
156
157/*
158 * Dump a bad file status record.
159 */
160static void xdr_dump_bad(const __be32 *bp)
161{
162 __be32 x[4];
163 int i;
164
165 pr_notice("YFS XDR: Bad status record\n");
David Howells3efe55b2020-04-01 23:32:12 +0100166 for (i = 0; i < 6 * 4 * 4; i += 16) {
David Howells30062bd2018-10-20 00:57:58 +0100167 memcpy(x, bp, 16);
168 bp += 4;
169 pr_notice("%03x: %08x %08x %08x %08x\n",
170 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
171 }
172
David Howells3efe55b2020-04-01 23:32:12 +0100173 memcpy(x, bp, 8);
174 pr_notice("0x60: %08x %08x\n", ntohl(x[0]), ntohl(x[1]));
David Howells30062bd2018-10-20 00:57:58 +0100175}
176
177/*
178 * Decode a YFSFetchStatus block
179 */
David Howells38355ee2020-04-08 16:13:20 +0100180static void xdr_decode_YFSFetchStatus(const __be32 **_bp,
181 struct afs_call *call,
182 struct afs_status_cb *scb)
David Howells30062bd2018-10-20 00:57:58 +0100183{
184 const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
David Howellsa58823a2019-05-09 15:16:10 +0100185 struct afs_file_status *status = &scb->status;
David Howells30062bd2018-10-20 00:57:58 +0100186 u32 type;
David Howells30062bd2018-10-20 00:57:58 +0100187
188 status->abort_code = ntohl(xdr->abort_code);
189 if (status->abort_code != 0) {
David Howellsa58823a2019-05-09 15:16:10 +0100190 if (status->abort_code == VNOVNODE)
David Howells30062bd2018-10-20 00:57:58 +0100191 status->nlink = 0;
David Howellsa38a7552019-05-14 12:29:11 +0100192 scb->have_error = true;
David Howells38355ee2020-04-08 16:13:20 +0100193 goto advance;
David Howells30062bd2018-10-20 00:57:58 +0100194 }
195
196 type = ntohl(xdr->type);
197 switch (type) {
198 case AFS_FTYPE_FILE:
199 case AFS_FTYPE_DIR:
200 case AFS_FTYPE_SYMLINK:
David Howells30062bd2018-10-20 00:57:58 +0100201 status->type = type;
202 break;
203 default:
204 goto bad;
205 }
206
David Howellsa58823a2019-05-09 15:16:10 +0100207 status->nlink = ntohl(xdr->nlink);
208 status->author = xdr_to_u64(xdr->author);
209 status->owner = xdr_to_u64(xdr->owner);
210 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
211 status->anon_access = ntohl(xdr->anon_access);
212 status->mode = ntohl(xdr->mode) & S_IALLUGO;
213 status->group = xdr_to_u64(xdr->group);
214 status->lock_count = ntohl(xdr->lock_count);
David Howells30062bd2018-10-20 00:57:58 +0100215
David Howellsa58823a2019-05-09 15:16:10 +0100216 status->mtime_client = xdr_to_time(xdr->mtime_client);
217 status->mtime_server = xdr_to_time(xdr->mtime_server);
218 status->size = xdr_to_u64(xdr->size);
219 status->data_version = xdr_to_u64(xdr->data_version);
David Howellsa38a7552019-05-14 12:29:11 +0100220 scb->have_status = true;
David Howellsc72057b2020-04-08 16:13:20 +0100221advance:
David Howells30062bd2018-10-20 00:57:58 +0100222 *_bp += xdr_size(xdr);
David Howells38355ee2020-04-08 16:13:20 +0100223 return;
David Howells30062bd2018-10-20 00:57:58 +0100224
225bad:
226 xdr_dump_bad(*_bp);
David Howells7126ead2020-04-08 16:49:08 +0100227 afs_protocol_error(call, afs_eproto_bad_status);
David Howellsc72057b2020-04-08 16:13:20 +0100228 goto advance;
David Howells30062bd2018-10-20 00:57:58 +0100229}
230
231/*
David Howellsa58823a2019-05-09 15:16:10 +0100232 * Decode a YFSCallBack block
David Howells30062bd2018-10-20 00:57:58 +0100233 */
David Howellsa58823a2019-05-09 15:16:10 +0100234static void xdr_decode_YFSCallBack(const __be32 **_bp,
235 struct afs_call *call,
236 struct afs_status_cb *scb)
David Howells78107052019-05-09 17:56:53 +0100237{
238 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
David Howellsa58823a2019-05-09 15:16:10 +0100239 struct afs_callback *cb = &scb->callback;
David Howells78107052019-05-09 17:56:53 +0100240 ktime_t cb_expiry;
241
242 cb_expiry = call->reply_time;
243 cb_expiry = ktime_add(cb_expiry, xdr_to_u64(x->expiration_time) * 100);
244 cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
David Howellsa58823a2019-05-09 15:16:10 +0100245 scb->have_cb = true;
David Howells78107052019-05-09 17:56:53 +0100246 *_bp += xdr_size(x);
247}
248
David Howells30062bd2018-10-20 00:57:58 +0100249/*
David Howells30062bd2018-10-20 00:57:58 +0100250 * Decode a YFSVolSync block
251 */
252static void xdr_decode_YFSVolSync(const __be32 **_bp,
253 struct afs_volsync *volsync)
254{
255 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
256 u64 creation;
257
258 if (volsync) {
259 creation = xdr_to_u64(x->vol_creation_date);
260 do_div(creation, 10 * 1000 * 1000);
261 volsync->creation = creation;
262 }
263
264 *_bp += xdr_size(x);
265}
266
267/*
268 * Encode the requested attributes into a YFSStoreStatus block
269 */
270static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
271{
272 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
273 s64 mtime = 0, owner = 0, group = 0;
274 u32 mask = 0, mode = 0;
275
276 mask = 0;
277 if (attr->ia_valid & ATTR_MTIME) {
278 mask |= AFS_SET_MTIME;
279 mtime = linux_to_yfs_time(&attr->ia_mtime);
280 }
281
282 if (attr->ia_valid & ATTR_UID) {
283 mask |= AFS_SET_OWNER;
284 owner = from_kuid(&init_user_ns, attr->ia_uid);
285 }
286
287 if (attr->ia_valid & ATTR_GID) {
288 mask |= AFS_SET_GROUP;
289 group = from_kgid(&init_user_ns, attr->ia_gid);
290 }
291
292 if (attr->ia_valid & ATTR_MODE) {
293 mask |= AFS_SET_MODE;
294 mode = attr->ia_mode & S_IALLUGO;
295 }
296
297 x->mask = htonl(mask);
298 x->mode = htonl(mode);
299 x->mtime_client = u64_to_xdr(mtime);
300 x->owner = u64_to_xdr(owner);
301 x->group = u64_to_xdr(group);
302 return bp + xdr_size(x);
303}
304
305/*
306 * Decode a YFSFetchVolumeStatus block.
307 */
308static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
309 struct afs_volume_status *vs)
310{
311 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
312 u32 flags;
313
314 vs->vid = xdr_to_u64(x->vid);
315 vs->parent_id = xdr_to_u64(x->parent_id);
316 flags = ntohl(x->flags);
317 vs->online = flags & yfs_FVSOnline;
318 vs->in_service = flags & yfs_FVSInservice;
319 vs->blessed = flags & yfs_FVSBlessed;
320 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
321 vs->type = ntohl(x->type);
322 vs->min_quota = 0;
323 vs->max_quota = xdr_to_u64(x->max_quota);
324 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
325 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
326 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
327 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
328 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
329 *_bp += sizeof(*x) / sizeof(__be32);
330}
331
332/*
David Howellsa58823a2019-05-09 15:16:10 +0100333 * Deliver reply data to operations that just return a file status and a volume
334 * sync record.
335 */
336static int yfs_deliver_status_and_volsync(struct afs_call *call)
337{
David Howellse49c7b22020-04-10 20:51:51 +0100338 struct afs_operation *op = call->op;
David Howellsa58823a2019-05-09 15:16:10 +0100339 const __be32 *bp;
340 int ret;
341
342 ret = afs_transfer_reply(call);
343 if (ret < 0)
344 return ret;
345
346 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100347 xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
348 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100349
350 _leave(" = 0 [done]");
351 return 0;
352}
353
354/*
David Howells30062bd2018-10-20 00:57:58 +0100355 * Deliver reply data to an YFS.FetchData64.
356 */
357static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
358{
David Howellse49c7b22020-04-10 20:51:51 +0100359 struct afs_operation *op = call->op;
360 struct afs_vnode_param *vp = &op->file[0];
361 struct afs_read *req = op->fetch.req;
David Howells30062bd2018-10-20 00:57:58 +0100362 const __be32 *bp;
363 unsigned int size;
364 int ret;
365
366 _enter("{%u,%zu/%llu}",
David Howellsfc276122019-11-21 09:12:17 +0000367 call->unmarshall, iov_iter_count(call->iter), req->actual_len);
David Howells30062bd2018-10-20 00:57:58 +0100368
369 switch (call->unmarshall) {
370 case 0:
371 req->actual_len = 0;
372 req->index = 0;
373 req->offset = req->pos & (PAGE_SIZE - 1);
374 afs_extract_to_tmp64(call);
375 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500376 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +0100377
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -0500378 /* extract the returned data length */
David Howells30062bd2018-10-20 00:57:58 +0100379 case 1:
380 _debug("extract data length");
381 ret = afs_extract_data(call, true);
382 if (ret < 0)
383 return ret;
384
385 req->actual_len = be64_to_cpu(call->tmp64);
386 _debug("DATA length: %llu", req->actual_len);
387 req->remain = min(req->len, req->actual_len);
388 if (req->remain == 0)
389 goto no_more_data;
390
391 call->unmarshall++;
392
393 begin_page:
394 ASSERTCMP(req->index, <, req->nr_pages);
395 if (req->remain > PAGE_SIZE - req->offset)
396 size = PAGE_SIZE - req->offset;
397 else
398 size = req->remain;
399 call->bvec[0].bv_len = size;
400 call->bvec[0].bv_offset = req->offset;
401 call->bvec[0].bv_page = req->pages[req->index];
David Howellsfc276122019-11-21 09:12:17 +0000402 iov_iter_bvec(&call->def_iter, READ, call->bvec, 1, size);
David Howells30062bd2018-10-20 00:57:58 +0100403 ASSERTCMP(size, <=, PAGE_SIZE);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500404 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +0100405
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -0500406 /* extract the returned data */
David Howells30062bd2018-10-20 00:57:58 +0100407 case 2:
408 _debug("extract data %zu/%llu",
David Howellsfc276122019-11-21 09:12:17 +0000409 iov_iter_count(call->iter), req->remain);
David Howells30062bd2018-10-20 00:57:58 +0100410
411 ret = afs_extract_data(call, true);
412 if (ret < 0)
413 return ret;
414 req->remain -= call->bvec[0].bv_len;
415 req->offset += call->bvec[0].bv_len;
416 ASSERTCMP(req->offset, <=, PAGE_SIZE);
417 if (req->offset == PAGE_SIZE) {
418 req->offset = 0;
David Howells30062bd2018-10-20 00:57:58 +0100419 req->index++;
420 if (req->remain > 0)
421 goto begin_page;
422 }
423
424 ASSERTCMP(req->remain, ==, 0);
425 if (req->actual_len <= req->len)
426 goto no_more_data;
427
428 /* Discard any excess data the server gave us */
David Howells23a28912019-08-20 09:22:38 +0100429 afs_extract_discard(call, req->actual_len - req->len);
David Howells30062bd2018-10-20 00:57:58 +0100430 call->unmarshall = 3;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500431 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -0500432
David Howells30062bd2018-10-20 00:57:58 +0100433 case 3:
434 _debug("extract discard %zu/%llu",
David Howellsfc276122019-11-21 09:12:17 +0000435 iov_iter_count(call->iter), req->actual_len - req->len);
David Howells30062bd2018-10-20 00:57:58 +0100436
437 ret = afs_extract_data(call, true);
438 if (ret < 0)
439 return ret;
440
441 no_more_data:
442 call->unmarshall = 4;
443 afs_extract_to_buf(call,
444 sizeof(struct yfs_xdr_YFSFetchStatus) +
445 sizeof(struct yfs_xdr_YFSCallBack) +
446 sizeof(struct yfs_xdr_YFSVolSync));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500447 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +0100448
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -0500449 /* extract the metadata */
David Howells30062bd2018-10-20 00:57:58 +0100450 case 4:
451 ret = afs_extract_data(call, false);
452 if (ret < 0)
453 return ret;
454
455 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100456 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
457 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
458 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100459
David Howellse49c7b22020-04-10 20:51:51 +0100460 req->data_version = vp->scb.status.data_version;
461 req->file_size = vp->scb.status.size;
David Howellsa58823a2019-05-09 15:16:10 +0100462
David Howells30062bd2018-10-20 00:57:58 +0100463 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500464 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -0500465
David Howells30062bd2018-10-20 00:57:58 +0100466 case 5:
467 break;
468 }
469
470 for (; req->index < req->nr_pages; req->index++) {
471 if (req->offset < PAGE_SIZE)
472 zero_user_segment(req->pages[req->index],
473 req->offset, PAGE_SIZE);
David Howells30062bd2018-10-20 00:57:58 +0100474 req->offset = 0;
475 }
476
David Howells9d1be4f2020-05-17 21:21:05 +0100477 if (req->page_done)
478 for (req->index = 0; req->index < req->nr_pages; req->index++)
479 req->page_done(req);
480
David Howells30062bd2018-10-20 00:57:58 +0100481 _leave(" = 0 [done]");
482 return 0;
483}
484
David Howells30062bd2018-10-20 00:57:58 +0100485/*
486 * YFS.FetchData64 operation type
487 */
488static const struct afs_call_type yfs_RXYFSFetchData64 = {
489 .name = "YFS.FetchData64",
490 .op = yfs_FS_FetchData64,
491 .deliver = yfs_deliver_fs_fetch_data64,
David Howellse49c7b22020-04-10 20:51:51 +0100492 .destructor = afs_flat_call_destructor,
David Howells30062bd2018-10-20 00:57:58 +0100493};
494
495/*
496 * Fetch data from a file.
497 */
David Howellse49c7b22020-04-10 20:51:51 +0100498void yfs_fs_fetch_data(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100499{
David Howellse49c7b22020-04-10 20:51:51 +0100500 struct afs_vnode_param *vp = &op->file[0];
501 struct afs_read *req = op->fetch.req;
David Howells30062bd2018-10-20 00:57:58 +0100502 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100503 __be32 *bp;
504
505 _enter(",%x,{%llx:%llu},%llx,%llx",
David Howellse49c7b22020-04-10 20:51:51 +0100506 key_serial(op->key), vp->fid.vid, vp->fid.vnode,
David Howells30062bd2018-10-20 00:57:58 +0100507 req->pos, req->len);
508
David Howellse49c7b22020-04-10 20:51:51 +0100509 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
David Howells30062bd2018-10-20 00:57:58 +0100510 sizeof(__be32) * 2 +
511 sizeof(struct yfs_xdr_YFSFid) +
512 sizeof(struct yfs_xdr_u64) * 2,
513 sizeof(struct yfs_xdr_YFSFetchStatus) +
514 sizeof(struct yfs_xdr_YFSCallBack) +
515 sizeof(struct yfs_xdr_YFSVolSync));
516 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100517 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100518
519 /* marshall the parameters */
520 bp = call->request;
521 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
522 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100523 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +0100524 bp = xdr_encode_u64(bp, req->pos);
525 bp = xdr_encode_u64(bp, req->len);
526 yfs_check_req(call, bp);
527
David Howellse49c7b22020-04-10 20:51:51 +0100528 trace_afs_make_fs_call(call, &vp->fid);
529 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100530}
531
532/*
533 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
534 */
535static int yfs_deliver_fs_create_vnode(struct afs_call *call)
536{
David Howellse49c7b22020-04-10 20:51:51 +0100537 struct afs_operation *op = call->op;
538 struct afs_vnode_param *dvp = &op->file[0];
539 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100540 const __be32 *bp;
541 int ret;
542
543 _enter("{%u}", call->unmarshall);
544
545 ret = afs_transfer_reply(call);
546 if (ret < 0)
547 return ret;
548
549 /* unmarshall the reply once we've received all of it */
550 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100551 xdr_decode_YFSFid(&bp, &op->file[1].fid);
552 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
553 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
554 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
555 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100556
557 _leave(" = 0 [done]");
558 return 0;
559}
560
561/*
562 * FS.CreateFile and FS.MakeDir operation type
563 */
564static const struct afs_call_type afs_RXFSCreateFile = {
565 .name = "YFS.CreateFile",
566 .op = yfs_FS_CreateFile,
567 .deliver = yfs_deliver_fs_create_vnode,
568 .destructor = afs_flat_call_destructor,
569};
570
571/*
572 * Create a file.
573 */
David Howellse49c7b22020-04-10 20:51:51 +0100574void yfs_fs_create_file(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100575{
David Howellse49c7b22020-04-10 20:51:51 +0100576 const struct qstr *name = &op->dentry->d_name;
577 struct afs_vnode_param *dvp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +0100578 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +0100579 size_t reqsz, rplsz;
David Howells30062bd2018-10-20 00:57:58 +0100580 __be32 *bp;
581
582 _enter("");
583
David Howells30062bd2018-10-20 00:57:58 +0100584 reqsz = (sizeof(__be32) +
585 sizeof(__be32) +
586 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +0100587 xdr_strlen(name->len) +
David Howells30062bd2018-10-20 00:57:58 +0100588 sizeof(struct yfs_xdr_YFSStoreStatus) +
589 sizeof(__be32));
590 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
591 sizeof(struct yfs_xdr_YFSFetchStatus) +
592 sizeof(struct yfs_xdr_YFSFetchStatus) +
593 sizeof(struct yfs_xdr_YFSCallBack) +
594 sizeof(struct yfs_xdr_YFSVolSync));
595
David Howellse49c7b22020-04-10 20:51:51 +0100596 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
David Howells30062bd2018-10-20 00:57:58 +0100597 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100598 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100599
600 /* marshall the parameters */
601 bp = call->request;
602 bp = xdr_encode_u32(bp, YFSCREATEFILE);
603 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100604 bp = xdr_encode_YFSFid(bp, &dvp->fid);
605 bp = xdr_encode_name(bp, name);
606 bp = xdr_encode_YFSStoreStatus_mode(bp, op->create.mode);
Marc Dionne5edc22c2019-01-09 17:23:54 +0000607 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
David Howells30062bd2018-10-20 00:57:58 +0100608 yfs_check_req(call, bp);
609
David Howellse49c7b22020-04-10 20:51:51 +0100610 trace_afs_make_fs_call1(call, &dvp->fid, name);
611 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100612}
613
614static const struct afs_call_type yfs_RXFSMakeDir = {
615 .name = "YFS.MakeDir",
616 .op = yfs_FS_MakeDir,
617 .deliver = yfs_deliver_fs_create_vnode,
618 .destructor = afs_flat_call_destructor,
619};
620
621/*
622 * Make a directory.
623 */
David Howellse49c7b22020-04-10 20:51:51 +0100624void yfs_fs_make_dir(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100625{
David Howellse49c7b22020-04-10 20:51:51 +0100626 const struct qstr *name = &op->dentry->d_name;
627 struct afs_vnode_param *dvp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +0100628 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +0100629 size_t reqsz, rplsz;
David Howells30062bd2018-10-20 00:57:58 +0100630 __be32 *bp;
631
632 _enter("");
633
David Howells30062bd2018-10-20 00:57:58 +0100634 reqsz = (sizeof(__be32) +
635 sizeof(struct yfs_xdr_RPCFlags) +
636 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +0100637 xdr_strlen(name->len) +
David Howells30062bd2018-10-20 00:57:58 +0100638 sizeof(struct yfs_xdr_YFSStoreStatus));
639 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
640 sizeof(struct yfs_xdr_YFSFetchStatus) +
641 sizeof(struct yfs_xdr_YFSFetchStatus) +
642 sizeof(struct yfs_xdr_YFSCallBack) +
643 sizeof(struct yfs_xdr_YFSVolSync));
644
David Howellse49c7b22020-04-10 20:51:51 +0100645 call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
David Howells30062bd2018-10-20 00:57:58 +0100646 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100647 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100648
649 /* marshall the parameters */
650 bp = call->request;
651 bp = xdr_encode_u32(bp, YFSMAKEDIR);
652 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100653 bp = xdr_encode_YFSFid(bp, &dvp->fid);
654 bp = xdr_encode_name(bp, name);
655 bp = xdr_encode_YFSStoreStatus_mode(bp, op->create.mode);
David Howells30062bd2018-10-20 00:57:58 +0100656 yfs_check_req(call, bp);
657
David Howellse49c7b22020-04-10 20:51:51 +0100658 trace_afs_make_fs_call1(call, &dvp->fid, name);
659 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100660}
661
662/*
663 * Deliver reply data to a YFS.RemoveFile2 operation.
664 */
665static int yfs_deliver_fs_remove_file2(struct afs_call *call)
666{
David Howellse49c7b22020-04-10 20:51:51 +0100667 struct afs_operation *op = call->op;
668 struct afs_vnode_param *dvp = &op->file[0];
669 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100670 struct afs_fid fid;
671 const __be32 *bp;
672 int ret;
673
674 _enter("{%u}", call->unmarshall);
675
676 ret = afs_transfer_reply(call);
677 if (ret < 0)
678 return ret;
679
David Howells30062bd2018-10-20 00:57:58 +0100680 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100681 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
David Howells30062bd2018-10-20 00:57:58 +0100682 xdr_decode_YFSFid(&bp, &fid);
David Howellse49c7b22020-04-10 20:51:51 +0100683 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
David Howells30062bd2018-10-20 00:57:58 +0100684 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
685
David Howellse49c7b22020-04-10 20:51:51 +0100686 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100687 return 0;
688}
689
David Howellse49c7b22020-04-10 20:51:51 +0100690static void yfs_done_fs_remove_file2(struct afs_call *call)
691{
692 if (call->error == -ECONNABORTED &&
693 call->abort_code == RX_INVALID_OPERATION) {
694 set_bit(AFS_SERVER_FL_NO_RM2, &call->server->flags);
695 call->op->flags |= AFS_OPERATION_DOWNGRADE;
696 }
697}
698
David Howells30062bd2018-10-20 00:57:58 +0100699/*
700 * YFS.RemoveFile2 operation type.
701 */
702static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
703 .name = "YFS.RemoveFile2",
704 .op = yfs_FS_RemoveFile2,
705 .deliver = yfs_deliver_fs_remove_file2,
David Howellse49c7b22020-04-10 20:51:51 +0100706 .done = yfs_done_fs_remove_file2,
David Howells30062bd2018-10-20 00:57:58 +0100707 .destructor = afs_flat_call_destructor,
708};
709
710/*
711 * Remove a file and retrieve new file status.
712 */
David Howellse49c7b22020-04-10 20:51:51 +0100713void yfs_fs_remove_file2(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100714{
David Howellse49c7b22020-04-10 20:51:51 +0100715 struct afs_vnode_param *dvp = &op->file[0];
716 const struct qstr *name = &op->dentry->d_name;
David Howells30062bd2018-10-20 00:57:58 +0100717 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100718 __be32 *bp;
719
720 _enter("");
721
David Howellse49c7b22020-04-10 20:51:51 +0100722 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
David Howells30062bd2018-10-20 00:57:58 +0100723 sizeof(__be32) +
724 sizeof(struct yfs_xdr_RPCFlags) +
725 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +0100726 xdr_strlen(name->len),
David Howells30062bd2018-10-20 00:57:58 +0100727 sizeof(struct yfs_xdr_YFSFetchStatus) +
728 sizeof(struct yfs_xdr_YFSFid) +
729 sizeof(struct yfs_xdr_YFSFetchStatus) +
730 sizeof(struct yfs_xdr_YFSVolSync));
731 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100732 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100733
734 /* marshall the parameters */
735 bp = call->request;
736 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
737 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100738 bp = xdr_encode_YFSFid(bp, &dvp->fid);
739 bp = xdr_encode_name(bp, name);
David Howells30062bd2018-10-20 00:57:58 +0100740 yfs_check_req(call, bp);
741
David Howellse49c7b22020-04-10 20:51:51 +0100742 trace_afs_make_fs_call1(call, &dvp->fid, name);
743 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100744}
745
746/*
747 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
748 */
749static int yfs_deliver_fs_remove(struct afs_call *call)
750{
David Howellse49c7b22020-04-10 20:51:51 +0100751 struct afs_operation *op = call->op;
752 struct afs_vnode_param *dvp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +0100753 const __be32 *bp;
754 int ret;
755
756 _enter("{%u}", call->unmarshall);
757
758 ret = afs_transfer_reply(call);
759 if (ret < 0)
760 return ret;
761
David Howells30062bd2018-10-20 00:57:58 +0100762 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100763 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
764 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100765 return 0;
766}
767
768/*
769 * FS.RemoveDir and FS.RemoveFile operation types.
770 */
771static const struct afs_call_type yfs_RXYFSRemoveFile = {
772 .name = "YFS.RemoveFile",
773 .op = yfs_FS_RemoveFile,
774 .deliver = yfs_deliver_fs_remove,
775 .destructor = afs_flat_call_destructor,
776};
777
David Howellse49c7b22020-04-10 20:51:51 +0100778/*
779 * Remove a file.
780 */
781void yfs_fs_remove_file(struct afs_operation *op)
782{
783 const struct qstr *name = &op->dentry->d_name;
784 struct afs_vnode_param *dvp = &op->file[0];
785 struct afs_call *call;
786 __be32 *bp;
787
788 _enter("");
789
David Howells20325962020-04-30 01:03:49 +0100790 if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
David Howellse49c7b22020-04-10 20:51:51 +0100791 return yfs_fs_remove_file2(op);
792
793 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
794 sizeof(__be32) +
795 sizeof(struct yfs_xdr_RPCFlags) +
796 sizeof(struct yfs_xdr_YFSFid) +
797 xdr_strlen(name->len),
798 sizeof(struct yfs_xdr_YFSFetchStatus) +
799 sizeof(struct yfs_xdr_YFSVolSync));
800 if (!call)
801 return afs_op_nomem(op);
802
803 /* marshall the parameters */
804 bp = call->request;
805 bp = xdr_encode_u32(bp, YFSREMOVEFILE);
806 bp = xdr_encode_u32(bp, 0); /* RPC flags */
807 bp = xdr_encode_YFSFid(bp, &dvp->fid);
808 bp = xdr_encode_name(bp, name);
809 yfs_check_req(call, bp);
810
811 trace_afs_make_fs_call1(call, &dvp->fid, name);
812 afs_make_op_call(op, call, GFP_NOFS);
813}
814
David Howells30062bd2018-10-20 00:57:58 +0100815static const struct afs_call_type yfs_RXYFSRemoveDir = {
816 .name = "YFS.RemoveDir",
817 .op = yfs_FS_RemoveDir,
818 .deliver = yfs_deliver_fs_remove,
819 .destructor = afs_flat_call_destructor,
820};
821
822/*
David Howellse49c7b22020-04-10 20:51:51 +0100823 * Remove a directory.
David Howells30062bd2018-10-20 00:57:58 +0100824 */
David Howellse49c7b22020-04-10 20:51:51 +0100825void yfs_fs_remove_dir(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100826{
David Howellse49c7b22020-04-10 20:51:51 +0100827 const struct qstr *name = &op->dentry->d_name;
828 struct afs_vnode_param *dvp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +0100829 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100830 __be32 *bp;
831
832 _enter("");
833
David Howellse49c7b22020-04-10 20:51:51 +0100834 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
835 sizeof(__be32) +
836 sizeof(struct yfs_xdr_RPCFlags) +
837 sizeof(struct yfs_xdr_YFSFid) +
838 xdr_strlen(name->len),
839 sizeof(struct yfs_xdr_YFSFetchStatus) +
840 sizeof(struct yfs_xdr_YFSVolSync));
David Howells30062bd2018-10-20 00:57:58 +0100841 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100842 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100843
844 /* marshall the parameters */
845 bp = call->request;
David Howellse49c7b22020-04-10 20:51:51 +0100846 bp = xdr_encode_u32(bp, YFSREMOVEDIR);
David Howells30062bd2018-10-20 00:57:58 +0100847 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100848 bp = xdr_encode_YFSFid(bp, &dvp->fid);
849 bp = xdr_encode_name(bp, name);
David Howells30062bd2018-10-20 00:57:58 +0100850 yfs_check_req(call, bp);
851
David Howellse49c7b22020-04-10 20:51:51 +0100852 trace_afs_make_fs_call1(call, &dvp->fid, name);
853 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100854}
855
856/*
857 * Deliver reply data to a YFS.Link operation.
858 */
859static int yfs_deliver_fs_link(struct afs_call *call)
860{
David Howellse49c7b22020-04-10 20:51:51 +0100861 struct afs_operation *op = call->op;
862 struct afs_vnode_param *dvp = &op->file[0];
863 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100864 const __be32 *bp;
865 int ret;
866
867 _enter("{%u}", call->unmarshall);
868
869 ret = afs_transfer_reply(call);
870 if (ret < 0)
871 return ret;
872
David Howells30062bd2018-10-20 00:57:58 +0100873 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100874 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
875 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
876 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100877 _leave(" = 0 [done]");
878 return 0;
879}
880
881/*
882 * YFS.Link operation type.
883 */
884static const struct afs_call_type yfs_RXYFSLink = {
885 .name = "YFS.Link",
886 .op = yfs_FS_Link,
887 .deliver = yfs_deliver_fs_link,
888 .destructor = afs_flat_call_destructor,
889};
890
891/*
892 * Make a hard link.
893 */
David Howellse49c7b22020-04-10 20:51:51 +0100894void yfs_fs_link(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100895{
David Howellse49c7b22020-04-10 20:51:51 +0100896 const struct qstr *name = &op->dentry->d_name;
897 struct afs_vnode_param *dvp = &op->file[0];
898 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100899 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100900 __be32 *bp;
901
902 _enter("");
903
David Howellse49c7b22020-04-10 20:51:51 +0100904 call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
David Howells30062bd2018-10-20 00:57:58 +0100905 sizeof(__be32) +
906 sizeof(struct yfs_xdr_RPCFlags) +
907 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +0100908 xdr_strlen(name->len) +
David Howells30062bd2018-10-20 00:57:58 +0100909 sizeof(struct yfs_xdr_YFSFid),
910 sizeof(struct yfs_xdr_YFSFetchStatus) +
911 sizeof(struct yfs_xdr_YFSFetchStatus) +
912 sizeof(struct yfs_xdr_YFSVolSync));
913 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100914 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100915
916 /* marshall the parameters */
917 bp = call->request;
918 bp = xdr_encode_u32(bp, YFSLINK);
919 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100920 bp = xdr_encode_YFSFid(bp, &dvp->fid);
921 bp = xdr_encode_name(bp, name);
922 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +0100923 yfs_check_req(call, bp);
924
David Howellse49c7b22020-04-10 20:51:51 +0100925 trace_afs_make_fs_call1(call, &vp->fid, name);
926 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +0100927}
928
929/*
930 * Deliver reply data to a YFS.Symlink operation.
931 */
932static int yfs_deliver_fs_symlink(struct afs_call *call)
933{
David Howellse49c7b22020-04-10 20:51:51 +0100934 struct afs_operation *op = call->op;
935 struct afs_vnode_param *dvp = &op->file[0];
936 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +0100937 const __be32 *bp;
938 int ret;
939
940 _enter("{%u}", call->unmarshall);
941
942 ret = afs_transfer_reply(call);
943 if (ret < 0)
944 return ret;
945
946 /* unmarshall the reply once we've received all of it */
947 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +0100948 xdr_decode_YFSFid(&bp, &vp->fid);
949 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
950 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
951 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +0100952
953 _leave(" = 0 [done]");
954 return 0;
955}
956
957/*
958 * YFS.Symlink operation type
959 */
960static const struct afs_call_type yfs_RXYFSSymlink = {
961 .name = "YFS.Symlink",
962 .op = yfs_FS_Symlink,
963 .deliver = yfs_deliver_fs_symlink,
964 .destructor = afs_flat_call_destructor,
965};
966
967/*
968 * Create a symbolic link.
969 */
David Howellse49c7b22020-04-10 20:51:51 +0100970void yfs_fs_symlink(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +0100971{
David Howellse49c7b22020-04-10 20:51:51 +0100972 const struct qstr *name = &op->dentry->d_name;
973 struct afs_vnode_param *dvp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +0100974 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +0100975 size_t contents_sz;
David Howells30062bd2018-10-20 00:57:58 +0100976 __be32 *bp;
977
978 _enter("");
979
David Howellse49c7b22020-04-10 20:51:51 +0100980 contents_sz = strlen(op->create.symlink);
981 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
David Howells30062bd2018-10-20 00:57:58 +0100982 sizeof(__be32) +
983 sizeof(struct yfs_xdr_RPCFlags) +
984 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +0100985 xdr_strlen(name->len) +
David Howells30062bd2018-10-20 00:57:58 +0100986 xdr_strlen(contents_sz) +
987 sizeof(struct yfs_xdr_YFSStoreStatus),
988 sizeof(struct yfs_xdr_YFSFid) +
989 sizeof(struct yfs_xdr_YFSFetchStatus) +
990 sizeof(struct yfs_xdr_YFSFetchStatus) +
991 sizeof(struct yfs_xdr_YFSVolSync));
992 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +0100993 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +0100994
995 /* marshall the parameters */
996 bp = call->request;
997 bp = xdr_encode_u32(bp, YFSSYMLINK);
998 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +0100999 bp = xdr_encode_YFSFid(bp, &dvp->fid);
1000 bp = xdr_encode_name(bp, name);
1001 bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
David Howells30062bd2018-10-20 00:57:58 +01001002 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
1003 yfs_check_req(call, bp);
1004
David Howellse49c7b22020-04-10 20:51:51 +01001005 trace_afs_make_fs_call1(call, &dvp->fid, name);
1006 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001007}
1008
1009/*
1010 * Deliver reply data to a YFS.Rename operation.
1011 */
1012static int yfs_deliver_fs_rename(struct afs_call *call)
1013{
David Howellse49c7b22020-04-10 20:51:51 +01001014 struct afs_operation *op = call->op;
1015 struct afs_vnode_param *orig_dvp = &op->file[0];
1016 struct afs_vnode_param *new_dvp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +01001017 const __be32 *bp;
1018 int ret;
1019
1020 _enter("{%u}", call->unmarshall);
1021
1022 ret = afs_transfer_reply(call);
1023 if (ret < 0)
1024 return ret;
1025
David Howells30062bd2018-10-20 00:57:58 +01001026 bp = call->buffer;
David Howells38355ee2020-04-08 16:13:20 +01001027 /* If the two dirs are the same, we have two copies of the same status
1028 * report, so we just decode it twice.
1029 */
David Howellse49c7b22020-04-10 20:51:51 +01001030 xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
1031 xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
1032 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +01001033 _leave(" = 0 [done]");
1034 return 0;
1035}
1036
1037/*
1038 * YFS.Rename operation type
1039 */
1040static const struct afs_call_type yfs_RXYFSRename = {
1041 .name = "FS.Rename",
1042 .op = yfs_FS_Rename,
1043 .deliver = yfs_deliver_fs_rename,
1044 .destructor = afs_flat_call_destructor,
1045};
1046
1047/*
1048 * Rename a file or directory.
1049 */
David Howellse49c7b22020-04-10 20:51:51 +01001050void yfs_fs_rename(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001051{
David Howellse49c7b22020-04-10 20:51:51 +01001052 struct afs_vnode_param *orig_dvp = &op->file[0];
1053 struct afs_vnode_param *new_dvp = &op->file[1];
1054 const struct qstr *orig_name = &op->dentry->d_name;
1055 const struct qstr *new_name = &op->dentry_2->d_name;
David Howells30062bd2018-10-20 00:57:58 +01001056 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001057 __be32 *bp;
1058
1059 _enter("");
1060
David Howellse49c7b22020-04-10 20:51:51 +01001061 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
David Howells30062bd2018-10-20 00:57:58 +01001062 sizeof(__be32) +
1063 sizeof(struct yfs_xdr_RPCFlags) +
1064 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +01001065 xdr_strlen(orig_name->len) +
David Howells30062bd2018-10-20 00:57:58 +01001066 sizeof(struct yfs_xdr_YFSFid) +
David Howellse49c7b22020-04-10 20:51:51 +01001067 xdr_strlen(new_name->len),
David Howells30062bd2018-10-20 00:57:58 +01001068 sizeof(struct yfs_xdr_YFSFetchStatus) +
1069 sizeof(struct yfs_xdr_YFSFetchStatus) +
1070 sizeof(struct yfs_xdr_YFSVolSync));
1071 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001072 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001073
1074 /* marshall the parameters */
1075 bp = call->request;
1076 bp = xdr_encode_u32(bp, YFSRENAME);
1077 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001078 bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
1079 bp = xdr_encode_name(bp, orig_name);
1080 bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
1081 bp = xdr_encode_name(bp, new_name);
David Howells30062bd2018-10-20 00:57:58 +01001082 yfs_check_req(call, bp);
1083
David Howellse49c7b22020-04-10 20:51:51 +01001084 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1085 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001086}
1087
1088/*
David Howells30062bd2018-10-20 00:57:58 +01001089 * YFS.StoreData64 operation type.
1090 */
1091static const struct afs_call_type yfs_RXYFSStoreData64 = {
1092 .name = "YFS.StoreData64",
1093 .op = yfs_FS_StoreData64,
David Howellsa58823a2019-05-09 15:16:10 +01001094 .deliver = yfs_deliver_status_and_volsync,
David Howells30062bd2018-10-20 00:57:58 +01001095 .destructor = afs_flat_call_destructor,
1096};
1097
1098/*
1099 * Store a set of pages to a large file.
1100 */
David Howellse49c7b22020-04-10 20:51:51 +01001101void yfs_fs_store_data(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001102{
David Howellse49c7b22020-04-10 20:51:51 +01001103 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001104 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001105 loff_t size, pos, i_size;
1106 __be32 *bp;
1107
1108 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001109 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells30062bd2018-10-20 00:57:58 +01001110
David Howellse49c7b22020-04-10 20:51:51 +01001111 size = (loff_t)op->store.last_to - (loff_t)op->store.first_offset;
1112 if (op->store.first != op->store.last)
1113 size += (loff_t)(op->store.last - op->store.first) << PAGE_SHIFT;
1114 pos = (loff_t)op->store.first << PAGE_SHIFT;
1115 pos += op->store.first_offset;
David Howells30062bd2018-10-20 00:57:58 +01001116
David Howellse49c7b22020-04-10 20:51:51 +01001117 i_size = i_size_read(&vp->vnode->vfs_inode);
David Howells30062bd2018-10-20 00:57:58 +01001118 if (pos + size > i_size)
1119 i_size = size + pos;
1120
1121 _debug("size %llx, at %llx, i_size %llx",
1122 (unsigned long long)size, (unsigned long long)pos,
1123 (unsigned long long)i_size);
1124
David Howellse49c7b22020-04-10 20:51:51 +01001125 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
David Howells30062bd2018-10-20 00:57:58 +01001126 sizeof(__be32) +
1127 sizeof(__be32) +
1128 sizeof(struct yfs_xdr_YFSFid) +
1129 sizeof(struct yfs_xdr_YFSStoreStatus) +
1130 sizeof(struct yfs_xdr_u64) * 3,
1131 sizeof(struct yfs_xdr_YFSFetchStatus) +
1132 sizeof(struct yfs_xdr_YFSVolSync));
1133 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001134 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001135
David Howellse49c7b22020-04-10 20:51:51 +01001136 call->key = op->key;
David Howells30062bd2018-10-20 00:57:58 +01001137 call->send_pages = true;
David Howells30062bd2018-10-20 00:57:58 +01001138
1139 /* marshall the parameters */
1140 bp = call->request;
1141 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1142 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001143 bp = xdr_encode_YFSFid(bp, &vp->fid);
1144 bp = xdr_encode_YFSStoreStatus_mtime(bp, &op->mtime);
David Howells30062bd2018-10-20 00:57:58 +01001145 bp = xdr_encode_u64(bp, pos);
1146 bp = xdr_encode_u64(bp, size);
1147 bp = xdr_encode_u64(bp, i_size);
1148 yfs_check_req(call, bp);
1149
David Howellse49c7b22020-04-10 20:51:51 +01001150 trace_afs_make_fs_call(call, &vp->fid);
1151 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001152}
1153
1154/*
David Howells30062bd2018-10-20 00:57:58 +01001155 * YFS.StoreStatus operation type
1156 */
1157static const struct afs_call_type yfs_RXYFSStoreStatus = {
1158 .name = "YFS.StoreStatus",
1159 .op = yfs_FS_StoreStatus,
David Howellsa58823a2019-05-09 15:16:10 +01001160 .deliver = yfs_deliver_status_and_volsync,
David Howells30062bd2018-10-20 00:57:58 +01001161 .destructor = afs_flat_call_destructor,
1162};
1163
1164static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1165 .name = "YFS.StoreData64",
1166 .op = yfs_FS_StoreData64,
David Howellsa58823a2019-05-09 15:16:10 +01001167 .deliver = yfs_deliver_status_and_volsync,
David Howells30062bd2018-10-20 00:57:58 +01001168 .destructor = afs_flat_call_destructor,
1169};
1170
1171/*
1172 * Set the attributes on a file, using YFS.StoreData64 rather than
1173 * YFS.StoreStatus so as to alter the file size also.
1174 */
David Howellse49c7b22020-04-10 20:51:51 +01001175static void yfs_fs_setattr_size(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001176{
David Howellse49c7b22020-04-10 20:51:51 +01001177 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001178 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +01001179 struct iattr *attr = op->setattr.attr;
David Howells30062bd2018-10-20 00:57:58 +01001180 __be32 *bp;
1181
1182 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001183 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells30062bd2018-10-20 00:57:58 +01001184
David Howellse49c7b22020-04-10 20:51:51 +01001185 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
David Howells30062bd2018-10-20 00:57:58 +01001186 sizeof(__be32) * 2 +
1187 sizeof(struct yfs_xdr_YFSFid) +
1188 sizeof(struct yfs_xdr_YFSStoreStatus) +
1189 sizeof(struct yfs_xdr_u64) * 3,
1190 sizeof(struct yfs_xdr_YFSFetchStatus) +
1191 sizeof(struct yfs_xdr_YFSVolSync));
1192 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001193 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001194
1195 /* marshall the parameters */
1196 bp = call->request;
1197 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1198 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001199 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +01001200 bp = xdr_encode_YFS_StoreStatus(bp, attr);
David Howells8c7ae382019-03-27 22:48:02 +00001201 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
David Howells30062bd2018-10-20 00:57:58 +01001202 bp = xdr_encode_u64(bp, 0); /* size of write */
1203 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1204 yfs_check_req(call, bp);
1205
David Howellse49c7b22020-04-10 20:51:51 +01001206 trace_afs_make_fs_call(call, &vp->fid);
1207 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001208}
1209
1210/*
1211 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1212 * file size, and YFS.StoreStatus otherwise.
1213 */
David Howellse49c7b22020-04-10 20:51:51 +01001214void yfs_fs_setattr(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001215{
David Howellse49c7b22020-04-10 20:51:51 +01001216 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001217 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +01001218 struct iattr *attr = op->setattr.attr;
David Howells30062bd2018-10-20 00:57:58 +01001219 __be32 *bp;
1220
1221 if (attr->ia_valid & ATTR_SIZE)
David Howellse49c7b22020-04-10 20:51:51 +01001222 return yfs_fs_setattr_size(op);
David Howells30062bd2018-10-20 00:57:58 +01001223
1224 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001225 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells30062bd2018-10-20 00:57:58 +01001226
David Howellse49c7b22020-04-10 20:51:51 +01001227 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
David Howells30062bd2018-10-20 00:57:58 +01001228 sizeof(__be32) * 2 +
1229 sizeof(struct yfs_xdr_YFSFid) +
1230 sizeof(struct yfs_xdr_YFSStoreStatus),
1231 sizeof(struct yfs_xdr_YFSFetchStatus) +
1232 sizeof(struct yfs_xdr_YFSVolSync));
1233 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001234 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001235
1236 /* marshall the parameters */
1237 bp = call->request;
1238 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1239 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001240 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +01001241 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1242 yfs_check_req(call, bp);
1243
David Howellse49c7b22020-04-10 20:51:51 +01001244 trace_afs_make_fs_call(call, &vp->fid);
1245 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001246}
1247
1248/*
1249 * Deliver reply data to a YFS.GetVolumeStatus operation.
1250 */
1251static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1252{
David Howellse49c7b22020-04-10 20:51:51 +01001253 struct afs_operation *op = call->op;
David Howells30062bd2018-10-20 00:57:58 +01001254 const __be32 *bp;
1255 char *p;
1256 u32 size;
1257 int ret;
1258
1259 _enter("{%u}", call->unmarshall);
1260
1261 switch (call->unmarshall) {
1262 case 0:
1263 call->unmarshall++;
1264 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001265 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001266
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001267 /* extract the returned status record */
David Howells30062bd2018-10-20 00:57:58 +01001268 case 1:
1269 _debug("extract status");
1270 ret = afs_extract_data(call, true);
1271 if (ret < 0)
1272 return ret;
1273
1274 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +01001275 xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
David Howells30062bd2018-10-20 00:57:58 +01001276 call->unmarshall++;
1277 afs_extract_to_tmp(call);
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 volume name length */
David Howells30062bd2018-10-20 00:57:58 +01001281 case 2:
1282 ret = afs_extract_data(call, true);
1283 if (ret < 0)
1284 return ret;
1285
1286 call->count = ntohl(call->tmp);
1287 _debug("volname length: %u", call->count);
1288 if (call->count >= AFSNAMEMAX)
David Howells7126ead2020-04-08 16:49:08 +01001289 return afs_protocol_error(call, afs_eproto_volname_len);
David Howells30062bd2018-10-20 00:57:58 +01001290 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001291 afs_extract_to_buf(call, size);
David Howells30062bd2018-10-20 00:57:58 +01001292 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 volume name */
David Howells30062bd2018-10-20 00:57:58 +01001296 case 3:
1297 _debug("extract volname");
1298 ret = afs_extract_data(call, true);
1299 if (ret < 0)
1300 return ret;
1301
David Howellsffba7182019-05-09 22:22:50 +01001302 p = call->buffer;
David Howells30062bd2018-10-20 00:57:58 +01001303 p[call->count] = 0;
1304 _debug("volname '%s'", p);
1305 afs_extract_to_tmp(call);
1306 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001307 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001308
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001309 /* extract the offline message length */
David Howells30062bd2018-10-20 00:57:58 +01001310 case 4:
1311 ret = afs_extract_data(call, true);
1312 if (ret < 0)
1313 return ret;
1314
1315 call->count = ntohl(call->tmp);
1316 _debug("offline msg length: %u", call->count);
1317 if (call->count >= AFSNAMEMAX)
David Howells7126ead2020-04-08 16:49:08 +01001318 return afs_protocol_error(call, afs_eproto_offline_msg_len);
David Howells30062bd2018-10-20 00:57:58 +01001319 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001320 afs_extract_to_buf(call, size);
David Howells30062bd2018-10-20 00:57:58 +01001321 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001322 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001323
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001324 /* extract the offline message */
David Howells30062bd2018-10-20 00:57:58 +01001325 case 5:
1326 _debug("extract offline");
1327 ret = afs_extract_data(call, true);
1328 if (ret < 0)
1329 return ret;
1330
David Howellsffba7182019-05-09 22:22:50 +01001331 p = call->buffer;
David Howells30062bd2018-10-20 00:57:58 +01001332 p[call->count] = 0;
1333 _debug("offline '%s'", p);
1334
1335 afs_extract_to_tmp(call);
1336 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001337 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001338
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001339 /* extract the message of the day length */
David Howells30062bd2018-10-20 00:57:58 +01001340 case 6:
1341 ret = afs_extract_data(call, true);
1342 if (ret < 0)
1343 return ret;
1344
1345 call->count = ntohl(call->tmp);
1346 _debug("motd length: %u", call->count);
1347 if (call->count >= AFSNAMEMAX)
David Howells7126ead2020-04-08 16:49:08 +01001348 return afs_protocol_error(call, afs_eproto_motd_len);
David Howells30062bd2018-10-20 00:57:58 +01001349 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001350 afs_extract_to_buf(call, size);
David Howells30062bd2018-10-20 00:57:58 +01001351 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001352 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001353
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001354 /* extract the message of the day */
David Howells30062bd2018-10-20 00:57:58 +01001355 case 7:
1356 _debug("extract motd");
1357 ret = afs_extract_data(call, false);
1358 if (ret < 0)
1359 return ret;
1360
David Howellsffba7182019-05-09 22:22:50 +01001361 p = call->buffer;
David Howells30062bd2018-10-20 00:57:58 +01001362 p[call->count] = 0;
1363 _debug("motd '%s'", p);
1364
1365 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001366 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001367
David Howells30062bd2018-10-20 00:57:58 +01001368 case 8:
1369 break;
1370 }
1371
1372 _leave(" = 0 [done]");
1373 return 0;
1374}
1375
1376/*
David Howells30062bd2018-10-20 00:57:58 +01001377 * YFS.GetVolumeStatus operation type
1378 */
1379static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1380 .name = "YFS.GetVolumeStatus",
1381 .op = yfs_FS_GetVolumeStatus,
1382 .deliver = yfs_deliver_fs_get_volume_status,
David Howellsffba7182019-05-09 22:22:50 +01001383 .destructor = afs_flat_call_destructor,
David Howells30062bd2018-10-20 00:57:58 +01001384};
1385
1386/*
1387 * fetch the status of a volume
1388 */
David Howellse49c7b22020-04-10 20:51:51 +01001389void yfs_fs_get_volume_status(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001390{
David Howellse49c7b22020-04-10 20:51:51 +01001391 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001392 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001393 __be32 *bp;
David Howells30062bd2018-10-20 00:57:58 +01001394
1395 _enter("");
1396
David Howellse49c7b22020-04-10 20:51:51 +01001397 call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
David Howells30062bd2018-10-20 00:57:58 +01001398 sizeof(__be32) * 2 +
1399 sizeof(struct yfs_xdr_u64),
David Howellsffba7182019-05-09 22:22:50 +01001400 max_t(size_t,
1401 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1402 sizeof(__be32),
1403 AFSOPAQUEMAX + 1));
1404 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001405 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001406
1407 /* marshall the parameters */
1408 bp = call->request;
1409 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1410 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001411 bp = xdr_encode_u64(bp, vp->fid.vid);
David Howells30062bd2018-10-20 00:57:58 +01001412 yfs_check_req(call, bp);
1413
David Howellse49c7b22020-04-10 20:51:51 +01001414 trace_afs_make_fs_call(call, &vp->fid);
1415 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001416}
1417
1418/*
David Howells30062bd2018-10-20 00:57:58 +01001419 * YFS.SetLock operation type
1420 */
1421static const struct afs_call_type yfs_RXYFSSetLock = {
1422 .name = "YFS.SetLock",
1423 .op = yfs_FS_SetLock,
David Howellsf5e45462019-05-01 14:05:27 +01001424 .deliver = yfs_deliver_status_and_volsync,
David Howellsa690f602019-04-25 14:26:50 +01001425 .done = afs_lock_op_done,
David Howells30062bd2018-10-20 00:57:58 +01001426 .destructor = afs_flat_call_destructor,
1427};
1428
1429/*
1430 * YFS.ExtendLock operation type
1431 */
1432static const struct afs_call_type yfs_RXYFSExtendLock = {
1433 .name = "YFS.ExtendLock",
1434 .op = yfs_FS_ExtendLock,
David Howellsf5e45462019-05-01 14:05:27 +01001435 .deliver = yfs_deliver_status_and_volsync,
David Howellsa690f602019-04-25 14:26:50 +01001436 .done = afs_lock_op_done,
David Howells30062bd2018-10-20 00:57:58 +01001437 .destructor = afs_flat_call_destructor,
1438};
1439
1440/*
1441 * YFS.ReleaseLock operation type
1442 */
1443static const struct afs_call_type yfs_RXYFSReleaseLock = {
1444 .name = "YFS.ReleaseLock",
1445 .op = yfs_FS_ReleaseLock,
David Howellsf5e45462019-05-01 14:05:27 +01001446 .deliver = yfs_deliver_status_and_volsync,
David Howells30062bd2018-10-20 00:57:58 +01001447 .destructor = afs_flat_call_destructor,
1448};
1449
1450/*
1451 * Set a lock on a file
1452 */
David Howellse49c7b22020-04-10 20:51:51 +01001453void yfs_fs_set_lock(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001454{
David Howellse49c7b22020-04-10 20:51:51 +01001455 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001456 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001457 __be32 *bp;
1458
1459 _enter("");
1460
David Howellse49c7b22020-04-10 20:51:51 +01001461 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
David Howells30062bd2018-10-20 00:57:58 +01001462 sizeof(__be32) * 2 +
1463 sizeof(struct yfs_xdr_YFSFid) +
1464 sizeof(__be32),
1465 sizeof(struct yfs_xdr_YFSFetchStatus) +
1466 sizeof(struct yfs_xdr_YFSVolSync));
1467 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001468 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001469
1470 /* marshall the parameters */
1471 bp = call->request;
1472 bp = xdr_encode_u32(bp, YFSSETLOCK);
1473 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001474 bp = xdr_encode_YFSFid(bp, &vp->fid);
1475 bp = xdr_encode_u32(bp, op->lock.type);
David Howells30062bd2018-10-20 00:57:58 +01001476 yfs_check_req(call, bp);
1477
David Howellse49c7b22020-04-10 20:51:51 +01001478 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1479 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001480}
1481
1482/*
1483 * extend a lock on a file
1484 */
David Howellse49c7b22020-04-10 20:51:51 +01001485void yfs_fs_extend_lock(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001486{
David Howellse49c7b22020-04-10 20:51:51 +01001487 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001488 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001489 __be32 *bp;
1490
1491 _enter("");
1492
David Howellse49c7b22020-04-10 20:51:51 +01001493 call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
David Howells30062bd2018-10-20 00:57:58 +01001494 sizeof(__be32) * 2 +
1495 sizeof(struct yfs_xdr_YFSFid),
1496 sizeof(struct yfs_xdr_YFSFetchStatus) +
1497 sizeof(struct yfs_xdr_YFSVolSync));
1498 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001499 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001500
1501 /* marshall the parameters */
1502 bp = call->request;
1503 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1504 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001505 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +01001506 yfs_check_req(call, bp);
1507
David Howellse49c7b22020-04-10 20:51:51 +01001508 trace_afs_make_fs_call(call, &vp->fid);
1509 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001510}
1511
1512/*
1513 * release a lock on a file
1514 */
David Howellse49c7b22020-04-10 20:51:51 +01001515void yfs_fs_release_lock(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001516{
David Howellse49c7b22020-04-10 20:51:51 +01001517 struct afs_vnode_param *vp = &op->file[0];
David Howells30062bd2018-10-20 00:57:58 +01001518 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +01001519 __be32 *bp;
1520
1521 _enter("");
1522
David Howellse49c7b22020-04-10 20:51:51 +01001523 call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
David Howells30062bd2018-10-20 00:57:58 +01001524 sizeof(__be32) * 2 +
1525 sizeof(struct yfs_xdr_YFSFid),
1526 sizeof(struct yfs_xdr_YFSFetchStatus) +
1527 sizeof(struct yfs_xdr_YFSVolSync));
1528 if (!call)
David Howellse49c7b22020-04-10 20:51:51 +01001529 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001530
1531 /* marshall the parameters */
1532 bp = call->request;
1533 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1534 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001535 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +01001536 yfs_check_req(call, bp);
1537
David Howellse49c7b22020-04-10 20:51:51 +01001538 trace_afs_make_fs_call(call, &vp->fid);
1539 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001540}
1541
1542/*
David Howells9bd87ec2020-06-16 00:23:12 +01001543 * Deliver a reply to YFS.FetchStatus
1544 */
1545static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1546{
1547 struct afs_operation *op = call->op;
1548 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1549 const __be32 *bp;
1550 int ret;
1551
1552 ret = afs_transfer_reply(call);
1553 if (ret < 0)
1554 return ret;
1555
1556 /* unmarshall the reply once we've received all of it */
1557 bp = call->buffer;
1558 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1559 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
1560 xdr_decode_YFSVolSync(&bp, &op->volsync);
1561
1562 _leave(" = 0 [done]");
1563 return 0;
1564}
1565
1566/*
David Howells30062bd2018-10-20 00:57:58 +01001567 * YFS.FetchStatus operation type
1568 */
1569static const struct afs_call_type yfs_RXYFSFetchStatus = {
1570 .name = "YFS.FetchStatus",
1571 .op = yfs_FS_FetchStatus,
David Howells9bd87ec2020-06-16 00:23:12 +01001572 .deliver = yfs_deliver_fs_fetch_status,
David Howells30062bd2018-10-20 00:57:58 +01001573 .destructor = afs_flat_call_destructor,
1574};
1575
1576/*
1577 * Fetch the status information for a fid without needing a vnode handle.
1578 */
David Howellse49c7b22020-04-10 20:51:51 +01001579void yfs_fs_fetch_status(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001580{
David Howells9bd87ec2020-06-16 00:23:12 +01001581 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
David Howells30062bd2018-10-20 00:57:58 +01001582 struct afs_call *call;
1583 __be32 *bp;
1584
1585 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001586 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howells30062bd2018-10-20 00:57:58 +01001587
David Howellse49c7b22020-04-10 20:51:51 +01001588 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
David Howells30062bd2018-10-20 00:57:58 +01001589 sizeof(__be32) * 2 +
1590 sizeof(struct yfs_xdr_YFSFid),
1591 sizeof(struct yfs_xdr_YFSFetchStatus) +
1592 sizeof(struct yfs_xdr_YFSCallBack) +
1593 sizeof(struct yfs_xdr_YFSVolSync));
David Howellse49c7b22020-04-10 20:51:51 +01001594 if (!call)
1595 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001596
1597 /* marshall the parameters */
1598 bp = call->request;
1599 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
1600 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001601 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howells30062bd2018-10-20 00:57:58 +01001602 yfs_check_req(call, bp);
1603
David Howellse49c7b22020-04-10 20:51:51 +01001604 trace_afs_make_fs_call(call, &vp->fid);
1605 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001606}
1607
1608/*
1609 * Deliver reply data to an YFS.InlineBulkStatus call
1610 */
1611static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
1612{
David Howellse49c7b22020-04-10 20:51:51 +01001613 struct afs_operation *op = call->op;
David Howells87182752019-05-09 16:17:05 +01001614 struct afs_status_cb *scb;
David Howells30062bd2018-10-20 00:57:58 +01001615 const __be32 *bp;
1616 u32 tmp;
1617 int ret;
1618
1619 _enter("{%u}", call->unmarshall);
1620
1621 switch (call->unmarshall) {
1622 case 0:
1623 afs_extract_to_tmp(call);
1624 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001625 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001626
1627 /* Extract the file status count and array in two steps */
1628 case 1:
1629 _debug("extract status count");
1630 ret = afs_extract_data(call, true);
1631 if (ret < 0)
1632 return ret;
1633
1634 tmp = ntohl(call->tmp);
David Howellse49c7b22020-04-10 20:51:51 +01001635 _debug("status count: %u/%u", tmp, op->nr_files);
1636 if (tmp != op->nr_files)
David Howells7126ead2020-04-08 16:49:08 +01001637 return afs_protocol_error(call, afs_eproto_ibulkst_count);
David Howells30062bd2018-10-20 00:57:58 +01001638
1639 call->count = 0;
1640 call->unmarshall++;
1641 more_counts:
1642 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001643 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001644
David Howells30062bd2018-10-20 00:57:58 +01001645 case 2:
1646 _debug("extract status array %u", call->count);
1647 ret = afs_extract_data(call, true);
1648 if (ret < 0)
1649 return ret;
1650
David Howellse49c7b22020-04-10 20:51:51 +01001651 switch (call->count) {
1652 case 0:
1653 scb = &op->file[0].scb;
1654 break;
1655 case 1:
1656 scb = &op->file[1].scb;
1657 break;
1658 default:
1659 scb = &op->more_files[call->count - 2].scb;
1660 break;
1661 }
1662
David Howells30062bd2018-10-20 00:57:58 +01001663 bp = call->buffer;
David Howells38355ee2020-04-08 16:13:20 +01001664 xdr_decode_YFSFetchStatus(&bp, call, scb);
David Howells30062bd2018-10-20 00:57:58 +01001665
1666 call->count++;
David Howellse49c7b22020-04-10 20:51:51 +01001667 if (call->count < op->nr_files)
David Howells30062bd2018-10-20 00:57:58 +01001668 goto more_counts;
1669
1670 call->count = 0;
1671 call->unmarshall++;
1672 afs_extract_to_tmp(call);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001673 fallthrough;
David Howells30062bd2018-10-20 00:57:58 +01001674
1675 /* Extract the callback count and array in two steps */
1676 case 3:
1677 _debug("extract CB count");
1678 ret = afs_extract_data(call, true);
1679 if (ret < 0)
1680 return ret;
1681
1682 tmp = ntohl(call->tmp);
1683 _debug("CB count: %u", tmp);
David Howellse49c7b22020-04-10 20:51:51 +01001684 if (tmp != op->nr_files)
David Howells7126ead2020-04-08 16:49:08 +01001685 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
David Howells30062bd2018-10-20 00:57:58 +01001686 call->count = 0;
1687 call->unmarshall++;
1688 more_cbs:
1689 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001690 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001691
David Howells30062bd2018-10-20 00:57:58 +01001692 case 4:
1693 _debug("extract CB array");
1694 ret = afs_extract_data(call, true);
1695 if (ret < 0)
1696 return ret;
1697
1698 _debug("unmarshall CB array");
David Howellse49c7b22020-04-10 20:51:51 +01001699 switch (call->count) {
1700 case 0:
1701 scb = &op->file[0].scb;
1702 break;
1703 case 1:
1704 scb = &op->file[1].scb;
1705 break;
1706 default:
1707 scb = &op->more_files[call->count - 2].scb;
1708 break;
1709 }
1710
David Howells30062bd2018-10-20 00:57:58 +01001711 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01001712 xdr_decode_YFSCallBack(&bp, call, scb);
David Howells30062bd2018-10-20 00:57:58 +01001713 call->count++;
David Howellse49c7b22020-04-10 20:51:51 +01001714 if (call->count < op->nr_files)
David Howells30062bd2018-10-20 00:57:58 +01001715 goto more_cbs;
1716
1717 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
1718 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001719 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001720
David Howells30062bd2018-10-20 00:57:58 +01001721 case 5:
1722 ret = afs_extract_data(call, false);
1723 if (ret < 0)
1724 return ret;
1725
1726 bp = call->buffer;
David Howellse49c7b22020-04-10 20:51:51 +01001727 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howells30062bd2018-10-20 00:57:58 +01001728
1729 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001730 fallthrough;
Gustavo A. R. Silva35a3a902019-05-19 18:56:50 -05001731
David Howells30062bd2018-10-20 00:57:58 +01001732 case 6:
1733 break;
1734 }
1735
1736 _leave(" = 0 [done]");
1737 return 0;
1738}
1739
1740/*
1741 * FS.InlineBulkStatus operation type
1742 */
1743static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
1744 .name = "YFS.InlineBulkStatus",
1745 .op = yfs_FS_InlineBulkStatus,
1746 .deliver = yfs_deliver_fs_inline_bulk_status,
1747 .destructor = afs_flat_call_destructor,
1748};
1749
1750/*
1751 * Fetch the status information for up to 1024 files
1752 */
David Howellse49c7b22020-04-10 20:51:51 +01001753void yfs_fs_inline_bulk_status(struct afs_operation *op)
David Howells30062bd2018-10-20 00:57:58 +01001754{
David Howellse49c7b22020-04-10 20:51:51 +01001755 struct afs_vnode_param *dvp = &op->file[0];
1756 struct afs_vnode_param *vp = &op->file[1];
David Howells30062bd2018-10-20 00:57:58 +01001757 struct afs_call *call;
1758 __be32 *bp;
1759 int i;
1760
1761 _enter(",%x,{%llx:%llu},%u",
David Howellse49c7b22020-04-10 20:51:51 +01001762 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
David Howells30062bd2018-10-20 00:57:58 +01001763
David Howellse49c7b22020-04-10 20:51:51 +01001764 call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
David Howells30062bd2018-10-20 00:57:58 +01001765 sizeof(__be32) +
1766 sizeof(__be32) +
1767 sizeof(__be32) +
David Howellse49c7b22020-04-10 20:51:51 +01001768 sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
David Howells30062bd2018-10-20 00:57:58 +01001769 sizeof(struct yfs_xdr_YFSFetchStatus));
David Howellse49c7b22020-04-10 20:51:51 +01001770 if (!call)
1771 return afs_op_nomem(op);
David Howells30062bd2018-10-20 00:57:58 +01001772
1773 /* marshall the parameters */
1774 bp = call->request;
1775 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
1776 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
David Howellse49c7b22020-04-10 20:51:51 +01001777 bp = xdr_encode_u32(bp, op->nr_files);
1778 bp = xdr_encode_YFSFid(bp, &dvp->fid);
1779 bp = xdr_encode_YFSFid(bp, &vp->fid);
1780 for (i = 0; i < op->nr_files - 2; i++)
1781 bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
David Howells30062bd2018-10-20 00:57:58 +01001782 yfs_check_req(call, bp);
1783
David Howellse49c7b22020-04-10 20:51:51 +01001784 trace_afs_make_fs_call(call, &vp->fid);
1785 afs_make_op_call(op, call, GFP_NOFS);
David Howells30062bd2018-10-20 00:57:58 +01001786}
David Howellsae465782019-04-30 18:30:21 +01001787
1788/*
1789 * Deliver reply data to an YFS.FetchOpaqueACL.
1790 */
1791static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
1792{
David Howellse49c7b22020-04-10 20:51:51 +01001793 struct afs_operation *op = call->op;
1794 struct afs_vnode_param *vp = &op->file[0];
1795 struct yfs_acl *yacl = op->yacl;
David Howellsae465782019-04-30 18:30:21 +01001796 struct afs_acl *acl;
1797 const __be32 *bp;
1798 unsigned int size;
1799 int ret;
1800
1801 _enter("{%u}", call->unmarshall);
1802
1803 switch (call->unmarshall) {
1804 case 0:
1805 afs_extract_to_tmp(call);
1806 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001807 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001808
1809 /* Extract the file ACL length */
1810 case 1:
1811 ret = afs_extract_data(call, true);
1812 if (ret < 0)
1813 return ret;
1814
1815 size = call->count2 = ntohl(call->tmp);
1816 size = round_up(size, 4);
1817
1818 if (yacl->flags & YFS_ACL_WANT_ACL) {
1819 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1820 if (!acl)
1821 return -ENOMEM;
1822 yacl->acl = acl;
1823 acl->size = call->count2;
1824 afs_extract_begin(call, acl->data, size);
1825 } else {
David Howells23a28912019-08-20 09:22:38 +01001826 afs_extract_discard(call, size);
David Howellsae465782019-04-30 18:30:21 +01001827 }
1828 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001829 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001830
1831 /* Extract the file ACL */
1832 case 2:
1833 ret = afs_extract_data(call, true);
1834 if (ret < 0)
1835 return ret;
1836
1837 afs_extract_to_tmp(call);
1838 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001839 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001840
1841 /* Extract the volume ACL length */
1842 case 3:
1843 ret = afs_extract_data(call, true);
1844 if (ret < 0)
1845 return ret;
1846
1847 size = call->count2 = ntohl(call->tmp);
1848 size = round_up(size, 4);
1849
1850 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
1851 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1852 if (!acl)
1853 return -ENOMEM;
1854 yacl->vol_acl = acl;
1855 acl->size = call->count2;
1856 afs_extract_begin(call, acl->data, size);
1857 } else {
David Howells23a28912019-08-20 09:22:38 +01001858 afs_extract_discard(call, size);
David Howellsae465782019-04-30 18:30:21 +01001859 }
1860 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001861 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001862
1863 /* Extract the volume ACL */
1864 case 4:
1865 ret = afs_extract_data(call, true);
1866 if (ret < 0)
1867 return ret;
1868
1869 afs_extract_to_buf(call,
1870 sizeof(__be32) * 2 +
1871 sizeof(struct yfs_xdr_YFSFetchStatus) +
1872 sizeof(struct yfs_xdr_YFSVolSync));
1873 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001874 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001875
1876 /* extract the metadata */
1877 case 5:
1878 ret = afs_extract_data(call, false);
1879 if (ret < 0)
1880 return ret;
1881
1882 bp = call->buffer;
1883 yacl->inherit_flag = ntohl(*bp++);
1884 yacl->num_cleaned = ntohl(*bp++);
David Howellse49c7b22020-04-10 20:51:51 +01001885 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1886 xdr_decode_YFSVolSync(&bp, &op->volsync);
David Howellsae465782019-04-30 18:30:21 +01001887
1888 call->unmarshall++;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001889 fallthrough;
David Howellsae465782019-04-30 18:30:21 +01001890
1891 case 6:
1892 break;
1893 }
1894
1895 _leave(" = 0 [done]");
1896 return 0;
1897}
1898
1899void yfs_free_opaque_acl(struct yfs_acl *yacl)
1900{
1901 if (yacl) {
1902 kfree(yacl->acl);
1903 kfree(yacl->vol_acl);
1904 kfree(yacl);
1905 }
1906}
1907
David Howellsae465782019-04-30 18:30:21 +01001908/*
1909 * YFS.FetchOpaqueACL operation type
1910 */
1911static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
1912 .name = "YFS.FetchOpaqueACL",
1913 .op = yfs_FS_FetchOpaqueACL,
1914 .deliver = yfs_deliver_fs_fetch_opaque_acl,
David Howells773e0c42019-05-12 08:31:23 +01001915 .destructor = afs_flat_call_destructor,
David Howellsae465782019-04-30 18:30:21 +01001916};
1917
1918/*
1919 * Fetch the YFS advanced ACLs for a file.
1920 */
David Howellse49c7b22020-04-10 20:51:51 +01001921void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
David Howellsae465782019-04-30 18:30:21 +01001922{
David Howellse49c7b22020-04-10 20:51:51 +01001923 struct afs_vnode_param *vp = &op->file[0];
David Howellsae465782019-04-30 18:30:21 +01001924 struct afs_call *call;
David Howellsae465782019-04-30 18:30:21 +01001925 __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 Howellsae465782019-04-30 18:30:21 +01001929
David Howellse49c7b22020-04-10 20:51:51 +01001930 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
David Howellsae465782019-04-30 18:30:21 +01001931 sizeof(__be32) * 2 +
1932 sizeof(struct yfs_xdr_YFSFid),
1933 sizeof(__be32) * 2 +
1934 sizeof(struct yfs_xdr_YFSFetchStatus) +
1935 sizeof(struct yfs_xdr_YFSVolSync));
David Howellse49c7b22020-04-10 20:51:51 +01001936 if (!call)
1937 return afs_op_nomem(op);
David Howellsae465782019-04-30 18:30:21 +01001938
1939 /* marshall the parameters */
1940 bp = call->request;
1941 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
1942 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001943 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howellsae465782019-04-30 18:30:21 +01001944 yfs_check_req(call, bp);
1945
David Howellse49c7b22020-04-10 20:51:51 +01001946 trace_afs_make_fs_call(call, &vp->fid);
1947 afs_make_op_call(op, call, GFP_KERNEL);
David Howellsae465782019-04-30 18:30:21 +01001948}
David Howellsf5e45462019-05-01 14:05:27 +01001949
1950/*
1951 * YFS.StoreOpaqueACL2 operation type
1952 */
1953static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
1954 .name = "YFS.StoreOpaqueACL2",
1955 .op = yfs_FS_StoreOpaqueACL2,
1956 .deliver = yfs_deliver_status_and_volsync,
1957 .destructor = afs_flat_call_destructor,
1958};
1959
1960/*
1961 * Fetch the YFS ACL for a file.
1962 */
David Howellse49c7b22020-04-10 20:51:51 +01001963void yfs_fs_store_opaque_acl2(struct afs_operation *op)
David Howellsf5e45462019-05-01 14:05:27 +01001964{
David Howellse49c7b22020-04-10 20:51:51 +01001965 struct afs_vnode_param *vp = &op->file[0];
David Howellsf5e45462019-05-01 14:05:27 +01001966 struct afs_call *call;
David Howellse49c7b22020-04-10 20:51:51 +01001967 struct afs_acl *acl = op->acl;
David Howellsf5e45462019-05-01 14:05:27 +01001968 size_t size;
1969 __be32 *bp;
1970
1971 _enter(",%x,{%llx:%llu},,",
David Howellse49c7b22020-04-10 20:51:51 +01001972 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
David Howellsf5e45462019-05-01 14:05:27 +01001973
1974 size = round_up(acl->size, 4);
David Howellse49c7b22020-04-10 20:51:51 +01001975 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
David Howellsf5e45462019-05-01 14:05:27 +01001976 sizeof(__be32) * 2 +
1977 sizeof(struct yfs_xdr_YFSFid) +
1978 sizeof(__be32) + size,
1979 sizeof(struct yfs_xdr_YFSFetchStatus) +
1980 sizeof(struct yfs_xdr_YFSVolSync));
David Howellse49c7b22020-04-10 20:51:51 +01001981 if (!call)
1982 return afs_op_nomem(op);
David Howellsf5e45462019-05-01 14:05:27 +01001983
1984 /* marshall the parameters */
1985 bp = call->request;
1986 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
1987 bp = xdr_encode_u32(bp, 0); /* RPC flags */
David Howellse49c7b22020-04-10 20:51:51 +01001988 bp = xdr_encode_YFSFid(bp, &vp->fid);
David Howellsf5e45462019-05-01 14:05:27 +01001989 bp = xdr_encode_u32(bp, acl->size);
1990 memcpy(bp, acl->data, acl->size);
1991 if (acl->size != size)
1992 memset((void *)bp + acl->size, 0, size - acl->size);
David Howellsc80afa12020-11-03 16:32:58 +00001993 bp += size / sizeof(__be32);
David Howellsf5e45462019-05-01 14:05:27 +01001994 yfs_check_req(call, bp);
1995
David Howellse49c7b22020-04-10 20:51:51 +01001996 trace_afs_make_fs_call(call, &vp->fid);
1997 afs_make_op_call(op, call, GFP_KERNEL);
David Howells30062bd2018-10-20 00:57:58 +01001998}