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_mode(__be32 *bp, mode_t mode)
88 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
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);
98 static __be32 *xdr_encode_YFSStoreStatus_mtime(__be32 *bp, const struct timespec64 *t)
100 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
101 s64 mtime = linux_to_yfs_time(t);
103 x->mask = htonl(AFS_SET_MTIME);
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);
112 * Convert a signed 100ns-resolution 64-bit time into a timespec.
114 static struct timespec64 yfs_time_to_linux(s64 t)
116 struct timespec64 ts;
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
126 ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100);
127 ts.tv_nsec = -ts.tv_nsec;
131 ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100;
138 static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr)
140 s64 t = xdr_to_u64(xdr);
142 return yfs_time_to_linux(t);
145 static void yfs_check_req(struct afs_call *call, __be32 *bp)
147 size_t len = (void *)bp - call->request;
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);
158 * Dump a bad file status record.
160 static void xdr_dump_bad(const __be32 *bp)
165 pr_notice("YFS XDR: Bad status record\n");
166 for (i = 0; i < 6 * 4 * 4; i += 16) {
169 pr_notice("%03x: %08x %08x %08x %08x\n",
170 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
174 pr_notice("0x60: %08x %08x\n", ntohl(x[0]), ntohl(x[1]));
178 * Decode a YFSFetchStatus block
180 static void xdr_decode_YFSFetchStatus(const __be32 **_bp,
181 struct afs_call *call,
182 struct afs_status_cb *scb)
184 const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
185 struct afs_file_status *status = &scb->status;
188 status->abort_code = ntohl(xdr->abort_code);
189 if (status->abort_code != 0) {
190 if (status->abort_code == VNOVNODE)
192 scb->have_error = true;
196 type = ntohl(xdr->type);
200 case AFS_FTYPE_SYMLINK:
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);
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;
222 *_bp += xdr_size(xdr);
227 afs_protocol_error(call, afs_eproto_bad_status);
232 * Decode a YFSCallBack block
234 static void xdr_decode_YFSCallBack(const __be32 **_bp,
235 struct afs_call *call,
236 struct afs_status_cb *scb)
238 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
239 struct afs_callback *cb = &scb->callback;
242 cb_expiry = ktime_add(call->issue_time, xdr_to_u64(x->expiration_time) * 100);
243 cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
249 * Decode a YFSVolSync block
251 static void xdr_decode_YFSVolSync(const __be32 **_bp,
252 struct afs_volsync *volsync)
254 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
258 creation = xdr_to_u64(x->vol_creation_date);
259 do_div(creation, 10 * 1000 * 1000);
260 volsync->creation = creation;
267 * Encode the requested attributes into a YFSStoreStatus block
269 static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
271 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
272 s64 mtime = 0, owner = 0, group = 0;
273 u32 mask = 0, mode = 0;
276 if (attr->ia_valid & ATTR_MTIME) {
277 mask |= AFS_SET_MTIME;
278 mtime = linux_to_yfs_time(&attr->ia_mtime);
281 if (attr->ia_valid & ATTR_UID) {
282 mask |= AFS_SET_OWNER;
283 owner = from_kuid(&init_user_ns, attr->ia_uid);
286 if (attr->ia_valid & ATTR_GID) {
287 mask |= AFS_SET_GROUP;
288 group = from_kgid(&init_user_ns, attr->ia_gid);
291 if (attr->ia_valid & ATTR_MODE) {
292 mask |= AFS_SET_MODE;
293 mode = attr->ia_mode & S_IALLUGO;
296 x->mask = htonl(mask);
297 x->mode = htonl(mode);
298 x->mtime_client = u64_to_xdr(mtime);
299 x->owner = u64_to_xdr(owner);
300 x->group = u64_to_xdr(group);
301 return bp + xdr_size(x);
305 * Decode a YFSFetchVolumeStatus block.
307 static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
308 struct afs_volume_status *vs)
310 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
313 vs->vid = xdr_to_u64(x->vid);
314 vs->parent_id = xdr_to_u64(x->parent_id);
315 flags = ntohl(x->flags);
316 vs->online = flags & yfs_FVSOnline;
317 vs->in_service = flags & yfs_FVSInservice;
318 vs->blessed = flags & yfs_FVSBlessed;
319 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
320 vs->type = ntohl(x->type);
322 vs->max_quota = xdr_to_u64(x->max_quota);
323 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
324 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
325 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
326 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
327 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
328 *_bp += sizeof(*x) / sizeof(__be32);
332 * Deliver reply data to operations that just return a file status and a volume
335 static int yfs_deliver_status_and_volsync(struct afs_call *call)
337 struct afs_operation *op = call->op;
341 ret = afs_transfer_reply(call);
346 xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
347 xdr_decode_YFSVolSync(&bp, &op->volsync);
349 _leave(" = 0 [done]");
354 * Deliver reply data to an YFS.FetchData64.
356 static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
358 struct afs_operation *op = call->op;
359 struct afs_vnode_param *vp = &op->file[0];
360 struct afs_read *req = op->fetch.req;
364 _enter("{%u,%zu, %zu/%llu}",
365 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
368 switch (call->unmarshall) {
371 afs_extract_to_tmp64(call);
375 /* Extract the returned data length into ->actual_len. This
376 * may indicate more or less data than was requested will be
380 _debug("extract data length");
381 ret = afs_extract_data(call, true);
385 req->actual_len = be64_to_cpu(call->tmp64);
386 _debug("DATA length: %llu", req->actual_len);
388 if (req->actual_len == 0)
391 call->iter = req->iter;
392 call->iov_len = min(req->actual_len, req->len);
396 /* extract the returned data */
398 _debug("extract data %zu/%llu",
399 iov_iter_count(call->iter), req->actual_len);
401 ret = afs_extract_data(call, true);
405 call->iter = &call->def_iter;
406 if (req->actual_len <= req->len)
409 /* Discard any excess data the server gave us */
410 afs_extract_discard(call, req->actual_len - req->len);
411 call->unmarshall = 3;
415 _debug("extract discard %zu/%llu",
416 iov_iter_count(call->iter), req->actual_len - req->len);
418 ret = afs_extract_data(call, true);
423 call->unmarshall = 4;
424 afs_extract_to_buf(call,
425 sizeof(struct yfs_xdr_YFSFetchStatus) +
426 sizeof(struct yfs_xdr_YFSCallBack) +
427 sizeof(struct yfs_xdr_YFSVolSync));
430 /* extract the metadata */
432 ret = afs_extract_data(call, false);
437 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
438 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
439 xdr_decode_YFSVolSync(&bp, &op->volsync);
441 req->data_version = vp->scb.status.data_version;
442 req->file_size = vp->scb.status.size;
451 _leave(" = 0 [done]");
456 * YFS.FetchData64 operation type
458 static const struct afs_call_type yfs_RXYFSFetchData64 = {
459 .name = "YFS.FetchData64",
460 .op = yfs_FS_FetchData64,
461 .deliver = yfs_deliver_fs_fetch_data64,
462 .destructor = afs_flat_call_destructor,
466 * Fetch data from a file.
468 void yfs_fs_fetch_data(struct afs_operation *op)
470 struct afs_vnode_param *vp = &op->file[0];
471 struct afs_read *req = op->fetch.req;
472 struct afs_call *call;
475 _enter(",%x,{%llx:%llu},%llx,%llx",
476 key_serial(op->key), vp->fid.vid, vp->fid.vnode,
479 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
481 sizeof(struct yfs_xdr_YFSFid) +
482 sizeof(struct yfs_xdr_u64) * 2,
483 sizeof(struct yfs_xdr_YFSFetchStatus) +
484 sizeof(struct yfs_xdr_YFSCallBack) +
485 sizeof(struct yfs_xdr_YFSVolSync));
487 return afs_op_nomem(op);
489 req->call_debug_id = call->debug_id;
491 /* marshall the parameters */
493 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
494 bp = xdr_encode_u32(bp, 0); /* RPC flags */
495 bp = xdr_encode_YFSFid(bp, &vp->fid);
496 bp = xdr_encode_u64(bp, req->pos);
497 bp = xdr_encode_u64(bp, req->len);
498 yfs_check_req(call, bp);
500 trace_afs_make_fs_call(call, &vp->fid);
501 afs_make_op_call(op, call, GFP_NOFS);
505 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
507 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
509 struct afs_operation *op = call->op;
510 struct afs_vnode_param *dvp = &op->file[0];
511 struct afs_vnode_param *vp = &op->file[1];
515 _enter("{%u}", call->unmarshall);
517 ret = afs_transfer_reply(call);
521 /* unmarshall the reply once we've received all of it */
523 xdr_decode_YFSFid(&bp, &op->file[1].fid);
524 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
525 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
526 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
527 xdr_decode_YFSVolSync(&bp, &op->volsync);
529 _leave(" = 0 [done]");
534 * FS.CreateFile and FS.MakeDir operation type
536 static const struct afs_call_type afs_RXFSCreateFile = {
537 .name = "YFS.CreateFile",
538 .op = yfs_FS_CreateFile,
539 .deliver = yfs_deliver_fs_create_vnode,
540 .destructor = afs_flat_call_destructor,
546 void yfs_fs_create_file(struct afs_operation *op)
548 const struct qstr *name = &op->dentry->d_name;
549 struct afs_vnode_param *dvp = &op->file[0];
550 struct afs_call *call;
556 reqsz = (sizeof(__be32) +
558 sizeof(struct yfs_xdr_YFSFid) +
559 xdr_strlen(name->len) +
560 sizeof(struct yfs_xdr_YFSStoreStatus) +
562 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
563 sizeof(struct yfs_xdr_YFSFetchStatus) +
564 sizeof(struct yfs_xdr_YFSFetchStatus) +
565 sizeof(struct yfs_xdr_YFSCallBack) +
566 sizeof(struct yfs_xdr_YFSVolSync));
568 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
570 return afs_op_nomem(op);
572 /* marshall the parameters */
574 bp = xdr_encode_u32(bp, YFSCREATEFILE);
575 bp = xdr_encode_u32(bp, 0); /* RPC flags */
576 bp = xdr_encode_YFSFid(bp, &dvp->fid);
577 bp = xdr_encode_name(bp, name);
578 bp = xdr_encode_YFSStoreStatus_mode(bp, op->create.mode);
579 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
580 yfs_check_req(call, bp);
582 trace_afs_make_fs_call1(call, &dvp->fid, name);
583 afs_make_op_call(op, call, GFP_NOFS);
586 static const struct afs_call_type yfs_RXFSMakeDir = {
587 .name = "YFS.MakeDir",
588 .op = yfs_FS_MakeDir,
589 .deliver = yfs_deliver_fs_create_vnode,
590 .destructor = afs_flat_call_destructor,
596 void yfs_fs_make_dir(struct afs_operation *op)
598 const struct qstr *name = &op->dentry->d_name;
599 struct afs_vnode_param *dvp = &op->file[0];
600 struct afs_call *call;
606 reqsz = (sizeof(__be32) +
607 sizeof(struct yfs_xdr_RPCFlags) +
608 sizeof(struct yfs_xdr_YFSFid) +
609 xdr_strlen(name->len) +
610 sizeof(struct yfs_xdr_YFSStoreStatus));
611 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
612 sizeof(struct yfs_xdr_YFSFetchStatus) +
613 sizeof(struct yfs_xdr_YFSFetchStatus) +
614 sizeof(struct yfs_xdr_YFSCallBack) +
615 sizeof(struct yfs_xdr_YFSVolSync));
617 call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
619 return afs_op_nomem(op);
621 /* marshall the parameters */
623 bp = xdr_encode_u32(bp, YFSMAKEDIR);
624 bp = xdr_encode_u32(bp, 0); /* RPC flags */
625 bp = xdr_encode_YFSFid(bp, &dvp->fid);
626 bp = xdr_encode_name(bp, name);
627 bp = xdr_encode_YFSStoreStatus_mode(bp, op->create.mode);
628 yfs_check_req(call, bp);
630 trace_afs_make_fs_call1(call, &dvp->fid, name);
631 afs_make_op_call(op, call, GFP_NOFS);
635 * Deliver reply data to a YFS.RemoveFile2 operation.
637 static int yfs_deliver_fs_remove_file2(struct afs_call *call)
639 struct afs_operation *op = call->op;
640 struct afs_vnode_param *dvp = &op->file[0];
641 struct afs_vnode_param *vp = &op->file[1];
646 _enter("{%u}", call->unmarshall);
648 ret = afs_transfer_reply(call);
653 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
654 xdr_decode_YFSFid(&bp, &fid);
655 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
656 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
658 xdr_decode_YFSVolSync(&bp, &op->volsync);
662 static void yfs_done_fs_remove_file2(struct afs_call *call)
664 if (call->error == -ECONNABORTED &&
665 call->abort_code == RX_INVALID_OPERATION) {
666 set_bit(AFS_SERVER_FL_NO_RM2, &call->server->flags);
667 call->op->flags |= AFS_OPERATION_DOWNGRADE;
672 * YFS.RemoveFile2 operation type.
674 static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
675 .name = "YFS.RemoveFile2",
676 .op = yfs_FS_RemoveFile2,
677 .deliver = yfs_deliver_fs_remove_file2,
678 .done = yfs_done_fs_remove_file2,
679 .destructor = afs_flat_call_destructor,
683 * Remove a file and retrieve new file status.
685 void yfs_fs_remove_file2(struct afs_operation *op)
687 struct afs_vnode_param *dvp = &op->file[0];
688 const struct qstr *name = &op->dentry->d_name;
689 struct afs_call *call;
694 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
696 sizeof(struct yfs_xdr_RPCFlags) +
697 sizeof(struct yfs_xdr_YFSFid) +
698 xdr_strlen(name->len),
699 sizeof(struct yfs_xdr_YFSFetchStatus) +
700 sizeof(struct yfs_xdr_YFSFid) +
701 sizeof(struct yfs_xdr_YFSFetchStatus) +
702 sizeof(struct yfs_xdr_YFSVolSync));
704 return afs_op_nomem(op);
706 /* marshall the parameters */
708 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
709 bp = xdr_encode_u32(bp, 0); /* RPC flags */
710 bp = xdr_encode_YFSFid(bp, &dvp->fid);
711 bp = xdr_encode_name(bp, name);
712 yfs_check_req(call, bp);
714 trace_afs_make_fs_call1(call, &dvp->fid, name);
715 afs_make_op_call(op, call, GFP_NOFS);
719 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
721 static int yfs_deliver_fs_remove(struct afs_call *call)
723 struct afs_operation *op = call->op;
724 struct afs_vnode_param *dvp = &op->file[0];
728 _enter("{%u}", call->unmarshall);
730 ret = afs_transfer_reply(call);
735 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
736 xdr_decode_YFSVolSync(&bp, &op->volsync);
741 * FS.RemoveDir and FS.RemoveFile operation types.
743 static 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,
753 void yfs_fs_remove_file(struct afs_operation *op)
755 const struct qstr *name = &op->dentry->d_name;
756 struct afs_vnode_param *dvp = &op->file[0];
757 struct afs_call *call;
762 if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
763 return yfs_fs_remove_file2(op);
765 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
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));
773 return afs_op_nomem(op);
775 /* marshall the parameters */
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);
783 trace_afs_make_fs_call1(call, &dvp->fid, name);
784 afs_make_op_call(op, call, GFP_NOFS);
787 static const struct afs_call_type yfs_RXYFSRemoveDir = {
788 .name = "YFS.RemoveDir",
789 .op = yfs_FS_RemoveDir,
790 .deliver = yfs_deliver_fs_remove,
791 .destructor = afs_flat_call_destructor,
795 * Remove a directory.
797 void yfs_fs_remove_dir(struct afs_operation *op)
799 const struct qstr *name = &op->dentry->d_name;
800 struct afs_vnode_param *dvp = &op->file[0];
801 struct afs_call *call;
806 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
808 sizeof(struct yfs_xdr_RPCFlags) +
809 sizeof(struct yfs_xdr_YFSFid) +
810 xdr_strlen(name->len),
811 sizeof(struct yfs_xdr_YFSFetchStatus) +
812 sizeof(struct yfs_xdr_YFSVolSync));
814 return afs_op_nomem(op);
816 /* marshall the parameters */
818 bp = xdr_encode_u32(bp, YFSREMOVEDIR);
819 bp = xdr_encode_u32(bp, 0); /* RPC flags */
820 bp = xdr_encode_YFSFid(bp, &dvp->fid);
821 bp = xdr_encode_name(bp, name);
822 yfs_check_req(call, bp);
824 trace_afs_make_fs_call1(call, &dvp->fid, name);
825 afs_make_op_call(op, call, GFP_NOFS);
829 * Deliver reply data to a YFS.Link operation.
831 static int yfs_deliver_fs_link(struct afs_call *call)
833 struct afs_operation *op = call->op;
834 struct afs_vnode_param *dvp = &op->file[0];
835 struct afs_vnode_param *vp = &op->file[1];
839 _enter("{%u}", call->unmarshall);
841 ret = afs_transfer_reply(call);
846 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
847 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
848 xdr_decode_YFSVolSync(&bp, &op->volsync);
849 _leave(" = 0 [done]");
854 * YFS.Link operation type.
856 static const struct afs_call_type yfs_RXYFSLink = {
859 .deliver = yfs_deliver_fs_link,
860 .destructor = afs_flat_call_destructor,
866 void yfs_fs_link(struct afs_operation *op)
868 const struct qstr *name = &op->dentry->d_name;
869 struct afs_vnode_param *dvp = &op->file[0];
870 struct afs_vnode_param *vp = &op->file[1];
871 struct afs_call *call;
876 call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
878 sizeof(struct yfs_xdr_RPCFlags) +
879 sizeof(struct yfs_xdr_YFSFid) +
880 xdr_strlen(name->len) +
881 sizeof(struct yfs_xdr_YFSFid),
882 sizeof(struct yfs_xdr_YFSFetchStatus) +
883 sizeof(struct yfs_xdr_YFSFetchStatus) +
884 sizeof(struct yfs_xdr_YFSVolSync));
886 return afs_op_nomem(op);
888 /* marshall the parameters */
890 bp = xdr_encode_u32(bp, YFSLINK);
891 bp = xdr_encode_u32(bp, 0); /* RPC flags */
892 bp = xdr_encode_YFSFid(bp, &dvp->fid);
893 bp = xdr_encode_name(bp, name);
894 bp = xdr_encode_YFSFid(bp, &vp->fid);
895 yfs_check_req(call, bp);
897 trace_afs_make_fs_call1(call, &vp->fid, name);
898 afs_make_op_call(op, call, GFP_NOFS);
902 * Deliver reply data to a YFS.Symlink operation.
904 static int yfs_deliver_fs_symlink(struct afs_call *call)
906 struct afs_operation *op = call->op;
907 struct afs_vnode_param *dvp = &op->file[0];
908 struct afs_vnode_param *vp = &op->file[1];
912 _enter("{%u}", call->unmarshall);
914 ret = afs_transfer_reply(call);
918 /* unmarshall the reply once we've received all of it */
920 xdr_decode_YFSFid(&bp, &vp->fid);
921 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
922 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
923 xdr_decode_YFSVolSync(&bp, &op->volsync);
925 _leave(" = 0 [done]");
930 * YFS.Symlink operation type
932 static const struct afs_call_type yfs_RXYFSSymlink = {
933 .name = "YFS.Symlink",
934 .op = yfs_FS_Symlink,
935 .deliver = yfs_deliver_fs_symlink,
936 .destructor = afs_flat_call_destructor,
940 * Create a symbolic link.
942 void yfs_fs_symlink(struct afs_operation *op)
944 const struct qstr *name = &op->dentry->d_name;
945 struct afs_vnode_param *dvp = &op->file[0];
946 struct afs_call *call;
952 contents_sz = strlen(op->create.symlink);
953 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
955 sizeof(struct yfs_xdr_RPCFlags) +
956 sizeof(struct yfs_xdr_YFSFid) +
957 xdr_strlen(name->len) +
958 xdr_strlen(contents_sz) +
959 sizeof(struct yfs_xdr_YFSStoreStatus),
960 sizeof(struct yfs_xdr_YFSFid) +
961 sizeof(struct yfs_xdr_YFSFetchStatus) +
962 sizeof(struct yfs_xdr_YFSFetchStatus) +
963 sizeof(struct yfs_xdr_YFSVolSync));
965 return afs_op_nomem(op);
967 /* marshall the parameters */
969 bp = xdr_encode_u32(bp, YFSSYMLINK);
970 bp = xdr_encode_u32(bp, 0); /* RPC flags */
971 bp = xdr_encode_YFSFid(bp, &dvp->fid);
972 bp = xdr_encode_name(bp, name);
973 bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
974 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
975 yfs_check_req(call, bp);
977 trace_afs_make_fs_call1(call, &dvp->fid, name);
978 afs_make_op_call(op, call, GFP_NOFS);
982 * Deliver reply data to a YFS.Rename operation.
984 static int yfs_deliver_fs_rename(struct afs_call *call)
986 struct afs_operation *op = call->op;
987 struct afs_vnode_param *orig_dvp = &op->file[0];
988 struct afs_vnode_param *new_dvp = &op->file[1];
992 _enter("{%u}", call->unmarshall);
994 ret = afs_transfer_reply(call);
999 /* If the two dirs are the same, we have two copies of the same status
1000 * report, so we just decode it twice.
1002 xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
1003 xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
1004 xdr_decode_YFSVolSync(&bp, &op->volsync);
1005 _leave(" = 0 [done]");
1010 * YFS.Rename operation type
1012 static const struct afs_call_type yfs_RXYFSRename = {
1013 .name = "FS.Rename",
1014 .op = yfs_FS_Rename,
1015 .deliver = yfs_deliver_fs_rename,
1016 .destructor = afs_flat_call_destructor,
1020 * Rename a file or directory.
1022 void yfs_fs_rename(struct afs_operation *op)
1024 struct afs_vnode_param *orig_dvp = &op->file[0];
1025 struct afs_vnode_param *new_dvp = &op->file[1];
1026 const struct qstr *orig_name = &op->dentry->d_name;
1027 const struct qstr *new_name = &op->dentry_2->d_name;
1028 struct afs_call *call;
1033 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
1035 sizeof(struct yfs_xdr_RPCFlags) +
1036 sizeof(struct yfs_xdr_YFSFid) +
1037 xdr_strlen(orig_name->len) +
1038 sizeof(struct yfs_xdr_YFSFid) +
1039 xdr_strlen(new_name->len),
1040 sizeof(struct yfs_xdr_YFSFetchStatus) +
1041 sizeof(struct yfs_xdr_YFSFetchStatus) +
1042 sizeof(struct yfs_xdr_YFSVolSync));
1044 return afs_op_nomem(op);
1046 /* marshall the parameters */
1048 bp = xdr_encode_u32(bp, YFSRENAME);
1049 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1050 bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
1051 bp = xdr_encode_name(bp, orig_name);
1052 bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
1053 bp = xdr_encode_name(bp, new_name);
1054 yfs_check_req(call, bp);
1056 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1057 afs_make_op_call(op, call, GFP_NOFS);
1061 * YFS.StoreData64 operation type.
1063 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1064 .name = "YFS.StoreData64",
1065 .op = yfs_FS_StoreData64,
1066 .deliver = yfs_deliver_status_and_volsync,
1067 .destructor = afs_flat_call_destructor,
1071 * Store a set of pages to a large file.
1073 void yfs_fs_store_data(struct afs_operation *op)
1075 struct afs_vnode_param *vp = &op->file[0];
1076 struct afs_call *call;
1079 _enter(",%x,{%llx:%llu},,",
1080 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1082 _debug("size %llx, at %llx, i_size %llx",
1083 (unsigned long long)op->store.size,
1084 (unsigned long long)op->store.pos,
1085 (unsigned long long)op->store.i_size);
1087 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
1090 sizeof(struct yfs_xdr_YFSFid) +
1091 sizeof(struct yfs_xdr_YFSStoreStatus) +
1092 sizeof(struct yfs_xdr_u64) * 3,
1093 sizeof(struct yfs_xdr_YFSFetchStatus) +
1094 sizeof(struct yfs_xdr_YFSVolSync));
1096 return afs_op_nomem(op);
1098 call->write_iter = op->store.write_iter;
1100 /* marshall the parameters */
1102 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1103 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1104 bp = xdr_encode_YFSFid(bp, &vp->fid);
1105 bp = xdr_encode_YFSStoreStatus_mtime(bp, &op->mtime);
1106 bp = xdr_encode_u64(bp, op->store.pos);
1107 bp = xdr_encode_u64(bp, op->store.size);
1108 bp = xdr_encode_u64(bp, op->store.i_size);
1109 yfs_check_req(call, bp);
1111 trace_afs_make_fs_call(call, &vp->fid);
1112 afs_make_op_call(op, call, GFP_NOFS);
1116 * YFS.StoreStatus operation type
1118 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1119 .name = "YFS.StoreStatus",
1120 .op = yfs_FS_StoreStatus,
1121 .deliver = yfs_deliver_status_and_volsync,
1122 .destructor = afs_flat_call_destructor,
1125 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1126 .name = "YFS.StoreData64",
1127 .op = yfs_FS_StoreData64,
1128 .deliver = yfs_deliver_status_and_volsync,
1129 .destructor = afs_flat_call_destructor,
1133 * Set the attributes on a file, using YFS.StoreData64 rather than
1134 * YFS.StoreStatus so as to alter the file size also.
1136 static void yfs_fs_setattr_size(struct afs_operation *op)
1138 struct afs_vnode_param *vp = &op->file[0];
1139 struct afs_call *call;
1140 struct iattr *attr = op->setattr.attr;
1143 _enter(",%x,{%llx:%llu},,",
1144 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1146 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
1147 sizeof(__be32) * 2 +
1148 sizeof(struct yfs_xdr_YFSFid) +
1149 sizeof(struct yfs_xdr_YFSStoreStatus) +
1150 sizeof(struct yfs_xdr_u64) * 3,
1151 sizeof(struct yfs_xdr_YFSFetchStatus) +
1152 sizeof(struct yfs_xdr_YFSVolSync));
1154 return afs_op_nomem(op);
1156 /* marshall the parameters */
1158 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1159 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1160 bp = xdr_encode_YFSFid(bp, &vp->fid);
1161 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1162 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1163 bp = xdr_encode_u64(bp, 0); /* size of write */
1164 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1165 yfs_check_req(call, bp);
1167 trace_afs_make_fs_call(call, &vp->fid);
1168 afs_make_op_call(op, call, GFP_NOFS);
1172 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1173 * file size, and YFS.StoreStatus otherwise.
1175 void yfs_fs_setattr(struct afs_operation *op)
1177 struct afs_vnode_param *vp = &op->file[0];
1178 struct afs_call *call;
1179 struct iattr *attr = op->setattr.attr;
1182 if (attr->ia_valid & ATTR_SIZE)
1183 return yfs_fs_setattr_size(op);
1185 _enter(",%x,{%llx:%llu},,",
1186 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1188 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
1189 sizeof(__be32) * 2 +
1190 sizeof(struct yfs_xdr_YFSFid) +
1191 sizeof(struct yfs_xdr_YFSStoreStatus),
1192 sizeof(struct yfs_xdr_YFSFetchStatus) +
1193 sizeof(struct yfs_xdr_YFSVolSync));
1195 return afs_op_nomem(op);
1197 /* marshall the parameters */
1199 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1200 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1201 bp = xdr_encode_YFSFid(bp, &vp->fid);
1202 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1203 yfs_check_req(call, bp);
1205 trace_afs_make_fs_call(call, &vp->fid);
1206 afs_make_op_call(op, call, GFP_NOFS);
1210 * Deliver reply data to a YFS.GetVolumeStatus operation.
1212 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1214 struct afs_operation *op = call->op;
1220 _enter("{%u}", call->unmarshall);
1222 switch (call->unmarshall) {
1225 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1228 /* extract the returned status record */
1230 _debug("extract status");
1231 ret = afs_extract_data(call, true);
1236 xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1238 afs_extract_to_tmp(call);
1241 /* extract the volume name length */
1243 ret = afs_extract_data(call, true);
1247 call->count = ntohl(call->tmp);
1248 _debug("volname length: %u", call->count);
1249 if (call->count >= AFSNAMEMAX)
1250 return afs_protocol_error(call, afs_eproto_volname_len);
1251 size = (call->count + 3) & ~3; /* It's padded */
1252 afs_extract_to_buf(call, size);
1256 /* extract the volume name */
1258 _debug("extract volname");
1259 ret = afs_extract_data(call, true);
1265 _debug("volname '%s'", p);
1266 afs_extract_to_tmp(call);
1270 /* extract the offline message length */
1272 ret = afs_extract_data(call, true);
1276 call->count = ntohl(call->tmp);
1277 _debug("offline msg length: %u", call->count);
1278 if (call->count >= AFSNAMEMAX)
1279 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1280 size = (call->count + 3) & ~3; /* It's padded */
1281 afs_extract_to_buf(call, size);
1285 /* extract the offline message */
1287 _debug("extract offline");
1288 ret = afs_extract_data(call, true);
1294 _debug("offline '%s'", p);
1296 afs_extract_to_tmp(call);
1300 /* extract the message of the day length */
1302 ret = afs_extract_data(call, true);
1306 call->count = ntohl(call->tmp);
1307 _debug("motd length: %u", call->count);
1308 if (call->count >= AFSNAMEMAX)
1309 return afs_protocol_error(call, afs_eproto_motd_len);
1310 size = (call->count + 3) & ~3; /* It's padded */
1311 afs_extract_to_buf(call, size);
1315 /* extract the message of the day */
1317 _debug("extract motd");
1318 ret = afs_extract_data(call, false);
1324 _debug("motd '%s'", p);
1333 _leave(" = 0 [done]");
1338 * YFS.GetVolumeStatus operation type
1340 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1341 .name = "YFS.GetVolumeStatus",
1342 .op = yfs_FS_GetVolumeStatus,
1343 .deliver = yfs_deliver_fs_get_volume_status,
1344 .destructor = afs_flat_call_destructor,
1348 * fetch the status of a volume
1350 void yfs_fs_get_volume_status(struct afs_operation *op)
1352 struct afs_vnode_param *vp = &op->file[0];
1353 struct afs_call *call;
1358 call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
1359 sizeof(__be32) * 2 +
1360 sizeof(struct yfs_xdr_u64),
1362 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1366 return afs_op_nomem(op);
1368 /* marshall the parameters */
1370 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1371 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1372 bp = xdr_encode_u64(bp, vp->fid.vid);
1373 yfs_check_req(call, bp);
1375 trace_afs_make_fs_call(call, &vp->fid);
1376 afs_make_op_call(op, call, GFP_NOFS);
1380 * YFS.SetLock operation type
1382 static const struct afs_call_type yfs_RXYFSSetLock = {
1383 .name = "YFS.SetLock",
1384 .op = yfs_FS_SetLock,
1385 .deliver = yfs_deliver_status_and_volsync,
1386 .done = afs_lock_op_done,
1387 .destructor = afs_flat_call_destructor,
1391 * YFS.ExtendLock operation type
1393 static const struct afs_call_type yfs_RXYFSExtendLock = {
1394 .name = "YFS.ExtendLock",
1395 .op = yfs_FS_ExtendLock,
1396 .deliver = yfs_deliver_status_and_volsync,
1397 .done = afs_lock_op_done,
1398 .destructor = afs_flat_call_destructor,
1402 * YFS.ReleaseLock operation type
1404 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1405 .name = "YFS.ReleaseLock",
1406 .op = yfs_FS_ReleaseLock,
1407 .deliver = yfs_deliver_status_and_volsync,
1408 .destructor = afs_flat_call_destructor,
1412 * Set a lock on a file
1414 void yfs_fs_set_lock(struct afs_operation *op)
1416 struct afs_vnode_param *vp = &op->file[0];
1417 struct afs_call *call;
1422 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
1423 sizeof(__be32) * 2 +
1424 sizeof(struct yfs_xdr_YFSFid) +
1426 sizeof(struct yfs_xdr_YFSFetchStatus) +
1427 sizeof(struct yfs_xdr_YFSVolSync));
1429 return afs_op_nomem(op);
1431 /* marshall the parameters */
1433 bp = xdr_encode_u32(bp, YFSSETLOCK);
1434 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1435 bp = xdr_encode_YFSFid(bp, &vp->fid);
1436 bp = xdr_encode_u32(bp, op->lock.type);
1437 yfs_check_req(call, bp);
1439 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1440 afs_make_op_call(op, call, GFP_NOFS);
1444 * extend a lock on a file
1446 void yfs_fs_extend_lock(struct afs_operation *op)
1448 struct afs_vnode_param *vp = &op->file[0];
1449 struct afs_call *call;
1454 call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
1455 sizeof(__be32) * 2 +
1456 sizeof(struct yfs_xdr_YFSFid),
1457 sizeof(struct yfs_xdr_YFSFetchStatus) +
1458 sizeof(struct yfs_xdr_YFSVolSync));
1460 return afs_op_nomem(op);
1462 /* marshall the parameters */
1464 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1465 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1466 bp = xdr_encode_YFSFid(bp, &vp->fid);
1467 yfs_check_req(call, bp);
1469 trace_afs_make_fs_call(call, &vp->fid);
1470 afs_make_op_call(op, call, GFP_NOFS);
1474 * release a lock on a file
1476 void yfs_fs_release_lock(struct afs_operation *op)
1478 struct afs_vnode_param *vp = &op->file[0];
1479 struct afs_call *call;
1484 call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
1485 sizeof(__be32) * 2 +
1486 sizeof(struct yfs_xdr_YFSFid),
1487 sizeof(struct yfs_xdr_YFSFetchStatus) +
1488 sizeof(struct yfs_xdr_YFSVolSync));
1490 return afs_op_nomem(op);
1492 /* marshall the parameters */
1494 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1495 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1496 bp = xdr_encode_YFSFid(bp, &vp->fid);
1497 yfs_check_req(call, bp);
1499 trace_afs_make_fs_call(call, &vp->fid);
1500 afs_make_op_call(op, call, GFP_NOFS);
1504 * Deliver a reply to YFS.FetchStatus
1506 static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1508 struct afs_operation *op = call->op;
1509 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1513 ret = afs_transfer_reply(call);
1517 /* unmarshall the reply once we've received all of it */
1519 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1520 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
1521 xdr_decode_YFSVolSync(&bp, &op->volsync);
1523 _leave(" = 0 [done]");
1528 * YFS.FetchStatus operation type
1530 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1531 .name = "YFS.FetchStatus",
1532 .op = yfs_FS_FetchStatus,
1533 .deliver = yfs_deliver_fs_fetch_status,
1534 .destructor = afs_flat_call_destructor,
1538 * Fetch the status information for a fid without needing a vnode handle.
1540 void yfs_fs_fetch_status(struct afs_operation *op)
1542 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1543 struct afs_call *call;
1546 _enter(",%x,{%llx:%llu},,",
1547 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1549 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
1550 sizeof(__be32) * 2 +
1551 sizeof(struct yfs_xdr_YFSFid),
1552 sizeof(struct yfs_xdr_YFSFetchStatus) +
1553 sizeof(struct yfs_xdr_YFSCallBack) +
1554 sizeof(struct yfs_xdr_YFSVolSync));
1556 return afs_op_nomem(op);
1558 /* marshall the parameters */
1560 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
1561 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1562 bp = xdr_encode_YFSFid(bp, &vp->fid);
1563 yfs_check_req(call, bp);
1565 trace_afs_make_fs_call(call, &vp->fid);
1566 afs_make_op_call(op, call, GFP_NOFS);
1570 * Deliver reply data to an YFS.InlineBulkStatus call
1572 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
1574 struct afs_operation *op = call->op;
1575 struct afs_status_cb *scb;
1580 _enter("{%u}", call->unmarshall);
1582 switch (call->unmarshall) {
1584 afs_extract_to_tmp(call);
1588 /* Extract the file status count and array in two steps */
1590 _debug("extract status count");
1591 ret = afs_extract_data(call, true);
1595 tmp = ntohl(call->tmp);
1596 _debug("status count: %u/%u", tmp, op->nr_files);
1597 if (tmp != op->nr_files)
1598 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1603 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
1607 _debug("extract status array %u", call->count);
1608 ret = afs_extract_data(call, true);
1612 switch (call->count) {
1614 scb = &op->file[0].scb;
1617 scb = &op->file[1].scb;
1620 scb = &op->more_files[call->count - 2].scb;
1625 xdr_decode_YFSFetchStatus(&bp, call, scb);
1628 if (call->count < op->nr_files)
1633 afs_extract_to_tmp(call);
1636 /* Extract the callback count and array in two steps */
1638 _debug("extract CB count");
1639 ret = afs_extract_data(call, true);
1643 tmp = ntohl(call->tmp);
1644 _debug("CB count: %u", tmp);
1645 if (tmp != op->nr_files)
1646 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1650 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
1654 _debug("extract CB array");
1655 ret = afs_extract_data(call, true);
1659 _debug("unmarshall CB array");
1660 switch (call->count) {
1662 scb = &op->file[0].scb;
1665 scb = &op->file[1].scb;
1668 scb = &op->more_files[call->count - 2].scb;
1673 xdr_decode_YFSCallBack(&bp, call, scb);
1675 if (call->count < op->nr_files)
1678 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
1683 ret = afs_extract_data(call, false);
1688 xdr_decode_YFSVolSync(&bp, &op->volsync);
1697 _leave(" = 0 [done]");
1702 * FS.InlineBulkStatus operation type
1704 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
1705 .name = "YFS.InlineBulkStatus",
1706 .op = yfs_FS_InlineBulkStatus,
1707 .deliver = yfs_deliver_fs_inline_bulk_status,
1708 .destructor = afs_flat_call_destructor,
1712 * Fetch the status information for up to 1024 files
1714 void yfs_fs_inline_bulk_status(struct afs_operation *op)
1716 struct afs_vnode_param *dvp = &op->file[0];
1717 struct afs_vnode_param *vp = &op->file[1];
1718 struct afs_call *call;
1722 _enter(",%x,{%llx:%llu},%u",
1723 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1725 call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
1729 sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
1730 sizeof(struct yfs_xdr_YFSFetchStatus));
1732 return afs_op_nomem(op);
1734 /* marshall the parameters */
1736 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
1737 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
1738 bp = xdr_encode_u32(bp, op->nr_files);
1739 bp = xdr_encode_YFSFid(bp, &dvp->fid);
1740 bp = xdr_encode_YFSFid(bp, &vp->fid);
1741 for (i = 0; i < op->nr_files - 2; i++)
1742 bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
1743 yfs_check_req(call, bp);
1745 trace_afs_make_fs_call(call, &vp->fid);
1746 afs_make_op_call(op, call, GFP_NOFS);
1750 * Deliver reply data to an YFS.FetchOpaqueACL.
1752 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
1754 struct afs_operation *op = call->op;
1755 struct afs_vnode_param *vp = &op->file[0];
1756 struct yfs_acl *yacl = op->yacl;
1757 struct afs_acl *acl;
1762 _enter("{%u}", call->unmarshall);
1764 switch (call->unmarshall) {
1766 afs_extract_to_tmp(call);
1770 /* Extract the file ACL length */
1772 ret = afs_extract_data(call, true);
1776 size = call->count2 = ntohl(call->tmp);
1777 size = round_up(size, 4);
1779 if (yacl->flags & YFS_ACL_WANT_ACL) {
1780 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1784 acl->size = call->count2;
1785 afs_extract_begin(call, acl->data, size);
1787 afs_extract_discard(call, size);
1792 /* Extract the file ACL */
1794 ret = afs_extract_data(call, true);
1798 afs_extract_to_tmp(call);
1802 /* Extract the volume ACL length */
1804 ret = afs_extract_data(call, true);
1808 size = call->count2 = ntohl(call->tmp);
1809 size = round_up(size, 4);
1811 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
1812 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1815 yacl->vol_acl = acl;
1816 acl->size = call->count2;
1817 afs_extract_begin(call, acl->data, size);
1819 afs_extract_discard(call, size);
1824 /* Extract the volume ACL */
1826 ret = afs_extract_data(call, true);
1830 afs_extract_to_buf(call,
1831 sizeof(__be32) * 2 +
1832 sizeof(struct yfs_xdr_YFSFetchStatus) +
1833 sizeof(struct yfs_xdr_YFSVolSync));
1837 /* extract the metadata */
1839 ret = afs_extract_data(call, false);
1844 yacl->inherit_flag = ntohl(*bp++);
1845 yacl->num_cleaned = ntohl(*bp++);
1846 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1847 xdr_decode_YFSVolSync(&bp, &op->volsync);
1856 _leave(" = 0 [done]");
1860 void yfs_free_opaque_acl(struct yfs_acl *yacl)
1864 kfree(yacl->vol_acl);
1870 * YFS.FetchOpaqueACL operation type
1872 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
1873 .name = "YFS.FetchOpaqueACL",
1874 .op = yfs_FS_FetchOpaqueACL,
1875 .deliver = yfs_deliver_fs_fetch_opaque_acl,
1876 .destructor = afs_flat_call_destructor,
1880 * Fetch the YFS advanced ACLs for a file.
1882 void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
1884 struct afs_vnode_param *vp = &op->file[0];
1885 struct afs_call *call;
1888 _enter(",%x,{%llx:%llu},,",
1889 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1891 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
1892 sizeof(__be32) * 2 +
1893 sizeof(struct yfs_xdr_YFSFid),
1894 sizeof(__be32) * 2 +
1895 sizeof(struct yfs_xdr_YFSFetchStatus) +
1896 sizeof(struct yfs_xdr_YFSVolSync));
1898 return afs_op_nomem(op);
1900 /* marshall the parameters */
1902 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
1903 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1904 bp = xdr_encode_YFSFid(bp, &vp->fid);
1905 yfs_check_req(call, bp);
1907 trace_afs_make_fs_call(call, &vp->fid);
1908 afs_make_op_call(op, call, GFP_KERNEL);
1912 * YFS.StoreOpaqueACL2 operation type
1914 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
1915 .name = "YFS.StoreOpaqueACL2",
1916 .op = yfs_FS_StoreOpaqueACL2,
1917 .deliver = yfs_deliver_status_and_volsync,
1918 .destructor = afs_flat_call_destructor,
1922 * Fetch the YFS ACL for a file.
1924 void yfs_fs_store_opaque_acl2(struct afs_operation *op)
1926 struct afs_vnode_param *vp = &op->file[0];
1927 struct afs_call *call;
1928 struct afs_acl *acl = op->acl;
1932 _enter(",%x,{%llx:%llu},,",
1933 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1935 size = round_up(acl->size, 4);
1936 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
1937 sizeof(__be32) * 2 +
1938 sizeof(struct yfs_xdr_YFSFid) +
1939 sizeof(__be32) + size,
1940 sizeof(struct yfs_xdr_YFSFetchStatus) +
1941 sizeof(struct yfs_xdr_YFSVolSync));
1943 return afs_op_nomem(op);
1945 /* marshall the parameters */
1947 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
1948 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1949 bp = xdr_encode_YFSFid(bp, &vp->fid);
1950 bp = xdr_encode_u32(bp, acl->size);
1951 memcpy(bp, acl->data, acl->size);
1952 if (acl->size != size)
1953 memset((void *)bp + acl->size, 0, size - acl->size);
1954 bp += size / sizeof(__be32);
1955 yfs_check_req(call, bp);
1957 trace_afs_make_fs_call(call, &vp->fid);
1958 afs_make_op_call(op, call, GFP_KERNEL);