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 = call->reply_time;
236 cb_expiry = ktime_add(cb_expiry, xdr_to_u64(x->expiration_time) * 100);
237 cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
243 * Decode a YFSVolSync block
245 static void xdr_decode_YFSVolSync(const __be32 **_bp,
246 struct afs_volsync *volsync)
248 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
252 creation = xdr_to_u64(x->vol_creation_date);
253 do_div(creation, 10 * 1000 * 1000);
254 volsync->creation = creation;
261 * Encode the requested attributes into a YFSStoreStatus block
263 static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
265 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
266 s64 mtime = 0, owner = 0, group = 0;
267 u32 mask = 0, mode = 0;
270 if (attr->ia_valid & ATTR_MTIME) {
271 mask |= AFS_SET_MTIME;
272 mtime = linux_to_yfs_time(&attr->ia_mtime);
275 if (attr->ia_valid & ATTR_UID) {
276 mask |= AFS_SET_OWNER;
277 owner = from_kuid(&init_user_ns, attr->ia_uid);
280 if (attr->ia_valid & ATTR_GID) {
281 mask |= AFS_SET_GROUP;
282 group = from_kgid(&init_user_ns, attr->ia_gid);
285 if (attr->ia_valid & ATTR_MODE) {
286 mask |= AFS_SET_MODE;
287 mode = attr->ia_mode & S_IALLUGO;
290 x->mask = htonl(mask);
291 x->mode = htonl(mode);
292 x->mtime_client = u64_to_xdr(mtime);
293 x->owner = u64_to_xdr(owner);
294 x->group = u64_to_xdr(group);
295 return bp + xdr_size(x);
299 * Decode a YFSFetchVolumeStatus block.
301 static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
302 struct afs_volume_status *vs)
304 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
307 vs->vid = xdr_to_u64(x->vid);
308 vs->parent_id = xdr_to_u64(x->parent_id);
309 flags = ntohl(x->flags);
310 vs->online = flags & yfs_FVSOnline;
311 vs->in_service = flags & yfs_FVSInservice;
312 vs->blessed = flags & yfs_FVSBlessed;
313 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
314 vs->type = ntohl(x->type);
316 vs->max_quota = xdr_to_u64(x->max_quota);
317 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
318 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
319 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
320 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
321 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
322 *_bp += sizeof(*x) / sizeof(__be32);
326 * Deliver reply data to operations that just return a file status and a volume
329 static int yfs_deliver_status_and_volsync(struct afs_call *call)
331 struct afs_operation *op = call->op;
335 ret = afs_transfer_reply(call);
340 xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
341 xdr_decode_YFSVolSync(&bp, &op->volsync);
343 _leave(" = 0 [done]");
348 * Deliver reply data to an YFS.FetchData64.
350 static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
352 struct afs_operation *op = call->op;
353 struct afs_vnode_param *vp = &op->file[0];
354 struct afs_read *req = op->fetch.req;
358 _enter("{%u,%zu, %zu/%llu}",
359 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
362 switch (call->unmarshall) {
365 afs_extract_to_tmp64(call);
369 /* Extract the returned data length into ->actual_len. This
370 * may indicate more or less data than was requested will be
374 _debug("extract data length");
375 ret = afs_extract_data(call, true);
379 req->actual_len = be64_to_cpu(call->tmp64);
380 _debug("DATA length: %llu", req->actual_len);
382 if (req->actual_len == 0)
385 call->iter = req->iter;
386 call->iov_len = min(req->actual_len, req->len);
390 /* extract the returned data */
392 _debug("extract data %zu/%llu",
393 iov_iter_count(call->iter), req->actual_len);
395 ret = afs_extract_data(call, true);
399 call->iter = &call->def_iter;
400 if (req->actual_len <= req->len)
403 /* Discard any excess data the server gave us */
404 afs_extract_discard(call, req->actual_len - req->len);
405 call->unmarshall = 3;
409 _debug("extract discard %zu/%llu",
410 iov_iter_count(call->iter), req->actual_len - req->len);
412 ret = afs_extract_data(call, true);
417 call->unmarshall = 4;
418 afs_extract_to_buf(call,
419 sizeof(struct yfs_xdr_YFSFetchStatus) +
420 sizeof(struct yfs_xdr_YFSCallBack) +
421 sizeof(struct yfs_xdr_YFSVolSync));
424 /* extract the metadata */
426 ret = afs_extract_data(call, false);
431 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
432 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
433 xdr_decode_YFSVolSync(&bp, &op->volsync);
435 req->data_version = vp->scb.status.data_version;
436 req->file_size = vp->scb.status.size;
445 _leave(" = 0 [done]");
450 * YFS.FetchData64 operation type
452 static const struct afs_call_type yfs_RXYFSFetchData64 = {
453 .name = "YFS.FetchData64",
454 .op = yfs_FS_FetchData64,
455 .deliver = yfs_deliver_fs_fetch_data64,
456 .destructor = afs_flat_call_destructor,
460 * Fetch data from a file.
462 void yfs_fs_fetch_data(struct afs_operation *op)
464 struct afs_vnode_param *vp = &op->file[0];
465 struct afs_read *req = op->fetch.req;
466 struct afs_call *call;
469 _enter(",%x,{%llx:%llu},%llx,%llx",
470 key_serial(op->key), vp->fid.vid, vp->fid.vnode,
473 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
475 sizeof(struct yfs_xdr_YFSFid) +
476 sizeof(struct yfs_xdr_u64) * 2,
477 sizeof(struct yfs_xdr_YFSFetchStatus) +
478 sizeof(struct yfs_xdr_YFSCallBack) +
479 sizeof(struct yfs_xdr_YFSVolSync));
481 return afs_op_nomem(op);
483 req->call_debug_id = call->debug_id;
485 /* marshall the parameters */
487 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
488 bp = xdr_encode_u32(bp, 0); /* RPC flags */
489 bp = xdr_encode_YFSFid(bp, &vp->fid);
490 bp = xdr_encode_u64(bp, req->pos);
491 bp = xdr_encode_u64(bp, req->len);
492 yfs_check_req(call, bp);
494 trace_afs_make_fs_call(call, &vp->fid);
495 afs_make_op_call(op, call, GFP_NOFS);
499 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
501 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
503 struct afs_operation *op = call->op;
504 struct afs_vnode_param *dvp = &op->file[0];
505 struct afs_vnode_param *vp = &op->file[1];
509 _enter("{%u}", call->unmarshall);
511 ret = afs_transfer_reply(call);
515 /* unmarshall the reply once we've received all of it */
517 xdr_decode_YFSFid(&bp, &op->file[1].fid);
518 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
519 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
520 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
521 xdr_decode_YFSVolSync(&bp, &op->volsync);
523 _leave(" = 0 [done]");
528 * FS.CreateFile and FS.MakeDir operation type
530 static const struct afs_call_type afs_RXFSCreateFile = {
531 .name = "YFS.CreateFile",
532 .op = yfs_FS_CreateFile,
533 .deliver = yfs_deliver_fs_create_vnode,
534 .destructor = afs_flat_call_destructor,
540 void yfs_fs_create_file(struct afs_operation *op)
542 const struct qstr *name = &op->dentry->d_name;
543 struct afs_vnode_param *dvp = &op->file[0];
544 struct afs_call *call;
550 reqsz = (sizeof(__be32) +
552 sizeof(struct yfs_xdr_YFSFid) +
553 xdr_strlen(name->len) +
554 sizeof(struct yfs_xdr_YFSStoreStatus) +
556 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
557 sizeof(struct yfs_xdr_YFSFetchStatus) +
558 sizeof(struct yfs_xdr_YFSFetchStatus) +
559 sizeof(struct yfs_xdr_YFSCallBack) +
560 sizeof(struct yfs_xdr_YFSVolSync));
562 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
564 return afs_op_nomem(op);
566 /* marshall the parameters */
568 bp = xdr_encode_u32(bp, YFSCREATEFILE);
569 bp = xdr_encode_u32(bp, 0); /* RPC flags */
570 bp = xdr_encode_YFSFid(bp, &dvp->fid);
571 bp = xdr_encode_name(bp, name);
572 bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
573 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
574 yfs_check_req(call, bp);
576 trace_afs_make_fs_call1(call, &dvp->fid, name);
577 afs_make_op_call(op, call, GFP_NOFS);
580 static const struct afs_call_type yfs_RXFSMakeDir = {
581 .name = "YFS.MakeDir",
582 .op = yfs_FS_MakeDir,
583 .deliver = yfs_deliver_fs_create_vnode,
584 .destructor = afs_flat_call_destructor,
590 void yfs_fs_make_dir(struct afs_operation *op)
592 const struct qstr *name = &op->dentry->d_name;
593 struct afs_vnode_param *dvp = &op->file[0];
594 struct afs_call *call;
600 reqsz = (sizeof(__be32) +
601 sizeof(struct yfs_xdr_RPCFlags) +
602 sizeof(struct yfs_xdr_YFSFid) +
603 xdr_strlen(name->len) +
604 sizeof(struct yfs_xdr_YFSStoreStatus));
605 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
606 sizeof(struct yfs_xdr_YFSFetchStatus) +
607 sizeof(struct yfs_xdr_YFSFetchStatus) +
608 sizeof(struct yfs_xdr_YFSCallBack) +
609 sizeof(struct yfs_xdr_YFSVolSync));
611 call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
613 return afs_op_nomem(op);
615 /* marshall the parameters */
617 bp = xdr_encode_u32(bp, YFSMAKEDIR);
618 bp = xdr_encode_u32(bp, 0); /* RPC flags */
619 bp = xdr_encode_YFSFid(bp, &dvp->fid);
620 bp = xdr_encode_name(bp, name);
621 bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
622 yfs_check_req(call, bp);
624 trace_afs_make_fs_call1(call, &dvp->fid, name);
625 afs_make_op_call(op, call, GFP_NOFS);
629 * Deliver reply data to a YFS.RemoveFile2 operation.
631 static int yfs_deliver_fs_remove_file2(struct afs_call *call)
633 struct afs_operation *op = call->op;
634 struct afs_vnode_param *dvp = &op->file[0];
635 struct afs_vnode_param *vp = &op->file[1];
640 _enter("{%u}", call->unmarshall);
642 ret = afs_transfer_reply(call);
647 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
648 xdr_decode_YFSFid(&bp, &fid);
649 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
650 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
652 xdr_decode_YFSVolSync(&bp, &op->volsync);
656 static void yfs_done_fs_remove_file2(struct afs_call *call)
658 if (call->error == -ECONNABORTED &&
659 call->abort_code == RX_INVALID_OPERATION) {
660 set_bit(AFS_SERVER_FL_NO_RM2, &call->server->flags);
661 call->op->flags |= AFS_OPERATION_DOWNGRADE;
666 * YFS.RemoveFile2 operation type.
668 static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
669 .name = "YFS.RemoveFile2",
670 .op = yfs_FS_RemoveFile2,
671 .deliver = yfs_deliver_fs_remove_file2,
672 .done = yfs_done_fs_remove_file2,
673 .destructor = afs_flat_call_destructor,
677 * Remove a file and retrieve new file status.
679 void yfs_fs_remove_file2(struct afs_operation *op)
681 struct afs_vnode_param *dvp = &op->file[0];
682 const struct qstr *name = &op->dentry->d_name;
683 struct afs_call *call;
688 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
690 sizeof(struct yfs_xdr_RPCFlags) +
691 sizeof(struct yfs_xdr_YFSFid) +
692 xdr_strlen(name->len),
693 sizeof(struct yfs_xdr_YFSFetchStatus) +
694 sizeof(struct yfs_xdr_YFSFid) +
695 sizeof(struct yfs_xdr_YFSFetchStatus) +
696 sizeof(struct yfs_xdr_YFSVolSync));
698 return afs_op_nomem(op);
700 /* marshall the parameters */
702 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
703 bp = xdr_encode_u32(bp, 0); /* RPC flags */
704 bp = xdr_encode_YFSFid(bp, &dvp->fid);
705 bp = xdr_encode_name(bp, name);
706 yfs_check_req(call, bp);
708 trace_afs_make_fs_call1(call, &dvp->fid, name);
709 afs_make_op_call(op, call, GFP_NOFS);
713 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
715 static int yfs_deliver_fs_remove(struct afs_call *call)
717 struct afs_operation *op = call->op;
718 struct afs_vnode_param *dvp = &op->file[0];
722 _enter("{%u}", call->unmarshall);
724 ret = afs_transfer_reply(call);
729 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
730 xdr_decode_YFSVolSync(&bp, &op->volsync);
735 * FS.RemoveDir and FS.RemoveFile operation types.
737 static const struct afs_call_type yfs_RXYFSRemoveFile = {
738 .name = "YFS.RemoveFile",
739 .op = yfs_FS_RemoveFile,
740 .deliver = yfs_deliver_fs_remove,
741 .destructor = afs_flat_call_destructor,
747 void yfs_fs_remove_file(struct afs_operation *op)
749 const struct qstr *name = &op->dentry->d_name;
750 struct afs_vnode_param *dvp = &op->file[0];
751 struct afs_call *call;
756 if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
757 return yfs_fs_remove_file2(op);
759 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
761 sizeof(struct yfs_xdr_RPCFlags) +
762 sizeof(struct yfs_xdr_YFSFid) +
763 xdr_strlen(name->len),
764 sizeof(struct yfs_xdr_YFSFetchStatus) +
765 sizeof(struct yfs_xdr_YFSVolSync));
767 return afs_op_nomem(op);
769 /* marshall the parameters */
771 bp = xdr_encode_u32(bp, YFSREMOVEFILE);
772 bp = xdr_encode_u32(bp, 0); /* RPC flags */
773 bp = xdr_encode_YFSFid(bp, &dvp->fid);
774 bp = xdr_encode_name(bp, name);
775 yfs_check_req(call, bp);
777 trace_afs_make_fs_call1(call, &dvp->fid, name);
778 afs_make_op_call(op, call, GFP_NOFS);
781 static const struct afs_call_type yfs_RXYFSRemoveDir = {
782 .name = "YFS.RemoveDir",
783 .op = yfs_FS_RemoveDir,
784 .deliver = yfs_deliver_fs_remove,
785 .destructor = afs_flat_call_destructor,
789 * Remove a directory.
791 void yfs_fs_remove_dir(struct afs_operation *op)
793 const struct qstr *name = &op->dentry->d_name;
794 struct afs_vnode_param *dvp = &op->file[0];
795 struct afs_call *call;
800 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
802 sizeof(struct yfs_xdr_RPCFlags) +
803 sizeof(struct yfs_xdr_YFSFid) +
804 xdr_strlen(name->len),
805 sizeof(struct yfs_xdr_YFSFetchStatus) +
806 sizeof(struct yfs_xdr_YFSVolSync));
808 return afs_op_nomem(op);
810 /* marshall the parameters */
812 bp = xdr_encode_u32(bp, YFSREMOVEDIR);
813 bp = xdr_encode_u32(bp, 0); /* RPC flags */
814 bp = xdr_encode_YFSFid(bp, &dvp->fid);
815 bp = xdr_encode_name(bp, name);
816 yfs_check_req(call, bp);
818 trace_afs_make_fs_call1(call, &dvp->fid, name);
819 afs_make_op_call(op, call, GFP_NOFS);
823 * Deliver reply data to a YFS.Link operation.
825 static int yfs_deliver_fs_link(struct afs_call *call)
827 struct afs_operation *op = call->op;
828 struct afs_vnode_param *dvp = &op->file[0];
829 struct afs_vnode_param *vp = &op->file[1];
833 _enter("{%u}", call->unmarshall);
835 ret = afs_transfer_reply(call);
840 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
841 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
842 xdr_decode_YFSVolSync(&bp, &op->volsync);
843 _leave(" = 0 [done]");
848 * YFS.Link operation type.
850 static const struct afs_call_type yfs_RXYFSLink = {
853 .deliver = yfs_deliver_fs_link,
854 .destructor = afs_flat_call_destructor,
860 void yfs_fs_link(struct afs_operation *op)
862 const struct qstr *name = &op->dentry->d_name;
863 struct afs_vnode_param *dvp = &op->file[0];
864 struct afs_vnode_param *vp = &op->file[1];
865 struct afs_call *call;
870 call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
872 sizeof(struct yfs_xdr_RPCFlags) +
873 sizeof(struct yfs_xdr_YFSFid) +
874 xdr_strlen(name->len) +
875 sizeof(struct yfs_xdr_YFSFid),
876 sizeof(struct yfs_xdr_YFSFetchStatus) +
877 sizeof(struct yfs_xdr_YFSFetchStatus) +
878 sizeof(struct yfs_xdr_YFSVolSync));
880 return afs_op_nomem(op);
882 /* marshall the parameters */
884 bp = xdr_encode_u32(bp, YFSLINK);
885 bp = xdr_encode_u32(bp, 0); /* RPC flags */
886 bp = xdr_encode_YFSFid(bp, &dvp->fid);
887 bp = xdr_encode_name(bp, name);
888 bp = xdr_encode_YFSFid(bp, &vp->fid);
889 yfs_check_req(call, bp);
891 trace_afs_make_fs_call1(call, &vp->fid, name);
892 afs_make_op_call(op, call, GFP_NOFS);
896 * Deliver reply data to a YFS.Symlink operation.
898 static int yfs_deliver_fs_symlink(struct afs_call *call)
900 struct afs_operation *op = call->op;
901 struct afs_vnode_param *dvp = &op->file[0];
902 struct afs_vnode_param *vp = &op->file[1];
906 _enter("{%u}", call->unmarshall);
908 ret = afs_transfer_reply(call);
912 /* unmarshall the reply once we've received all of it */
914 xdr_decode_YFSFid(&bp, &vp->fid);
915 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
916 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
917 xdr_decode_YFSVolSync(&bp, &op->volsync);
919 _leave(" = 0 [done]");
924 * YFS.Symlink operation type
926 static const struct afs_call_type yfs_RXYFSSymlink = {
927 .name = "YFS.Symlink",
928 .op = yfs_FS_Symlink,
929 .deliver = yfs_deliver_fs_symlink,
930 .destructor = afs_flat_call_destructor,
934 * Create a symbolic link.
936 void yfs_fs_symlink(struct afs_operation *op)
938 const struct qstr *name = &op->dentry->d_name;
939 struct afs_vnode_param *dvp = &op->file[0];
940 struct afs_call *call;
947 contents_sz = strlen(op->create.symlink);
948 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
950 sizeof(struct yfs_xdr_RPCFlags) +
951 sizeof(struct yfs_xdr_YFSFid) +
952 xdr_strlen(name->len) +
953 xdr_strlen(contents_sz) +
954 sizeof(struct yfs_xdr_YFSStoreStatus),
955 sizeof(struct yfs_xdr_YFSFid) +
956 sizeof(struct yfs_xdr_YFSFetchStatus) +
957 sizeof(struct yfs_xdr_YFSFetchStatus) +
958 sizeof(struct yfs_xdr_YFSVolSync));
960 return afs_op_nomem(op);
962 /* marshall the parameters */
964 bp = xdr_encode_u32(bp, YFSSYMLINK);
965 bp = xdr_encode_u32(bp, 0); /* RPC flags */
966 bp = xdr_encode_YFSFid(bp, &dvp->fid);
967 bp = xdr_encode_name(bp, name);
968 bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
969 bp = xdr_encode_YFSStoreStatus(bp, &mode, &op->mtime);
970 yfs_check_req(call, bp);
972 trace_afs_make_fs_call1(call, &dvp->fid, name);
973 afs_make_op_call(op, call, GFP_NOFS);
977 * Deliver reply data to a YFS.Rename operation.
979 static int yfs_deliver_fs_rename(struct afs_call *call)
981 struct afs_operation *op = call->op;
982 struct afs_vnode_param *orig_dvp = &op->file[0];
983 struct afs_vnode_param *new_dvp = &op->file[1];
987 _enter("{%u}", call->unmarshall);
989 ret = afs_transfer_reply(call);
994 /* If the two dirs are the same, we have two copies of the same status
995 * report, so we just decode it twice.
997 xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
998 xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
999 xdr_decode_YFSVolSync(&bp, &op->volsync);
1000 _leave(" = 0 [done]");
1005 * YFS.Rename operation type
1007 static const struct afs_call_type yfs_RXYFSRename = {
1008 .name = "FS.Rename",
1009 .op = yfs_FS_Rename,
1010 .deliver = yfs_deliver_fs_rename,
1011 .destructor = afs_flat_call_destructor,
1015 * Rename a file or directory.
1017 void yfs_fs_rename(struct afs_operation *op)
1019 struct afs_vnode_param *orig_dvp = &op->file[0];
1020 struct afs_vnode_param *new_dvp = &op->file[1];
1021 const struct qstr *orig_name = &op->dentry->d_name;
1022 const struct qstr *new_name = &op->dentry_2->d_name;
1023 struct afs_call *call;
1028 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
1030 sizeof(struct yfs_xdr_RPCFlags) +
1031 sizeof(struct yfs_xdr_YFSFid) +
1032 xdr_strlen(orig_name->len) +
1033 sizeof(struct yfs_xdr_YFSFid) +
1034 xdr_strlen(new_name->len),
1035 sizeof(struct yfs_xdr_YFSFetchStatus) +
1036 sizeof(struct yfs_xdr_YFSFetchStatus) +
1037 sizeof(struct yfs_xdr_YFSVolSync));
1039 return afs_op_nomem(op);
1041 /* marshall the parameters */
1043 bp = xdr_encode_u32(bp, YFSRENAME);
1044 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1045 bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
1046 bp = xdr_encode_name(bp, orig_name);
1047 bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
1048 bp = xdr_encode_name(bp, new_name);
1049 yfs_check_req(call, bp);
1051 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1052 afs_make_op_call(op, call, GFP_NOFS);
1056 * YFS.StoreData64 operation type.
1058 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1059 .name = "YFS.StoreData64",
1060 .op = yfs_FS_StoreData64,
1061 .deliver = yfs_deliver_status_and_volsync,
1062 .destructor = afs_flat_call_destructor,
1066 * Store a set of pages to a large file.
1068 void yfs_fs_store_data(struct afs_operation *op)
1070 struct afs_vnode_param *vp = &op->file[0];
1071 struct afs_call *call;
1074 _enter(",%x,{%llx:%llu},,",
1075 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1077 _debug("size %llx, at %llx, i_size %llx",
1078 (unsigned long long)op->store.size,
1079 (unsigned long long)op->store.pos,
1080 (unsigned long long)op->store.i_size);
1082 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
1085 sizeof(struct yfs_xdr_YFSFid) +
1086 sizeof(struct yfs_xdr_YFSStoreStatus) +
1087 sizeof(struct yfs_xdr_u64) * 3,
1088 sizeof(struct yfs_xdr_YFSFetchStatus) +
1089 sizeof(struct yfs_xdr_YFSVolSync));
1091 return afs_op_nomem(op);
1093 call->write_iter = op->store.write_iter;
1095 /* marshall the parameters */
1097 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1098 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1099 bp = xdr_encode_YFSFid(bp, &vp->fid);
1100 bp = xdr_encode_YFSStoreStatus(bp, NULL, &op->mtime);
1101 bp = xdr_encode_u64(bp, op->store.pos);
1102 bp = xdr_encode_u64(bp, op->store.size);
1103 bp = xdr_encode_u64(bp, op->store.i_size);
1104 yfs_check_req(call, bp);
1106 trace_afs_make_fs_call(call, &vp->fid);
1107 afs_make_op_call(op, call, GFP_NOFS);
1111 * YFS.StoreStatus operation type
1113 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1114 .name = "YFS.StoreStatus",
1115 .op = yfs_FS_StoreStatus,
1116 .deliver = yfs_deliver_status_and_volsync,
1117 .destructor = afs_flat_call_destructor,
1120 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1121 .name = "YFS.StoreData64",
1122 .op = yfs_FS_StoreData64,
1123 .deliver = yfs_deliver_status_and_volsync,
1124 .destructor = afs_flat_call_destructor,
1128 * Set the attributes on a file, using YFS.StoreData64 rather than
1129 * YFS.StoreStatus so as to alter the file size also.
1131 static void yfs_fs_setattr_size(struct afs_operation *op)
1133 struct afs_vnode_param *vp = &op->file[0];
1134 struct afs_call *call;
1135 struct iattr *attr = op->setattr.attr;
1138 _enter(",%x,{%llx:%llu},,",
1139 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1141 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
1142 sizeof(__be32) * 2 +
1143 sizeof(struct yfs_xdr_YFSFid) +
1144 sizeof(struct yfs_xdr_YFSStoreStatus) +
1145 sizeof(struct yfs_xdr_u64) * 3,
1146 sizeof(struct yfs_xdr_YFSFetchStatus) +
1147 sizeof(struct yfs_xdr_YFSVolSync));
1149 return afs_op_nomem(op);
1151 /* marshall the parameters */
1153 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1154 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1155 bp = xdr_encode_YFSFid(bp, &vp->fid);
1156 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1157 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1158 bp = xdr_encode_u64(bp, 0); /* size of write */
1159 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1160 yfs_check_req(call, bp);
1162 trace_afs_make_fs_call(call, &vp->fid);
1163 afs_make_op_call(op, call, GFP_NOFS);
1167 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1168 * file size, and YFS.StoreStatus otherwise.
1170 void yfs_fs_setattr(struct afs_operation *op)
1172 struct afs_vnode_param *vp = &op->file[0];
1173 struct afs_call *call;
1174 struct iattr *attr = op->setattr.attr;
1177 if (attr->ia_valid & ATTR_SIZE)
1178 return yfs_fs_setattr_size(op);
1180 _enter(",%x,{%llx:%llu},,",
1181 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1183 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
1184 sizeof(__be32) * 2 +
1185 sizeof(struct yfs_xdr_YFSFid) +
1186 sizeof(struct yfs_xdr_YFSStoreStatus),
1187 sizeof(struct yfs_xdr_YFSFetchStatus) +
1188 sizeof(struct yfs_xdr_YFSVolSync));
1190 return afs_op_nomem(op);
1192 /* marshall the parameters */
1194 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1195 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1196 bp = xdr_encode_YFSFid(bp, &vp->fid);
1197 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1198 yfs_check_req(call, bp);
1200 trace_afs_make_fs_call(call, &vp->fid);
1201 afs_make_op_call(op, call, GFP_NOFS);
1205 * Deliver reply data to a YFS.GetVolumeStatus operation.
1207 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1209 struct afs_operation *op = call->op;
1215 _enter("{%u}", call->unmarshall);
1217 switch (call->unmarshall) {
1220 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1223 /* extract the returned status record */
1225 _debug("extract status");
1226 ret = afs_extract_data(call, true);
1231 xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1233 afs_extract_to_tmp(call);
1236 /* extract the volume name length */
1238 ret = afs_extract_data(call, true);
1242 call->count = ntohl(call->tmp);
1243 _debug("volname length: %u", call->count);
1244 if (call->count >= AFSNAMEMAX)
1245 return afs_protocol_error(call, afs_eproto_volname_len);
1246 size = (call->count + 3) & ~3; /* It's padded */
1247 afs_extract_to_buf(call, size);
1251 /* extract the volume name */
1253 _debug("extract volname");
1254 ret = afs_extract_data(call, true);
1260 _debug("volname '%s'", p);
1261 afs_extract_to_tmp(call);
1265 /* extract the offline message length */
1267 ret = afs_extract_data(call, true);
1271 call->count = ntohl(call->tmp);
1272 _debug("offline msg length: %u", call->count);
1273 if (call->count >= AFSNAMEMAX)
1274 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1275 size = (call->count + 3) & ~3; /* It's padded */
1276 afs_extract_to_buf(call, size);
1280 /* extract the offline message */
1282 _debug("extract offline");
1283 ret = afs_extract_data(call, true);
1289 _debug("offline '%s'", p);
1291 afs_extract_to_tmp(call);
1295 /* extract the message of the day length */
1297 ret = afs_extract_data(call, true);
1301 call->count = ntohl(call->tmp);
1302 _debug("motd length: %u", call->count);
1303 if (call->count >= AFSNAMEMAX)
1304 return afs_protocol_error(call, afs_eproto_motd_len);
1305 size = (call->count + 3) & ~3; /* It's padded */
1306 afs_extract_to_buf(call, size);
1310 /* extract the message of the day */
1312 _debug("extract motd");
1313 ret = afs_extract_data(call, false);
1319 _debug("motd '%s'", p);
1328 _leave(" = 0 [done]");
1333 * YFS.GetVolumeStatus operation type
1335 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1336 .name = "YFS.GetVolumeStatus",
1337 .op = yfs_FS_GetVolumeStatus,
1338 .deliver = yfs_deliver_fs_get_volume_status,
1339 .destructor = afs_flat_call_destructor,
1343 * fetch the status of a volume
1345 void yfs_fs_get_volume_status(struct afs_operation *op)
1347 struct afs_vnode_param *vp = &op->file[0];
1348 struct afs_call *call;
1353 call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
1354 sizeof(__be32) * 2 +
1355 sizeof(struct yfs_xdr_u64),
1357 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1361 return afs_op_nomem(op);
1363 /* marshall the parameters */
1365 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1366 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1367 bp = xdr_encode_u64(bp, vp->fid.vid);
1368 yfs_check_req(call, bp);
1370 trace_afs_make_fs_call(call, &vp->fid);
1371 afs_make_op_call(op, call, GFP_NOFS);
1375 * YFS.SetLock operation type
1377 static const struct afs_call_type yfs_RXYFSSetLock = {
1378 .name = "YFS.SetLock",
1379 .op = yfs_FS_SetLock,
1380 .deliver = yfs_deliver_status_and_volsync,
1381 .done = afs_lock_op_done,
1382 .destructor = afs_flat_call_destructor,
1386 * YFS.ExtendLock operation type
1388 static const struct afs_call_type yfs_RXYFSExtendLock = {
1389 .name = "YFS.ExtendLock",
1390 .op = yfs_FS_ExtendLock,
1391 .deliver = yfs_deliver_status_and_volsync,
1392 .done = afs_lock_op_done,
1393 .destructor = afs_flat_call_destructor,
1397 * YFS.ReleaseLock operation type
1399 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1400 .name = "YFS.ReleaseLock",
1401 .op = yfs_FS_ReleaseLock,
1402 .deliver = yfs_deliver_status_and_volsync,
1403 .destructor = afs_flat_call_destructor,
1407 * Set a lock on a file
1409 void yfs_fs_set_lock(struct afs_operation *op)
1411 struct afs_vnode_param *vp = &op->file[0];
1412 struct afs_call *call;
1417 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
1418 sizeof(__be32) * 2 +
1419 sizeof(struct yfs_xdr_YFSFid) +
1421 sizeof(struct yfs_xdr_YFSFetchStatus) +
1422 sizeof(struct yfs_xdr_YFSVolSync));
1424 return afs_op_nomem(op);
1426 /* marshall the parameters */
1428 bp = xdr_encode_u32(bp, YFSSETLOCK);
1429 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1430 bp = xdr_encode_YFSFid(bp, &vp->fid);
1431 bp = xdr_encode_u32(bp, op->lock.type);
1432 yfs_check_req(call, bp);
1434 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1435 afs_make_op_call(op, call, GFP_NOFS);
1439 * extend a lock on a file
1441 void yfs_fs_extend_lock(struct afs_operation *op)
1443 struct afs_vnode_param *vp = &op->file[0];
1444 struct afs_call *call;
1449 call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
1450 sizeof(__be32) * 2 +
1451 sizeof(struct yfs_xdr_YFSFid),
1452 sizeof(struct yfs_xdr_YFSFetchStatus) +
1453 sizeof(struct yfs_xdr_YFSVolSync));
1455 return afs_op_nomem(op);
1457 /* marshall the parameters */
1459 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1460 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1461 bp = xdr_encode_YFSFid(bp, &vp->fid);
1462 yfs_check_req(call, bp);
1464 trace_afs_make_fs_call(call, &vp->fid);
1465 afs_make_op_call(op, call, GFP_NOFS);
1469 * release a lock on a file
1471 void yfs_fs_release_lock(struct afs_operation *op)
1473 struct afs_vnode_param *vp = &op->file[0];
1474 struct afs_call *call;
1479 call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
1480 sizeof(__be32) * 2 +
1481 sizeof(struct yfs_xdr_YFSFid),
1482 sizeof(struct yfs_xdr_YFSFetchStatus) +
1483 sizeof(struct yfs_xdr_YFSVolSync));
1485 return afs_op_nomem(op);
1487 /* marshall the parameters */
1489 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1490 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1491 bp = xdr_encode_YFSFid(bp, &vp->fid);
1492 yfs_check_req(call, bp);
1494 trace_afs_make_fs_call(call, &vp->fid);
1495 afs_make_op_call(op, call, GFP_NOFS);
1499 * Deliver a reply to YFS.FetchStatus
1501 static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1503 struct afs_operation *op = call->op;
1504 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1508 ret = afs_transfer_reply(call);
1512 /* unmarshall the reply once we've received all of it */
1514 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1515 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
1516 xdr_decode_YFSVolSync(&bp, &op->volsync);
1518 _leave(" = 0 [done]");
1523 * YFS.FetchStatus operation type
1525 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1526 .name = "YFS.FetchStatus",
1527 .op = yfs_FS_FetchStatus,
1528 .deliver = yfs_deliver_fs_fetch_status,
1529 .destructor = afs_flat_call_destructor,
1533 * Fetch the status information for a fid without needing a vnode handle.
1535 void yfs_fs_fetch_status(struct afs_operation *op)
1537 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1538 struct afs_call *call;
1541 _enter(",%x,{%llx:%llu},,",
1542 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1544 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
1545 sizeof(__be32) * 2 +
1546 sizeof(struct yfs_xdr_YFSFid),
1547 sizeof(struct yfs_xdr_YFSFetchStatus) +
1548 sizeof(struct yfs_xdr_YFSCallBack) +
1549 sizeof(struct yfs_xdr_YFSVolSync));
1551 return afs_op_nomem(op);
1553 /* marshall the parameters */
1555 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
1556 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1557 bp = xdr_encode_YFSFid(bp, &vp->fid);
1558 yfs_check_req(call, bp);
1560 trace_afs_make_fs_call(call, &vp->fid);
1561 afs_make_op_call(op, call, GFP_NOFS);
1565 * Deliver reply data to an YFS.InlineBulkStatus call
1567 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
1569 struct afs_operation *op = call->op;
1570 struct afs_status_cb *scb;
1575 _enter("{%u}", call->unmarshall);
1577 switch (call->unmarshall) {
1579 afs_extract_to_tmp(call);
1583 /* Extract the file status count and array in two steps */
1585 _debug("extract status count");
1586 ret = afs_extract_data(call, true);
1590 tmp = ntohl(call->tmp);
1591 _debug("status count: %u/%u", tmp, op->nr_files);
1592 if (tmp != op->nr_files)
1593 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1598 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
1602 _debug("extract status array %u", call->count);
1603 ret = afs_extract_data(call, true);
1607 switch (call->count) {
1609 scb = &op->file[0].scb;
1612 scb = &op->file[1].scb;
1615 scb = &op->more_files[call->count - 2].scb;
1620 xdr_decode_YFSFetchStatus(&bp, call, scb);
1623 if (call->count < op->nr_files)
1628 afs_extract_to_tmp(call);
1631 /* Extract the callback count and array in two steps */
1633 _debug("extract CB count");
1634 ret = afs_extract_data(call, true);
1638 tmp = ntohl(call->tmp);
1639 _debug("CB count: %u", tmp);
1640 if (tmp != op->nr_files)
1641 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1645 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
1649 _debug("extract CB array");
1650 ret = afs_extract_data(call, true);
1654 _debug("unmarshall CB array");
1655 switch (call->count) {
1657 scb = &op->file[0].scb;
1660 scb = &op->file[1].scb;
1663 scb = &op->more_files[call->count - 2].scb;
1668 xdr_decode_YFSCallBack(&bp, call, scb);
1670 if (call->count < op->nr_files)
1673 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
1678 ret = afs_extract_data(call, false);
1683 xdr_decode_YFSVolSync(&bp, &op->volsync);
1692 _leave(" = 0 [done]");
1697 * FS.InlineBulkStatus operation type
1699 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
1700 .name = "YFS.InlineBulkStatus",
1701 .op = yfs_FS_InlineBulkStatus,
1702 .deliver = yfs_deliver_fs_inline_bulk_status,
1703 .destructor = afs_flat_call_destructor,
1707 * Fetch the status information for up to 1024 files
1709 void yfs_fs_inline_bulk_status(struct afs_operation *op)
1711 struct afs_vnode_param *dvp = &op->file[0];
1712 struct afs_vnode_param *vp = &op->file[1];
1713 struct afs_call *call;
1717 _enter(",%x,{%llx:%llu},%u",
1718 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1720 call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
1724 sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
1725 sizeof(struct yfs_xdr_YFSFetchStatus));
1727 return afs_op_nomem(op);
1729 /* marshall the parameters */
1731 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
1732 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
1733 bp = xdr_encode_u32(bp, op->nr_files);
1734 bp = xdr_encode_YFSFid(bp, &dvp->fid);
1735 bp = xdr_encode_YFSFid(bp, &vp->fid);
1736 for (i = 0; i < op->nr_files - 2; i++)
1737 bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
1738 yfs_check_req(call, bp);
1740 trace_afs_make_fs_call(call, &vp->fid);
1741 afs_make_op_call(op, call, GFP_NOFS);
1745 * Deliver reply data to an YFS.FetchOpaqueACL.
1747 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
1749 struct afs_operation *op = call->op;
1750 struct afs_vnode_param *vp = &op->file[0];
1751 struct yfs_acl *yacl = op->yacl;
1752 struct afs_acl *acl;
1757 _enter("{%u}", call->unmarshall);
1759 switch (call->unmarshall) {
1761 afs_extract_to_tmp(call);
1765 /* Extract the file ACL length */
1767 ret = afs_extract_data(call, true);
1771 size = call->count2 = ntohl(call->tmp);
1772 size = round_up(size, 4);
1774 if (yacl->flags & YFS_ACL_WANT_ACL) {
1775 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1779 acl->size = call->count2;
1780 afs_extract_begin(call, acl->data, size);
1782 afs_extract_discard(call, size);
1787 /* Extract the file ACL */
1789 ret = afs_extract_data(call, true);
1793 afs_extract_to_tmp(call);
1797 /* Extract the volume ACL length */
1799 ret = afs_extract_data(call, true);
1803 size = call->count2 = ntohl(call->tmp);
1804 size = round_up(size, 4);
1806 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
1807 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1810 yacl->vol_acl = acl;
1811 acl->size = call->count2;
1812 afs_extract_begin(call, acl->data, size);
1814 afs_extract_discard(call, size);
1819 /* Extract the volume ACL */
1821 ret = afs_extract_data(call, true);
1825 afs_extract_to_buf(call,
1826 sizeof(__be32) * 2 +
1827 sizeof(struct yfs_xdr_YFSFetchStatus) +
1828 sizeof(struct yfs_xdr_YFSVolSync));
1832 /* extract the metadata */
1834 ret = afs_extract_data(call, false);
1839 yacl->inherit_flag = ntohl(*bp++);
1840 yacl->num_cleaned = ntohl(*bp++);
1841 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1842 xdr_decode_YFSVolSync(&bp, &op->volsync);
1851 _leave(" = 0 [done]");
1855 void yfs_free_opaque_acl(struct yfs_acl *yacl)
1859 kfree(yacl->vol_acl);
1865 * YFS.FetchOpaqueACL operation type
1867 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
1868 .name = "YFS.FetchOpaqueACL",
1869 .op = yfs_FS_FetchOpaqueACL,
1870 .deliver = yfs_deliver_fs_fetch_opaque_acl,
1871 .destructor = afs_flat_call_destructor,
1875 * Fetch the YFS advanced ACLs for a file.
1877 void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
1879 struct afs_vnode_param *vp = &op->file[0];
1880 struct afs_call *call;
1883 _enter(",%x,{%llx:%llu},,",
1884 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1886 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
1887 sizeof(__be32) * 2 +
1888 sizeof(struct yfs_xdr_YFSFid),
1889 sizeof(__be32) * 2 +
1890 sizeof(struct yfs_xdr_YFSFetchStatus) +
1891 sizeof(struct yfs_xdr_YFSVolSync));
1893 return afs_op_nomem(op);
1895 /* marshall the parameters */
1897 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
1898 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1899 bp = xdr_encode_YFSFid(bp, &vp->fid);
1900 yfs_check_req(call, bp);
1902 trace_afs_make_fs_call(call, &vp->fid);
1903 afs_make_op_call(op, call, GFP_KERNEL);
1907 * YFS.StoreOpaqueACL2 operation type
1909 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
1910 .name = "YFS.StoreOpaqueACL2",
1911 .op = yfs_FS_StoreOpaqueACL2,
1912 .deliver = yfs_deliver_status_and_volsync,
1913 .destructor = afs_flat_call_destructor,
1917 * Fetch the YFS ACL for a file.
1919 void yfs_fs_store_opaque_acl2(struct afs_operation *op)
1921 struct afs_vnode_param *vp = &op->file[0];
1922 struct afs_call *call;
1923 struct afs_acl *acl = op->acl;
1927 _enter(",%x,{%llx:%llu},,",
1928 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1930 size = round_up(acl->size, 4);
1931 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
1932 sizeof(__be32) * 2 +
1933 sizeof(struct yfs_xdr_YFSFid) +
1934 sizeof(__be32) + size,
1935 sizeof(struct yfs_xdr_YFSFetchStatus) +
1936 sizeof(struct yfs_xdr_YFSVolSync));
1938 return afs_op_nomem(op);
1940 /* marshall the parameters */
1942 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
1943 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1944 bp = xdr_encode_YFSFid(bp, &vp->fid);
1945 bp = xdr_encode_u32(bp, acl->size);
1946 memcpy(bp, acl->data, acl->size);
1947 if (acl->size != size)
1948 memset((void *)bp + acl->size, 0, size - acl->size);
1949 bp += size / sizeof(__be32);
1950 yfs_check_req(call, bp);
1952 trace_afs_make_fs_call(call, &vp->fid);
1953 afs_make_op_call(op, call, GFP_KERNEL);