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;
365 _enter("{%u,%zu/%llu}",
366 call->unmarshall, iov_iter_count(call->iter), req->actual_len);
368 switch (call->unmarshall) {
372 req->offset = req->pos & (PAGE_SIZE - 1);
373 afs_extract_to_tmp64(call);
377 /* extract the returned data length */
379 _debug("extract data length");
380 ret = afs_extract_data(call, true);
384 req->actual_len = be64_to_cpu(call->tmp64);
385 _debug("DATA length: %llu", req->actual_len);
386 req->remain = min(req->len, req->actual_len);
387 if (req->remain == 0)
393 ASSERTCMP(req->index, <, req->nr_pages);
394 if (req->remain > PAGE_SIZE - req->offset)
395 size = PAGE_SIZE - req->offset;
398 call->bvec[0].bv_len = size;
399 call->bvec[0].bv_offset = req->offset;
400 call->bvec[0].bv_page = req->pages[req->index];
401 iov_iter_bvec(&call->def_iter, READ, call->bvec, 1, size);
402 ASSERTCMP(size, <=, PAGE_SIZE);
405 /* extract the returned data */
407 _debug("extract data %zu/%llu",
408 iov_iter_count(call->iter), req->remain);
410 ret = afs_extract_data(call, true);
413 req->remain -= call->bvec[0].bv_len;
414 req->offset += call->bvec[0].bv_len;
415 ASSERTCMP(req->offset, <=, PAGE_SIZE);
416 if (req->offset == PAGE_SIZE) {
423 ASSERTCMP(req->remain, ==, 0);
424 if (req->actual_len <= req->len)
427 /* Discard any excess data the server gave us */
428 afs_extract_discard(call, req->actual_len - req->len);
429 call->unmarshall = 3;
433 _debug("extract discard %zu/%llu",
434 iov_iter_count(call->iter), req->actual_len - req->len);
436 ret = afs_extract_data(call, true);
441 call->unmarshall = 4;
442 afs_extract_to_buf(call,
443 sizeof(struct yfs_xdr_YFSFetchStatus) +
444 sizeof(struct yfs_xdr_YFSCallBack) +
445 sizeof(struct yfs_xdr_YFSVolSync));
448 /* extract the metadata */
450 ret = afs_extract_data(call, false);
455 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
456 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
457 xdr_decode_YFSVolSync(&bp, &op->volsync);
459 req->data_version = vp->scb.status.data_version;
460 req->file_size = vp->scb.status.size;
469 for (; req->index < req->nr_pages; req->index++) {
470 if (req->offset < PAGE_SIZE)
471 zero_user_segment(req->pages[req->index],
472 req->offset, PAGE_SIZE);
477 for (req->index = 0; req->index < req->nr_pages; req->index++)
480 _leave(" = 0 [done]");
485 * YFS.FetchData64 operation type
487 static const struct afs_call_type yfs_RXYFSFetchData64 = {
488 .name = "YFS.FetchData64",
489 .op = yfs_FS_FetchData64,
490 .deliver = yfs_deliver_fs_fetch_data64,
491 .destructor = afs_flat_call_destructor,
495 * Fetch data from a file.
497 void yfs_fs_fetch_data(struct afs_operation *op)
499 struct afs_vnode_param *vp = &op->file[0];
500 struct afs_read *req = op->fetch.req;
501 struct afs_call *call;
504 _enter(",%x,{%llx:%llu},%llx,%llx",
505 key_serial(op->key), vp->fid.vid, vp->fid.vnode,
508 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
510 sizeof(struct yfs_xdr_YFSFid) +
511 sizeof(struct yfs_xdr_u64) * 2,
512 sizeof(struct yfs_xdr_YFSFetchStatus) +
513 sizeof(struct yfs_xdr_YFSCallBack) +
514 sizeof(struct yfs_xdr_YFSVolSync));
516 return afs_op_nomem(op);
518 /* marshall the parameters */
520 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
521 bp = xdr_encode_u32(bp, 0); /* RPC flags */
522 bp = xdr_encode_YFSFid(bp, &vp->fid);
523 bp = xdr_encode_u64(bp, req->pos);
524 bp = xdr_encode_u64(bp, req->len);
525 yfs_check_req(call, bp);
527 trace_afs_make_fs_call(call, &vp->fid);
528 afs_make_op_call(op, call, GFP_NOFS);
532 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
534 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
536 struct afs_operation *op = call->op;
537 struct afs_vnode_param *dvp = &op->file[0];
538 struct afs_vnode_param *vp = &op->file[1];
542 _enter("{%u}", call->unmarshall);
544 ret = afs_transfer_reply(call);
548 /* unmarshall the reply once we've received all of it */
550 xdr_decode_YFSFid(&bp, &op->file[1].fid);
551 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
552 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
553 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
554 xdr_decode_YFSVolSync(&bp, &op->volsync);
556 _leave(" = 0 [done]");
561 * FS.CreateFile and FS.MakeDir operation type
563 static const struct afs_call_type afs_RXFSCreateFile = {
564 .name = "YFS.CreateFile",
565 .op = yfs_FS_CreateFile,
566 .deliver = yfs_deliver_fs_create_vnode,
567 .destructor = afs_flat_call_destructor,
573 void yfs_fs_create_file(struct afs_operation *op)
575 const struct qstr *name = &op->dentry->d_name;
576 struct afs_vnode_param *dvp = &op->file[0];
577 struct afs_call *call;
583 reqsz = (sizeof(__be32) +
585 sizeof(struct yfs_xdr_YFSFid) +
586 xdr_strlen(name->len) +
587 sizeof(struct yfs_xdr_YFSStoreStatus) +
589 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
590 sizeof(struct yfs_xdr_YFSFetchStatus) +
591 sizeof(struct yfs_xdr_YFSFetchStatus) +
592 sizeof(struct yfs_xdr_YFSCallBack) +
593 sizeof(struct yfs_xdr_YFSVolSync));
595 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
597 return afs_op_nomem(op);
599 /* marshall the parameters */
601 bp = xdr_encode_u32(bp, YFSCREATEFILE);
602 bp = xdr_encode_u32(bp, 0); /* RPC flags */
603 bp = xdr_encode_YFSFid(bp, &dvp->fid);
604 bp = xdr_encode_name(bp, name);
605 bp = xdr_encode_YFSStoreStatus_mode(bp, op->create.mode);
606 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
607 yfs_check_req(call, bp);
609 trace_afs_make_fs_call1(call, &dvp->fid, name);
610 afs_make_op_call(op, call, GFP_NOFS);
613 static const struct afs_call_type yfs_RXFSMakeDir = {
614 .name = "YFS.MakeDir",
615 .op = yfs_FS_MakeDir,
616 .deliver = yfs_deliver_fs_create_vnode,
617 .destructor = afs_flat_call_destructor,
623 void yfs_fs_make_dir(struct afs_operation *op)
625 const struct qstr *name = &op->dentry->d_name;
626 struct afs_vnode_param *dvp = &op->file[0];
627 struct afs_call *call;
633 reqsz = (sizeof(__be32) +
634 sizeof(struct yfs_xdr_RPCFlags) +
635 sizeof(struct yfs_xdr_YFSFid) +
636 xdr_strlen(name->len) +
637 sizeof(struct yfs_xdr_YFSStoreStatus));
638 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
639 sizeof(struct yfs_xdr_YFSFetchStatus) +
640 sizeof(struct yfs_xdr_YFSFetchStatus) +
641 sizeof(struct yfs_xdr_YFSCallBack) +
642 sizeof(struct yfs_xdr_YFSVolSync));
644 call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
646 return afs_op_nomem(op);
648 /* marshall the parameters */
650 bp = xdr_encode_u32(bp, YFSMAKEDIR);
651 bp = xdr_encode_u32(bp, 0); /* RPC flags */
652 bp = xdr_encode_YFSFid(bp, &dvp->fid);
653 bp = xdr_encode_name(bp, name);
654 bp = xdr_encode_YFSStoreStatus_mode(bp, op->create.mode);
655 yfs_check_req(call, bp);
657 trace_afs_make_fs_call1(call, &dvp->fid, name);
658 afs_make_op_call(op, call, GFP_NOFS);
662 * Deliver reply data to a YFS.RemoveFile2 operation.
664 static int yfs_deliver_fs_remove_file2(struct afs_call *call)
666 struct afs_operation *op = call->op;
667 struct afs_vnode_param *dvp = &op->file[0];
668 struct afs_vnode_param *vp = &op->file[1];
673 _enter("{%u}", call->unmarshall);
675 ret = afs_transfer_reply(call);
680 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
681 xdr_decode_YFSFid(&bp, &fid);
682 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
683 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
685 xdr_decode_YFSVolSync(&bp, &op->volsync);
689 static void yfs_done_fs_remove_file2(struct afs_call *call)
691 if (call->error == -ECONNABORTED &&
692 call->abort_code == RX_INVALID_OPERATION) {
693 set_bit(AFS_SERVER_FL_NO_RM2, &call->server->flags);
694 call->op->flags |= AFS_OPERATION_DOWNGRADE;
699 * YFS.RemoveFile2 operation type.
701 static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
702 .name = "YFS.RemoveFile2",
703 .op = yfs_FS_RemoveFile2,
704 .deliver = yfs_deliver_fs_remove_file2,
705 .done = yfs_done_fs_remove_file2,
706 .destructor = afs_flat_call_destructor,
710 * Remove a file and retrieve new file status.
712 void yfs_fs_remove_file2(struct afs_operation *op)
714 struct afs_vnode_param *dvp = &op->file[0];
715 const struct qstr *name = &op->dentry->d_name;
716 struct afs_call *call;
721 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
723 sizeof(struct yfs_xdr_RPCFlags) +
724 sizeof(struct yfs_xdr_YFSFid) +
725 xdr_strlen(name->len),
726 sizeof(struct yfs_xdr_YFSFetchStatus) +
727 sizeof(struct yfs_xdr_YFSFid) +
728 sizeof(struct yfs_xdr_YFSFetchStatus) +
729 sizeof(struct yfs_xdr_YFSVolSync));
731 return afs_op_nomem(op);
733 /* marshall the parameters */
735 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
736 bp = xdr_encode_u32(bp, 0); /* RPC flags */
737 bp = xdr_encode_YFSFid(bp, &dvp->fid);
738 bp = xdr_encode_name(bp, name);
739 yfs_check_req(call, bp);
741 trace_afs_make_fs_call1(call, &dvp->fid, name);
742 afs_make_op_call(op, call, GFP_NOFS);
746 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
748 static int yfs_deliver_fs_remove(struct afs_call *call)
750 struct afs_operation *op = call->op;
751 struct afs_vnode_param *dvp = &op->file[0];
755 _enter("{%u}", call->unmarshall);
757 ret = afs_transfer_reply(call);
762 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
763 xdr_decode_YFSVolSync(&bp, &op->volsync);
768 * FS.RemoveDir and FS.RemoveFile operation types.
770 static const struct afs_call_type yfs_RXYFSRemoveFile = {
771 .name = "YFS.RemoveFile",
772 .op = yfs_FS_RemoveFile,
773 .deliver = yfs_deliver_fs_remove,
774 .destructor = afs_flat_call_destructor,
780 void yfs_fs_remove_file(struct afs_operation *op)
782 const struct qstr *name = &op->dentry->d_name;
783 struct afs_vnode_param *dvp = &op->file[0];
784 struct afs_call *call;
789 if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
790 return yfs_fs_remove_file2(op);
792 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
794 sizeof(struct yfs_xdr_RPCFlags) +
795 sizeof(struct yfs_xdr_YFSFid) +
796 xdr_strlen(name->len),
797 sizeof(struct yfs_xdr_YFSFetchStatus) +
798 sizeof(struct yfs_xdr_YFSVolSync));
800 return afs_op_nomem(op);
802 /* marshall the parameters */
804 bp = xdr_encode_u32(bp, YFSREMOVEFILE);
805 bp = xdr_encode_u32(bp, 0); /* RPC flags */
806 bp = xdr_encode_YFSFid(bp, &dvp->fid);
807 bp = xdr_encode_name(bp, name);
808 yfs_check_req(call, bp);
810 trace_afs_make_fs_call1(call, &dvp->fid, name);
811 afs_make_op_call(op, call, GFP_NOFS);
814 static const struct afs_call_type yfs_RXYFSRemoveDir = {
815 .name = "YFS.RemoveDir",
816 .op = yfs_FS_RemoveDir,
817 .deliver = yfs_deliver_fs_remove,
818 .destructor = afs_flat_call_destructor,
822 * Remove a directory.
824 void yfs_fs_remove_dir(struct afs_operation *op)
826 const struct qstr *name = &op->dentry->d_name;
827 struct afs_vnode_param *dvp = &op->file[0];
828 struct afs_call *call;
833 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
835 sizeof(struct yfs_xdr_RPCFlags) +
836 sizeof(struct yfs_xdr_YFSFid) +
837 xdr_strlen(name->len),
838 sizeof(struct yfs_xdr_YFSFetchStatus) +
839 sizeof(struct yfs_xdr_YFSVolSync));
841 return afs_op_nomem(op);
843 /* marshall the parameters */
845 bp = xdr_encode_u32(bp, YFSREMOVEDIR);
846 bp = xdr_encode_u32(bp, 0); /* RPC flags */
847 bp = xdr_encode_YFSFid(bp, &dvp->fid);
848 bp = xdr_encode_name(bp, name);
849 yfs_check_req(call, bp);
851 trace_afs_make_fs_call1(call, &dvp->fid, name);
852 afs_make_op_call(op, call, GFP_NOFS);
856 * Deliver reply data to a YFS.Link operation.
858 static int yfs_deliver_fs_link(struct afs_call *call)
860 struct afs_operation *op = call->op;
861 struct afs_vnode_param *dvp = &op->file[0];
862 struct afs_vnode_param *vp = &op->file[1];
866 _enter("{%u}", call->unmarshall);
868 ret = afs_transfer_reply(call);
873 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
874 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
875 xdr_decode_YFSVolSync(&bp, &op->volsync);
876 _leave(" = 0 [done]");
881 * YFS.Link operation type.
883 static const struct afs_call_type yfs_RXYFSLink = {
886 .deliver = yfs_deliver_fs_link,
887 .destructor = afs_flat_call_destructor,
893 void yfs_fs_link(struct afs_operation *op)
895 const struct qstr *name = &op->dentry->d_name;
896 struct afs_vnode_param *dvp = &op->file[0];
897 struct afs_vnode_param *vp = &op->file[1];
898 struct afs_call *call;
903 call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
905 sizeof(struct yfs_xdr_RPCFlags) +
906 sizeof(struct yfs_xdr_YFSFid) +
907 xdr_strlen(name->len) +
908 sizeof(struct yfs_xdr_YFSFid),
909 sizeof(struct yfs_xdr_YFSFetchStatus) +
910 sizeof(struct yfs_xdr_YFSFetchStatus) +
911 sizeof(struct yfs_xdr_YFSVolSync));
913 return afs_op_nomem(op);
915 /* marshall the parameters */
917 bp = xdr_encode_u32(bp, YFSLINK);
918 bp = xdr_encode_u32(bp, 0); /* RPC flags */
919 bp = xdr_encode_YFSFid(bp, &dvp->fid);
920 bp = xdr_encode_name(bp, name);
921 bp = xdr_encode_YFSFid(bp, &vp->fid);
922 yfs_check_req(call, bp);
924 trace_afs_make_fs_call1(call, &vp->fid, name);
925 afs_make_op_call(op, call, GFP_NOFS);
929 * Deliver reply data to a YFS.Symlink operation.
931 static int yfs_deliver_fs_symlink(struct afs_call *call)
933 struct afs_operation *op = call->op;
934 struct afs_vnode_param *dvp = &op->file[0];
935 struct afs_vnode_param *vp = &op->file[1];
939 _enter("{%u}", call->unmarshall);
941 ret = afs_transfer_reply(call);
945 /* unmarshall the reply once we've received all of it */
947 xdr_decode_YFSFid(&bp, &vp->fid);
948 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
949 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
950 xdr_decode_YFSVolSync(&bp, &op->volsync);
952 _leave(" = 0 [done]");
957 * YFS.Symlink operation type
959 static const struct afs_call_type yfs_RXYFSSymlink = {
960 .name = "YFS.Symlink",
961 .op = yfs_FS_Symlink,
962 .deliver = yfs_deliver_fs_symlink,
963 .destructor = afs_flat_call_destructor,
967 * Create a symbolic link.
969 void yfs_fs_symlink(struct afs_operation *op)
971 const struct qstr *name = &op->dentry->d_name;
972 struct afs_vnode_param *dvp = &op->file[0];
973 struct afs_call *call;
979 contents_sz = strlen(op->create.symlink);
980 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
982 sizeof(struct yfs_xdr_RPCFlags) +
983 sizeof(struct yfs_xdr_YFSFid) +
984 xdr_strlen(name->len) +
985 xdr_strlen(contents_sz) +
986 sizeof(struct yfs_xdr_YFSStoreStatus),
987 sizeof(struct yfs_xdr_YFSFid) +
988 sizeof(struct yfs_xdr_YFSFetchStatus) +
989 sizeof(struct yfs_xdr_YFSFetchStatus) +
990 sizeof(struct yfs_xdr_YFSVolSync));
992 return afs_op_nomem(op);
994 /* marshall the parameters */
996 bp = xdr_encode_u32(bp, YFSSYMLINK);
997 bp = xdr_encode_u32(bp, 0); /* RPC flags */
998 bp = xdr_encode_YFSFid(bp, &dvp->fid);
999 bp = xdr_encode_name(bp, name);
1000 bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
1001 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
1002 yfs_check_req(call, bp);
1004 trace_afs_make_fs_call1(call, &dvp->fid, name);
1005 afs_make_op_call(op, call, GFP_NOFS);
1009 * Deliver reply data to a YFS.Rename operation.
1011 static int yfs_deliver_fs_rename(struct afs_call *call)
1013 struct afs_operation *op = call->op;
1014 struct afs_vnode_param *orig_dvp = &op->file[0];
1015 struct afs_vnode_param *new_dvp = &op->file[1];
1019 _enter("{%u}", call->unmarshall);
1021 ret = afs_transfer_reply(call);
1026 /* If the two dirs are the same, we have two copies of the same status
1027 * report, so we just decode it twice.
1029 xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
1030 xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
1031 xdr_decode_YFSVolSync(&bp, &op->volsync);
1032 _leave(" = 0 [done]");
1037 * YFS.Rename operation type
1039 static const struct afs_call_type yfs_RXYFSRename = {
1040 .name = "FS.Rename",
1041 .op = yfs_FS_Rename,
1042 .deliver = yfs_deliver_fs_rename,
1043 .destructor = afs_flat_call_destructor,
1047 * Rename a file or directory.
1049 void yfs_fs_rename(struct afs_operation *op)
1051 struct afs_vnode_param *orig_dvp = &op->file[0];
1052 struct afs_vnode_param *new_dvp = &op->file[1];
1053 const struct qstr *orig_name = &op->dentry->d_name;
1054 const struct qstr *new_name = &op->dentry_2->d_name;
1055 struct afs_call *call;
1060 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
1062 sizeof(struct yfs_xdr_RPCFlags) +
1063 sizeof(struct yfs_xdr_YFSFid) +
1064 xdr_strlen(orig_name->len) +
1065 sizeof(struct yfs_xdr_YFSFid) +
1066 xdr_strlen(new_name->len),
1067 sizeof(struct yfs_xdr_YFSFetchStatus) +
1068 sizeof(struct yfs_xdr_YFSFetchStatus) +
1069 sizeof(struct yfs_xdr_YFSVolSync));
1071 return afs_op_nomem(op);
1073 /* marshall the parameters */
1075 bp = xdr_encode_u32(bp, YFSRENAME);
1076 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1077 bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
1078 bp = xdr_encode_name(bp, orig_name);
1079 bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
1080 bp = xdr_encode_name(bp, new_name);
1081 yfs_check_req(call, bp);
1083 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1084 afs_make_op_call(op, call, GFP_NOFS);
1088 * YFS.StoreData64 operation type.
1090 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1091 .name = "YFS.StoreData64",
1092 .op = yfs_FS_StoreData64,
1093 .deliver = yfs_deliver_status_and_volsync,
1094 .destructor = afs_flat_call_destructor,
1098 * Store a set of pages to a large file.
1100 void yfs_fs_store_data(struct afs_operation *op)
1102 struct afs_vnode_param *vp = &op->file[0];
1103 struct afs_call *call;
1104 loff_t size, pos, i_size;
1107 _enter(",%x,{%llx:%llu},,",
1108 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1110 size = (loff_t)op->store.last_to - (loff_t)op->store.first_offset;
1111 if (op->store.first != op->store.last)
1112 size += (loff_t)(op->store.last - op->store.first) << PAGE_SHIFT;
1113 pos = (loff_t)op->store.first << PAGE_SHIFT;
1114 pos += op->store.first_offset;
1116 i_size = i_size_read(&vp->vnode->vfs_inode);
1117 if (pos + size > i_size)
1118 i_size = size + pos;
1120 _debug("size %llx, at %llx, i_size %llx",
1121 (unsigned long long)size, (unsigned long long)pos,
1122 (unsigned long long)i_size);
1124 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
1127 sizeof(struct yfs_xdr_YFSFid) +
1128 sizeof(struct yfs_xdr_YFSStoreStatus) +
1129 sizeof(struct yfs_xdr_u64) * 3,
1130 sizeof(struct yfs_xdr_YFSFetchStatus) +
1131 sizeof(struct yfs_xdr_YFSVolSync));
1133 return afs_op_nomem(op);
1135 call->key = op->key;
1136 call->send_pages = true;
1138 /* marshall the parameters */
1140 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1141 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1142 bp = xdr_encode_YFSFid(bp, &vp->fid);
1143 bp = xdr_encode_YFSStoreStatus_mtime(bp, &op->mtime);
1144 bp = xdr_encode_u64(bp, pos);
1145 bp = xdr_encode_u64(bp, size);
1146 bp = xdr_encode_u64(bp, i_size);
1147 yfs_check_req(call, bp);
1149 trace_afs_make_fs_call(call, &vp->fid);
1150 afs_make_op_call(op, call, GFP_NOFS);
1154 * YFS.StoreStatus operation type
1156 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1157 .name = "YFS.StoreStatus",
1158 .op = yfs_FS_StoreStatus,
1159 .deliver = yfs_deliver_status_and_volsync,
1160 .destructor = afs_flat_call_destructor,
1163 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1164 .name = "YFS.StoreData64",
1165 .op = yfs_FS_StoreData64,
1166 .deliver = yfs_deliver_status_and_volsync,
1167 .destructor = afs_flat_call_destructor,
1171 * Set the attributes on a file, using YFS.StoreData64 rather than
1172 * YFS.StoreStatus so as to alter the file size also.
1174 static void yfs_fs_setattr_size(struct afs_operation *op)
1176 struct afs_vnode_param *vp = &op->file[0];
1177 struct afs_call *call;
1178 struct iattr *attr = op->setattr.attr;
1181 _enter(",%x,{%llx:%llu},,",
1182 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1184 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
1185 sizeof(__be32) * 2 +
1186 sizeof(struct yfs_xdr_YFSFid) +
1187 sizeof(struct yfs_xdr_YFSStoreStatus) +
1188 sizeof(struct yfs_xdr_u64) * 3,
1189 sizeof(struct yfs_xdr_YFSFetchStatus) +
1190 sizeof(struct yfs_xdr_YFSVolSync));
1192 return afs_op_nomem(op);
1194 /* marshall the parameters */
1196 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1197 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1198 bp = xdr_encode_YFSFid(bp, &vp->fid);
1199 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1200 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1201 bp = xdr_encode_u64(bp, 0); /* size of write */
1202 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
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 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1211 * file size, and YFS.StoreStatus otherwise.
1213 void yfs_fs_setattr(struct afs_operation *op)
1215 struct afs_vnode_param *vp = &op->file[0];
1216 struct afs_call *call;
1217 struct iattr *attr = op->setattr.attr;
1220 if (attr->ia_valid & ATTR_SIZE)
1221 return yfs_fs_setattr_size(op);
1223 _enter(",%x,{%llx:%llu},,",
1224 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1226 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
1227 sizeof(__be32) * 2 +
1228 sizeof(struct yfs_xdr_YFSFid) +
1229 sizeof(struct yfs_xdr_YFSStoreStatus),
1230 sizeof(struct yfs_xdr_YFSFetchStatus) +
1231 sizeof(struct yfs_xdr_YFSVolSync));
1233 return afs_op_nomem(op);
1235 /* marshall the parameters */
1237 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1238 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1239 bp = xdr_encode_YFSFid(bp, &vp->fid);
1240 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1241 yfs_check_req(call, bp);
1243 trace_afs_make_fs_call(call, &vp->fid);
1244 afs_make_op_call(op, call, GFP_NOFS);
1248 * Deliver reply data to a YFS.GetVolumeStatus operation.
1250 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1252 struct afs_operation *op = call->op;
1258 _enter("{%u}", call->unmarshall);
1260 switch (call->unmarshall) {
1263 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1266 /* extract the returned status record */
1268 _debug("extract status");
1269 ret = afs_extract_data(call, true);
1274 xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1276 afs_extract_to_tmp(call);
1279 /* extract the volume name length */
1281 ret = afs_extract_data(call, true);
1285 call->count = ntohl(call->tmp);
1286 _debug("volname length: %u", call->count);
1287 if (call->count >= AFSNAMEMAX)
1288 return afs_protocol_error(call, afs_eproto_volname_len);
1289 size = (call->count + 3) & ~3; /* It's padded */
1290 afs_extract_to_buf(call, size);
1294 /* extract the volume name */
1296 _debug("extract volname");
1297 ret = afs_extract_data(call, true);
1303 _debug("volname '%s'", p);
1304 afs_extract_to_tmp(call);
1308 /* extract the offline message length */
1310 ret = afs_extract_data(call, true);
1314 call->count = ntohl(call->tmp);
1315 _debug("offline msg length: %u", call->count);
1316 if (call->count >= AFSNAMEMAX)
1317 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1318 size = (call->count + 3) & ~3; /* It's padded */
1319 afs_extract_to_buf(call, size);
1323 /* extract the offline message */
1325 _debug("extract offline");
1326 ret = afs_extract_data(call, true);
1332 _debug("offline '%s'", p);
1334 afs_extract_to_tmp(call);
1338 /* extract the message of the day length */
1340 ret = afs_extract_data(call, true);
1344 call->count = ntohl(call->tmp);
1345 _debug("motd length: %u", call->count);
1346 if (call->count >= AFSNAMEMAX)
1347 return afs_protocol_error(call, afs_eproto_motd_len);
1348 size = (call->count + 3) & ~3; /* It's padded */
1349 afs_extract_to_buf(call, size);
1353 /* extract the message of the day */
1355 _debug("extract motd");
1356 ret = afs_extract_data(call, false);
1362 _debug("motd '%s'", p);
1371 _leave(" = 0 [done]");
1376 * YFS.GetVolumeStatus operation type
1378 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1379 .name = "YFS.GetVolumeStatus",
1380 .op = yfs_FS_GetVolumeStatus,
1381 .deliver = yfs_deliver_fs_get_volume_status,
1382 .destructor = afs_flat_call_destructor,
1386 * fetch the status of a volume
1388 void yfs_fs_get_volume_status(struct afs_operation *op)
1390 struct afs_vnode_param *vp = &op->file[0];
1391 struct afs_call *call;
1396 call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
1397 sizeof(__be32) * 2 +
1398 sizeof(struct yfs_xdr_u64),
1400 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1404 return afs_op_nomem(op);
1406 /* marshall the parameters */
1408 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1409 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1410 bp = xdr_encode_u64(bp, vp->fid.vid);
1411 yfs_check_req(call, bp);
1413 trace_afs_make_fs_call(call, &vp->fid);
1414 afs_make_op_call(op, call, GFP_NOFS);
1418 * YFS.SetLock operation type
1420 static const struct afs_call_type yfs_RXYFSSetLock = {
1421 .name = "YFS.SetLock",
1422 .op = yfs_FS_SetLock,
1423 .deliver = yfs_deliver_status_and_volsync,
1424 .done = afs_lock_op_done,
1425 .destructor = afs_flat_call_destructor,
1429 * YFS.ExtendLock operation type
1431 static const struct afs_call_type yfs_RXYFSExtendLock = {
1432 .name = "YFS.ExtendLock",
1433 .op = yfs_FS_ExtendLock,
1434 .deliver = yfs_deliver_status_and_volsync,
1435 .done = afs_lock_op_done,
1436 .destructor = afs_flat_call_destructor,
1440 * YFS.ReleaseLock operation type
1442 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1443 .name = "YFS.ReleaseLock",
1444 .op = yfs_FS_ReleaseLock,
1445 .deliver = yfs_deliver_status_and_volsync,
1446 .destructor = afs_flat_call_destructor,
1450 * Set a lock on a file
1452 void yfs_fs_set_lock(struct afs_operation *op)
1454 struct afs_vnode_param *vp = &op->file[0];
1455 struct afs_call *call;
1460 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
1461 sizeof(__be32) * 2 +
1462 sizeof(struct yfs_xdr_YFSFid) +
1464 sizeof(struct yfs_xdr_YFSFetchStatus) +
1465 sizeof(struct yfs_xdr_YFSVolSync));
1467 return afs_op_nomem(op);
1469 /* marshall the parameters */
1471 bp = xdr_encode_u32(bp, YFSSETLOCK);
1472 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1473 bp = xdr_encode_YFSFid(bp, &vp->fid);
1474 bp = xdr_encode_u32(bp, op->lock.type);
1475 yfs_check_req(call, bp);
1477 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1478 afs_make_op_call(op, call, GFP_NOFS);
1482 * extend a lock on a file
1484 void yfs_fs_extend_lock(struct afs_operation *op)
1486 struct afs_vnode_param *vp = &op->file[0];
1487 struct afs_call *call;
1492 call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
1493 sizeof(__be32) * 2 +
1494 sizeof(struct yfs_xdr_YFSFid),
1495 sizeof(struct yfs_xdr_YFSFetchStatus) +
1496 sizeof(struct yfs_xdr_YFSVolSync));
1498 return afs_op_nomem(op);
1500 /* marshall the parameters */
1502 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1503 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1504 bp = xdr_encode_YFSFid(bp, &vp->fid);
1505 yfs_check_req(call, bp);
1507 trace_afs_make_fs_call(call, &vp->fid);
1508 afs_make_op_call(op, call, GFP_NOFS);
1512 * release a lock on a file
1514 void yfs_fs_release_lock(struct afs_operation *op)
1516 struct afs_vnode_param *vp = &op->file[0];
1517 struct afs_call *call;
1522 call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
1523 sizeof(__be32) * 2 +
1524 sizeof(struct yfs_xdr_YFSFid),
1525 sizeof(struct yfs_xdr_YFSFetchStatus) +
1526 sizeof(struct yfs_xdr_YFSVolSync));
1528 return afs_op_nomem(op);
1530 /* marshall the parameters */
1532 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1533 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1534 bp = xdr_encode_YFSFid(bp, &vp->fid);
1535 yfs_check_req(call, bp);
1537 trace_afs_make_fs_call(call, &vp->fid);
1538 afs_make_op_call(op, call, GFP_NOFS);
1542 * Deliver a reply to YFS.FetchStatus
1544 static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1546 struct afs_operation *op = call->op;
1547 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1551 ret = afs_transfer_reply(call);
1555 /* unmarshall the reply once we've received all of it */
1557 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1558 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
1559 xdr_decode_YFSVolSync(&bp, &op->volsync);
1561 _leave(" = 0 [done]");
1566 * YFS.FetchStatus operation type
1568 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1569 .name = "YFS.FetchStatus",
1570 .op = yfs_FS_FetchStatus,
1571 .deliver = yfs_deliver_fs_fetch_status,
1572 .destructor = afs_flat_call_destructor,
1576 * Fetch the status information for a fid without needing a vnode handle.
1578 void yfs_fs_fetch_status(struct afs_operation *op)
1580 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1581 struct afs_call *call;
1584 _enter(",%x,{%llx:%llu},,",
1585 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1587 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
1588 sizeof(__be32) * 2 +
1589 sizeof(struct yfs_xdr_YFSFid),
1590 sizeof(struct yfs_xdr_YFSFetchStatus) +
1591 sizeof(struct yfs_xdr_YFSCallBack) +
1592 sizeof(struct yfs_xdr_YFSVolSync));
1594 return afs_op_nomem(op);
1596 /* marshall the parameters */
1598 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
1599 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1600 bp = xdr_encode_YFSFid(bp, &vp->fid);
1601 yfs_check_req(call, bp);
1603 trace_afs_make_fs_call(call, &vp->fid);
1604 afs_make_op_call(op, call, GFP_NOFS);
1608 * Deliver reply data to an YFS.InlineBulkStatus call
1610 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
1612 struct afs_operation *op = call->op;
1613 struct afs_status_cb *scb;
1618 _enter("{%u}", call->unmarshall);
1620 switch (call->unmarshall) {
1622 afs_extract_to_tmp(call);
1626 /* Extract the file status count and array in two steps */
1628 _debug("extract status count");
1629 ret = afs_extract_data(call, true);
1633 tmp = ntohl(call->tmp);
1634 _debug("status count: %u/%u", tmp, op->nr_files);
1635 if (tmp != op->nr_files)
1636 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1641 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
1645 _debug("extract status array %u", call->count);
1646 ret = afs_extract_data(call, true);
1650 switch (call->count) {
1652 scb = &op->file[0].scb;
1655 scb = &op->file[1].scb;
1658 scb = &op->more_files[call->count - 2].scb;
1663 xdr_decode_YFSFetchStatus(&bp, call, scb);
1666 if (call->count < op->nr_files)
1671 afs_extract_to_tmp(call);
1674 /* Extract the callback count and array in two steps */
1676 _debug("extract CB count");
1677 ret = afs_extract_data(call, true);
1681 tmp = ntohl(call->tmp);
1682 _debug("CB count: %u", tmp);
1683 if (tmp != op->nr_files)
1684 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1688 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
1692 _debug("extract CB array");
1693 ret = afs_extract_data(call, true);
1697 _debug("unmarshall CB array");
1698 switch (call->count) {
1700 scb = &op->file[0].scb;
1703 scb = &op->file[1].scb;
1706 scb = &op->more_files[call->count - 2].scb;
1711 xdr_decode_YFSCallBack(&bp, call, scb);
1713 if (call->count < op->nr_files)
1716 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
1721 ret = afs_extract_data(call, false);
1726 xdr_decode_YFSVolSync(&bp, &op->volsync);
1735 _leave(" = 0 [done]");
1740 * FS.InlineBulkStatus operation type
1742 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
1743 .name = "YFS.InlineBulkStatus",
1744 .op = yfs_FS_InlineBulkStatus,
1745 .deliver = yfs_deliver_fs_inline_bulk_status,
1746 .destructor = afs_flat_call_destructor,
1750 * Fetch the status information for up to 1024 files
1752 void yfs_fs_inline_bulk_status(struct afs_operation *op)
1754 struct afs_vnode_param *dvp = &op->file[0];
1755 struct afs_vnode_param *vp = &op->file[1];
1756 struct afs_call *call;
1760 _enter(",%x,{%llx:%llu},%u",
1761 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1763 call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
1767 sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
1768 sizeof(struct yfs_xdr_YFSFetchStatus));
1770 return afs_op_nomem(op);
1772 /* marshall the parameters */
1774 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
1775 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
1776 bp = xdr_encode_u32(bp, op->nr_files);
1777 bp = xdr_encode_YFSFid(bp, &dvp->fid);
1778 bp = xdr_encode_YFSFid(bp, &vp->fid);
1779 for (i = 0; i < op->nr_files - 2; i++)
1780 bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
1781 yfs_check_req(call, bp);
1783 trace_afs_make_fs_call(call, &vp->fid);
1784 afs_make_op_call(op, call, GFP_NOFS);
1788 * Deliver reply data to an YFS.FetchOpaqueACL.
1790 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
1792 struct afs_operation *op = call->op;
1793 struct afs_vnode_param *vp = &op->file[0];
1794 struct yfs_acl *yacl = op->yacl;
1795 struct afs_acl *acl;
1800 _enter("{%u}", call->unmarshall);
1802 switch (call->unmarshall) {
1804 afs_extract_to_tmp(call);
1808 /* Extract the file ACL length */
1810 ret = afs_extract_data(call, true);
1814 size = call->count2 = ntohl(call->tmp);
1815 size = round_up(size, 4);
1817 if (yacl->flags & YFS_ACL_WANT_ACL) {
1818 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1822 acl->size = call->count2;
1823 afs_extract_begin(call, acl->data, size);
1825 afs_extract_discard(call, size);
1830 /* Extract the file ACL */
1832 ret = afs_extract_data(call, true);
1836 afs_extract_to_tmp(call);
1840 /* Extract the volume ACL length */
1842 ret = afs_extract_data(call, true);
1846 size = call->count2 = ntohl(call->tmp);
1847 size = round_up(size, 4);
1849 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
1850 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1853 yacl->vol_acl = acl;
1854 acl->size = call->count2;
1855 afs_extract_begin(call, acl->data, size);
1857 afs_extract_discard(call, size);
1862 /* Extract the volume ACL */
1864 ret = afs_extract_data(call, true);
1868 afs_extract_to_buf(call,
1869 sizeof(__be32) * 2 +
1870 sizeof(struct yfs_xdr_YFSFetchStatus) +
1871 sizeof(struct yfs_xdr_YFSVolSync));
1875 /* extract the metadata */
1877 ret = afs_extract_data(call, false);
1882 yacl->inherit_flag = ntohl(*bp++);
1883 yacl->num_cleaned = ntohl(*bp++);
1884 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1885 xdr_decode_YFSVolSync(&bp, &op->volsync);
1894 _leave(" = 0 [done]");
1898 void yfs_free_opaque_acl(struct yfs_acl *yacl)
1902 kfree(yacl->vol_acl);
1908 * YFS.FetchOpaqueACL operation type
1910 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
1911 .name = "YFS.FetchOpaqueACL",
1912 .op = yfs_FS_FetchOpaqueACL,
1913 .deliver = yfs_deliver_fs_fetch_opaque_acl,
1914 .destructor = afs_flat_call_destructor,
1918 * Fetch the YFS advanced ACLs for a file.
1920 void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
1922 struct afs_vnode_param *vp = &op->file[0];
1923 struct afs_call *call;
1926 _enter(",%x,{%llx:%llu},,",
1927 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1929 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
1930 sizeof(__be32) * 2 +
1931 sizeof(struct yfs_xdr_YFSFid),
1932 sizeof(__be32) * 2 +
1933 sizeof(struct yfs_xdr_YFSFetchStatus) +
1934 sizeof(struct yfs_xdr_YFSVolSync));
1936 return afs_op_nomem(op);
1938 /* marshall the parameters */
1940 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
1941 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1942 bp = xdr_encode_YFSFid(bp, &vp->fid);
1943 yfs_check_req(call, bp);
1945 trace_afs_make_fs_call(call, &vp->fid);
1946 afs_make_op_call(op, call, GFP_KERNEL);
1950 * YFS.StoreOpaqueACL2 operation type
1952 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
1953 .name = "YFS.StoreOpaqueACL2",
1954 .op = yfs_FS_StoreOpaqueACL2,
1955 .deliver = yfs_deliver_status_and_volsync,
1956 .destructor = afs_flat_call_destructor,
1960 * Fetch the YFS ACL for a file.
1962 void yfs_fs_store_opaque_acl2(struct afs_operation *op)
1964 struct afs_vnode_param *vp = &op->file[0];
1965 struct afs_call *call;
1966 struct afs_acl *acl = op->acl;
1970 _enter(",%x,{%llx:%llu},,",
1971 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1973 size = round_up(acl->size, 4);
1974 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
1975 sizeof(__be32) * 2 +
1976 sizeof(struct yfs_xdr_YFSFid) +
1977 sizeof(__be32) + size,
1978 sizeof(struct yfs_xdr_YFSFetchStatus) +
1979 sizeof(struct yfs_xdr_YFSVolSync));
1981 return afs_op_nomem(op);
1983 /* marshall the parameters */
1985 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
1986 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1987 bp = xdr_encode_YFSFid(bp, &vp->fid);
1988 bp = xdr_encode_u32(bp, acl->size);
1989 memcpy(bp, acl->data, acl->size);
1990 if (acl->size != size)
1991 memset((void *)bp + acl->size, 0, size - acl->size);
1992 bp += size / sizeof(__be32);
1993 yfs_check_req(call, bp);
1995 trace_afs_make_fs_call(call, &vp->fid);
1996 afs_make_op_call(op, call, GFP_KERNEL);