1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* YFS File Server client stubs
4 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
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>
16 #include "protocol_yfs.h"
18 #define xdr_size(x) (sizeof(*x) / sizeof(__be32))
20 static void xdr_decode_YFSFid(const __be32 **_bp, struct afs_fid *fid)
22 const struct yfs_xdr_YFSFid *x = (const void *)*_bp;
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);
31 static __be32 *xdr_encode_u32(__be32 *bp, u32 n)
37 static __be32 *xdr_encode_u64(__be32 *bp, u64 n)
39 struct yfs_xdr_u64 *x = (void *)bp;
42 return bp + xdr_size(x);
45 static __be32 *xdr_encode_YFSFid(__be32 *bp, struct afs_fid *fid)
47 struct yfs_xdr_YFSFid *x = (void *)bp;
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);
56 static size_t xdr_strlen(unsigned int len)
58 return sizeof(__be32) + round_up(len, sizeof(__be32));
61 static __be32 *xdr_encode_string(__be32 *bp, const char *p, unsigned int len)
63 bp = xdr_encode_u32(bp, len);
64 bp = memcpy(bp, p, len);
66 unsigned int pad = 4 - (len & 3);
68 memset((u8 *)bp + len, 0, pad);
72 return bp + len / sizeof(__be32);
75 static __be32 *xdr_encode_name(__be32 *bp, const struct qstr *p)
77 return xdr_encode_string(bp, p->name, p->len);
80 static s64 linux_to_yfs_time(const struct timespec64 *t)
82 /* Convert to 100ns intervals. */
83 return (u64)t->tv_sec * 10000000 + t->tv_nsec/100;
86 static __be32 *xdr_encode_YFSStoreStatus(__be32 *bp, mode_t *mode,
87 const struct timespec64 *t)
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;
94 mask |= mode ? AFS_SET_MODE : 0;
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);
105 * Convert a signed 100ns-resolution 64-bit time into a timespec.
107 static struct timespec64 yfs_time_to_linux(s64 t)
109 struct timespec64 ts;
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
119 ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100);
120 ts.tv_nsec = -ts.tv_nsec;
124 ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100;
131 static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr)
133 s64 t = xdr_to_u64(xdr);
135 return yfs_time_to_linux(t);
138 static void yfs_check_req(struct afs_call *call, __be32 *bp)
140 size_t len = (void *)bp - call->request;
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);
151 * Dump a bad file status record.
153 static void xdr_dump_bad(const __be32 *bp)
158 pr_notice("YFS XDR: Bad status record\n");
159 for (i = 0; i < 6 * 4 * 4; i += 16) {
162 pr_notice("%03x: %08x %08x %08x %08x\n",
163 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
167 pr_notice("0x60: %08x %08x\n", ntohl(x[0]), ntohl(x[1]));
171 * Decode a YFSFetchStatus block
173 static void xdr_decode_YFSFetchStatus(const __be32 **_bp,
174 struct afs_call *call,
175 struct afs_status_cb *scb)
177 const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
178 struct afs_file_status *status = &scb->status;
181 status->abort_code = ntohl(xdr->abort_code);
182 if (status->abort_code != 0) {
183 if (status->abort_code == VNOVNODE)
185 scb->have_error = true;
189 type = ntohl(xdr->type);
193 case AFS_FTYPE_SYMLINK:
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);
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;
215 *_bp += xdr_size(xdr);
220 afs_protocol_error(call, afs_eproto_bad_status);
225 * Decode a YFSCallBack block
227 static void xdr_decode_YFSCallBack(const __be32 **_bp,
228 struct afs_call *call,
229 struct afs_status_cb *scb)
231 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
232 struct afs_callback *cb = &scb->callback;
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);
242 * Decode a YFSVolSync block
244 static void xdr_decode_YFSVolSync(const __be32 **_bp,
245 struct afs_volsync *volsync)
247 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
251 creation = xdr_to_u64(x->vol_creation_date);
252 do_div(creation, 10 * 1000 * 1000);
253 volsync->creation = creation;
260 * Encode the requested attributes into a YFSStoreStatus block
262 static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
264 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
265 s64 mtime = 0, owner = 0, group = 0;
266 u32 mask = 0, mode = 0;
269 if (attr->ia_valid & ATTR_MTIME) {
270 mask |= AFS_SET_MTIME;
271 mtime = linux_to_yfs_time(&attr->ia_mtime);
274 if (attr->ia_valid & ATTR_UID) {
275 mask |= AFS_SET_OWNER;
276 owner = from_kuid(&init_user_ns, attr->ia_uid);
279 if (attr->ia_valid & ATTR_GID) {
280 mask |= AFS_SET_GROUP;
281 group = from_kgid(&init_user_ns, attr->ia_gid);
284 if (attr->ia_valid & ATTR_MODE) {
285 mask |= AFS_SET_MODE;
286 mode = attr->ia_mode & S_IALLUGO;
289 x->mask = htonl(mask);
290 x->mode = htonl(mode);
291 x->mtime_client = u64_to_xdr(mtime);
292 x->owner = u64_to_xdr(owner);
293 x->group = u64_to_xdr(group);
294 return bp + xdr_size(x);
298 * Decode a YFSFetchVolumeStatus block.
300 static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
301 struct afs_volume_status *vs)
303 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
306 vs->vid = xdr_to_u64(x->vid);
307 vs->parent_id = xdr_to_u64(x->parent_id);
308 flags = ntohl(x->flags);
309 vs->online = flags & yfs_FVSOnline;
310 vs->in_service = flags & yfs_FVSInservice;
311 vs->blessed = flags & yfs_FVSBlessed;
312 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
313 vs->type = ntohl(x->type);
315 vs->max_quota = xdr_to_u64(x->max_quota);
316 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
317 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
318 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
319 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
320 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
321 *_bp += sizeof(*x) / sizeof(__be32);
325 * Deliver reply data to operations that just return a file status and a volume
328 static int yfs_deliver_status_and_volsync(struct afs_call *call)
330 struct afs_operation *op = call->op;
334 ret = afs_transfer_reply(call);
339 xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
340 xdr_decode_YFSVolSync(&bp, &op->volsync);
342 _leave(" = 0 [done]");
347 * Deliver reply data to an YFS.FetchData64.
349 static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
351 struct afs_operation *op = call->op;
352 struct afs_vnode_param *vp = &op->file[0];
353 struct afs_read *req = op->fetch.req;
357 _enter("{%u,%zu, %zu/%llu}",
358 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
361 switch (call->unmarshall) {
364 afs_extract_to_tmp64(call);
368 /* Extract the returned data length into ->actual_len. This
369 * may indicate more or less data than was requested will be
373 _debug("extract data length");
374 ret = afs_extract_data(call, true);
378 req->actual_len = be64_to_cpu(call->tmp64);
379 _debug("DATA length: %llu", req->actual_len);
381 if (req->actual_len == 0)
384 call->iter = req->iter;
385 call->iov_len = min(req->actual_len, req->len);
389 /* extract the returned data */
391 _debug("extract data %zu/%llu",
392 iov_iter_count(call->iter), req->actual_len);
394 ret = afs_extract_data(call, true);
398 call->iter = &call->def_iter;
399 if (req->actual_len <= req->len)
402 /* Discard any excess data the server gave us */
403 afs_extract_discard(call, req->actual_len - req->len);
404 call->unmarshall = 3;
408 _debug("extract discard %zu/%llu",
409 iov_iter_count(call->iter), req->actual_len - req->len);
411 ret = afs_extract_data(call, true);
416 call->unmarshall = 4;
417 afs_extract_to_buf(call,
418 sizeof(struct yfs_xdr_YFSFetchStatus) +
419 sizeof(struct yfs_xdr_YFSCallBack) +
420 sizeof(struct yfs_xdr_YFSVolSync));
423 /* extract the metadata */
425 ret = afs_extract_data(call, false);
430 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
431 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
432 xdr_decode_YFSVolSync(&bp, &op->volsync);
434 req->data_version = vp->scb.status.data_version;
435 req->file_size = vp->scb.status.size;
444 _leave(" = 0 [done]");
449 * YFS.FetchData64 operation type
451 static const struct afs_call_type yfs_RXYFSFetchData64 = {
452 .name = "YFS.FetchData64",
453 .op = yfs_FS_FetchData64,
454 .deliver = yfs_deliver_fs_fetch_data64,
455 .destructor = afs_flat_call_destructor,
459 * Fetch data from a file.
461 void yfs_fs_fetch_data(struct afs_operation *op)
463 struct afs_vnode_param *vp = &op->file[0];
464 struct afs_read *req = op->fetch.req;
465 struct afs_call *call;
468 _enter(",%x,{%llx:%llu},%llx,%llx",
469 key_serial(op->key), vp->fid.vid, vp->fid.vnode,
472 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
474 sizeof(struct yfs_xdr_YFSFid) +
475 sizeof(struct yfs_xdr_u64) * 2,
476 sizeof(struct yfs_xdr_YFSFetchStatus) +
477 sizeof(struct yfs_xdr_YFSCallBack) +
478 sizeof(struct yfs_xdr_YFSVolSync));
480 return afs_op_nomem(op);
482 req->call_debug_id = call->debug_id;
484 /* marshall the parameters */
486 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
487 bp = xdr_encode_u32(bp, 0); /* RPC flags */
488 bp = xdr_encode_YFSFid(bp, &vp->fid);
489 bp = xdr_encode_u64(bp, req->pos);
490 bp = xdr_encode_u64(bp, req->len);
491 yfs_check_req(call, bp);
493 trace_afs_make_fs_call(call, &vp->fid);
494 afs_make_op_call(op, call, GFP_NOFS);
498 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
500 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
502 struct afs_operation *op = call->op;
503 struct afs_vnode_param *dvp = &op->file[0];
504 struct afs_vnode_param *vp = &op->file[1];
508 _enter("{%u}", call->unmarshall);
510 ret = afs_transfer_reply(call);
514 /* unmarshall the reply once we've received all of it */
516 xdr_decode_YFSFid(&bp, &op->file[1].fid);
517 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
518 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
519 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
520 xdr_decode_YFSVolSync(&bp, &op->volsync);
522 _leave(" = 0 [done]");
527 * FS.CreateFile and FS.MakeDir operation type
529 static const struct afs_call_type afs_RXFSCreateFile = {
530 .name = "YFS.CreateFile",
531 .op = yfs_FS_CreateFile,
532 .deliver = yfs_deliver_fs_create_vnode,
533 .destructor = afs_flat_call_destructor,
539 void yfs_fs_create_file(struct afs_operation *op)
541 const struct qstr *name = &op->dentry->d_name;
542 struct afs_vnode_param *dvp = &op->file[0];
543 struct afs_call *call;
549 reqsz = (sizeof(__be32) +
551 sizeof(struct yfs_xdr_YFSFid) +
552 xdr_strlen(name->len) +
553 sizeof(struct yfs_xdr_YFSStoreStatus) +
555 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
556 sizeof(struct yfs_xdr_YFSFetchStatus) +
557 sizeof(struct yfs_xdr_YFSFetchStatus) +
558 sizeof(struct yfs_xdr_YFSCallBack) +
559 sizeof(struct yfs_xdr_YFSVolSync));
561 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
563 return afs_op_nomem(op);
565 /* marshall the parameters */
567 bp = xdr_encode_u32(bp, YFSCREATEFILE);
568 bp = xdr_encode_u32(bp, 0); /* RPC flags */
569 bp = xdr_encode_YFSFid(bp, &dvp->fid);
570 bp = xdr_encode_name(bp, name);
571 bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
572 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
573 yfs_check_req(call, bp);
575 trace_afs_make_fs_call1(call, &dvp->fid, name);
576 afs_make_op_call(op, call, GFP_NOFS);
579 static const struct afs_call_type yfs_RXFSMakeDir = {
580 .name = "YFS.MakeDir",
581 .op = yfs_FS_MakeDir,
582 .deliver = yfs_deliver_fs_create_vnode,
583 .destructor = afs_flat_call_destructor,
589 void yfs_fs_make_dir(struct afs_operation *op)
591 const struct qstr *name = &op->dentry->d_name;
592 struct afs_vnode_param *dvp = &op->file[0];
593 struct afs_call *call;
599 reqsz = (sizeof(__be32) +
600 sizeof(struct yfs_xdr_RPCFlags) +
601 sizeof(struct yfs_xdr_YFSFid) +
602 xdr_strlen(name->len) +
603 sizeof(struct yfs_xdr_YFSStoreStatus));
604 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
605 sizeof(struct yfs_xdr_YFSFetchStatus) +
606 sizeof(struct yfs_xdr_YFSFetchStatus) +
607 sizeof(struct yfs_xdr_YFSCallBack) +
608 sizeof(struct yfs_xdr_YFSVolSync));
610 call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
612 return afs_op_nomem(op);
614 /* marshall the parameters */
616 bp = xdr_encode_u32(bp, YFSMAKEDIR);
617 bp = xdr_encode_u32(bp, 0); /* RPC flags */
618 bp = xdr_encode_YFSFid(bp, &dvp->fid);
619 bp = xdr_encode_name(bp, name);
620 bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
621 yfs_check_req(call, bp);
623 trace_afs_make_fs_call1(call, &dvp->fid, name);
624 afs_make_op_call(op, call, GFP_NOFS);
628 * Deliver reply data to a YFS.RemoveFile2 operation.
630 static int yfs_deliver_fs_remove_file2(struct afs_call *call)
632 struct afs_operation *op = call->op;
633 struct afs_vnode_param *dvp = &op->file[0];
634 struct afs_vnode_param *vp = &op->file[1];
639 _enter("{%u}", call->unmarshall);
641 ret = afs_transfer_reply(call);
646 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
647 xdr_decode_YFSFid(&bp, &fid);
648 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
649 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
651 xdr_decode_YFSVolSync(&bp, &op->volsync);
655 static void yfs_done_fs_remove_file2(struct afs_call *call)
657 if (call->error == -ECONNABORTED &&
658 call->abort_code == RX_INVALID_OPERATION) {
659 set_bit(AFS_SERVER_FL_NO_RM2, &call->server->flags);
660 call->op->flags |= AFS_OPERATION_DOWNGRADE;
665 * YFS.RemoveFile2 operation type.
667 static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
668 .name = "YFS.RemoveFile2",
669 .op = yfs_FS_RemoveFile2,
670 .deliver = yfs_deliver_fs_remove_file2,
671 .done = yfs_done_fs_remove_file2,
672 .destructor = afs_flat_call_destructor,
676 * Remove a file and retrieve new file status.
678 void yfs_fs_remove_file2(struct afs_operation *op)
680 struct afs_vnode_param *dvp = &op->file[0];
681 const struct qstr *name = &op->dentry->d_name;
682 struct afs_call *call;
687 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
689 sizeof(struct yfs_xdr_RPCFlags) +
690 sizeof(struct yfs_xdr_YFSFid) +
691 xdr_strlen(name->len),
692 sizeof(struct yfs_xdr_YFSFetchStatus) +
693 sizeof(struct yfs_xdr_YFSFid) +
694 sizeof(struct yfs_xdr_YFSFetchStatus) +
695 sizeof(struct yfs_xdr_YFSVolSync));
697 return afs_op_nomem(op);
699 /* marshall the parameters */
701 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
702 bp = xdr_encode_u32(bp, 0); /* RPC flags */
703 bp = xdr_encode_YFSFid(bp, &dvp->fid);
704 bp = xdr_encode_name(bp, name);
705 yfs_check_req(call, bp);
707 trace_afs_make_fs_call1(call, &dvp->fid, name);
708 afs_make_op_call(op, call, GFP_NOFS);
712 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
714 static int yfs_deliver_fs_remove(struct afs_call *call)
716 struct afs_operation *op = call->op;
717 struct afs_vnode_param *dvp = &op->file[0];
721 _enter("{%u}", call->unmarshall);
723 ret = afs_transfer_reply(call);
728 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
729 xdr_decode_YFSVolSync(&bp, &op->volsync);
734 * FS.RemoveDir and FS.RemoveFile operation types.
736 static const struct afs_call_type yfs_RXYFSRemoveFile = {
737 .name = "YFS.RemoveFile",
738 .op = yfs_FS_RemoveFile,
739 .deliver = yfs_deliver_fs_remove,
740 .destructor = afs_flat_call_destructor,
746 void yfs_fs_remove_file(struct afs_operation *op)
748 const struct qstr *name = &op->dentry->d_name;
749 struct afs_vnode_param *dvp = &op->file[0];
750 struct afs_call *call;
755 if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
756 return yfs_fs_remove_file2(op);
758 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
760 sizeof(struct yfs_xdr_RPCFlags) +
761 sizeof(struct yfs_xdr_YFSFid) +
762 xdr_strlen(name->len),
763 sizeof(struct yfs_xdr_YFSFetchStatus) +
764 sizeof(struct yfs_xdr_YFSVolSync));
766 return afs_op_nomem(op);
768 /* marshall the parameters */
770 bp = xdr_encode_u32(bp, YFSREMOVEFILE);
771 bp = xdr_encode_u32(bp, 0); /* RPC flags */
772 bp = xdr_encode_YFSFid(bp, &dvp->fid);
773 bp = xdr_encode_name(bp, name);
774 yfs_check_req(call, bp);
776 trace_afs_make_fs_call1(call, &dvp->fid, name);
777 afs_make_op_call(op, call, GFP_NOFS);
780 static const struct afs_call_type yfs_RXYFSRemoveDir = {
781 .name = "YFS.RemoveDir",
782 .op = yfs_FS_RemoveDir,
783 .deliver = yfs_deliver_fs_remove,
784 .destructor = afs_flat_call_destructor,
788 * Remove a directory.
790 void yfs_fs_remove_dir(struct afs_operation *op)
792 const struct qstr *name = &op->dentry->d_name;
793 struct afs_vnode_param *dvp = &op->file[0];
794 struct afs_call *call;
799 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
801 sizeof(struct yfs_xdr_RPCFlags) +
802 sizeof(struct yfs_xdr_YFSFid) +
803 xdr_strlen(name->len),
804 sizeof(struct yfs_xdr_YFSFetchStatus) +
805 sizeof(struct yfs_xdr_YFSVolSync));
807 return afs_op_nomem(op);
809 /* marshall the parameters */
811 bp = xdr_encode_u32(bp, YFSREMOVEDIR);
812 bp = xdr_encode_u32(bp, 0); /* RPC flags */
813 bp = xdr_encode_YFSFid(bp, &dvp->fid);
814 bp = xdr_encode_name(bp, name);
815 yfs_check_req(call, bp);
817 trace_afs_make_fs_call1(call, &dvp->fid, name);
818 afs_make_op_call(op, call, GFP_NOFS);
822 * Deliver reply data to a YFS.Link operation.
824 static int yfs_deliver_fs_link(struct afs_call *call)
826 struct afs_operation *op = call->op;
827 struct afs_vnode_param *dvp = &op->file[0];
828 struct afs_vnode_param *vp = &op->file[1];
832 _enter("{%u}", call->unmarshall);
834 ret = afs_transfer_reply(call);
839 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
840 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
841 xdr_decode_YFSVolSync(&bp, &op->volsync);
842 _leave(" = 0 [done]");
847 * YFS.Link operation type.
849 static const struct afs_call_type yfs_RXYFSLink = {
852 .deliver = yfs_deliver_fs_link,
853 .destructor = afs_flat_call_destructor,
859 void yfs_fs_link(struct afs_operation *op)
861 const struct qstr *name = &op->dentry->d_name;
862 struct afs_vnode_param *dvp = &op->file[0];
863 struct afs_vnode_param *vp = &op->file[1];
864 struct afs_call *call;
869 call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
871 sizeof(struct yfs_xdr_RPCFlags) +
872 sizeof(struct yfs_xdr_YFSFid) +
873 xdr_strlen(name->len) +
874 sizeof(struct yfs_xdr_YFSFid),
875 sizeof(struct yfs_xdr_YFSFetchStatus) +
876 sizeof(struct yfs_xdr_YFSFetchStatus) +
877 sizeof(struct yfs_xdr_YFSVolSync));
879 return afs_op_nomem(op);
881 /* marshall the parameters */
883 bp = xdr_encode_u32(bp, YFSLINK);
884 bp = xdr_encode_u32(bp, 0); /* RPC flags */
885 bp = xdr_encode_YFSFid(bp, &dvp->fid);
886 bp = xdr_encode_name(bp, name);
887 bp = xdr_encode_YFSFid(bp, &vp->fid);
888 yfs_check_req(call, bp);
890 trace_afs_make_fs_call1(call, &vp->fid, name);
891 afs_make_op_call(op, call, GFP_NOFS);
895 * Deliver reply data to a YFS.Symlink operation.
897 static int yfs_deliver_fs_symlink(struct afs_call *call)
899 struct afs_operation *op = call->op;
900 struct afs_vnode_param *dvp = &op->file[0];
901 struct afs_vnode_param *vp = &op->file[1];
905 _enter("{%u}", call->unmarshall);
907 ret = afs_transfer_reply(call);
911 /* unmarshall the reply once we've received all of it */
913 xdr_decode_YFSFid(&bp, &vp->fid);
914 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
915 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
916 xdr_decode_YFSVolSync(&bp, &op->volsync);
918 _leave(" = 0 [done]");
923 * YFS.Symlink operation type
925 static const struct afs_call_type yfs_RXYFSSymlink = {
926 .name = "YFS.Symlink",
927 .op = yfs_FS_Symlink,
928 .deliver = yfs_deliver_fs_symlink,
929 .destructor = afs_flat_call_destructor,
933 * Create a symbolic link.
935 void yfs_fs_symlink(struct afs_operation *op)
937 const struct qstr *name = &op->dentry->d_name;
938 struct afs_vnode_param *dvp = &op->file[0];
939 struct afs_call *call;
946 contents_sz = strlen(op->create.symlink);
947 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
949 sizeof(struct yfs_xdr_RPCFlags) +
950 sizeof(struct yfs_xdr_YFSFid) +
951 xdr_strlen(name->len) +
952 xdr_strlen(contents_sz) +
953 sizeof(struct yfs_xdr_YFSStoreStatus),
954 sizeof(struct yfs_xdr_YFSFid) +
955 sizeof(struct yfs_xdr_YFSFetchStatus) +
956 sizeof(struct yfs_xdr_YFSFetchStatus) +
957 sizeof(struct yfs_xdr_YFSVolSync));
959 return afs_op_nomem(op);
961 /* marshall the parameters */
963 bp = xdr_encode_u32(bp, YFSSYMLINK);
964 bp = xdr_encode_u32(bp, 0); /* RPC flags */
965 bp = xdr_encode_YFSFid(bp, &dvp->fid);
966 bp = xdr_encode_name(bp, name);
967 bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
968 bp = xdr_encode_YFSStoreStatus(bp, &mode, &op->mtime);
969 yfs_check_req(call, bp);
971 trace_afs_make_fs_call1(call, &dvp->fid, name);
972 afs_make_op_call(op, call, GFP_NOFS);
976 * Deliver reply data to a YFS.Rename operation.
978 static int yfs_deliver_fs_rename(struct afs_call *call)
980 struct afs_operation *op = call->op;
981 struct afs_vnode_param *orig_dvp = &op->file[0];
982 struct afs_vnode_param *new_dvp = &op->file[1];
986 _enter("{%u}", call->unmarshall);
988 ret = afs_transfer_reply(call);
993 /* If the two dirs are the same, we have two copies of the same status
994 * report, so we just decode it twice.
996 xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
997 xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
998 xdr_decode_YFSVolSync(&bp, &op->volsync);
999 _leave(" = 0 [done]");
1004 * YFS.Rename operation type
1006 static const struct afs_call_type yfs_RXYFSRename = {
1007 .name = "FS.Rename",
1008 .op = yfs_FS_Rename,
1009 .deliver = yfs_deliver_fs_rename,
1010 .destructor = afs_flat_call_destructor,
1014 * Rename a file or directory.
1016 void yfs_fs_rename(struct afs_operation *op)
1018 struct afs_vnode_param *orig_dvp = &op->file[0];
1019 struct afs_vnode_param *new_dvp = &op->file[1];
1020 const struct qstr *orig_name = &op->dentry->d_name;
1021 const struct qstr *new_name = &op->dentry_2->d_name;
1022 struct afs_call *call;
1027 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
1029 sizeof(struct yfs_xdr_RPCFlags) +
1030 sizeof(struct yfs_xdr_YFSFid) +
1031 xdr_strlen(orig_name->len) +
1032 sizeof(struct yfs_xdr_YFSFid) +
1033 xdr_strlen(new_name->len),
1034 sizeof(struct yfs_xdr_YFSFetchStatus) +
1035 sizeof(struct yfs_xdr_YFSFetchStatus) +
1036 sizeof(struct yfs_xdr_YFSVolSync));
1038 return afs_op_nomem(op);
1040 /* marshall the parameters */
1042 bp = xdr_encode_u32(bp, YFSRENAME);
1043 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1044 bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
1045 bp = xdr_encode_name(bp, orig_name);
1046 bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
1047 bp = xdr_encode_name(bp, new_name);
1048 yfs_check_req(call, bp);
1050 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1051 afs_make_op_call(op, call, GFP_NOFS);
1055 * YFS.StoreData64 operation type.
1057 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1058 .name = "YFS.StoreData64",
1059 .op = yfs_FS_StoreData64,
1060 .deliver = yfs_deliver_status_and_volsync,
1061 .destructor = afs_flat_call_destructor,
1065 * Store a set of pages to a large file.
1067 void yfs_fs_store_data(struct afs_operation *op)
1069 struct afs_vnode_param *vp = &op->file[0];
1070 struct afs_call *call;
1073 _enter(",%x,{%llx:%llu},,",
1074 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1076 _debug("size %llx, at %llx, i_size %llx",
1077 (unsigned long long)op->store.size,
1078 (unsigned long long)op->store.pos,
1079 (unsigned long long)op->store.i_size);
1081 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
1084 sizeof(struct yfs_xdr_YFSFid) +
1085 sizeof(struct yfs_xdr_YFSStoreStatus) +
1086 sizeof(struct yfs_xdr_u64) * 3,
1087 sizeof(struct yfs_xdr_YFSFetchStatus) +
1088 sizeof(struct yfs_xdr_YFSVolSync));
1090 return afs_op_nomem(op);
1092 call->write_iter = op->store.write_iter;
1094 /* marshall the parameters */
1096 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1097 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1098 bp = xdr_encode_YFSFid(bp, &vp->fid);
1099 bp = xdr_encode_YFSStoreStatus(bp, NULL, &op->mtime);
1100 bp = xdr_encode_u64(bp, op->store.pos);
1101 bp = xdr_encode_u64(bp, op->store.size);
1102 bp = xdr_encode_u64(bp, op->store.i_size);
1103 yfs_check_req(call, bp);
1105 trace_afs_make_fs_call(call, &vp->fid);
1106 afs_make_op_call(op, call, GFP_NOFS);
1110 * YFS.StoreStatus operation type
1112 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1113 .name = "YFS.StoreStatus",
1114 .op = yfs_FS_StoreStatus,
1115 .deliver = yfs_deliver_status_and_volsync,
1116 .destructor = afs_flat_call_destructor,
1119 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1120 .name = "YFS.StoreData64",
1121 .op = yfs_FS_StoreData64,
1122 .deliver = yfs_deliver_status_and_volsync,
1123 .destructor = afs_flat_call_destructor,
1127 * Set the attributes on a file, using YFS.StoreData64 rather than
1128 * YFS.StoreStatus so as to alter the file size also.
1130 static void yfs_fs_setattr_size(struct afs_operation *op)
1132 struct afs_vnode_param *vp = &op->file[0];
1133 struct afs_call *call;
1134 struct iattr *attr = op->setattr.attr;
1137 _enter(",%x,{%llx:%llu},,",
1138 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1140 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
1141 sizeof(__be32) * 2 +
1142 sizeof(struct yfs_xdr_YFSFid) +
1143 sizeof(struct yfs_xdr_YFSStoreStatus) +
1144 sizeof(struct yfs_xdr_u64) * 3,
1145 sizeof(struct yfs_xdr_YFSFetchStatus) +
1146 sizeof(struct yfs_xdr_YFSVolSync));
1148 return afs_op_nomem(op);
1150 /* marshall the parameters */
1152 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1153 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1154 bp = xdr_encode_YFSFid(bp, &vp->fid);
1155 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1156 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1157 bp = xdr_encode_u64(bp, 0); /* size of write */
1158 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1159 yfs_check_req(call, bp);
1161 trace_afs_make_fs_call(call, &vp->fid);
1162 afs_make_op_call(op, call, GFP_NOFS);
1166 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1167 * file size, and YFS.StoreStatus otherwise.
1169 void yfs_fs_setattr(struct afs_operation *op)
1171 struct afs_vnode_param *vp = &op->file[0];
1172 struct afs_call *call;
1173 struct iattr *attr = op->setattr.attr;
1176 if (attr->ia_valid & ATTR_SIZE)
1177 return yfs_fs_setattr_size(op);
1179 _enter(",%x,{%llx:%llu},,",
1180 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1182 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
1183 sizeof(__be32) * 2 +
1184 sizeof(struct yfs_xdr_YFSFid) +
1185 sizeof(struct yfs_xdr_YFSStoreStatus),
1186 sizeof(struct yfs_xdr_YFSFetchStatus) +
1187 sizeof(struct yfs_xdr_YFSVolSync));
1189 return afs_op_nomem(op);
1191 /* marshall the parameters */
1193 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1194 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1195 bp = xdr_encode_YFSFid(bp, &vp->fid);
1196 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1197 yfs_check_req(call, bp);
1199 trace_afs_make_fs_call(call, &vp->fid);
1200 afs_make_op_call(op, call, GFP_NOFS);
1204 * Deliver reply data to a YFS.GetVolumeStatus operation.
1206 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1208 struct afs_operation *op = call->op;
1214 _enter("{%u}", call->unmarshall);
1216 switch (call->unmarshall) {
1219 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1222 /* extract the returned status record */
1224 _debug("extract status");
1225 ret = afs_extract_data(call, true);
1230 xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1232 afs_extract_to_tmp(call);
1235 /* extract the volume name length */
1237 ret = afs_extract_data(call, true);
1241 call->count = ntohl(call->tmp);
1242 _debug("volname length: %u", call->count);
1243 if (call->count >= AFSNAMEMAX)
1244 return afs_protocol_error(call, afs_eproto_volname_len);
1245 size = (call->count + 3) & ~3; /* It's padded */
1246 afs_extract_to_buf(call, size);
1250 /* extract the volume name */
1252 _debug("extract volname");
1253 ret = afs_extract_data(call, true);
1259 _debug("volname '%s'", p);
1260 afs_extract_to_tmp(call);
1264 /* extract the offline message length */
1266 ret = afs_extract_data(call, true);
1270 call->count = ntohl(call->tmp);
1271 _debug("offline msg length: %u", call->count);
1272 if (call->count >= AFSNAMEMAX)
1273 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1274 size = (call->count + 3) & ~3; /* It's padded */
1275 afs_extract_to_buf(call, size);
1279 /* extract the offline message */
1281 _debug("extract offline");
1282 ret = afs_extract_data(call, true);
1288 _debug("offline '%s'", p);
1290 afs_extract_to_tmp(call);
1294 /* extract the message of the day length */
1296 ret = afs_extract_data(call, true);
1300 call->count = ntohl(call->tmp);
1301 _debug("motd length: %u", call->count);
1302 if (call->count >= AFSNAMEMAX)
1303 return afs_protocol_error(call, afs_eproto_motd_len);
1304 size = (call->count + 3) & ~3; /* It's padded */
1305 afs_extract_to_buf(call, size);
1309 /* extract the message of the day */
1311 _debug("extract motd");
1312 ret = afs_extract_data(call, false);
1318 _debug("motd '%s'", p);
1327 _leave(" = 0 [done]");
1332 * YFS.GetVolumeStatus operation type
1334 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1335 .name = "YFS.GetVolumeStatus",
1336 .op = yfs_FS_GetVolumeStatus,
1337 .deliver = yfs_deliver_fs_get_volume_status,
1338 .destructor = afs_flat_call_destructor,
1342 * fetch the status of a volume
1344 void yfs_fs_get_volume_status(struct afs_operation *op)
1346 struct afs_vnode_param *vp = &op->file[0];
1347 struct afs_call *call;
1352 call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
1353 sizeof(__be32) * 2 +
1354 sizeof(struct yfs_xdr_u64),
1356 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1360 return afs_op_nomem(op);
1362 /* marshall the parameters */
1364 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1365 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1366 bp = xdr_encode_u64(bp, vp->fid.vid);
1367 yfs_check_req(call, bp);
1369 trace_afs_make_fs_call(call, &vp->fid);
1370 afs_make_op_call(op, call, GFP_NOFS);
1374 * YFS.SetLock operation type
1376 static const struct afs_call_type yfs_RXYFSSetLock = {
1377 .name = "YFS.SetLock",
1378 .op = yfs_FS_SetLock,
1379 .deliver = yfs_deliver_status_and_volsync,
1380 .done = afs_lock_op_done,
1381 .destructor = afs_flat_call_destructor,
1385 * YFS.ExtendLock operation type
1387 static const struct afs_call_type yfs_RXYFSExtendLock = {
1388 .name = "YFS.ExtendLock",
1389 .op = yfs_FS_ExtendLock,
1390 .deliver = yfs_deliver_status_and_volsync,
1391 .done = afs_lock_op_done,
1392 .destructor = afs_flat_call_destructor,
1396 * YFS.ReleaseLock operation type
1398 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1399 .name = "YFS.ReleaseLock",
1400 .op = yfs_FS_ReleaseLock,
1401 .deliver = yfs_deliver_status_and_volsync,
1402 .destructor = afs_flat_call_destructor,
1406 * Set a lock on a file
1408 void yfs_fs_set_lock(struct afs_operation *op)
1410 struct afs_vnode_param *vp = &op->file[0];
1411 struct afs_call *call;
1416 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
1417 sizeof(__be32) * 2 +
1418 sizeof(struct yfs_xdr_YFSFid) +
1420 sizeof(struct yfs_xdr_YFSFetchStatus) +
1421 sizeof(struct yfs_xdr_YFSVolSync));
1423 return afs_op_nomem(op);
1425 /* marshall the parameters */
1427 bp = xdr_encode_u32(bp, YFSSETLOCK);
1428 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1429 bp = xdr_encode_YFSFid(bp, &vp->fid);
1430 bp = xdr_encode_u32(bp, op->lock.type);
1431 yfs_check_req(call, bp);
1433 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1434 afs_make_op_call(op, call, GFP_NOFS);
1438 * extend a lock on a file
1440 void yfs_fs_extend_lock(struct afs_operation *op)
1442 struct afs_vnode_param *vp = &op->file[0];
1443 struct afs_call *call;
1448 call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
1449 sizeof(__be32) * 2 +
1450 sizeof(struct yfs_xdr_YFSFid),
1451 sizeof(struct yfs_xdr_YFSFetchStatus) +
1452 sizeof(struct yfs_xdr_YFSVolSync));
1454 return afs_op_nomem(op);
1456 /* marshall the parameters */
1458 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1459 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1460 bp = xdr_encode_YFSFid(bp, &vp->fid);
1461 yfs_check_req(call, bp);
1463 trace_afs_make_fs_call(call, &vp->fid);
1464 afs_make_op_call(op, call, GFP_NOFS);
1468 * release a lock on a file
1470 void yfs_fs_release_lock(struct afs_operation *op)
1472 struct afs_vnode_param *vp = &op->file[0];
1473 struct afs_call *call;
1478 call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
1479 sizeof(__be32) * 2 +
1480 sizeof(struct yfs_xdr_YFSFid),
1481 sizeof(struct yfs_xdr_YFSFetchStatus) +
1482 sizeof(struct yfs_xdr_YFSVolSync));
1484 return afs_op_nomem(op);
1486 /* marshall the parameters */
1488 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1489 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1490 bp = xdr_encode_YFSFid(bp, &vp->fid);
1491 yfs_check_req(call, bp);
1493 trace_afs_make_fs_call(call, &vp->fid);
1494 afs_make_op_call(op, call, GFP_NOFS);
1498 * Deliver a reply to YFS.FetchStatus
1500 static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1502 struct afs_operation *op = call->op;
1503 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1507 ret = afs_transfer_reply(call);
1511 /* unmarshall the reply once we've received all of it */
1513 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1514 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
1515 xdr_decode_YFSVolSync(&bp, &op->volsync);
1517 _leave(" = 0 [done]");
1522 * YFS.FetchStatus operation type
1524 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1525 .name = "YFS.FetchStatus",
1526 .op = yfs_FS_FetchStatus,
1527 .deliver = yfs_deliver_fs_fetch_status,
1528 .destructor = afs_flat_call_destructor,
1532 * Fetch the status information for a fid without needing a vnode handle.
1534 void yfs_fs_fetch_status(struct afs_operation *op)
1536 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1537 struct afs_call *call;
1540 _enter(",%x,{%llx:%llu},,",
1541 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1543 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
1544 sizeof(__be32) * 2 +
1545 sizeof(struct yfs_xdr_YFSFid),
1546 sizeof(struct yfs_xdr_YFSFetchStatus) +
1547 sizeof(struct yfs_xdr_YFSCallBack) +
1548 sizeof(struct yfs_xdr_YFSVolSync));
1550 return afs_op_nomem(op);
1552 /* marshall the parameters */
1554 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
1555 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1556 bp = xdr_encode_YFSFid(bp, &vp->fid);
1557 yfs_check_req(call, bp);
1559 trace_afs_make_fs_call(call, &vp->fid);
1560 afs_make_op_call(op, call, GFP_NOFS);
1564 * Deliver reply data to an YFS.InlineBulkStatus call
1566 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
1568 struct afs_operation *op = call->op;
1569 struct afs_status_cb *scb;
1574 _enter("{%u}", call->unmarshall);
1576 switch (call->unmarshall) {
1578 afs_extract_to_tmp(call);
1582 /* Extract the file status count and array in two steps */
1584 _debug("extract status count");
1585 ret = afs_extract_data(call, true);
1589 tmp = ntohl(call->tmp);
1590 _debug("status count: %u/%u", tmp, op->nr_files);
1591 if (tmp != op->nr_files)
1592 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1597 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
1601 _debug("extract status array %u", call->count);
1602 ret = afs_extract_data(call, true);
1606 switch (call->count) {
1608 scb = &op->file[0].scb;
1611 scb = &op->file[1].scb;
1614 scb = &op->more_files[call->count - 2].scb;
1619 xdr_decode_YFSFetchStatus(&bp, call, scb);
1622 if (call->count < op->nr_files)
1627 afs_extract_to_tmp(call);
1630 /* Extract the callback count and array in two steps */
1632 _debug("extract CB count");
1633 ret = afs_extract_data(call, true);
1637 tmp = ntohl(call->tmp);
1638 _debug("CB count: %u", tmp);
1639 if (tmp != op->nr_files)
1640 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1644 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
1648 _debug("extract CB array");
1649 ret = afs_extract_data(call, true);
1653 _debug("unmarshall CB array");
1654 switch (call->count) {
1656 scb = &op->file[0].scb;
1659 scb = &op->file[1].scb;
1662 scb = &op->more_files[call->count - 2].scb;
1667 xdr_decode_YFSCallBack(&bp, call, scb);
1669 if (call->count < op->nr_files)
1672 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
1677 ret = afs_extract_data(call, false);
1682 xdr_decode_YFSVolSync(&bp, &op->volsync);
1691 _leave(" = 0 [done]");
1696 * FS.InlineBulkStatus operation type
1698 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
1699 .name = "YFS.InlineBulkStatus",
1700 .op = yfs_FS_InlineBulkStatus,
1701 .deliver = yfs_deliver_fs_inline_bulk_status,
1702 .destructor = afs_flat_call_destructor,
1706 * Fetch the status information for up to 1024 files
1708 void yfs_fs_inline_bulk_status(struct afs_operation *op)
1710 struct afs_vnode_param *dvp = &op->file[0];
1711 struct afs_vnode_param *vp = &op->file[1];
1712 struct afs_call *call;
1716 _enter(",%x,{%llx:%llu},%u",
1717 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1719 call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
1723 sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
1724 sizeof(struct yfs_xdr_YFSFetchStatus));
1726 return afs_op_nomem(op);
1728 /* marshall the parameters */
1730 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
1731 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
1732 bp = xdr_encode_u32(bp, op->nr_files);
1733 bp = xdr_encode_YFSFid(bp, &dvp->fid);
1734 bp = xdr_encode_YFSFid(bp, &vp->fid);
1735 for (i = 0; i < op->nr_files - 2; i++)
1736 bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
1737 yfs_check_req(call, bp);
1739 trace_afs_make_fs_call(call, &vp->fid);
1740 afs_make_op_call(op, call, GFP_NOFS);
1744 * Deliver reply data to an YFS.FetchOpaqueACL.
1746 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
1748 struct afs_operation *op = call->op;
1749 struct afs_vnode_param *vp = &op->file[0];
1750 struct yfs_acl *yacl = op->yacl;
1751 struct afs_acl *acl;
1756 _enter("{%u}", call->unmarshall);
1758 switch (call->unmarshall) {
1760 afs_extract_to_tmp(call);
1764 /* Extract the file ACL length */
1766 ret = afs_extract_data(call, true);
1770 size = call->count2 = ntohl(call->tmp);
1771 size = round_up(size, 4);
1773 if (yacl->flags & YFS_ACL_WANT_ACL) {
1774 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1778 acl->size = call->count2;
1779 afs_extract_begin(call, acl->data, size);
1781 afs_extract_discard(call, size);
1786 /* Extract the file ACL */
1788 ret = afs_extract_data(call, true);
1792 afs_extract_to_tmp(call);
1796 /* Extract the volume ACL length */
1798 ret = afs_extract_data(call, true);
1802 size = call->count2 = ntohl(call->tmp);
1803 size = round_up(size, 4);
1805 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
1806 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1809 yacl->vol_acl = acl;
1810 acl->size = call->count2;
1811 afs_extract_begin(call, acl->data, size);
1813 afs_extract_discard(call, size);
1818 /* Extract the volume ACL */
1820 ret = afs_extract_data(call, true);
1824 afs_extract_to_buf(call,
1825 sizeof(__be32) * 2 +
1826 sizeof(struct yfs_xdr_YFSFetchStatus) +
1827 sizeof(struct yfs_xdr_YFSVolSync));
1831 /* extract the metadata */
1833 ret = afs_extract_data(call, false);
1838 yacl->inherit_flag = ntohl(*bp++);
1839 yacl->num_cleaned = ntohl(*bp++);
1840 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1841 xdr_decode_YFSVolSync(&bp, &op->volsync);
1850 _leave(" = 0 [done]");
1854 void yfs_free_opaque_acl(struct yfs_acl *yacl)
1858 kfree(yacl->vol_acl);
1864 * YFS.FetchOpaqueACL operation type
1866 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
1867 .name = "YFS.FetchOpaqueACL",
1868 .op = yfs_FS_FetchOpaqueACL,
1869 .deliver = yfs_deliver_fs_fetch_opaque_acl,
1870 .destructor = afs_flat_call_destructor,
1874 * Fetch the YFS advanced ACLs for a file.
1876 void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
1878 struct afs_vnode_param *vp = &op->file[0];
1879 struct afs_call *call;
1882 _enter(",%x,{%llx:%llu},,",
1883 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1885 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
1886 sizeof(__be32) * 2 +
1887 sizeof(struct yfs_xdr_YFSFid),
1888 sizeof(__be32) * 2 +
1889 sizeof(struct yfs_xdr_YFSFetchStatus) +
1890 sizeof(struct yfs_xdr_YFSVolSync));
1892 return afs_op_nomem(op);
1894 /* marshall the parameters */
1896 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
1897 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1898 bp = xdr_encode_YFSFid(bp, &vp->fid);
1899 yfs_check_req(call, bp);
1901 trace_afs_make_fs_call(call, &vp->fid);
1902 afs_make_op_call(op, call, GFP_KERNEL);
1906 * YFS.StoreOpaqueACL2 operation type
1908 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
1909 .name = "YFS.StoreOpaqueACL2",
1910 .op = yfs_FS_StoreOpaqueACL2,
1911 .deliver = yfs_deliver_status_and_volsync,
1912 .destructor = afs_flat_call_destructor,
1916 * Fetch the YFS ACL for a file.
1918 void yfs_fs_store_opaque_acl2(struct afs_operation *op)
1920 struct afs_vnode_param *vp = &op->file[0];
1921 struct afs_call *call;
1922 struct afs_acl *acl = op->acl;
1926 _enter(",%x,{%llx:%llu},,",
1927 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1929 size = round_up(acl->size, 4);
1930 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
1931 sizeof(__be32) * 2 +
1932 sizeof(struct yfs_xdr_YFSFid) +
1933 sizeof(__be32) + size,
1934 sizeof(struct yfs_xdr_YFSFetchStatus) +
1935 sizeof(struct yfs_xdr_YFSVolSync));
1937 return afs_op_nomem(op);
1939 /* marshall the parameters */
1941 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
1942 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1943 bp = xdr_encode_YFSFid(bp, &vp->fid);
1944 bp = xdr_encode_u32(bp, acl->size);
1945 memcpy(bp, acl->data, acl->size);
1946 if (acl->size != size)
1947 memset((void *)bp + acl->size, 0, size - acl->size);
1948 bp += size / sizeof(__be32);
1949 yfs_check_req(call, bp);
1951 trace_afs_make_fs_call(call, &vp->fid);
1952 afs_make_op_call(op, call, GFP_KERNEL);