Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* YFS File Server client stubs
3 *
4 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
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
18#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
75static __be32 *xdr_encode_name(__be32 *bp, const struct qstr *p)
76{
77 return xdr_encode_string(bp, p->name, p->len);
78}
79
80static 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)
153 pr_warn("kAFS: %s: Request buffer underflow (%zu<%u)\n",
154 call->type->name, len, call->request_size);
155}
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");
166 for (i = 0; i < 6 * 4 * 4; i += 16) {
167 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
173 memcpy(x, bp, 8);
174 pr_notice("0x60: %08x %08x\n", ntohl(x[0]), ntohl(x[1]));
175}
176
177/*
178 * Decode a YFSFetchStatus block
179 */
180static void xdr_decode_YFSFetchStatus(const __be32 **_bp,
181 struct afs_call *call,
182 struct afs_status_cb *scb)
183{
184 const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
185 struct afs_file_status *status = &scb->status;
186 u32 type;
187
188 status->abort_code = ntohl(xdr->abort_code);
189 if (status->abort_code != 0) {
190 if (status->abort_code == VNOVNODE)
191 status->nlink = 0;
192 scb->have_error = true;
193 goto advance;
194 }
195
196 type = ntohl(xdr->type);
197 switch (type) {
198 case AFS_FTYPE_FILE:
199 case AFS_FTYPE_DIR:
200 case AFS_FTYPE_SYMLINK:
201 status->type = type;
202 break;
203 default:
204 goto bad;
205 }
206
207 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);
215
216 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);
220 scb->have_status = true;
221advance:
222 *_bp += xdr_size(xdr);
223 return;
224
225bad:
226 xdr_dump_bad(*_bp);
227 afs_protocol_error(call, afs_eproto_bad_status);
228 goto advance;
229}
230
231/*
232 * Decode a YFSCallBack block
233 */
234static void xdr_decode_YFSCallBack(const __be32 **_bp,
235 struct afs_call *call,
236 struct afs_status_cb *scb)
237{
238 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
239 struct afs_callback *cb = &scb->callback;
240 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);
245 scb->have_cb = true;
246 *_bp += xdr_size(x);
247}
248
249/*
250 * 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/*
333 * 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{
338 struct afs_operation *op = call->op;
339 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;
347 xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
348 xdr_decode_YFSVolSync(&bp, &op->volsync);
349
350 _leave(" = 0 [done]");
351 return 0;
352}
353
354/*
355 * Deliver reply data to an YFS.FetchData64.
356 */
357static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
358{
359 struct afs_operation *op = call->op;
360 struct afs_vnode_param *vp = &op->file[0];
361 struct afs_read *req = op->fetch.req;
362 const __be32 *bp;
363 int ret;
364
365 _enter("{%u,%zu, %zu/%llu}",
366 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
367 req->actual_len);
368
369 switch (call->unmarshall) {
370 case 0:
371 req->actual_len = 0;
372 afs_extract_to_tmp64(call);
373 call->unmarshall++;
374 fallthrough;
375
376 /* Extract the returned data length into ->actual_len. This
377 * may indicate more or less data than was requested will be
378 * returned.
379 */
380 case 1:
381 _debug("extract data length");
382 ret = afs_extract_data(call, true);
383 if (ret < 0)
384 return ret;
385
386 req->actual_len = be64_to_cpu(call->tmp64);
387 _debug("DATA length: %llu", req->actual_len);
388
389 if (req->actual_len == 0)
390 goto no_more_data;
391
392 call->iter = req->iter;
393 call->iov_len = min(req->actual_len, req->len);
394 call->unmarshall++;
395 fallthrough;
396
397 /* extract the returned data */
398 case 2:
399 _debug("extract data %zu/%llu",
400 iov_iter_count(call->iter), req->actual_len);
401
402 ret = afs_extract_data(call, true);
403 if (ret < 0)
404 return ret;
405
406 call->iter = &call->def_iter;
407 if (req->actual_len <= req->len)
408 goto no_more_data;
409
410 /* Discard any excess data the server gave us */
411 afs_extract_discard(call, req->actual_len - req->len);
412 call->unmarshall = 3;
413 fallthrough;
414
415 case 3:
416 _debug("extract discard %zu/%llu",
417 iov_iter_count(call->iter), req->actual_len - req->len);
418
419 ret = afs_extract_data(call, true);
420 if (ret < 0)
421 return ret;
422
423 no_more_data:
424 call->unmarshall = 4;
425 afs_extract_to_buf(call,
426 sizeof(struct yfs_xdr_YFSFetchStatus) +
427 sizeof(struct yfs_xdr_YFSCallBack) +
428 sizeof(struct yfs_xdr_YFSVolSync));
429 fallthrough;
430
431 /* extract the metadata */
432 case 4:
433 ret = afs_extract_data(call, false);
434 if (ret < 0)
435 return ret;
436
437 bp = call->buffer;
438 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
439 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
440 xdr_decode_YFSVolSync(&bp, &op->volsync);
441
442 req->data_version = vp->scb.status.data_version;
443 req->file_size = vp->scb.status.size;
444
445 call->unmarshall++;
446 fallthrough;
447
448 case 5:
449 break;
450 }
451
452 _leave(" = 0 [done]");
453 return 0;
454}
455
456/*
457 * YFS.FetchData64 operation type
458 */
459static const struct afs_call_type yfs_RXYFSFetchData64 = {
460 .name = "YFS.FetchData64",
461 .op = yfs_FS_FetchData64,
462 .deliver = yfs_deliver_fs_fetch_data64,
463 .destructor = afs_flat_call_destructor,
464};
465
466/*
467 * Fetch data from a file.
468 */
469void yfs_fs_fetch_data(struct afs_operation *op)
470{
471 struct afs_vnode_param *vp = &op->file[0];
472 struct afs_read *req = op->fetch.req;
473 struct afs_call *call;
474 __be32 *bp;
475
476 _enter(",%x,{%llx:%llu},%llx,%llx",
477 key_serial(op->key), vp->fid.vid, vp->fid.vnode,
478 req->pos, req->len);
479
480 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
481 sizeof(__be32) * 2 +
482 sizeof(struct yfs_xdr_YFSFid) +
483 sizeof(struct yfs_xdr_u64) * 2,
484 sizeof(struct yfs_xdr_YFSFetchStatus) +
485 sizeof(struct yfs_xdr_YFSCallBack) +
486 sizeof(struct yfs_xdr_YFSVolSync));
487 if (!call)
488 return afs_op_nomem(op);
489
490 req->call_debug_id = call->debug_id;
491
492 /* marshall the parameters */
493 bp = call->request;
494 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
495 bp = xdr_encode_u32(bp, 0); /* RPC flags */
496 bp = xdr_encode_YFSFid(bp, &vp->fid);
497 bp = xdr_encode_u64(bp, req->pos);
498 bp = xdr_encode_u64(bp, req->len);
499 yfs_check_req(call, bp);
500
501 trace_afs_make_fs_call(call, &vp->fid);
502 afs_make_op_call(op, call, GFP_NOFS);
503}
504
505/*
506 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
507 */
508static int yfs_deliver_fs_create_vnode(struct afs_call *call)
509{
510 struct afs_operation *op = call->op;
511 struct afs_vnode_param *dvp = &op->file[0];
512 struct afs_vnode_param *vp = &op->file[1];
513 const __be32 *bp;
514 int ret;
515
516 _enter("{%u}", call->unmarshall);
517
518 ret = afs_transfer_reply(call);
519 if (ret < 0)
520 return ret;
521
522 /* unmarshall the reply once we've received all of it */
523 bp = call->buffer;
524 xdr_decode_YFSFid(&bp, &op->file[1].fid);
525 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
526 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
527 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
528 xdr_decode_YFSVolSync(&bp, &op->volsync);
529
530 _leave(" = 0 [done]");
531 return 0;
532}
533
534/*
535 * FS.CreateFile and FS.MakeDir operation type
536 */
537static const struct afs_call_type afs_RXFSCreateFile = {
538 .name = "YFS.CreateFile",
539 .op = yfs_FS_CreateFile,
540 .deliver = yfs_deliver_fs_create_vnode,
541 .destructor = afs_flat_call_destructor,
542};
543
544/*
545 * Create a file.
546 */
547void yfs_fs_create_file(struct afs_operation *op)
548{
549 const struct qstr *name = &op->dentry->d_name;
550 struct afs_vnode_param *dvp = &op->file[0];
551 struct afs_call *call;
552 size_t reqsz, rplsz;
553 __be32 *bp;
554
555 _enter("");
556
557 reqsz = (sizeof(__be32) +
558 sizeof(__be32) +
559 sizeof(struct yfs_xdr_YFSFid) +
560 xdr_strlen(name->len) +
561 sizeof(struct yfs_xdr_YFSStoreStatus) +
562 sizeof(__be32));
563 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
564 sizeof(struct yfs_xdr_YFSFetchStatus) +
565 sizeof(struct yfs_xdr_YFSFetchStatus) +
566 sizeof(struct yfs_xdr_YFSCallBack) +
567 sizeof(struct yfs_xdr_YFSVolSync));
568
569 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
570 if (!call)
571 return afs_op_nomem(op);
572
573 /* marshall the parameters */
574 bp = call->request;
575 bp = xdr_encode_u32(bp, YFSCREATEFILE);
576 bp = xdr_encode_u32(bp, 0); /* RPC flags */
577 bp = xdr_encode_YFSFid(bp, &dvp->fid);
578 bp = xdr_encode_name(bp, name);
579 bp = xdr_encode_YFSStoreStatus_mode(bp, op->create.mode);
580 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
581 yfs_check_req(call, bp);
582
583 trace_afs_make_fs_call1(call, &dvp->fid, name);
584 afs_make_op_call(op, call, GFP_NOFS);
585}
586
587static const struct afs_call_type yfs_RXFSMakeDir = {
588 .name = "YFS.MakeDir",
589 .op = yfs_FS_MakeDir,
590 .deliver = yfs_deliver_fs_create_vnode,
591 .destructor = afs_flat_call_destructor,
592};
593
594/*
595 * Make a directory.
596 */
597void yfs_fs_make_dir(struct afs_operation *op)
598{
599 const struct qstr *name = &op->dentry->d_name;
600 struct afs_vnode_param *dvp = &op->file[0];
601 struct afs_call *call;
602 size_t reqsz, rplsz;
603 __be32 *bp;
604
605 _enter("");
606
607 reqsz = (sizeof(__be32) +
608 sizeof(struct yfs_xdr_RPCFlags) +
609 sizeof(struct yfs_xdr_YFSFid) +
610 xdr_strlen(name->len) +
611 sizeof(struct yfs_xdr_YFSStoreStatus));
612 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
613 sizeof(struct yfs_xdr_YFSFetchStatus) +
614 sizeof(struct yfs_xdr_YFSFetchStatus) +
615 sizeof(struct yfs_xdr_YFSCallBack) +
616 sizeof(struct yfs_xdr_YFSVolSync));
617
618 call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
619 if (!call)
620 return afs_op_nomem(op);
621
622 /* marshall the parameters */
623 bp = call->request;
624 bp = xdr_encode_u32(bp, YFSMAKEDIR);
625 bp = xdr_encode_u32(bp, 0); /* RPC flags */
626 bp = xdr_encode_YFSFid(bp, &dvp->fid);
627 bp = xdr_encode_name(bp, name);
628 bp = xdr_encode_YFSStoreStatus_mode(bp, op->create.mode);
629 yfs_check_req(call, bp);
630
631 trace_afs_make_fs_call1(call, &dvp->fid, name);
632 afs_make_op_call(op, call, GFP_NOFS);
633}
634
635/*
636 * Deliver reply data to a YFS.RemoveFile2 operation.
637 */
638static int yfs_deliver_fs_remove_file2(struct afs_call *call)
639{
640 struct afs_operation *op = call->op;
641 struct afs_vnode_param *dvp = &op->file[0];
642 struct afs_vnode_param *vp = &op->file[1];
643 struct afs_fid fid;
644 const __be32 *bp;
645 int ret;
646
647 _enter("{%u}", call->unmarshall);
648
649 ret = afs_transfer_reply(call);
650 if (ret < 0)
651 return ret;
652
653 bp = call->buffer;
654 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
655 xdr_decode_YFSFid(&bp, &fid);
656 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
657 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
658
659 xdr_decode_YFSVolSync(&bp, &op->volsync);
660 return 0;
661}
662
663static void yfs_done_fs_remove_file2(struct afs_call *call)
664{
665 if (call->error == -ECONNABORTED &&
666 call->abort_code == RX_INVALID_OPERATION) {
667 set_bit(AFS_SERVER_FL_NO_RM2, &call->server->flags);
668 call->op->flags |= AFS_OPERATION_DOWNGRADE;
669 }
670}
671
672/*
673 * YFS.RemoveFile2 operation type.
674 */
675static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
676 .name = "YFS.RemoveFile2",
677 .op = yfs_FS_RemoveFile2,
678 .deliver = yfs_deliver_fs_remove_file2,
679 .done = yfs_done_fs_remove_file2,
680 .destructor = afs_flat_call_destructor,
681};
682
683/*
684 * Remove a file and retrieve new file status.
685 */
686void yfs_fs_remove_file2(struct afs_operation *op)
687{
688 struct afs_vnode_param *dvp = &op->file[0];
689 const struct qstr *name = &op->dentry->d_name;
690 struct afs_call *call;
691 __be32 *bp;
692
693 _enter("");
694
695 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
696 sizeof(__be32) +
697 sizeof(struct yfs_xdr_RPCFlags) +
698 sizeof(struct yfs_xdr_YFSFid) +
699 xdr_strlen(name->len),
700 sizeof(struct yfs_xdr_YFSFetchStatus) +
701 sizeof(struct yfs_xdr_YFSFid) +
702 sizeof(struct yfs_xdr_YFSFetchStatus) +
703 sizeof(struct yfs_xdr_YFSVolSync));
704 if (!call)
705 return afs_op_nomem(op);
706
707 /* marshall the parameters */
708 bp = call->request;
709 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
710 bp = xdr_encode_u32(bp, 0); /* RPC flags */
711 bp = xdr_encode_YFSFid(bp, &dvp->fid);
712 bp = xdr_encode_name(bp, name);
713 yfs_check_req(call, bp);
714
715 trace_afs_make_fs_call1(call, &dvp->fid, name);
716 afs_make_op_call(op, call, GFP_NOFS);
717}
718
719/*
720 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
721 */
722static int yfs_deliver_fs_remove(struct afs_call *call)
723{
724 struct afs_operation *op = call->op;
725 struct afs_vnode_param *dvp = &op->file[0];
726 const __be32 *bp;
727 int ret;
728
729 _enter("{%u}", call->unmarshall);
730
731 ret = afs_transfer_reply(call);
732 if (ret < 0)
733 return ret;
734
735 bp = call->buffer;
736 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
737 xdr_decode_YFSVolSync(&bp, &op->volsync);
738 return 0;
739}
740
741/*
742 * FS.RemoveDir and FS.RemoveFile operation types.
743 */
744static const struct afs_call_type yfs_RXYFSRemoveFile = {
745 .name = "YFS.RemoveFile",
746 .op = yfs_FS_RemoveFile,
747 .deliver = yfs_deliver_fs_remove,
748 .destructor = afs_flat_call_destructor,
749};
750
751/*
752 * Remove a file.
753 */
754void yfs_fs_remove_file(struct afs_operation *op)
755{
756 const struct qstr *name = &op->dentry->d_name;
757 struct afs_vnode_param *dvp = &op->file[0];
758 struct afs_call *call;
759 __be32 *bp;
760
761 _enter("");
762
763 if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
764 return yfs_fs_remove_file2(op);
765
766 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
767 sizeof(__be32) +
768 sizeof(struct yfs_xdr_RPCFlags) +
769 sizeof(struct yfs_xdr_YFSFid) +
770 xdr_strlen(name->len),
771 sizeof(struct yfs_xdr_YFSFetchStatus) +
772 sizeof(struct yfs_xdr_YFSVolSync));
773 if (!call)
774 return afs_op_nomem(op);
775
776 /* marshall the parameters */
777 bp = call->request;
778 bp = xdr_encode_u32(bp, YFSREMOVEFILE);
779 bp = xdr_encode_u32(bp, 0); /* RPC flags */
780 bp = xdr_encode_YFSFid(bp, &dvp->fid);
781 bp = xdr_encode_name(bp, name);
782 yfs_check_req(call, bp);
783
784 trace_afs_make_fs_call1(call, &dvp->fid, name);
785 afs_make_op_call(op, call, GFP_NOFS);
786}
787
788static const struct afs_call_type yfs_RXYFSRemoveDir = {
789 .name = "YFS.RemoveDir",
790 .op = yfs_FS_RemoveDir,
791 .deliver = yfs_deliver_fs_remove,
792 .destructor = afs_flat_call_destructor,
793};
794
795/*
796 * Remove a directory.
797 */
798void yfs_fs_remove_dir(struct afs_operation *op)
799{
800 const struct qstr *name = &op->dentry->d_name;
801 struct afs_vnode_param *dvp = &op->file[0];
802 struct afs_call *call;
803 __be32 *bp;
804
805 _enter("");
806
807 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
808 sizeof(__be32) +
809 sizeof(struct yfs_xdr_RPCFlags) +
810 sizeof(struct yfs_xdr_YFSFid) +
811 xdr_strlen(name->len),
812 sizeof(struct yfs_xdr_YFSFetchStatus) +
813 sizeof(struct yfs_xdr_YFSVolSync));
814 if (!call)
815 return afs_op_nomem(op);
816
817 /* marshall the parameters */
818 bp = call->request;
819 bp = xdr_encode_u32(bp, YFSREMOVEDIR);
820 bp = xdr_encode_u32(bp, 0); /* RPC flags */
821 bp = xdr_encode_YFSFid(bp, &dvp->fid);
822 bp = xdr_encode_name(bp, name);
823 yfs_check_req(call, bp);
824
825 trace_afs_make_fs_call1(call, &dvp->fid, name);
826 afs_make_op_call(op, call, GFP_NOFS);
827}
828
829/*
830 * Deliver reply data to a YFS.Link operation.
831 */
832static int yfs_deliver_fs_link(struct afs_call *call)
833{
834 struct afs_operation *op = call->op;
835 struct afs_vnode_param *dvp = &op->file[0];
836 struct afs_vnode_param *vp = &op->file[1];
837 const __be32 *bp;
838 int ret;
839
840 _enter("{%u}", call->unmarshall);
841
842 ret = afs_transfer_reply(call);
843 if (ret < 0)
844 return ret;
845
846 bp = call->buffer;
847 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
848 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
849 xdr_decode_YFSVolSync(&bp, &op->volsync);
850 _leave(" = 0 [done]");
851 return 0;
852}
853
854/*
855 * YFS.Link operation type.
856 */
857static const struct afs_call_type yfs_RXYFSLink = {
858 .name = "YFS.Link",
859 .op = yfs_FS_Link,
860 .deliver = yfs_deliver_fs_link,
861 .destructor = afs_flat_call_destructor,
862};
863
864/*
865 * Make a hard link.
866 */
867void yfs_fs_link(struct afs_operation *op)
868{
869 const struct qstr *name = &op->dentry->d_name;
870 struct afs_vnode_param *dvp = &op->file[0];
871 struct afs_vnode_param *vp = &op->file[1];
872 struct afs_call *call;
873 __be32 *bp;
874
875 _enter("");
876
877 call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
878 sizeof(__be32) +
879 sizeof(struct yfs_xdr_RPCFlags) +
880 sizeof(struct yfs_xdr_YFSFid) +
881 xdr_strlen(name->len) +
882 sizeof(struct yfs_xdr_YFSFid),
883 sizeof(struct yfs_xdr_YFSFetchStatus) +
884 sizeof(struct yfs_xdr_YFSFetchStatus) +
885 sizeof(struct yfs_xdr_YFSVolSync));
886 if (!call)
887 return afs_op_nomem(op);
888
889 /* marshall the parameters */
890 bp = call->request;
891 bp = xdr_encode_u32(bp, YFSLINK);
892 bp = xdr_encode_u32(bp, 0); /* RPC flags */
893 bp = xdr_encode_YFSFid(bp, &dvp->fid);
894 bp = xdr_encode_name(bp, name);
895 bp = xdr_encode_YFSFid(bp, &vp->fid);
896 yfs_check_req(call, bp);
897
898 trace_afs_make_fs_call1(call, &vp->fid, name);
899 afs_make_op_call(op, call, GFP_NOFS);
900}
901
902/*
903 * Deliver reply data to a YFS.Symlink operation.
904 */
905static int yfs_deliver_fs_symlink(struct afs_call *call)
906{
907 struct afs_operation *op = call->op;
908 struct afs_vnode_param *dvp = &op->file[0];
909 struct afs_vnode_param *vp = &op->file[1];
910 const __be32 *bp;
911 int ret;
912
913 _enter("{%u}", call->unmarshall);
914
915 ret = afs_transfer_reply(call);
916 if (ret < 0)
917 return ret;
918
919 /* unmarshall the reply once we've received all of it */
920 bp = call->buffer;
921 xdr_decode_YFSFid(&bp, &vp->fid);
922 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
923 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
924 xdr_decode_YFSVolSync(&bp, &op->volsync);
925
926 _leave(" = 0 [done]");
927 return 0;
928}
929
930/*
931 * YFS.Symlink operation type
932 */
933static const struct afs_call_type yfs_RXYFSSymlink = {
934 .name = "YFS.Symlink",
935 .op = yfs_FS_Symlink,
936 .deliver = yfs_deliver_fs_symlink,
937 .destructor = afs_flat_call_destructor,
938};
939
940/*
941 * Create a symbolic link.
942 */
943void yfs_fs_symlink(struct afs_operation *op)
944{
945 const struct qstr *name = &op->dentry->d_name;
946 struct afs_vnode_param *dvp = &op->file[0];
947 struct afs_call *call;
948 size_t contents_sz;
949 __be32 *bp;
950
951 _enter("");
952
953 contents_sz = strlen(op->create.symlink);
954 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
955 sizeof(__be32) +
956 sizeof(struct yfs_xdr_RPCFlags) +
957 sizeof(struct yfs_xdr_YFSFid) +
958 xdr_strlen(name->len) +
959 xdr_strlen(contents_sz) +
960 sizeof(struct yfs_xdr_YFSStoreStatus),
961 sizeof(struct yfs_xdr_YFSFid) +
962 sizeof(struct yfs_xdr_YFSFetchStatus) +
963 sizeof(struct yfs_xdr_YFSFetchStatus) +
964 sizeof(struct yfs_xdr_YFSVolSync));
965 if (!call)
966 return afs_op_nomem(op);
967
968 /* marshall the parameters */
969 bp = call->request;
970 bp = xdr_encode_u32(bp, YFSSYMLINK);
971 bp = xdr_encode_u32(bp, 0); /* RPC flags */
972 bp = xdr_encode_YFSFid(bp, &dvp->fid);
973 bp = xdr_encode_name(bp, name);
974 bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
975 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
976 yfs_check_req(call, bp);
977
978 trace_afs_make_fs_call1(call, &dvp->fid, name);
979 afs_make_op_call(op, call, GFP_NOFS);
980}
981
982/*
983 * Deliver reply data to a YFS.Rename operation.
984 */
985static int yfs_deliver_fs_rename(struct afs_call *call)
986{
987 struct afs_operation *op = call->op;
988 struct afs_vnode_param *orig_dvp = &op->file[0];
989 struct afs_vnode_param *new_dvp = &op->file[1];
990 const __be32 *bp;
991 int ret;
992
993 _enter("{%u}", call->unmarshall);
994
995 ret = afs_transfer_reply(call);
996 if (ret < 0)
997 return ret;
998
999 bp = call->buffer;
1000 /* If the two dirs are the same, we have two copies of the same status
1001 * report, so we just decode it twice.
1002 */
1003 xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
1004 xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
1005 xdr_decode_YFSVolSync(&bp, &op->volsync);
1006 _leave(" = 0 [done]");
1007 return 0;
1008}
1009
1010/*
1011 * YFS.Rename operation type
1012 */
1013static const struct afs_call_type yfs_RXYFSRename = {
1014 .name = "FS.Rename",
1015 .op = yfs_FS_Rename,
1016 .deliver = yfs_deliver_fs_rename,
1017 .destructor = afs_flat_call_destructor,
1018};
1019
1020/*
1021 * Rename a file or directory.
1022 */
1023void yfs_fs_rename(struct afs_operation *op)
1024{
1025 struct afs_vnode_param *orig_dvp = &op->file[0];
1026 struct afs_vnode_param *new_dvp = &op->file[1];
1027 const struct qstr *orig_name = &op->dentry->d_name;
1028 const struct qstr *new_name = &op->dentry_2->d_name;
1029 struct afs_call *call;
1030 __be32 *bp;
1031
1032 _enter("");
1033
1034 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
1035 sizeof(__be32) +
1036 sizeof(struct yfs_xdr_RPCFlags) +
1037 sizeof(struct yfs_xdr_YFSFid) +
1038 xdr_strlen(orig_name->len) +
1039 sizeof(struct yfs_xdr_YFSFid) +
1040 xdr_strlen(new_name->len),
1041 sizeof(struct yfs_xdr_YFSFetchStatus) +
1042 sizeof(struct yfs_xdr_YFSFetchStatus) +
1043 sizeof(struct yfs_xdr_YFSVolSync));
1044 if (!call)
1045 return afs_op_nomem(op);
1046
1047 /* marshall the parameters */
1048 bp = call->request;
1049 bp = xdr_encode_u32(bp, YFSRENAME);
1050 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1051 bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
1052 bp = xdr_encode_name(bp, orig_name);
1053 bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
1054 bp = xdr_encode_name(bp, new_name);
1055 yfs_check_req(call, bp);
1056
1057 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1058 afs_make_op_call(op, call, GFP_NOFS);
1059}
1060
1061/*
1062 * YFS.StoreData64 operation type.
1063 */
1064static const struct afs_call_type yfs_RXYFSStoreData64 = {
1065 .name = "YFS.StoreData64",
1066 .op = yfs_FS_StoreData64,
1067 .deliver = yfs_deliver_status_and_volsync,
1068 .destructor = afs_flat_call_destructor,
1069};
1070
1071/*
1072 * Store a set of pages to a large file.
1073 */
1074void yfs_fs_store_data(struct afs_operation *op)
1075{
1076 struct afs_vnode_param *vp = &op->file[0];
1077 struct afs_call *call;
1078 __be32 *bp;
1079
1080 _enter(",%x,{%llx:%llu},,",
1081 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1082
1083 _debug("size %llx, at %llx, i_size %llx",
1084 (unsigned long long)op->store.size,
1085 (unsigned long long)op->store.pos,
1086 (unsigned long long)op->store.i_size);
1087
1088 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
1089 sizeof(__be32) +
1090 sizeof(__be32) +
1091 sizeof(struct yfs_xdr_YFSFid) +
1092 sizeof(struct yfs_xdr_YFSStoreStatus) +
1093 sizeof(struct yfs_xdr_u64) * 3,
1094 sizeof(struct yfs_xdr_YFSFetchStatus) +
1095 sizeof(struct yfs_xdr_YFSVolSync));
1096 if (!call)
1097 return afs_op_nomem(op);
1098
1099 call->write_iter = op->store.write_iter;
1100
1101 /* marshall the parameters */
1102 bp = call->request;
1103 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1104 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1105 bp = xdr_encode_YFSFid(bp, &vp->fid);
1106 bp = xdr_encode_YFSStoreStatus_mtime(bp, &op->mtime);
1107 bp = xdr_encode_u64(bp, op->store.pos);
1108 bp = xdr_encode_u64(bp, op->store.size);
1109 bp = xdr_encode_u64(bp, op->store.i_size);
1110 yfs_check_req(call, bp);
1111
1112 trace_afs_make_fs_call(call, &vp->fid);
1113 afs_make_op_call(op, call, GFP_NOFS);
1114}
1115
1116/*
1117 * YFS.StoreStatus operation type
1118 */
1119static const struct afs_call_type yfs_RXYFSStoreStatus = {
1120 .name = "YFS.StoreStatus",
1121 .op = yfs_FS_StoreStatus,
1122 .deliver = yfs_deliver_status_and_volsync,
1123 .destructor = afs_flat_call_destructor,
1124};
1125
1126static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1127 .name = "YFS.StoreData64",
1128 .op = yfs_FS_StoreData64,
1129 .deliver = yfs_deliver_status_and_volsync,
1130 .destructor = afs_flat_call_destructor,
1131};
1132
1133/*
1134 * Set the attributes on a file, using YFS.StoreData64 rather than
1135 * YFS.StoreStatus so as to alter the file size also.
1136 */
1137static void yfs_fs_setattr_size(struct afs_operation *op)
1138{
1139 struct afs_vnode_param *vp = &op->file[0];
1140 struct afs_call *call;
1141 struct iattr *attr = op->setattr.attr;
1142 __be32 *bp;
1143
1144 _enter(",%x,{%llx:%llu},,",
1145 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1146
1147 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
1148 sizeof(__be32) * 2 +
1149 sizeof(struct yfs_xdr_YFSFid) +
1150 sizeof(struct yfs_xdr_YFSStoreStatus) +
1151 sizeof(struct yfs_xdr_u64) * 3,
1152 sizeof(struct yfs_xdr_YFSFetchStatus) +
1153 sizeof(struct yfs_xdr_YFSVolSync));
1154 if (!call)
1155 return afs_op_nomem(op);
1156
1157 /* marshall the parameters */
1158 bp = call->request;
1159 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1160 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1161 bp = xdr_encode_YFSFid(bp, &vp->fid);
1162 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1163 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1164 bp = xdr_encode_u64(bp, 0); /* size of write */
1165 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1166 yfs_check_req(call, bp);
1167
1168 trace_afs_make_fs_call(call, &vp->fid);
1169 afs_make_op_call(op, call, GFP_NOFS);
1170}
1171
1172/*
1173 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1174 * file size, and YFS.StoreStatus otherwise.
1175 */
1176void yfs_fs_setattr(struct afs_operation *op)
1177{
1178 struct afs_vnode_param *vp = &op->file[0];
1179 struct afs_call *call;
1180 struct iattr *attr = op->setattr.attr;
1181 __be32 *bp;
1182
1183 if (attr->ia_valid & ATTR_SIZE)
1184 return yfs_fs_setattr_size(op);
1185
1186 _enter(",%x,{%llx:%llu},,",
1187 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1188
1189 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
1190 sizeof(__be32) * 2 +
1191 sizeof(struct yfs_xdr_YFSFid) +
1192 sizeof(struct yfs_xdr_YFSStoreStatus),
1193 sizeof(struct yfs_xdr_YFSFetchStatus) +
1194 sizeof(struct yfs_xdr_YFSVolSync));
1195 if (!call)
1196 return afs_op_nomem(op);
1197
1198 /* marshall the parameters */
1199 bp = call->request;
1200 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1201 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1202 bp = xdr_encode_YFSFid(bp, &vp->fid);
1203 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1204 yfs_check_req(call, bp);
1205
1206 trace_afs_make_fs_call(call, &vp->fid);
1207 afs_make_op_call(op, call, GFP_NOFS);
1208}
1209
1210/*
1211 * Deliver reply data to a YFS.GetVolumeStatus operation.
1212 */
1213static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1214{
1215 struct afs_operation *op = call->op;
1216 const __be32 *bp;
1217 char *p;
1218 u32 size;
1219 int ret;
1220
1221 _enter("{%u}", call->unmarshall);
1222
1223 switch (call->unmarshall) {
1224 case 0:
1225 call->unmarshall++;
1226 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1227 fallthrough;
1228
1229 /* extract the returned status record */
1230 case 1:
1231 _debug("extract status");
1232 ret = afs_extract_data(call, true);
1233 if (ret < 0)
1234 return ret;
1235
1236 bp = call->buffer;
1237 xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1238 call->unmarshall++;
1239 afs_extract_to_tmp(call);
1240 fallthrough;
1241
1242 /* extract the volume name length */
1243 case 2:
1244 ret = afs_extract_data(call, true);
1245 if (ret < 0)
1246 return ret;
1247
1248 call->count = ntohl(call->tmp);
1249 _debug("volname length: %u", call->count);
1250 if (call->count >= AFSNAMEMAX)
1251 return afs_protocol_error(call, afs_eproto_volname_len);
1252 size = (call->count + 3) & ~3; /* It's padded */
1253 afs_extract_to_buf(call, size);
1254 call->unmarshall++;
1255 fallthrough;
1256
1257 /* extract the volume name */
1258 case 3:
1259 _debug("extract volname");
1260 ret = afs_extract_data(call, true);
1261 if (ret < 0)
1262 return ret;
1263
1264 p = call->buffer;
1265 p[call->count] = 0;
1266 _debug("volname '%s'", p);
1267 afs_extract_to_tmp(call);
1268 call->unmarshall++;
1269 fallthrough;
1270
1271 /* extract the offline message length */
1272 case 4:
1273 ret = afs_extract_data(call, true);
1274 if (ret < 0)
1275 return ret;
1276
1277 call->count = ntohl(call->tmp);
1278 _debug("offline msg length: %u", call->count);
1279 if (call->count >= AFSNAMEMAX)
1280 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1281 size = (call->count + 3) & ~3; /* It's padded */
1282 afs_extract_to_buf(call, size);
1283 call->unmarshall++;
1284 fallthrough;
1285
1286 /* extract the offline message */
1287 case 5:
1288 _debug("extract offline");
1289 ret = afs_extract_data(call, true);
1290 if (ret < 0)
1291 return ret;
1292
1293 p = call->buffer;
1294 p[call->count] = 0;
1295 _debug("offline '%s'", p);
1296
1297 afs_extract_to_tmp(call);
1298 call->unmarshall++;
1299 fallthrough;
1300
1301 /* extract the message of the day length */
1302 case 6:
1303 ret = afs_extract_data(call, true);
1304 if (ret < 0)
1305 return ret;
1306
1307 call->count = ntohl(call->tmp);
1308 _debug("motd length: %u", call->count);
1309 if (call->count >= AFSNAMEMAX)
1310 return afs_protocol_error(call, afs_eproto_motd_len);
1311 size = (call->count + 3) & ~3; /* It's padded */
1312 afs_extract_to_buf(call, size);
1313 call->unmarshall++;
1314 fallthrough;
1315
1316 /* extract the message of the day */
1317 case 7:
1318 _debug("extract motd");
1319 ret = afs_extract_data(call, false);
1320 if (ret < 0)
1321 return ret;
1322
1323 p = call->buffer;
1324 p[call->count] = 0;
1325 _debug("motd '%s'", p);
1326
1327 call->unmarshall++;
1328 fallthrough;
1329
1330 case 8:
1331 break;
1332 }
1333
1334 _leave(" = 0 [done]");
1335 return 0;
1336}
1337
1338/*
1339 * YFS.GetVolumeStatus operation type
1340 */
1341static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1342 .name = "YFS.GetVolumeStatus",
1343 .op = yfs_FS_GetVolumeStatus,
1344 .deliver = yfs_deliver_fs_get_volume_status,
1345 .destructor = afs_flat_call_destructor,
1346};
1347
1348/*
1349 * fetch the status of a volume
1350 */
1351void yfs_fs_get_volume_status(struct afs_operation *op)
1352{
1353 struct afs_vnode_param *vp = &op->file[0];
1354 struct afs_call *call;
1355 __be32 *bp;
1356
1357 _enter("");
1358
1359 call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
1360 sizeof(__be32) * 2 +
1361 sizeof(struct yfs_xdr_u64),
1362 max_t(size_t,
1363 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1364 sizeof(__be32),
1365 AFSOPAQUEMAX + 1));
1366 if (!call)
1367 return afs_op_nomem(op);
1368
1369 /* marshall the parameters */
1370 bp = call->request;
1371 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1372 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1373 bp = xdr_encode_u64(bp, vp->fid.vid);
1374 yfs_check_req(call, bp);
1375
1376 trace_afs_make_fs_call(call, &vp->fid);
1377 afs_make_op_call(op, call, GFP_NOFS);
1378}
1379
1380/*
1381 * YFS.SetLock operation type
1382 */
1383static const struct afs_call_type yfs_RXYFSSetLock = {
1384 .name = "YFS.SetLock",
1385 .op = yfs_FS_SetLock,
1386 .deliver = yfs_deliver_status_and_volsync,
1387 .done = afs_lock_op_done,
1388 .destructor = afs_flat_call_destructor,
1389};
1390
1391/*
1392 * YFS.ExtendLock operation type
1393 */
1394static const struct afs_call_type yfs_RXYFSExtendLock = {
1395 .name = "YFS.ExtendLock",
1396 .op = yfs_FS_ExtendLock,
1397 .deliver = yfs_deliver_status_and_volsync,
1398 .done = afs_lock_op_done,
1399 .destructor = afs_flat_call_destructor,
1400};
1401
1402/*
1403 * YFS.ReleaseLock operation type
1404 */
1405static const struct afs_call_type yfs_RXYFSReleaseLock = {
1406 .name = "YFS.ReleaseLock",
1407 .op = yfs_FS_ReleaseLock,
1408 .deliver = yfs_deliver_status_and_volsync,
1409 .destructor = afs_flat_call_destructor,
1410};
1411
1412/*
1413 * Set a lock on a file
1414 */
1415void yfs_fs_set_lock(struct afs_operation *op)
1416{
1417 struct afs_vnode_param *vp = &op->file[0];
1418 struct afs_call *call;
1419 __be32 *bp;
1420
1421 _enter("");
1422
1423 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
1424 sizeof(__be32) * 2 +
1425 sizeof(struct yfs_xdr_YFSFid) +
1426 sizeof(__be32),
1427 sizeof(struct yfs_xdr_YFSFetchStatus) +
1428 sizeof(struct yfs_xdr_YFSVolSync));
1429 if (!call)
1430 return afs_op_nomem(op);
1431
1432 /* marshall the parameters */
1433 bp = call->request;
1434 bp = xdr_encode_u32(bp, YFSSETLOCK);
1435 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1436 bp = xdr_encode_YFSFid(bp, &vp->fid);
1437 bp = xdr_encode_u32(bp, op->lock.type);
1438 yfs_check_req(call, bp);
1439
1440 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1441 afs_make_op_call(op, call, GFP_NOFS);
1442}
1443
1444/*
1445 * extend a lock on a file
1446 */
1447void yfs_fs_extend_lock(struct afs_operation *op)
1448{
1449 struct afs_vnode_param *vp = &op->file[0];
1450 struct afs_call *call;
1451 __be32 *bp;
1452
1453 _enter("");
1454
1455 call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
1456 sizeof(__be32) * 2 +
1457 sizeof(struct yfs_xdr_YFSFid),
1458 sizeof(struct yfs_xdr_YFSFetchStatus) +
1459 sizeof(struct yfs_xdr_YFSVolSync));
1460 if (!call)
1461 return afs_op_nomem(op);
1462
1463 /* marshall the parameters */
1464 bp = call->request;
1465 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1466 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1467 bp = xdr_encode_YFSFid(bp, &vp->fid);
1468 yfs_check_req(call, bp);
1469
1470 trace_afs_make_fs_call(call, &vp->fid);
1471 afs_make_op_call(op, call, GFP_NOFS);
1472}
1473
1474/*
1475 * release a lock on a file
1476 */
1477void yfs_fs_release_lock(struct afs_operation *op)
1478{
1479 struct afs_vnode_param *vp = &op->file[0];
1480 struct afs_call *call;
1481 __be32 *bp;
1482
1483 _enter("");
1484
1485 call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
1486 sizeof(__be32) * 2 +
1487 sizeof(struct yfs_xdr_YFSFid),
1488 sizeof(struct yfs_xdr_YFSFetchStatus) +
1489 sizeof(struct yfs_xdr_YFSVolSync));
1490 if (!call)
1491 return afs_op_nomem(op);
1492
1493 /* marshall the parameters */
1494 bp = call->request;
1495 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1496 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1497 bp = xdr_encode_YFSFid(bp, &vp->fid);
1498 yfs_check_req(call, bp);
1499
1500 trace_afs_make_fs_call(call, &vp->fid);
1501 afs_make_op_call(op, call, GFP_NOFS);
1502}
1503
1504/*
1505 * Deliver a reply to YFS.FetchStatus
1506 */
1507static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1508{
1509 struct afs_operation *op = call->op;
1510 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1511 const __be32 *bp;
1512 int ret;
1513
1514 ret = afs_transfer_reply(call);
1515 if (ret < 0)
1516 return ret;
1517
1518 /* unmarshall the reply once we've received all of it */
1519 bp = call->buffer;
1520 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1521 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
1522 xdr_decode_YFSVolSync(&bp, &op->volsync);
1523
1524 _leave(" = 0 [done]");
1525 return 0;
1526}
1527
1528/*
1529 * YFS.FetchStatus operation type
1530 */
1531static const struct afs_call_type yfs_RXYFSFetchStatus = {
1532 .name = "YFS.FetchStatus",
1533 .op = yfs_FS_FetchStatus,
1534 .deliver = yfs_deliver_fs_fetch_status,
1535 .destructor = afs_flat_call_destructor,
1536};
1537
1538/*
1539 * Fetch the status information for a fid without needing a vnode handle.
1540 */
1541void yfs_fs_fetch_status(struct afs_operation *op)
1542{
1543 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1544 struct afs_call *call;
1545 __be32 *bp;
1546
1547 _enter(",%x,{%llx:%llu},,",
1548 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1549
1550 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
1551 sizeof(__be32) * 2 +
1552 sizeof(struct yfs_xdr_YFSFid),
1553 sizeof(struct yfs_xdr_YFSFetchStatus) +
1554 sizeof(struct yfs_xdr_YFSCallBack) +
1555 sizeof(struct yfs_xdr_YFSVolSync));
1556 if (!call)
1557 return afs_op_nomem(op);
1558
1559 /* marshall the parameters */
1560 bp = call->request;
1561 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
1562 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1563 bp = xdr_encode_YFSFid(bp, &vp->fid);
1564 yfs_check_req(call, bp);
1565
1566 trace_afs_make_fs_call(call, &vp->fid);
1567 afs_make_op_call(op, call, GFP_NOFS);
1568}
1569
1570/*
1571 * Deliver reply data to an YFS.InlineBulkStatus call
1572 */
1573static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
1574{
1575 struct afs_operation *op = call->op;
1576 struct afs_status_cb *scb;
1577 const __be32 *bp;
1578 u32 tmp;
1579 int ret;
1580
1581 _enter("{%u}", call->unmarshall);
1582
1583 switch (call->unmarshall) {
1584 case 0:
1585 afs_extract_to_tmp(call);
1586 call->unmarshall++;
1587 fallthrough;
1588
1589 /* Extract the file status count and array in two steps */
1590 case 1:
1591 _debug("extract status count");
1592 ret = afs_extract_data(call, true);
1593 if (ret < 0)
1594 return ret;
1595
1596 tmp = ntohl(call->tmp);
1597 _debug("status count: %u/%u", tmp, op->nr_files);
1598 if (tmp != op->nr_files)
1599 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1600
1601 call->count = 0;
1602 call->unmarshall++;
1603 more_counts:
1604 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
1605 fallthrough;
1606
1607 case 2:
1608 _debug("extract status array %u", call->count);
1609 ret = afs_extract_data(call, true);
1610 if (ret < 0)
1611 return ret;
1612
1613 switch (call->count) {
1614 case 0:
1615 scb = &op->file[0].scb;
1616 break;
1617 case 1:
1618 scb = &op->file[1].scb;
1619 break;
1620 default:
1621 scb = &op->more_files[call->count - 2].scb;
1622 break;
1623 }
1624
1625 bp = call->buffer;
1626 xdr_decode_YFSFetchStatus(&bp, call, scb);
1627
1628 call->count++;
1629 if (call->count < op->nr_files)
1630 goto more_counts;
1631
1632 call->count = 0;
1633 call->unmarshall++;
1634 afs_extract_to_tmp(call);
1635 fallthrough;
1636
1637 /* Extract the callback count and array in two steps */
1638 case 3:
1639 _debug("extract CB count");
1640 ret = afs_extract_data(call, true);
1641 if (ret < 0)
1642 return ret;
1643
1644 tmp = ntohl(call->tmp);
1645 _debug("CB count: %u", tmp);
1646 if (tmp != op->nr_files)
1647 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1648 call->count = 0;
1649 call->unmarshall++;
1650 more_cbs:
1651 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
1652 fallthrough;
1653
1654 case 4:
1655 _debug("extract CB array");
1656 ret = afs_extract_data(call, true);
1657 if (ret < 0)
1658 return ret;
1659
1660 _debug("unmarshall CB array");
1661 switch (call->count) {
1662 case 0:
1663 scb = &op->file[0].scb;
1664 break;
1665 case 1:
1666 scb = &op->file[1].scb;
1667 break;
1668 default:
1669 scb = &op->more_files[call->count - 2].scb;
1670 break;
1671 }
1672
1673 bp = call->buffer;
1674 xdr_decode_YFSCallBack(&bp, call, scb);
1675 call->count++;
1676 if (call->count < op->nr_files)
1677 goto more_cbs;
1678
1679 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
1680 call->unmarshall++;
1681 fallthrough;
1682
1683 case 5:
1684 ret = afs_extract_data(call, false);
1685 if (ret < 0)
1686 return ret;
1687
1688 bp = call->buffer;
1689 xdr_decode_YFSVolSync(&bp, &op->volsync);
1690
1691 call->unmarshall++;
1692 fallthrough;
1693
1694 case 6:
1695 break;
1696 }
1697
1698 _leave(" = 0 [done]");
1699 return 0;
1700}
1701
1702/*
1703 * FS.InlineBulkStatus operation type
1704 */
1705static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
1706 .name = "YFS.InlineBulkStatus",
1707 .op = yfs_FS_InlineBulkStatus,
1708 .deliver = yfs_deliver_fs_inline_bulk_status,
1709 .destructor = afs_flat_call_destructor,
1710};
1711
1712/*
1713 * Fetch the status information for up to 1024 files
1714 */
1715void yfs_fs_inline_bulk_status(struct afs_operation *op)
1716{
1717 struct afs_vnode_param *dvp = &op->file[0];
1718 struct afs_vnode_param *vp = &op->file[1];
1719 struct afs_call *call;
1720 __be32 *bp;
1721 int i;
1722
1723 _enter(",%x,{%llx:%llu},%u",
1724 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1725
1726 call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
1727 sizeof(__be32) +
1728 sizeof(__be32) +
1729 sizeof(__be32) +
1730 sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
1731 sizeof(struct yfs_xdr_YFSFetchStatus));
1732 if (!call)
1733 return afs_op_nomem(op);
1734
1735 /* marshall the parameters */
1736 bp = call->request;
1737 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
1738 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
1739 bp = xdr_encode_u32(bp, op->nr_files);
1740 bp = xdr_encode_YFSFid(bp, &dvp->fid);
1741 bp = xdr_encode_YFSFid(bp, &vp->fid);
1742 for (i = 0; i < op->nr_files - 2; i++)
1743 bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
1744 yfs_check_req(call, bp);
1745
1746 trace_afs_make_fs_call(call, &vp->fid);
1747 afs_make_op_call(op, call, GFP_NOFS);
1748}
1749
1750/*
1751 * Deliver reply data to an YFS.FetchOpaqueACL.
1752 */
1753static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
1754{
1755 struct afs_operation *op = call->op;
1756 struct afs_vnode_param *vp = &op->file[0];
1757 struct yfs_acl *yacl = op->yacl;
1758 struct afs_acl *acl;
1759 const __be32 *bp;
1760 unsigned int size;
1761 int ret;
1762
1763 _enter("{%u}", call->unmarshall);
1764
1765 switch (call->unmarshall) {
1766 case 0:
1767 afs_extract_to_tmp(call);
1768 call->unmarshall++;
1769 fallthrough;
1770
1771 /* Extract the file ACL length */
1772 case 1:
1773 ret = afs_extract_data(call, true);
1774 if (ret < 0)
1775 return ret;
1776
1777 size = call->count2 = ntohl(call->tmp);
1778 size = round_up(size, 4);
1779
1780 if (yacl->flags & YFS_ACL_WANT_ACL) {
1781 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1782 if (!acl)
1783 return -ENOMEM;
1784 yacl->acl = acl;
1785 acl->size = call->count2;
1786 afs_extract_begin(call, acl->data, size);
1787 } else {
1788 afs_extract_discard(call, size);
1789 }
1790 call->unmarshall++;
1791 fallthrough;
1792
1793 /* Extract the file ACL */
1794 case 2:
1795 ret = afs_extract_data(call, true);
1796 if (ret < 0)
1797 return ret;
1798
1799 afs_extract_to_tmp(call);
1800 call->unmarshall++;
1801 fallthrough;
1802
1803 /* Extract the volume ACL length */
1804 case 3:
1805 ret = afs_extract_data(call, true);
1806 if (ret < 0)
1807 return ret;
1808
1809 size = call->count2 = ntohl(call->tmp);
1810 size = round_up(size, 4);
1811
1812 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
1813 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1814 if (!acl)
1815 return -ENOMEM;
1816 yacl->vol_acl = acl;
1817 acl->size = call->count2;
1818 afs_extract_begin(call, acl->data, size);
1819 } else {
1820 afs_extract_discard(call, size);
1821 }
1822 call->unmarshall++;
1823 fallthrough;
1824
1825 /* Extract the volume ACL */
1826 case 4:
1827 ret = afs_extract_data(call, true);
1828 if (ret < 0)
1829 return ret;
1830
1831 afs_extract_to_buf(call,
1832 sizeof(__be32) * 2 +
1833 sizeof(struct yfs_xdr_YFSFetchStatus) +
1834 sizeof(struct yfs_xdr_YFSVolSync));
1835 call->unmarshall++;
1836 fallthrough;
1837
1838 /* extract the metadata */
1839 case 5:
1840 ret = afs_extract_data(call, false);
1841 if (ret < 0)
1842 return ret;
1843
1844 bp = call->buffer;
1845 yacl->inherit_flag = ntohl(*bp++);
1846 yacl->num_cleaned = ntohl(*bp++);
1847 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1848 xdr_decode_YFSVolSync(&bp, &op->volsync);
1849
1850 call->unmarshall++;
1851 fallthrough;
1852
1853 case 6:
1854 break;
1855 }
1856
1857 _leave(" = 0 [done]");
1858 return 0;
1859}
1860
1861void yfs_free_opaque_acl(struct yfs_acl *yacl)
1862{
1863 if (yacl) {
1864 kfree(yacl->acl);
1865 kfree(yacl->vol_acl);
1866 kfree(yacl);
1867 }
1868}
1869
1870/*
1871 * YFS.FetchOpaqueACL operation type
1872 */
1873static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
1874 .name = "YFS.FetchOpaqueACL",
1875 .op = yfs_FS_FetchOpaqueACL,
1876 .deliver = yfs_deliver_fs_fetch_opaque_acl,
1877 .destructor = afs_flat_call_destructor,
1878};
1879
1880/*
1881 * Fetch the YFS advanced ACLs for a file.
1882 */
1883void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
1884{
1885 struct afs_vnode_param *vp = &op->file[0];
1886 struct afs_call *call;
1887 __be32 *bp;
1888
1889 _enter(",%x,{%llx:%llu},,",
1890 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1891
1892 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
1893 sizeof(__be32) * 2 +
1894 sizeof(struct yfs_xdr_YFSFid),
1895 sizeof(__be32) * 2 +
1896 sizeof(struct yfs_xdr_YFSFetchStatus) +
1897 sizeof(struct yfs_xdr_YFSVolSync));
1898 if (!call)
1899 return afs_op_nomem(op);
1900
1901 /* marshall the parameters */
1902 bp = call->request;
1903 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
1904 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1905 bp = xdr_encode_YFSFid(bp, &vp->fid);
1906 yfs_check_req(call, bp);
1907
1908 trace_afs_make_fs_call(call, &vp->fid);
1909 afs_make_op_call(op, call, GFP_KERNEL);
1910}
1911
1912/*
1913 * YFS.StoreOpaqueACL2 operation type
1914 */
1915static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
1916 .name = "YFS.StoreOpaqueACL2",
1917 .op = yfs_FS_StoreOpaqueACL2,
1918 .deliver = yfs_deliver_status_and_volsync,
1919 .destructor = afs_flat_call_destructor,
1920};
1921
1922/*
1923 * Fetch the YFS ACL for a file.
1924 */
1925void yfs_fs_store_opaque_acl2(struct afs_operation *op)
1926{
1927 struct afs_vnode_param *vp = &op->file[0];
1928 struct afs_call *call;
1929 struct afs_acl *acl = op->acl;
1930 size_t size;
1931 __be32 *bp;
1932
1933 _enter(",%x,{%llx:%llu},,",
1934 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1935
1936 size = round_up(acl->size, 4);
1937 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
1938 sizeof(__be32) * 2 +
1939 sizeof(struct yfs_xdr_YFSFid) +
1940 sizeof(__be32) + size,
1941 sizeof(struct yfs_xdr_YFSFetchStatus) +
1942 sizeof(struct yfs_xdr_YFSVolSync));
1943 if (!call)
1944 return afs_op_nomem(op);
1945
1946 /* marshall the parameters */
1947 bp = call->request;
1948 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
1949 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1950 bp = xdr_encode_YFSFid(bp, &vp->fid);
1951 bp = xdr_encode_u32(bp, acl->size);
1952 memcpy(bp, acl->data, acl->size);
1953 if (acl->size != size)
1954 memset((void *)bp + acl->size, 0, size - acl->size);
1955 bp += size / sizeof(__be32);
1956 yfs_check_req(call, bp);
1957
1958 trace_afs_make_fs_call(call, &vp->fid);
1959 afs_make_op_call(op, call, GFP_KERNEL);
1960}
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* YFS File Server client stubs
3 *
4 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
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
18#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
75static __be32 *xdr_encode_name(__be32 *bp, const struct qstr *p)
76{
77 return xdr_encode_string(bp, p->name, p->len);
78}
79
80static 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(__be32 *bp, mode_t *mode,
87 const struct timespec64 *t)
88{
89 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
90 mode_t masked_mode = mode ? *mode & S_IALLUGO : 0;
91 s64 mtime = linux_to_yfs_time(t);
92 u32 mask = AFS_SET_MTIME;
93
94 mask |= mode ? AFS_SET_MODE : 0;
95
96 x->mask = htonl(mask);
97 x->mode = htonl(masked_mode);
98 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)
146 pr_warn("kAFS: %s: Request buffer underflow (%zu<%u)\n",
147 call->type->name, len, call->request_size);
148}
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");
159 for (i = 0; i < 6 * 4 * 4; i += 16) {
160 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
166 memcpy(x, bp, 8);
167 pr_notice("0x60: %08x %08x\n", ntohl(x[0]), ntohl(x[1]));
168}
169
170/*
171 * Decode a YFSFetchStatus block
172 */
173static void xdr_decode_YFSFetchStatus(const __be32 **_bp,
174 struct afs_call *call,
175 struct afs_status_cb *scb)
176{
177 const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
178 struct afs_file_status *status = &scb->status;
179 u32 type;
180
181 status->abort_code = ntohl(xdr->abort_code);
182 if (status->abort_code != 0) {
183 if (status->abort_code == VNOVNODE)
184 status->nlink = 0;
185 scb->have_error = true;
186 goto advance;
187 }
188
189 type = ntohl(xdr->type);
190 switch (type) {
191 case AFS_FTYPE_FILE:
192 case AFS_FTYPE_DIR:
193 case AFS_FTYPE_SYMLINK:
194 status->type = type;
195 break;
196 default:
197 goto bad;
198 }
199
200 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);
208
209 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);
213 scb->have_status = true;
214advance:
215 *_bp += xdr_size(xdr);
216 return;
217
218bad:
219 xdr_dump_bad(*_bp);
220 afs_protocol_error(call, afs_eproto_bad_status);
221 goto advance;
222}
223
224/*
225 * Decode a YFSCallBack block
226 */
227static void xdr_decode_YFSCallBack(const __be32 **_bp,
228 struct afs_call *call,
229 struct afs_status_cb *scb)
230{
231 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
232 struct afs_callback *cb = &scb->callback;
233 ktime_t cb_expiry;
234
235 cb_expiry = ktime_add(call->issue_time, xdr_to_u64(x->expiration_time) * 100);
236 cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
237 scb->have_cb = true;
238 *_bp += xdr_size(x);
239}
240
241/*
242 * Decode a YFSVolSync block
243 */
244static void xdr_decode_YFSVolSync(const __be32 **_bp,
245 struct afs_volsync *volsync)
246{
247 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
248 u64 creation, update;
249
250 if (volsync) {
251 creation = xdr_to_u64(x->vol_creation_date);
252 do_div(creation, 10 * 1000 * 1000);
253 volsync->creation = creation;
254 update = xdr_to_u64(x->vol_update_date);
255 do_div(update, 10 * 1000 * 1000);
256 volsync->update = update;
257 }
258
259 *_bp += xdr_size(x);
260}
261
262/*
263 * Encode the requested attributes into a YFSStoreStatus block
264 */
265static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
266{
267 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
268 s64 mtime = 0, owner = 0, group = 0;
269 u32 mask = 0, mode = 0;
270
271 mask = 0;
272 if (attr->ia_valid & ATTR_MTIME) {
273 mask |= AFS_SET_MTIME;
274 mtime = linux_to_yfs_time(&attr->ia_mtime);
275 }
276
277 if (attr->ia_valid & ATTR_UID) {
278 mask |= AFS_SET_OWNER;
279 owner = from_kuid(&init_user_ns, attr->ia_uid);
280 }
281
282 if (attr->ia_valid & ATTR_GID) {
283 mask |= AFS_SET_GROUP;
284 group = from_kgid(&init_user_ns, attr->ia_gid);
285 }
286
287 if (attr->ia_valid & ATTR_MODE) {
288 mask |= AFS_SET_MODE;
289 mode = attr->ia_mode & S_IALLUGO;
290 }
291
292 x->mask = htonl(mask);
293 x->mode = htonl(mode);
294 x->mtime_client = u64_to_xdr(mtime);
295 x->owner = u64_to_xdr(owner);
296 x->group = u64_to_xdr(group);
297 return bp + xdr_size(x);
298}
299
300/*
301 * Decode a YFSFetchVolumeStatus block.
302 */
303static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
304 struct afs_volume_status *vs)
305{
306 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
307 u32 flags;
308
309 vs->vid = xdr_to_u64(x->vid);
310 vs->parent_id = xdr_to_u64(x->parent_id);
311 flags = ntohl(x->flags);
312 vs->online = flags & yfs_FVSOnline;
313 vs->in_service = flags & yfs_FVSInservice;
314 vs->blessed = flags & yfs_FVSBlessed;
315 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
316 vs->type = ntohl(x->type);
317 vs->min_quota = 0;
318 vs->max_quota = xdr_to_u64(x->max_quota);
319 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
320 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
321 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
322 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
323 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
324 *_bp += sizeof(*x) / sizeof(__be32);
325}
326
327/*
328 * Deliver reply data to operations that just return a file status and a volume
329 * sync record.
330 */
331static int yfs_deliver_status_and_volsync(struct afs_call *call)
332{
333 struct afs_operation *op = call->op;
334 const __be32 *bp;
335 int ret;
336
337 ret = afs_transfer_reply(call);
338 if (ret < 0)
339 return ret;
340
341 bp = call->buffer;
342 xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
343 xdr_decode_YFSVolSync(&bp, &op->volsync);
344
345 _leave(" = 0 [done]");
346 return 0;
347}
348
349/*
350 * Deliver reply data to an YFS.FetchData64.
351 */
352static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
353{
354 struct afs_operation *op = call->op;
355 struct afs_vnode_param *vp = &op->file[0];
356 struct afs_read *req = op->fetch.req;
357 const __be32 *bp;
358 int ret;
359
360 _enter("{%u,%zu, %zu/%llu}",
361 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
362 req->actual_len);
363
364 switch (call->unmarshall) {
365 case 0:
366 req->actual_len = 0;
367 afs_extract_to_tmp64(call);
368 call->unmarshall++;
369 fallthrough;
370
371 /* Extract the returned data length into ->actual_len. This
372 * may indicate more or less data than was requested will be
373 * returned.
374 */
375 case 1:
376 _debug("extract data length");
377 ret = afs_extract_data(call, true);
378 if (ret < 0)
379 return ret;
380
381 req->actual_len = be64_to_cpu(call->tmp64);
382 _debug("DATA length: %llu", req->actual_len);
383
384 if (req->actual_len == 0)
385 goto no_more_data;
386
387 call->iter = req->iter;
388 call->iov_len = min(req->actual_len, req->len);
389 call->unmarshall++;
390 fallthrough;
391
392 /* extract the returned data */
393 case 2:
394 _debug("extract data %zu/%llu",
395 iov_iter_count(call->iter), req->actual_len);
396
397 ret = afs_extract_data(call, true);
398 if (ret < 0)
399 return ret;
400
401 call->iter = &call->def_iter;
402 if (req->actual_len <= req->len)
403 goto no_more_data;
404
405 /* Discard any excess data the server gave us */
406 afs_extract_discard(call, req->actual_len - req->len);
407 call->unmarshall = 3;
408 fallthrough;
409
410 case 3:
411 _debug("extract discard %zu/%llu",
412 iov_iter_count(call->iter), req->actual_len - req->len);
413
414 ret = afs_extract_data(call, true);
415 if (ret < 0)
416 return ret;
417
418 no_more_data:
419 call->unmarshall = 4;
420 afs_extract_to_buf(call,
421 sizeof(struct yfs_xdr_YFSFetchStatus) +
422 sizeof(struct yfs_xdr_YFSCallBack) +
423 sizeof(struct yfs_xdr_YFSVolSync));
424 fallthrough;
425
426 /* extract the metadata */
427 case 4:
428 ret = afs_extract_data(call, false);
429 if (ret < 0)
430 return ret;
431
432 bp = call->buffer;
433 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
434 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
435 xdr_decode_YFSVolSync(&bp, &op->volsync);
436
437 req->data_version = vp->scb.status.data_version;
438 req->file_size = vp->scb.status.size;
439
440 call->unmarshall++;
441 fallthrough;
442
443 case 5:
444 break;
445 }
446
447 _leave(" = 0 [done]");
448 return 0;
449}
450
451/*
452 * YFS.FetchData64 operation type
453 */
454static const struct afs_call_type yfs_RXYFSFetchData64 = {
455 .name = "YFS.FetchData64",
456 .op = yfs_FS_FetchData64,
457 .deliver = yfs_deliver_fs_fetch_data64,
458 .destructor = afs_flat_call_destructor,
459};
460
461/*
462 * Fetch data from a file.
463 */
464void yfs_fs_fetch_data(struct afs_operation *op)
465{
466 struct afs_vnode_param *vp = &op->file[0];
467 struct afs_read *req = op->fetch.req;
468 struct afs_call *call;
469 __be32 *bp;
470
471 _enter(",%x,{%llx:%llu},%llx,%llx",
472 key_serial(op->key), vp->fid.vid, vp->fid.vnode,
473 req->pos, req->len);
474
475 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
476 sizeof(__be32) * 2 +
477 sizeof(struct yfs_xdr_YFSFid) +
478 sizeof(struct yfs_xdr_u64) * 2,
479 sizeof(struct yfs_xdr_YFSFetchStatus) +
480 sizeof(struct yfs_xdr_YFSCallBack) +
481 sizeof(struct yfs_xdr_YFSVolSync));
482 if (!call)
483 return afs_op_nomem(op);
484
485 req->call_debug_id = call->debug_id;
486
487 /* marshall the parameters */
488 bp = call->request;
489 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
490 bp = xdr_encode_u32(bp, 0); /* RPC flags */
491 bp = xdr_encode_YFSFid(bp, &vp->fid);
492 bp = xdr_encode_u64(bp, req->pos);
493 bp = xdr_encode_u64(bp, req->len);
494 yfs_check_req(call, bp);
495
496 call->fid = vp->fid;
497 trace_afs_make_fs_call(call, &vp->fid);
498 afs_make_op_call(op, call, GFP_NOFS);
499}
500
501/*
502 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
503 */
504static int yfs_deliver_fs_create_vnode(struct afs_call *call)
505{
506 struct afs_operation *op = call->op;
507 struct afs_vnode_param *dvp = &op->file[0];
508 struct afs_vnode_param *vp = &op->file[1];
509 const __be32 *bp;
510 int ret;
511
512 _enter("{%u}", call->unmarshall);
513
514 ret = afs_transfer_reply(call);
515 if (ret < 0)
516 return ret;
517
518 /* unmarshall the reply once we've received all of it */
519 bp = call->buffer;
520 xdr_decode_YFSFid(&bp, &op->file[1].fid);
521 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
522 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
523 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
524 xdr_decode_YFSVolSync(&bp, &op->volsync);
525
526 _leave(" = 0 [done]");
527 return 0;
528}
529
530/*
531 * FS.CreateFile and FS.MakeDir operation type
532 */
533static const struct afs_call_type afs_RXFSCreateFile = {
534 .name = "YFS.CreateFile",
535 .op = yfs_FS_CreateFile,
536 .deliver = yfs_deliver_fs_create_vnode,
537 .destructor = afs_flat_call_destructor,
538};
539
540/*
541 * Create a file.
542 */
543void yfs_fs_create_file(struct afs_operation *op)
544{
545 const struct qstr *name = &op->dentry->d_name;
546 struct afs_vnode_param *dvp = &op->file[0];
547 struct afs_call *call;
548 size_t reqsz, rplsz;
549 __be32 *bp;
550
551 _enter("");
552
553 reqsz = (sizeof(__be32) +
554 sizeof(__be32) +
555 sizeof(struct yfs_xdr_YFSFid) +
556 xdr_strlen(name->len) +
557 sizeof(struct yfs_xdr_YFSStoreStatus) +
558 sizeof(__be32));
559 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
560 sizeof(struct yfs_xdr_YFSFetchStatus) +
561 sizeof(struct yfs_xdr_YFSFetchStatus) +
562 sizeof(struct yfs_xdr_YFSCallBack) +
563 sizeof(struct yfs_xdr_YFSVolSync));
564
565 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
566 if (!call)
567 return afs_op_nomem(op);
568
569 /* marshall the parameters */
570 bp = call->request;
571 bp = xdr_encode_u32(bp, YFSCREATEFILE);
572 bp = xdr_encode_u32(bp, 0); /* RPC flags */
573 bp = xdr_encode_YFSFid(bp, &dvp->fid);
574 bp = xdr_encode_name(bp, name);
575 bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
576 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
577 yfs_check_req(call, bp);
578
579 call->fid = dvp->fid;
580 trace_afs_make_fs_call1(call, &dvp->fid, name);
581 afs_make_op_call(op, call, GFP_NOFS);
582}
583
584static const struct afs_call_type yfs_RXFSMakeDir = {
585 .name = "YFS.MakeDir",
586 .op = yfs_FS_MakeDir,
587 .deliver = yfs_deliver_fs_create_vnode,
588 .destructor = afs_flat_call_destructor,
589};
590
591/*
592 * Make a directory.
593 */
594void yfs_fs_make_dir(struct afs_operation *op)
595{
596 const struct qstr *name = &op->dentry->d_name;
597 struct afs_vnode_param *dvp = &op->file[0];
598 struct afs_call *call;
599 size_t reqsz, rplsz;
600 __be32 *bp;
601
602 _enter("");
603
604 reqsz = (sizeof(__be32) +
605 sizeof(struct yfs_xdr_RPCFlags) +
606 sizeof(struct yfs_xdr_YFSFid) +
607 xdr_strlen(name->len) +
608 sizeof(struct yfs_xdr_YFSStoreStatus));
609 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
610 sizeof(struct yfs_xdr_YFSFetchStatus) +
611 sizeof(struct yfs_xdr_YFSFetchStatus) +
612 sizeof(struct yfs_xdr_YFSCallBack) +
613 sizeof(struct yfs_xdr_YFSVolSync));
614
615 call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
616 if (!call)
617 return afs_op_nomem(op);
618
619 /* marshall the parameters */
620 bp = call->request;
621 bp = xdr_encode_u32(bp, YFSMAKEDIR);
622 bp = xdr_encode_u32(bp, 0); /* RPC flags */
623 bp = xdr_encode_YFSFid(bp, &dvp->fid);
624 bp = xdr_encode_name(bp, name);
625 bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
626 yfs_check_req(call, bp);
627
628 call->fid = dvp->fid;
629 trace_afs_make_fs_call1(call, &dvp->fid, name);
630 afs_make_op_call(op, call, GFP_NOFS);
631}
632
633/*
634 * Deliver reply data to a YFS.RemoveFile2 operation.
635 */
636static int yfs_deliver_fs_remove_file2(struct afs_call *call)
637{
638 struct afs_operation *op = call->op;
639 struct afs_vnode_param *dvp = &op->file[0];
640 struct afs_vnode_param *vp = &op->file[1];
641 struct afs_fid fid;
642 const __be32 *bp;
643 int ret;
644
645 _enter("{%u}", call->unmarshall);
646
647 ret = afs_transfer_reply(call);
648 if (ret < 0)
649 return ret;
650
651 bp = call->buffer;
652 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
653 xdr_decode_YFSFid(&bp, &fid);
654 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
655 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
656
657 xdr_decode_YFSVolSync(&bp, &op->volsync);
658 return 0;
659}
660
661static void yfs_done_fs_remove_file2(struct afs_call *call)
662{
663 if (call->error == -ECONNABORTED &&
664 call->abort_code == RX_INVALID_OPERATION) {
665 set_bit(AFS_SERVER_FL_NO_RM2, &call->server->flags);
666 call->op->flags |= AFS_OPERATION_DOWNGRADE;
667 }
668}
669
670/*
671 * YFS.RemoveFile2 operation type.
672 */
673static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
674 .name = "YFS.RemoveFile2",
675 .op = yfs_FS_RemoveFile2,
676 .deliver = yfs_deliver_fs_remove_file2,
677 .done = yfs_done_fs_remove_file2,
678 .destructor = afs_flat_call_destructor,
679};
680
681/*
682 * Remove a file and retrieve new file status.
683 */
684void yfs_fs_remove_file2(struct afs_operation *op)
685{
686 struct afs_vnode_param *dvp = &op->file[0];
687 const struct qstr *name = &op->dentry->d_name;
688 struct afs_call *call;
689 __be32 *bp;
690
691 _enter("");
692
693 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
694 sizeof(__be32) +
695 sizeof(struct yfs_xdr_RPCFlags) +
696 sizeof(struct yfs_xdr_YFSFid) +
697 xdr_strlen(name->len),
698 sizeof(struct yfs_xdr_YFSFetchStatus) +
699 sizeof(struct yfs_xdr_YFSFid) +
700 sizeof(struct yfs_xdr_YFSFetchStatus) +
701 sizeof(struct yfs_xdr_YFSVolSync));
702 if (!call)
703 return afs_op_nomem(op);
704
705 /* marshall the parameters */
706 bp = call->request;
707 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
708 bp = xdr_encode_u32(bp, 0); /* RPC flags */
709 bp = xdr_encode_YFSFid(bp, &dvp->fid);
710 bp = xdr_encode_name(bp, name);
711 yfs_check_req(call, bp);
712
713 call->fid = dvp->fid;
714 trace_afs_make_fs_call1(call, &dvp->fid, name);
715 afs_make_op_call(op, call, GFP_NOFS);
716}
717
718/*
719 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
720 */
721static int yfs_deliver_fs_remove(struct afs_call *call)
722{
723 struct afs_operation *op = call->op;
724 struct afs_vnode_param *dvp = &op->file[0];
725 const __be32 *bp;
726 int ret;
727
728 _enter("{%u}", call->unmarshall);
729
730 ret = afs_transfer_reply(call);
731 if (ret < 0)
732 return ret;
733
734 bp = call->buffer;
735 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
736 xdr_decode_YFSVolSync(&bp, &op->volsync);
737 return 0;
738}
739
740/*
741 * FS.RemoveDir and FS.RemoveFile operation types.
742 */
743static const struct afs_call_type yfs_RXYFSRemoveFile = {
744 .name = "YFS.RemoveFile",
745 .op = yfs_FS_RemoveFile,
746 .deliver = yfs_deliver_fs_remove,
747 .destructor = afs_flat_call_destructor,
748};
749
750/*
751 * Remove a file.
752 */
753void yfs_fs_remove_file(struct afs_operation *op)
754{
755 const struct qstr *name = &op->dentry->d_name;
756 struct afs_vnode_param *dvp = &op->file[0];
757 struct afs_call *call;
758 __be32 *bp;
759
760 _enter("");
761
762 if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
763 return yfs_fs_remove_file2(op);
764
765 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
766 sizeof(__be32) +
767 sizeof(struct yfs_xdr_RPCFlags) +
768 sizeof(struct yfs_xdr_YFSFid) +
769 xdr_strlen(name->len),
770 sizeof(struct yfs_xdr_YFSFetchStatus) +
771 sizeof(struct yfs_xdr_YFSVolSync));
772 if (!call)
773 return afs_op_nomem(op);
774
775 /* marshall the parameters */
776 bp = call->request;
777 bp = xdr_encode_u32(bp, YFSREMOVEFILE);
778 bp = xdr_encode_u32(bp, 0); /* RPC flags */
779 bp = xdr_encode_YFSFid(bp, &dvp->fid);
780 bp = xdr_encode_name(bp, name);
781 yfs_check_req(call, bp);
782
783 call->fid = dvp->fid;
784 trace_afs_make_fs_call1(call, &dvp->fid, name);
785 afs_make_op_call(op, call, GFP_NOFS);
786}
787
788static const struct afs_call_type yfs_RXYFSRemoveDir = {
789 .name = "YFS.RemoveDir",
790 .op = yfs_FS_RemoveDir,
791 .deliver = yfs_deliver_fs_remove,
792 .destructor = afs_flat_call_destructor,
793};
794
795/*
796 * Remove a directory.
797 */
798void yfs_fs_remove_dir(struct afs_operation *op)
799{
800 const struct qstr *name = &op->dentry->d_name;
801 struct afs_vnode_param *dvp = &op->file[0];
802 struct afs_call *call;
803 __be32 *bp;
804
805 _enter("");
806
807 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
808 sizeof(__be32) +
809 sizeof(struct yfs_xdr_RPCFlags) +
810 sizeof(struct yfs_xdr_YFSFid) +
811 xdr_strlen(name->len),
812 sizeof(struct yfs_xdr_YFSFetchStatus) +
813 sizeof(struct yfs_xdr_YFSVolSync));
814 if (!call)
815 return afs_op_nomem(op);
816
817 /* marshall the parameters */
818 bp = call->request;
819 bp = xdr_encode_u32(bp, YFSREMOVEDIR);
820 bp = xdr_encode_u32(bp, 0); /* RPC flags */
821 bp = xdr_encode_YFSFid(bp, &dvp->fid);
822 bp = xdr_encode_name(bp, name);
823 yfs_check_req(call, bp);
824
825 call->fid = dvp->fid;
826 trace_afs_make_fs_call1(call, &dvp->fid, name);
827 afs_make_op_call(op, call, GFP_NOFS);
828}
829
830/*
831 * Deliver reply data to a YFS.Link operation.
832 */
833static int yfs_deliver_fs_link(struct afs_call *call)
834{
835 struct afs_operation *op = call->op;
836 struct afs_vnode_param *dvp = &op->file[0];
837 struct afs_vnode_param *vp = &op->file[1];
838 const __be32 *bp;
839 int ret;
840
841 _enter("{%u}", call->unmarshall);
842
843 ret = afs_transfer_reply(call);
844 if (ret < 0)
845 return ret;
846
847 bp = call->buffer;
848 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
849 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
850 xdr_decode_YFSVolSync(&bp, &op->volsync);
851 _leave(" = 0 [done]");
852 return 0;
853}
854
855/*
856 * YFS.Link operation type.
857 */
858static const struct afs_call_type yfs_RXYFSLink = {
859 .name = "YFS.Link",
860 .op = yfs_FS_Link,
861 .deliver = yfs_deliver_fs_link,
862 .destructor = afs_flat_call_destructor,
863};
864
865/*
866 * Make a hard link.
867 */
868void yfs_fs_link(struct afs_operation *op)
869{
870 const struct qstr *name = &op->dentry->d_name;
871 struct afs_vnode_param *dvp = &op->file[0];
872 struct afs_vnode_param *vp = &op->file[1];
873 struct afs_call *call;
874 __be32 *bp;
875
876 _enter("");
877
878 call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
879 sizeof(__be32) +
880 sizeof(struct yfs_xdr_RPCFlags) +
881 sizeof(struct yfs_xdr_YFSFid) +
882 xdr_strlen(name->len) +
883 sizeof(struct yfs_xdr_YFSFid),
884 sizeof(struct yfs_xdr_YFSFetchStatus) +
885 sizeof(struct yfs_xdr_YFSFetchStatus) +
886 sizeof(struct yfs_xdr_YFSVolSync));
887 if (!call)
888 return afs_op_nomem(op);
889
890 /* marshall the parameters */
891 bp = call->request;
892 bp = xdr_encode_u32(bp, YFSLINK);
893 bp = xdr_encode_u32(bp, 0); /* RPC flags */
894 bp = xdr_encode_YFSFid(bp, &dvp->fid);
895 bp = xdr_encode_name(bp, name);
896 bp = xdr_encode_YFSFid(bp, &vp->fid);
897 yfs_check_req(call, bp);
898
899 call->fid = vp->fid;
900 trace_afs_make_fs_call1(call, &vp->fid, name);
901 afs_make_op_call(op, call, GFP_NOFS);
902}
903
904/*
905 * Deliver reply data to a YFS.Symlink operation.
906 */
907static int yfs_deliver_fs_symlink(struct afs_call *call)
908{
909 struct afs_operation *op = call->op;
910 struct afs_vnode_param *dvp = &op->file[0];
911 struct afs_vnode_param *vp = &op->file[1];
912 const __be32 *bp;
913 int ret;
914
915 _enter("{%u}", call->unmarshall);
916
917 ret = afs_transfer_reply(call);
918 if (ret < 0)
919 return ret;
920
921 /* unmarshall the reply once we've received all of it */
922 bp = call->buffer;
923 xdr_decode_YFSFid(&bp, &vp->fid);
924 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
925 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
926 xdr_decode_YFSVolSync(&bp, &op->volsync);
927
928 _leave(" = 0 [done]");
929 return 0;
930}
931
932/*
933 * YFS.Symlink operation type
934 */
935static const struct afs_call_type yfs_RXYFSSymlink = {
936 .name = "YFS.Symlink",
937 .op = yfs_FS_Symlink,
938 .deliver = yfs_deliver_fs_symlink,
939 .destructor = afs_flat_call_destructor,
940};
941
942/*
943 * Create a symbolic link.
944 */
945void yfs_fs_symlink(struct afs_operation *op)
946{
947 const struct qstr *name = &op->dentry->d_name;
948 struct afs_vnode_param *dvp = &op->file[0];
949 struct afs_call *call;
950 size_t contents_sz;
951 mode_t mode = 0777;
952 __be32 *bp;
953
954 _enter("");
955
956 contents_sz = strlen(op->create.symlink);
957 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
958 sizeof(__be32) +
959 sizeof(struct yfs_xdr_RPCFlags) +
960 sizeof(struct yfs_xdr_YFSFid) +
961 xdr_strlen(name->len) +
962 xdr_strlen(contents_sz) +
963 sizeof(struct yfs_xdr_YFSStoreStatus),
964 sizeof(struct yfs_xdr_YFSFid) +
965 sizeof(struct yfs_xdr_YFSFetchStatus) +
966 sizeof(struct yfs_xdr_YFSFetchStatus) +
967 sizeof(struct yfs_xdr_YFSVolSync));
968 if (!call)
969 return afs_op_nomem(op);
970
971 /* marshall the parameters */
972 bp = call->request;
973 bp = xdr_encode_u32(bp, YFSSYMLINK);
974 bp = xdr_encode_u32(bp, 0); /* RPC flags */
975 bp = xdr_encode_YFSFid(bp, &dvp->fid);
976 bp = xdr_encode_name(bp, name);
977 bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
978 bp = xdr_encode_YFSStoreStatus(bp, &mode, &op->mtime);
979 yfs_check_req(call, bp);
980
981 call->fid = dvp->fid;
982 trace_afs_make_fs_call1(call, &dvp->fid, name);
983 afs_make_op_call(op, call, GFP_NOFS);
984}
985
986/*
987 * Deliver reply data to a YFS.Rename operation.
988 */
989static int yfs_deliver_fs_rename(struct afs_call *call)
990{
991 struct afs_operation *op = call->op;
992 struct afs_vnode_param *orig_dvp = &op->file[0];
993 struct afs_vnode_param *new_dvp = &op->file[1];
994 const __be32 *bp;
995 int ret;
996
997 _enter("{%u}", call->unmarshall);
998
999 ret = afs_transfer_reply(call);
1000 if (ret < 0)
1001 return ret;
1002
1003 bp = call->buffer;
1004 /* If the two dirs are the same, we have two copies of the same status
1005 * report, so we just decode it twice.
1006 */
1007 xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
1008 xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
1009 xdr_decode_YFSVolSync(&bp, &op->volsync);
1010 _leave(" = 0 [done]");
1011 return 0;
1012}
1013
1014/*
1015 * YFS.Rename operation type
1016 */
1017static const struct afs_call_type yfs_RXYFSRename = {
1018 .name = "FS.Rename",
1019 .op = yfs_FS_Rename,
1020 .deliver = yfs_deliver_fs_rename,
1021 .destructor = afs_flat_call_destructor,
1022};
1023
1024/*
1025 * Rename a file or directory.
1026 */
1027void yfs_fs_rename(struct afs_operation *op)
1028{
1029 struct afs_vnode_param *orig_dvp = &op->file[0];
1030 struct afs_vnode_param *new_dvp = &op->file[1];
1031 const struct qstr *orig_name = &op->dentry->d_name;
1032 const struct qstr *new_name = &op->dentry_2->d_name;
1033 struct afs_call *call;
1034 __be32 *bp;
1035
1036 _enter("");
1037
1038 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
1039 sizeof(__be32) +
1040 sizeof(struct yfs_xdr_RPCFlags) +
1041 sizeof(struct yfs_xdr_YFSFid) +
1042 xdr_strlen(orig_name->len) +
1043 sizeof(struct yfs_xdr_YFSFid) +
1044 xdr_strlen(new_name->len),
1045 sizeof(struct yfs_xdr_YFSFetchStatus) +
1046 sizeof(struct yfs_xdr_YFSFetchStatus) +
1047 sizeof(struct yfs_xdr_YFSVolSync));
1048 if (!call)
1049 return afs_op_nomem(op);
1050
1051 /* marshall the parameters */
1052 bp = call->request;
1053 bp = xdr_encode_u32(bp, YFSRENAME);
1054 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1055 bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
1056 bp = xdr_encode_name(bp, orig_name);
1057 bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
1058 bp = xdr_encode_name(bp, new_name);
1059 yfs_check_req(call, bp);
1060
1061 call->fid = orig_dvp->fid;
1062 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1063 afs_make_op_call(op, call, GFP_NOFS);
1064}
1065
1066/*
1067 * YFS.StoreData64 operation type.
1068 */
1069static const struct afs_call_type yfs_RXYFSStoreData64 = {
1070 .name = "YFS.StoreData64",
1071 .op = yfs_FS_StoreData64,
1072 .deliver = yfs_deliver_status_and_volsync,
1073 .destructor = afs_flat_call_destructor,
1074};
1075
1076/*
1077 * Store a set of pages to a large file.
1078 */
1079void yfs_fs_store_data(struct afs_operation *op)
1080{
1081 struct afs_vnode_param *vp = &op->file[0];
1082 struct afs_call *call;
1083 __be32 *bp;
1084
1085 _enter(",%x,{%llx:%llu},,",
1086 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1087
1088 _debug("size %llx, at %llx, i_size %llx",
1089 (unsigned long long)op->store.size,
1090 (unsigned long long)op->store.pos,
1091 (unsigned long long)op->store.i_size);
1092
1093 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
1094 sizeof(__be32) +
1095 sizeof(__be32) +
1096 sizeof(struct yfs_xdr_YFSFid) +
1097 sizeof(struct yfs_xdr_YFSStoreStatus) +
1098 sizeof(struct yfs_xdr_u64) * 3,
1099 sizeof(struct yfs_xdr_YFSFetchStatus) +
1100 sizeof(struct yfs_xdr_YFSVolSync));
1101 if (!call)
1102 return afs_op_nomem(op);
1103
1104 call->write_iter = op->store.write_iter;
1105
1106 /* marshall the parameters */
1107 bp = call->request;
1108 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1109 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1110 bp = xdr_encode_YFSFid(bp, &vp->fid);
1111 bp = xdr_encode_YFSStoreStatus(bp, NULL, &op->mtime);
1112 bp = xdr_encode_u64(bp, op->store.pos);
1113 bp = xdr_encode_u64(bp, op->store.size);
1114 bp = xdr_encode_u64(bp, op->store.i_size);
1115 yfs_check_req(call, bp);
1116
1117 call->fid = vp->fid;
1118 trace_afs_make_fs_call(call, &vp->fid);
1119 afs_make_op_call(op, call, GFP_NOFS);
1120}
1121
1122/*
1123 * YFS.StoreStatus operation type
1124 */
1125static const struct afs_call_type yfs_RXYFSStoreStatus = {
1126 .name = "YFS.StoreStatus",
1127 .op = yfs_FS_StoreStatus,
1128 .deliver = yfs_deliver_status_and_volsync,
1129 .destructor = afs_flat_call_destructor,
1130};
1131
1132static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1133 .name = "YFS.StoreData64",
1134 .op = yfs_FS_StoreData64,
1135 .deliver = yfs_deliver_status_and_volsync,
1136 .destructor = afs_flat_call_destructor,
1137};
1138
1139/*
1140 * Set the attributes on a file, using YFS.StoreData64 rather than
1141 * YFS.StoreStatus so as to alter the file size also.
1142 */
1143static void yfs_fs_setattr_size(struct afs_operation *op)
1144{
1145 struct afs_vnode_param *vp = &op->file[0];
1146 struct afs_call *call;
1147 struct iattr *attr = op->setattr.attr;
1148 __be32 *bp;
1149
1150 _enter(",%x,{%llx:%llu},,",
1151 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1152
1153 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
1154 sizeof(__be32) * 2 +
1155 sizeof(struct yfs_xdr_YFSFid) +
1156 sizeof(struct yfs_xdr_YFSStoreStatus) +
1157 sizeof(struct yfs_xdr_u64) * 3,
1158 sizeof(struct yfs_xdr_YFSFetchStatus) +
1159 sizeof(struct yfs_xdr_YFSVolSync));
1160 if (!call)
1161 return afs_op_nomem(op);
1162
1163 /* marshall the parameters */
1164 bp = call->request;
1165 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1166 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1167 bp = xdr_encode_YFSFid(bp, &vp->fid);
1168 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1169 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1170 bp = xdr_encode_u64(bp, 0); /* size of write */
1171 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1172 yfs_check_req(call, bp);
1173
1174 call->fid = vp->fid;
1175 trace_afs_make_fs_call(call, &vp->fid);
1176 afs_make_op_call(op, call, GFP_NOFS);
1177}
1178
1179/*
1180 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1181 * file size, and YFS.StoreStatus otherwise.
1182 */
1183void yfs_fs_setattr(struct afs_operation *op)
1184{
1185 struct afs_vnode_param *vp = &op->file[0];
1186 struct afs_call *call;
1187 struct iattr *attr = op->setattr.attr;
1188 __be32 *bp;
1189
1190 if (attr->ia_valid & ATTR_SIZE)
1191 return yfs_fs_setattr_size(op);
1192
1193 _enter(",%x,{%llx:%llu},,",
1194 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1195
1196 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
1197 sizeof(__be32) * 2 +
1198 sizeof(struct yfs_xdr_YFSFid) +
1199 sizeof(struct yfs_xdr_YFSStoreStatus),
1200 sizeof(struct yfs_xdr_YFSFetchStatus) +
1201 sizeof(struct yfs_xdr_YFSVolSync));
1202 if (!call)
1203 return afs_op_nomem(op);
1204
1205 /* marshall the parameters */
1206 bp = call->request;
1207 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1208 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1209 bp = xdr_encode_YFSFid(bp, &vp->fid);
1210 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1211 yfs_check_req(call, bp);
1212
1213 call->fid = vp->fid;
1214 trace_afs_make_fs_call(call, &vp->fid);
1215 afs_make_op_call(op, call, GFP_NOFS);
1216}
1217
1218/*
1219 * Deliver reply data to a YFS.GetVolumeStatus operation.
1220 */
1221static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1222{
1223 struct afs_operation *op = call->op;
1224 const __be32 *bp;
1225 char *p;
1226 u32 size;
1227 int ret;
1228
1229 _enter("{%u}", call->unmarshall);
1230
1231 switch (call->unmarshall) {
1232 case 0:
1233 call->unmarshall++;
1234 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1235 fallthrough;
1236
1237 /* extract the returned status record */
1238 case 1:
1239 _debug("extract status");
1240 ret = afs_extract_data(call, true);
1241 if (ret < 0)
1242 return ret;
1243
1244 bp = call->buffer;
1245 xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1246 call->unmarshall++;
1247 afs_extract_to_tmp(call);
1248 fallthrough;
1249
1250 /* extract the volume name length */
1251 case 2:
1252 ret = afs_extract_data(call, true);
1253 if (ret < 0)
1254 return ret;
1255
1256 call->count = ntohl(call->tmp);
1257 _debug("volname length: %u", call->count);
1258 if (call->count >= AFSNAMEMAX)
1259 return afs_protocol_error(call, afs_eproto_volname_len);
1260 size = (call->count + 3) & ~3; /* It's padded */
1261 afs_extract_to_buf(call, size);
1262 call->unmarshall++;
1263 fallthrough;
1264
1265 /* extract the volume name */
1266 case 3:
1267 _debug("extract volname");
1268 ret = afs_extract_data(call, true);
1269 if (ret < 0)
1270 return ret;
1271
1272 p = call->buffer;
1273 p[call->count] = 0;
1274 _debug("volname '%s'", p);
1275 afs_extract_to_tmp(call);
1276 call->unmarshall++;
1277 fallthrough;
1278
1279 /* extract the offline message length */
1280 case 4:
1281 ret = afs_extract_data(call, true);
1282 if (ret < 0)
1283 return ret;
1284
1285 call->count = ntohl(call->tmp);
1286 _debug("offline msg length: %u", call->count);
1287 if (call->count >= AFSNAMEMAX)
1288 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1289 size = (call->count + 3) & ~3; /* It's padded */
1290 afs_extract_to_buf(call, size);
1291 call->unmarshall++;
1292 fallthrough;
1293
1294 /* extract the offline message */
1295 case 5:
1296 _debug("extract offline");
1297 ret = afs_extract_data(call, true);
1298 if (ret < 0)
1299 return ret;
1300
1301 p = call->buffer;
1302 p[call->count] = 0;
1303 _debug("offline '%s'", p);
1304
1305 afs_extract_to_tmp(call);
1306 call->unmarshall++;
1307 fallthrough;
1308
1309 /* extract the message of the day length */
1310 case 6:
1311 ret = afs_extract_data(call, true);
1312 if (ret < 0)
1313 return ret;
1314
1315 call->count = ntohl(call->tmp);
1316 _debug("motd length: %u", call->count);
1317 if (call->count >= AFSNAMEMAX)
1318 return afs_protocol_error(call, afs_eproto_motd_len);
1319 size = (call->count + 3) & ~3; /* It's padded */
1320 afs_extract_to_buf(call, size);
1321 call->unmarshall++;
1322 fallthrough;
1323
1324 /* extract the message of the day */
1325 case 7:
1326 _debug("extract motd");
1327 ret = afs_extract_data(call, false);
1328 if (ret < 0)
1329 return ret;
1330
1331 p = call->buffer;
1332 p[call->count] = 0;
1333 _debug("motd '%s'", p);
1334
1335 call->unmarshall++;
1336 fallthrough;
1337
1338 case 8:
1339 break;
1340 }
1341
1342 _leave(" = 0 [done]");
1343 return 0;
1344}
1345
1346/*
1347 * YFS.GetVolumeStatus operation type
1348 */
1349static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1350 .name = "YFS.GetVolumeStatus",
1351 .op = yfs_FS_GetVolumeStatus,
1352 .deliver = yfs_deliver_fs_get_volume_status,
1353 .destructor = afs_flat_call_destructor,
1354};
1355
1356/*
1357 * fetch the status of a volume
1358 */
1359void yfs_fs_get_volume_status(struct afs_operation *op)
1360{
1361 struct afs_vnode_param *vp = &op->file[0];
1362 struct afs_call *call;
1363 __be32 *bp;
1364
1365 _enter("");
1366
1367 call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
1368 sizeof(__be32) * 2 +
1369 sizeof(struct yfs_xdr_u64),
1370 max_t(size_t,
1371 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1372 sizeof(__be32),
1373 AFSOPAQUEMAX + 1));
1374 if (!call)
1375 return afs_op_nomem(op);
1376
1377 /* marshall the parameters */
1378 bp = call->request;
1379 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1380 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1381 bp = xdr_encode_u64(bp, vp->fid.vid);
1382 yfs_check_req(call, bp);
1383
1384 call->fid = vp->fid;
1385 trace_afs_make_fs_call(call, &vp->fid);
1386 afs_make_op_call(op, call, GFP_NOFS);
1387}
1388
1389/*
1390 * YFS.SetLock operation type
1391 */
1392static const struct afs_call_type yfs_RXYFSSetLock = {
1393 .name = "YFS.SetLock",
1394 .op = yfs_FS_SetLock,
1395 .deliver = yfs_deliver_status_and_volsync,
1396 .done = afs_lock_op_done,
1397 .destructor = afs_flat_call_destructor,
1398};
1399
1400/*
1401 * YFS.ExtendLock operation type
1402 */
1403static const struct afs_call_type yfs_RXYFSExtendLock = {
1404 .name = "YFS.ExtendLock",
1405 .op = yfs_FS_ExtendLock,
1406 .deliver = yfs_deliver_status_and_volsync,
1407 .done = afs_lock_op_done,
1408 .destructor = afs_flat_call_destructor,
1409};
1410
1411/*
1412 * YFS.ReleaseLock operation type
1413 */
1414static const struct afs_call_type yfs_RXYFSReleaseLock = {
1415 .name = "YFS.ReleaseLock",
1416 .op = yfs_FS_ReleaseLock,
1417 .deliver = yfs_deliver_status_and_volsync,
1418 .destructor = afs_flat_call_destructor,
1419};
1420
1421/*
1422 * Set a lock on a file
1423 */
1424void yfs_fs_set_lock(struct afs_operation *op)
1425{
1426 struct afs_vnode_param *vp = &op->file[0];
1427 struct afs_call *call;
1428 __be32 *bp;
1429
1430 _enter("");
1431
1432 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
1433 sizeof(__be32) * 2 +
1434 sizeof(struct yfs_xdr_YFSFid) +
1435 sizeof(__be32),
1436 sizeof(struct yfs_xdr_YFSFetchStatus) +
1437 sizeof(struct yfs_xdr_YFSVolSync));
1438 if (!call)
1439 return afs_op_nomem(op);
1440
1441 /* marshall the parameters */
1442 bp = call->request;
1443 bp = xdr_encode_u32(bp, YFSSETLOCK);
1444 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1445 bp = xdr_encode_YFSFid(bp, &vp->fid);
1446 bp = xdr_encode_u32(bp, op->lock.type);
1447 yfs_check_req(call, bp);
1448
1449 call->fid = vp->fid;
1450 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1451 afs_make_op_call(op, call, GFP_NOFS);
1452}
1453
1454/*
1455 * extend a lock on a file
1456 */
1457void yfs_fs_extend_lock(struct afs_operation *op)
1458{
1459 struct afs_vnode_param *vp = &op->file[0];
1460 struct afs_call *call;
1461 __be32 *bp;
1462
1463 _enter("");
1464
1465 call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
1466 sizeof(__be32) * 2 +
1467 sizeof(struct yfs_xdr_YFSFid),
1468 sizeof(struct yfs_xdr_YFSFetchStatus) +
1469 sizeof(struct yfs_xdr_YFSVolSync));
1470 if (!call)
1471 return afs_op_nomem(op);
1472
1473 /* marshall the parameters */
1474 bp = call->request;
1475 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1476 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1477 bp = xdr_encode_YFSFid(bp, &vp->fid);
1478 yfs_check_req(call, bp);
1479
1480 call->fid = vp->fid;
1481 trace_afs_make_fs_call(call, &vp->fid);
1482 afs_make_op_call(op, call, GFP_NOFS);
1483}
1484
1485/*
1486 * release a lock on a file
1487 */
1488void yfs_fs_release_lock(struct afs_operation *op)
1489{
1490 struct afs_vnode_param *vp = &op->file[0];
1491 struct afs_call *call;
1492 __be32 *bp;
1493
1494 _enter("");
1495
1496 call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
1497 sizeof(__be32) * 2 +
1498 sizeof(struct yfs_xdr_YFSFid),
1499 sizeof(struct yfs_xdr_YFSFetchStatus) +
1500 sizeof(struct yfs_xdr_YFSVolSync));
1501 if (!call)
1502 return afs_op_nomem(op);
1503
1504 /* marshall the parameters */
1505 bp = call->request;
1506 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1507 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1508 bp = xdr_encode_YFSFid(bp, &vp->fid);
1509 yfs_check_req(call, bp);
1510
1511 call->fid = vp->fid;
1512 trace_afs_make_fs_call(call, &vp->fid);
1513 afs_make_op_call(op, call, GFP_NOFS);
1514}
1515
1516/*
1517 * Deliver a reply to YFS.FetchStatus
1518 */
1519static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1520{
1521 struct afs_operation *op = call->op;
1522 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1523 const __be32 *bp;
1524 int ret;
1525
1526 ret = afs_transfer_reply(call);
1527 if (ret < 0)
1528 return ret;
1529
1530 /* unmarshall the reply once we've received all of it */
1531 bp = call->buffer;
1532 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1533 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
1534 xdr_decode_YFSVolSync(&bp, &op->volsync);
1535
1536 _leave(" = 0 [done]");
1537 return 0;
1538}
1539
1540/*
1541 * YFS.FetchStatus operation type
1542 */
1543static const struct afs_call_type yfs_RXYFSFetchStatus = {
1544 .name = "YFS.FetchStatus",
1545 .op = yfs_FS_FetchStatus,
1546 .deliver = yfs_deliver_fs_fetch_status,
1547 .destructor = afs_flat_call_destructor,
1548};
1549
1550/*
1551 * Fetch the status information for a fid without needing a vnode handle.
1552 */
1553void yfs_fs_fetch_status(struct afs_operation *op)
1554{
1555 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1556 struct afs_call *call;
1557 __be32 *bp;
1558
1559 _enter(",%x,{%llx:%llu},,",
1560 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1561
1562 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
1563 sizeof(__be32) * 2 +
1564 sizeof(struct yfs_xdr_YFSFid),
1565 sizeof(struct yfs_xdr_YFSFetchStatus) +
1566 sizeof(struct yfs_xdr_YFSCallBack) +
1567 sizeof(struct yfs_xdr_YFSVolSync));
1568 if (!call)
1569 return afs_op_nomem(op);
1570
1571 /* marshall the parameters */
1572 bp = call->request;
1573 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
1574 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1575 bp = xdr_encode_YFSFid(bp, &vp->fid);
1576 yfs_check_req(call, bp);
1577
1578 call->fid = vp->fid;
1579 trace_afs_make_fs_call(call, &vp->fid);
1580 afs_make_op_call(op, call, GFP_NOFS);
1581}
1582
1583/*
1584 * Deliver reply data to an YFS.InlineBulkStatus call
1585 */
1586static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
1587{
1588 struct afs_operation *op = call->op;
1589 struct afs_status_cb *scb;
1590 const __be32 *bp;
1591 u32 tmp;
1592 int ret;
1593
1594 _enter("{%u}", call->unmarshall);
1595
1596 switch (call->unmarshall) {
1597 case 0:
1598 afs_extract_to_tmp(call);
1599 call->unmarshall++;
1600 fallthrough;
1601
1602 /* Extract the file status count and array in two steps */
1603 case 1:
1604 _debug("extract status count");
1605 ret = afs_extract_data(call, true);
1606 if (ret < 0)
1607 return ret;
1608
1609 tmp = ntohl(call->tmp);
1610 _debug("status count: %u/%u", tmp, op->nr_files);
1611 if (tmp != op->nr_files)
1612 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1613
1614 call->count = 0;
1615 call->unmarshall++;
1616 more_counts:
1617 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
1618 fallthrough;
1619
1620 case 2:
1621 _debug("extract status array %u", call->count);
1622 ret = afs_extract_data(call, true);
1623 if (ret < 0)
1624 return ret;
1625
1626 switch (call->count) {
1627 case 0:
1628 scb = &op->file[0].scb;
1629 break;
1630 case 1:
1631 scb = &op->file[1].scb;
1632 break;
1633 default:
1634 scb = &op->more_files[call->count - 2].scb;
1635 break;
1636 }
1637
1638 bp = call->buffer;
1639 xdr_decode_YFSFetchStatus(&bp, call, scb);
1640
1641 call->count++;
1642 if (call->count < op->nr_files)
1643 goto more_counts;
1644
1645 call->count = 0;
1646 call->unmarshall++;
1647 afs_extract_to_tmp(call);
1648 fallthrough;
1649
1650 /* Extract the callback count and array in two steps */
1651 case 3:
1652 _debug("extract CB count");
1653 ret = afs_extract_data(call, true);
1654 if (ret < 0)
1655 return ret;
1656
1657 tmp = ntohl(call->tmp);
1658 _debug("CB count: %u", tmp);
1659 if (tmp != op->nr_files)
1660 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1661 call->count = 0;
1662 call->unmarshall++;
1663 more_cbs:
1664 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
1665 fallthrough;
1666
1667 case 4:
1668 _debug("extract CB array");
1669 ret = afs_extract_data(call, true);
1670 if (ret < 0)
1671 return ret;
1672
1673 _debug("unmarshall CB array");
1674 switch (call->count) {
1675 case 0:
1676 scb = &op->file[0].scb;
1677 break;
1678 case 1:
1679 scb = &op->file[1].scb;
1680 break;
1681 default:
1682 scb = &op->more_files[call->count - 2].scb;
1683 break;
1684 }
1685
1686 bp = call->buffer;
1687 xdr_decode_YFSCallBack(&bp, call, scb);
1688 call->count++;
1689 if (call->count < op->nr_files)
1690 goto more_cbs;
1691
1692 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
1693 call->unmarshall++;
1694 fallthrough;
1695
1696 case 5:
1697 ret = afs_extract_data(call, false);
1698 if (ret < 0)
1699 return ret;
1700
1701 bp = call->buffer;
1702 xdr_decode_YFSVolSync(&bp, &op->volsync);
1703
1704 call->unmarshall++;
1705 fallthrough;
1706
1707 case 6:
1708 break;
1709 }
1710
1711 _leave(" = 0 [done]");
1712 return 0;
1713}
1714
1715/*
1716 * FS.InlineBulkStatus operation type
1717 */
1718static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
1719 .name = "YFS.InlineBulkStatus",
1720 .op = yfs_FS_InlineBulkStatus,
1721 .deliver = yfs_deliver_fs_inline_bulk_status,
1722 .destructor = afs_flat_call_destructor,
1723};
1724
1725/*
1726 * Fetch the status information for up to 1024 files
1727 */
1728void yfs_fs_inline_bulk_status(struct afs_operation *op)
1729{
1730 struct afs_vnode_param *dvp = &op->file[0];
1731 struct afs_vnode_param *vp = &op->file[1];
1732 struct afs_call *call;
1733 __be32 *bp;
1734 int i;
1735
1736 _enter(",%x,{%llx:%llu},%u",
1737 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1738
1739 call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
1740 sizeof(__be32) +
1741 sizeof(__be32) +
1742 sizeof(__be32) +
1743 sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
1744 sizeof(struct yfs_xdr_YFSFetchStatus));
1745 if (!call)
1746 return afs_op_nomem(op);
1747
1748 /* marshall the parameters */
1749 bp = call->request;
1750 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
1751 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
1752 bp = xdr_encode_u32(bp, op->nr_files);
1753 bp = xdr_encode_YFSFid(bp, &dvp->fid);
1754 bp = xdr_encode_YFSFid(bp, &vp->fid);
1755 for (i = 0; i < op->nr_files - 2; i++)
1756 bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
1757 yfs_check_req(call, bp);
1758
1759 call->fid = vp->fid;
1760 trace_afs_make_fs_call(call, &vp->fid);
1761 afs_make_op_call(op, call, GFP_NOFS);
1762}
1763
1764/*
1765 * Deliver reply data to an YFS.FetchOpaqueACL.
1766 */
1767static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
1768{
1769 struct afs_operation *op = call->op;
1770 struct afs_vnode_param *vp = &op->file[0];
1771 struct yfs_acl *yacl = op->yacl;
1772 struct afs_acl *acl;
1773 const __be32 *bp;
1774 unsigned int size;
1775 int ret;
1776
1777 _enter("{%u}", call->unmarshall);
1778
1779 switch (call->unmarshall) {
1780 case 0:
1781 afs_extract_to_tmp(call);
1782 call->unmarshall++;
1783 fallthrough;
1784
1785 /* Extract the file ACL length */
1786 case 1:
1787 ret = afs_extract_data(call, true);
1788 if (ret < 0)
1789 return ret;
1790
1791 size = call->count2 = ntohl(call->tmp);
1792 size = round_up(size, 4);
1793
1794 if (yacl->flags & YFS_ACL_WANT_ACL) {
1795 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1796 if (!acl)
1797 return -ENOMEM;
1798 yacl->acl = acl;
1799 acl->size = call->count2;
1800 afs_extract_begin(call, acl->data, size);
1801 } else {
1802 afs_extract_discard(call, size);
1803 }
1804 call->unmarshall++;
1805 fallthrough;
1806
1807 /* Extract the file ACL */
1808 case 2:
1809 ret = afs_extract_data(call, true);
1810 if (ret < 0)
1811 return ret;
1812
1813 afs_extract_to_tmp(call);
1814 call->unmarshall++;
1815 fallthrough;
1816
1817 /* Extract the volume ACL length */
1818 case 3:
1819 ret = afs_extract_data(call, true);
1820 if (ret < 0)
1821 return ret;
1822
1823 size = call->count2 = ntohl(call->tmp);
1824 size = round_up(size, 4);
1825
1826 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
1827 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1828 if (!acl)
1829 return -ENOMEM;
1830 yacl->vol_acl = acl;
1831 acl->size = call->count2;
1832 afs_extract_begin(call, acl->data, size);
1833 } else {
1834 afs_extract_discard(call, size);
1835 }
1836 call->unmarshall++;
1837 fallthrough;
1838
1839 /* Extract the volume ACL */
1840 case 4:
1841 ret = afs_extract_data(call, true);
1842 if (ret < 0)
1843 return ret;
1844
1845 afs_extract_to_buf(call,
1846 sizeof(__be32) * 2 +
1847 sizeof(struct yfs_xdr_YFSFetchStatus) +
1848 sizeof(struct yfs_xdr_YFSVolSync));
1849 call->unmarshall++;
1850 fallthrough;
1851
1852 /* extract the metadata */
1853 case 5:
1854 ret = afs_extract_data(call, false);
1855 if (ret < 0)
1856 return ret;
1857
1858 bp = call->buffer;
1859 yacl->inherit_flag = ntohl(*bp++);
1860 yacl->num_cleaned = ntohl(*bp++);
1861 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1862 xdr_decode_YFSVolSync(&bp, &op->volsync);
1863
1864 call->unmarshall++;
1865 fallthrough;
1866
1867 case 6:
1868 break;
1869 }
1870
1871 _leave(" = 0 [done]");
1872 return 0;
1873}
1874
1875void yfs_free_opaque_acl(struct yfs_acl *yacl)
1876{
1877 if (yacl) {
1878 kfree(yacl->acl);
1879 kfree(yacl->vol_acl);
1880 kfree(yacl);
1881 }
1882}
1883
1884/*
1885 * YFS.FetchOpaqueACL operation type
1886 */
1887static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
1888 .name = "YFS.FetchOpaqueACL",
1889 .op = yfs_FS_FetchOpaqueACL,
1890 .deliver = yfs_deliver_fs_fetch_opaque_acl,
1891 .destructor = afs_flat_call_destructor,
1892};
1893
1894/*
1895 * Fetch the YFS advanced ACLs for a file.
1896 */
1897void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
1898{
1899 struct afs_vnode_param *vp = &op->file[0];
1900 struct afs_call *call;
1901 __be32 *bp;
1902
1903 _enter(",%x,{%llx:%llu},,",
1904 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1905
1906 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
1907 sizeof(__be32) * 2 +
1908 sizeof(struct yfs_xdr_YFSFid),
1909 sizeof(__be32) * 2 +
1910 sizeof(struct yfs_xdr_YFSFetchStatus) +
1911 sizeof(struct yfs_xdr_YFSVolSync));
1912 if (!call)
1913 return afs_op_nomem(op);
1914
1915 /* marshall the parameters */
1916 bp = call->request;
1917 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
1918 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1919 bp = xdr_encode_YFSFid(bp, &vp->fid);
1920 yfs_check_req(call, bp);
1921
1922 call->fid = vp->fid;
1923 trace_afs_make_fs_call(call, &vp->fid);
1924 afs_make_op_call(op, call, GFP_KERNEL);
1925}
1926
1927/*
1928 * YFS.StoreOpaqueACL2 operation type
1929 */
1930static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
1931 .name = "YFS.StoreOpaqueACL2",
1932 .op = yfs_FS_StoreOpaqueACL2,
1933 .deliver = yfs_deliver_status_and_volsync,
1934 .destructor = afs_flat_call_destructor,
1935};
1936
1937/*
1938 * Fetch the YFS ACL for a file.
1939 */
1940void yfs_fs_store_opaque_acl2(struct afs_operation *op)
1941{
1942 struct afs_vnode_param *vp = &op->file[0];
1943 struct afs_call *call;
1944 struct afs_acl *acl = op->acl;
1945 size_t size;
1946 __be32 *bp;
1947
1948 _enter(",%x,{%llx:%llu},,",
1949 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1950
1951 size = round_up(acl->size, 4);
1952 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
1953 sizeof(__be32) * 2 +
1954 sizeof(struct yfs_xdr_YFSFid) +
1955 sizeof(__be32) + size,
1956 sizeof(struct yfs_xdr_YFSFetchStatus) +
1957 sizeof(struct yfs_xdr_YFSVolSync));
1958 if (!call)
1959 return afs_op_nomem(op);
1960
1961 /* marshall the parameters */
1962 bp = call->request;
1963 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
1964 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1965 bp = xdr_encode_YFSFid(bp, &vp->fid);
1966 bp = xdr_encode_u32(bp, acl->size);
1967 memcpy(bp, acl->data, acl->size);
1968 if (acl->size != size)
1969 memset((void *)bp + acl->size, 0, size - acl->size);
1970 bp += size / sizeof(__be32);
1971 yfs_check_req(call, bp);
1972
1973 call->fid = vp->fid;
1974 trace_afs_make_fs_call(call, &vp->fid);
1975 afs_make_op_call(op, call, GFP_KERNEL);
1976}