1 /* YFS File Server client stubs
3 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/sched.h>
15 #include <linux/circ_buf.h>
16 #include <linux/iversion.h>
20 #include "protocol_yfs.h"
22 static const struct afs_fid afs_zero_fid;
24 static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
26 call->cbi = afs_get_cb_interest(cbi);
29 #define xdr_size(x) (sizeof(*x) / sizeof(__be32))
31 static void xdr_decode_YFSFid(const __be32 **_bp, struct afs_fid *fid)
33 const struct yfs_xdr_YFSFid *x = (const void *)*_bp;
35 fid->vid = xdr_to_u64(x->volume);
36 fid->vnode = xdr_to_u64(x->vnode.lo);
37 fid->vnode_hi = ntohl(x->vnode.hi);
38 fid->unique = ntohl(x->vnode.unique);
42 static __be32 *xdr_encode_u32(__be32 *bp, u32 n)
48 static __be32 *xdr_encode_u64(__be32 *bp, u64 n)
50 struct yfs_xdr_u64 *x = (void *)bp;
53 return bp + xdr_size(x);
56 static __be32 *xdr_encode_YFSFid(__be32 *bp, struct afs_fid *fid)
58 struct yfs_xdr_YFSFid *x = (void *)bp;
60 x->volume = u64_to_xdr(fid->vid);
61 x->vnode.lo = u64_to_xdr(fid->vnode);
62 x->vnode.hi = htonl(fid->vnode_hi);
63 x->vnode.unique = htonl(fid->unique);
64 return bp + xdr_size(x);
67 static size_t xdr_strlen(unsigned int len)
69 return sizeof(__be32) + round_up(len, sizeof(__be32));
72 static __be32 *xdr_encode_string(__be32 *bp, const char *p, unsigned int len)
74 bp = xdr_encode_u32(bp, len);
75 bp = memcpy(bp, p, len);
77 unsigned int pad = 4 - (len & 3);
79 memset((u8 *)bp + len, 0, pad);
83 return bp + len / sizeof(__be32);
86 static s64 linux_to_yfs_time(const struct timespec64 *t)
88 /* Convert to 100ns intervals. */
89 return (u64)t->tv_sec * 10000000 + t->tv_nsec/100;
92 static __be32 *xdr_encode_YFSStoreStatus_mode(__be32 *bp, mode_t mode)
94 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
96 x->mask = htonl(AFS_SET_MODE);
97 x->mode = htonl(mode & S_IALLUGO);
98 x->mtime_client = u64_to_xdr(0);
99 x->owner = u64_to_xdr(0);
100 x->group = u64_to_xdr(0);
101 return bp + xdr_size(x);
104 static __be32 *xdr_encode_YFSStoreStatus_mtime(__be32 *bp, const struct timespec64 *t)
106 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
107 s64 mtime = linux_to_yfs_time(t);
109 x->mask = htonl(AFS_SET_MTIME);
111 x->mtime_client = u64_to_xdr(mtime);
112 x->owner = u64_to_xdr(0);
113 x->group = u64_to_xdr(0);
114 return bp + xdr_size(x);
118 * Convert a signed 100ns-resolution 64-bit time into a timespec.
120 static struct timespec64 yfs_time_to_linux(s64 t)
122 struct timespec64 ts;
126 * Unfortunately can not use normal 64 bit division on 32 bit arch, but
127 * the alternative, do_div, does not work with negative numbers so have
128 * to special case them
132 ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100);
133 ts.tv_nsec = -ts.tv_nsec;
137 ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100;
144 static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr)
146 s64 t = xdr_to_u64(xdr);
148 return yfs_time_to_linux(t);
151 static void yfs_check_req(struct afs_call *call, __be32 *bp)
153 size_t len = (void *)bp - call->request;
155 if (len > call->request_size)
156 pr_err("kAFS: %s: Request buffer overflow (%zu>%u)\n",
157 call->type->name, len, call->request_size);
158 else if (len < call->request_size)
159 pr_warning("kAFS: %s: Request buffer underflow (%zu<%u)\n",
160 call->type->name, len, call->request_size);
164 * Dump a bad file status record.
166 static void xdr_dump_bad(const __be32 *bp)
171 pr_notice("YFS XDR: Bad status record\n");
172 for (i = 0; i < 5 * 4 * 4; i += 16) {
175 pr_notice("%03x: %08x %08x %08x %08x\n",
176 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
180 pr_notice("0x50: %08x\n", ntohl(x[0]));
184 * Decode a YFSFetchStatus block
186 static int xdr_decode_YFSFetchStatus(struct afs_call *call,
188 struct afs_file_status *status,
189 struct afs_vnode *vnode,
190 const afs_dataversion_t *expected_version,
191 struct afs_read *read_req)
193 const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
197 status->abort_code = ntohl(xdr->abort_code);
198 if (status->abort_code != 0) {
199 if (vnode && status->abort_code == VNOVNODE) {
200 set_bit(AFS_VNODE_DELETED, &vnode->flags);
202 __afs_break_callback(vnode);
207 type = ntohl(xdr->type);
211 case AFS_FTYPE_SYMLINK:
212 if (type != status->type &&
214 !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
215 pr_warning("Vnode %llx:%llx:%x changed type %u to %u\n",
228 #define EXTRACT_M4(FIELD) \
230 u32 x = ntohl(xdr->FIELD); \
231 if (status->FIELD != x) { \
232 flags |= AFS_VNODE_META_CHANGED; \
237 #define EXTRACT_M8(FIELD) \
239 u64 x = xdr_to_u64(xdr->FIELD); \
240 if (status->FIELD != x) { \
241 flags |= AFS_VNODE_META_CHANGED; \
246 #define EXTRACT_D8(FIELD) \
248 u64 x = xdr_to_u64(xdr->FIELD); \
249 if (status->FIELD != x) { \
250 flags |= AFS_VNODE_DATA_CHANGED; \
257 EXTRACT_D8(data_version);
262 EXTRACT_M4(caller_access); /* call ticket dependent */
263 EXTRACT_M4(anon_access);
265 status->mtime_client = xdr_to_time(xdr->mtime_client);
266 status->mtime_server = xdr_to_time(xdr->mtime_server);
267 status->lock_count = ntohl(xdr->lock_count);
270 read_req->data_version = status->data_version;
271 read_req->file_size = status->size;
274 *_bp += xdr_size(xdr);
277 if (test_bit(AFS_VNODE_UNSET, &vnode->flags))
278 flags |= AFS_VNODE_NOT_YET_SET;
279 afs_update_inode_from_status(vnode, status, expected_version,
287 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
291 * Decode the file status. We need to lock the target vnode if we're going to
292 * update its status so that stat() sees the attributes update atomically.
294 static int yfs_decode_status(struct afs_call *call,
296 struct afs_file_status *status,
297 struct afs_vnode *vnode,
298 const afs_dataversion_t *expected_version,
299 struct afs_read *read_req)
304 return xdr_decode_YFSFetchStatus(call, _bp, status, vnode,
305 expected_version, read_req);
307 write_seqlock(&vnode->cb_lock);
308 ret = xdr_decode_YFSFetchStatus(call, _bp, status, vnode,
309 expected_version, read_req);
310 write_sequnlock(&vnode->cb_lock);
314 static void xdr_decode_YFSCallBack_raw(struct afs_call *call,
315 struct afs_callback *cb,
318 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
321 cb_expiry = call->reply_time;
322 cb_expiry = ktime_add(cb_expiry, xdr_to_u64(x->expiration_time) * 100);
323 cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
324 cb->version = ntohl(x->version);
325 cb->type = ntohl(x->type);
331 * Decode a YFSCallBack block
333 static void xdr_decode_YFSCallBack(struct afs_call *call,
334 struct afs_vnode *vnode,
337 struct afs_cb_interest *old, *cbi = call->cbi;
338 struct afs_callback cb;
340 xdr_decode_YFSCallBack_raw(call, &cb, _bp);
342 write_seqlock(&vnode->cb_lock);
344 if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
345 vnode->cb_version = cb.version;
346 vnode->cb_type = cb.type;
347 vnode->cb_expires_at = cb.expires_at;
348 old = vnode->cb_interest;
349 if (old != call->cbi) {
350 vnode->cb_interest = cbi;
353 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
356 write_sequnlock(&vnode->cb_lock);
361 * Decode a YFSVolSync block
363 static void xdr_decode_YFSVolSync(const __be32 **_bp,
364 struct afs_volsync *volsync)
366 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
370 creation = xdr_to_u64(x->vol_creation_date);
371 do_div(creation, 10 * 1000 * 1000);
372 volsync->creation = creation;
379 * Encode the requested attributes into a YFSStoreStatus block
381 static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
383 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
384 s64 mtime = 0, owner = 0, group = 0;
385 u32 mask = 0, mode = 0;
388 if (attr->ia_valid & ATTR_MTIME) {
389 mask |= AFS_SET_MTIME;
390 mtime = linux_to_yfs_time(&attr->ia_mtime);
393 if (attr->ia_valid & ATTR_UID) {
394 mask |= AFS_SET_OWNER;
395 owner = from_kuid(&init_user_ns, attr->ia_uid);
398 if (attr->ia_valid & ATTR_GID) {
399 mask |= AFS_SET_GROUP;
400 group = from_kgid(&init_user_ns, attr->ia_gid);
403 if (attr->ia_valid & ATTR_MODE) {
404 mask |= AFS_SET_MODE;
405 mode = attr->ia_mode & S_IALLUGO;
408 x->mask = htonl(mask);
409 x->mode = htonl(mode);
410 x->mtime_client = u64_to_xdr(mtime);
411 x->owner = u64_to_xdr(owner);
412 x->group = u64_to_xdr(group);
413 return bp + xdr_size(x);
417 * Decode a YFSFetchVolumeStatus block.
419 static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
420 struct afs_volume_status *vs)
422 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
425 vs->vid = xdr_to_u64(x->vid);
426 vs->parent_id = xdr_to_u64(x->parent_id);
427 flags = ntohl(x->flags);
428 vs->online = flags & yfs_FVSOnline;
429 vs->in_service = flags & yfs_FVSInservice;
430 vs->blessed = flags & yfs_FVSBlessed;
431 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
432 vs->type = ntohl(x->type);
434 vs->max_quota = xdr_to_u64(x->max_quota);
435 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
436 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
437 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
438 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
439 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
440 *_bp += sizeof(*x) / sizeof(__be32);
444 * deliver reply data to an FS.FetchStatus
446 static int yfs_deliver_fs_fetch_status_vnode(struct afs_call *call)
448 struct afs_vnode *vnode = call->xvnode;
452 ret = afs_transfer_reply(call);
456 _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
458 /* unmarshall the reply once we've received all of it */
460 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
461 &call->expected_version, NULL);
464 xdr_decode_YFSCallBack(call, vnode, &bp);
465 xdr_decode_YFSVolSync(&bp, call->out_volsync);
467 _leave(" = 0 [done]");
472 * YFS.FetchStatus operation type
474 static const struct afs_call_type yfs_RXYFSFetchStatus_vnode = {
475 .name = "YFS.FetchStatus(vnode)",
476 .op = yfs_FS_FetchStatus,
477 .deliver = yfs_deliver_fs_fetch_status_vnode,
478 .destructor = afs_flat_call_destructor,
482 * Fetch the status information for a file.
484 int yfs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_volsync *volsync,
487 struct afs_vnode *vnode = fc->vnode;
488 struct afs_call *call;
489 struct afs_net *net = afs_v2net(vnode);
492 _enter(",%x,{%llx:%llu},,",
493 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
495 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus_vnode,
497 sizeof(struct yfs_xdr_YFSFid),
498 sizeof(struct yfs_xdr_YFSFetchStatus) +
499 sizeof(struct yfs_xdr_YFSCallBack) +
500 sizeof(struct yfs_xdr_YFSVolSync));
502 fc->ac.error = -ENOMEM;
507 call->xvnode = vnode;
508 call->out_volsync = volsync;
509 call->expected_version = new_inode ? 1 : vnode->status.data_version;
511 /* marshall the parameters */
513 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
514 bp = xdr_encode_u32(bp, 0); /* RPC flags */
515 bp = xdr_encode_YFSFid(bp, &vnode->fid);
516 yfs_check_req(call, bp);
518 call->cb_break = fc->cb_break;
519 afs_use_fs_server(call, fc->cbi);
520 trace_afs_make_fs_call(call, &vnode->fid);
521 afs_set_fc_call(call, fc);
522 afs_make_call(&fc->ac, call, GFP_NOFS);
523 return afs_wait_for_call_to_complete(call, &fc->ac);
527 * Deliver reply data to an YFS.FetchData64.
529 static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
531 struct afs_vnode *vnode = call->xvnode;
532 struct afs_read *req = call->read_request;
537 _enter("{%u,%zu/%llu}",
538 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
540 switch (call->unmarshall) {
544 req->offset = req->pos & (PAGE_SIZE - 1);
545 afs_extract_to_tmp64(call);
548 /* Fall through - and extract the returned data length */
550 _debug("extract data length");
551 ret = afs_extract_data(call, true);
555 req->actual_len = be64_to_cpu(call->tmp64);
556 _debug("DATA length: %llu", req->actual_len);
557 req->remain = min(req->len, req->actual_len);
558 if (req->remain == 0)
564 ASSERTCMP(req->index, <, req->nr_pages);
565 if (req->remain > PAGE_SIZE - req->offset)
566 size = PAGE_SIZE - req->offset;
569 call->bvec[0].bv_len = size;
570 call->bvec[0].bv_offset = req->offset;
571 call->bvec[0].bv_page = req->pages[req->index];
572 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
573 ASSERTCMP(size, <=, PAGE_SIZE);
575 /* Fall through - and extract the returned data */
577 _debug("extract data %zu/%llu",
578 iov_iter_count(&call->iter), req->remain);
580 ret = afs_extract_data(call, true);
583 req->remain -= call->bvec[0].bv_len;
584 req->offset += call->bvec[0].bv_len;
585 ASSERTCMP(req->offset, <=, PAGE_SIZE);
586 if (req->offset == PAGE_SIZE) {
589 req->page_done(call, req);
595 ASSERTCMP(req->remain, ==, 0);
596 if (req->actual_len <= req->len)
599 /* Discard any excess data the server gave us */
600 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
601 call->unmarshall = 3;
605 _debug("extract discard %zu/%llu",
606 iov_iter_count(&call->iter), req->actual_len - req->len);
608 ret = afs_extract_data(call, true);
613 call->unmarshall = 4;
614 afs_extract_to_buf(call,
615 sizeof(struct yfs_xdr_YFSFetchStatus) +
616 sizeof(struct yfs_xdr_YFSCallBack) +
617 sizeof(struct yfs_xdr_YFSVolSync));
619 /* Fall through - and extract the metadata */
621 ret = afs_extract_data(call, false);
626 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
627 &vnode->status.data_version, req);
630 xdr_decode_YFSCallBack(call, vnode, &bp);
631 xdr_decode_YFSVolSync(&bp, call->out_volsync);
640 for (; req->index < req->nr_pages; req->index++) {
641 if (req->offset < PAGE_SIZE)
642 zero_user_segment(req->pages[req->index],
643 req->offset, PAGE_SIZE);
645 req->page_done(call, req);
649 _leave(" = 0 [done]");
653 static void yfs_fetch_data_destructor(struct afs_call *call)
655 afs_put_read(call->read_request);
656 afs_flat_call_destructor(call);
660 * YFS.FetchData64 operation type
662 static const struct afs_call_type yfs_RXYFSFetchData64 = {
663 .name = "YFS.FetchData64",
664 .op = yfs_FS_FetchData64,
665 .deliver = yfs_deliver_fs_fetch_data64,
666 .destructor = yfs_fetch_data_destructor,
670 * Fetch data from a file.
672 int yfs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
674 struct afs_vnode *vnode = fc->vnode;
675 struct afs_call *call;
676 struct afs_net *net = afs_v2net(vnode);
679 _enter(",%x,{%llx:%llu},%llx,%llx",
680 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode,
683 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchData64,
685 sizeof(struct yfs_xdr_YFSFid) +
686 sizeof(struct yfs_xdr_u64) * 2,
687 sizeof(struct yfs_xdr_YFSFetchStatus) +
688 sizeof(struct yfs_xdr_YFSCallBack) +
689 sizeof(struct yfs_xdr_YFSVolSync));
694 call->xvnode = vnode;
695 call->out_volsync = NULL;
696 call->read_request = req;
697 call->expected_version = vnode->status.data_version;
698 call->want_reply_time = true;
700 /* marshall the parameters */
702 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
703 bp = xdr_encode_u32(bp, 0); /* RPC flags */
704 bp = xdr_encode_YFSFid(bp, &vnode->fid);
705 bp = xdr_encode_u64(bp, req->pos);
706 bp = xdr_encode_u64(bp, req->len);
707 yfs_check_req(call, bp);
709 refcount_inc(&req->usage);
710 call->cb_break = fc->cb_break;
711 afs_use_fs_server(call, fc->cbi);
712 trace_afs_make_fs_call(call, &vnode->fid);
713 afs_set_fc_call(call, fc);
714 afs_make_call(&fc->ac, call, GFP_NOFS);
715 return afs_wait_for_call_to_complete(call, &fc->ac);
719 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
721 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
723 struct afs_vnode *dvnode = call->dvnode;
727 _enter("{%u}", call->unmarshall);
729 ret = afs_transfer_reply(call);
733 /* unmarshall the reply once we've received all of it */
735 xdr_decode_YFSFid(&bp, call->out_fid);
736 ret = yfs_decode_status(call, &bp, call->out_extra_status, NULL, NULL, NULL);
739 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
740 &call->expected_version, NULL);
743 xdr_decode_YFSCallBack_raw(call, call->out_cb, &bp);
744 xdr_decode_YFSVolSync(&bp, NULL);
746 _leave(" = 0 [done]");
751 * FS.CreateFile and FS.MakeDir operation type
753 static const struct afs_call_type afs_RXFSCreateFile = {
754 .name = "YFS.CreateFile",
755 .op = yfs_FS_CreateFile,
756 .deliver = yfs_deliver_fs_create_vnode,
757 .destructor = afs_flat_call_destructor,
763 int yfs_fs_create_file(struct afs_fs_cursor *fc,
766 u64 current_data_version,
767 struct afs_fid *newfid,
768 struct afs_file_status *newstatus,
769 struct afs_callback *newcb)
771 struct afs_vnode *dvnode = fc->vnode;
772 struct afs_call *call;
773 struct afs_net *net = afs_v2net(dvnode);
774 size_t namesz, reqsz, rplsz;
779 namesz = strlen(name);
780 reqsz = (sizeof(__be32) +
782 sizeof(struct yfs_xdr_YFSFid) +
784 sizeof(struct yfs_xdr_YFSStoreStatus) +
786 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
787 sizeof(struct yfs_xdr_YFSFetchStatus) +
788 sizeof(struct yfs_xdr_YFSFetchStatus) +
789 sizeof(struct yfs_xdr_YFSCallBack) +
790 sizeof(struct yfs_xdr_YFSVolSync));
792 call = afs_alloc_flat_call(net, &afs_RXFSCreateFile, reqsz, rplsz);
797 call->dvnode = dvnode;
798 call->out_fid = newfid;
799 call->out_extra_status = newstatus;
800 call->out_cb = newcb;
801 call->expected_version = current_data_version + 1;
803 /* marshall the parameters */
805 bp = xdr_encode_u32(bp, YFSCREATEFILE);
806 bp = xdr_encode_u32(bp, 0); /* RPC flags */
807 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
808 bp = xdr_encode_string(bp, name, namesz);
809 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
810 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
811 yfs_check_req(call, bp);
813 afs_use_fs_server(call, fc->cbi);
814 trace_afs_make_fs_call1(call, &dvnode->fid, name);
815 afs_set_fc_call(call, fc);
816 afs_make_call(&fc->ac, call, GFP_NOFS);
817 return afs_wait_for_call_to_complete(call, &fc->ac);
820 static const struct afs_call_type yfs_RXFSMakeDir = {
821 .name = "YFS.MakeDir",
822 .op = yfs_FS_MakeDir,
823 .deliver = yfs_deliver_fs_create_vnode,
824 .destructor = afs_flat_call_destructor,
830 int yfs_fs_make_dir(struct afs_fs_cursor *fc,
833 u64 current_data_version,
834 struct afs_fid *newfid,
835 struct afs_file_status *newstatus,
836 struct afs_callback *newcb)
838 struct afs_vnode *dvnode = fc->vnode;
839 struct afs_call *call;
840 struct afs_net *net = afs_v2net(dvnode);
841 size_t namesz, reqsz, rplsz;
846 namesz = strlen(name);
847 reqsz = (sizeof(__be32) +
848 sizeof(struct yfs_xdr_RPCFlags) +
849 sizeof(struct yfs_xdr_YFSFid) +
851 sizeof(struct yfs_xdr_YFSStoreStatus));
852 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
853 sizeof(struct yfs_xdr_YFSFetchStatus) +
854 sizeof(struct yfs_xdr_YFSFetchStatus) +
855 sizeof(struct yfs_xdr_YFSCallBack) +
856 sizeof(struct yfs_xdr_YFSVolSync));
858 call = afs_alloc_flat_call(net, &yfs_RXFSMakeDir, reqsz, rplsz);
863 call->dvnode = dvnode;
864 call->out_fid = newfid;
865 call->out_extra_status = newstatus;
866 call->out_cb = newcb;
867 call->expected_version = current_data_version + 1;
869 /* marshall the parameters */
871 bp = xdr_encode_u32(bp, YFSMAKEDIR);
872 bp = xdr_encode_u32(bp, 0); /* RPC flags */
873 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
874 bp = xdr_encode_string(bp, name, namesz);
875 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
876 yfs_check_req(call, bp);
878 afs_use_fs_server(call, fc->cbi);
879 trace_afs_make_fs_call1(call, &dvnode->fid, name);
880 afs_set_fc_call(call, fc);
881 afs_make_call(&fc->ac, call, GFP_NOFS);
882 return afs_wait_for_call_to_complete(call, &fc->ac);
886 * Deliver reply data to a YFS.RemoveFile2 operation.
888 static int yfs_deliver_fs_remove_file2(struct afs_call *call)
890 struct afs_vnode *dvnode = call->dvnode;
891 struct afs_vnode *vnode = call->xvnode;
896 _enter("{%u}", call->unmarshall);
898 ret = afs_transfer_reply(call);
902 /* unmarshall the reply once we've received all of it */
904 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
905 &call->expected_version, NULL);
909 xdr_decode_YFSFid(&bp, &fid);
910 ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
913 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
915 xdr_decode_YFSVolSync(&bp, NULL);
920 * YFS.RemoveFile2 operation type.
922 static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
923 .name = "YFS.RemoveFile2",
924 .op = yfs_FS_RemoveFile2,
925 .deliver = yfs_deliver_fs_remove_file2,
926 .destructor = afs_flat_call_destructor,
930 * Remove a file and retrieve new file status.
932 int yfs_fs_remove_file2(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
933 const char *name, u64 current_data_version)
935 struct afs_vnode *dvnode = fc->vnode;
936 struct afs_call *call;
937 struct afs_net *net = afs_v2net(dvnode);
943 namesz = strlen(name);
945 call = afs_alloc_flat_call(net, &yfs_RXYFSRemoveFile2,
947 sizeof(struct yfs_xdr_RPCFlags) +
948 sizeof(struct yfs_xdr_YFSFid) +
950 sizeof(struct yfs_xdr_YFSFetchStatus) +
951 sizeof(struct yfs_xdr_YFSFid) +
952 sizeof(struct yfs_xdr_YFSFetchStatus) +
953 sizeof(struct yfs_xdr_YFSVolSync));
958 call->dvnode = dvnode;
959 call->xvnode = vnode;
960 call->expected_version = current_data_version + 1;
962 /* marshall the parameters */
964 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
965 bp = xdr_encode_u32(bp, 0); /* RPC flags */
966 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
967 bp = xdr_encode_string(bp, name, namesz);
968 yfs_check_req(call, bp);
970 afs_use_fs_server(call, fc->cbi);
971 trace_afs_make_fs_call1(call, &dvnode->fid, name);
972 afs_set_fc_call(call, fc);
973 afs_make_call(&fc->ac, call, GFP_NOFS);
974 return afs_wait_for_call_to_complete(call, &fc->ac);
978 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
980 static int yfs_deliver_fs_remove(struct afs_call *call)
982 struct afs_vnode *dvnode = call->dvnode;
986 _enter("{%u}", call->unmarshall);
988 ret = afs_transfer_reply(call);
992 /* unmarshall the reply once we've received all of it */
994 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
995 &call->expected_version, NULL);
999 xdr_decode_YFSVolSync(&bp, NULL);
1004 * FS.RemoveDir and FS.RemoveFile operation types.
1006 static const struct afs_call_type yfs_RXYFSRemoveFile = {
1007 .name = "YFS.RemoveFile",
1008 .op = yfs_FS_RemoveFile,
1009 .deliver = yfs_deliver_fs_remove,
1010 .destructor = afs_flat_call_destructor,
1013 static const struct afs_call_type yfs_RXYFSRemoveDir = {
1014 .name = "YFS.RemoveDir",
1015 .op = yfs_FS_RemoveDir,
1016 .deliver = yfs_deliver_fs_remove,
1017 .destructor = afs_flat_call_destructor,
1021 * remove a file or directory
1023 int yfs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
1024 const char *name, bool isdir, u64 current_data_version)
1026 struct afs_vnode *dvnode = fc->vnode;
1027 struct afs_call *call;
1028 struct afs_net *net = afs_v2net(dvnode);
1034 namesz = strlen(name);
1035 call = afs_alloc_flat_call(
1036 net, isdir ? &yfs_RXYFSRemoveDir : &yfs_RXYFSRemoveFile,
1038 sizeof(struct yfs_xdr_RPCFlags) +
1039 sizeof(struct yfs_xdr_YFSFid) +
1041 sizeof(struct yfs_xdr_YFSFetchStatus) +
1042 sizeof(struct yfs_xdr_YFSVolSync));
1046 call->key = fc->key;
1047 call->dvnode = dvnode;
1048 call->xvnode = vnode;
1049 call->expected_version = current_data_version + 1;
1051 /* marshall the parameters */
1053 bp = xdr_encode_u32(bp, isdir ? YFSREMOVEDIR : YFSREMOVEFILE);
1054 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1055 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1056 bp = xdr_encode_string(bp, name, namesz);
1057 yfs_check_req(call, bp);
1059 afs_use_fs_server(call, fc->cbi);
1060 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1061 afs_set_fc_call(call, fc);
1062 afs_make_call(&fc->ac, call, GFP_NOFS);
1063 return afs_wait_for_call_to_complete(call, &fc->ac);
1067 * Deliver reply data to a YFS.Link operation.
1069 static int yfs_deliver_fs_link(struct afs_call *call)
1071 struct afs_vnode *dvnode = call->dvnode, *vnode = call->xvnode;
1075 _enter("{%u}", call->unmarshall);
1077 ret = afs_transfer_reply(call);
1081 /* unmarshall the reply once we've received all of it */
1083 ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
1086 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
1087 &call->expected_version, NULL);
1090 xdr_decode_YFSVolSync(&bp, NULL);
1091 _leave(" = 0 [done]");
1096 * YFS.Link operation type.
1098 static const struct afs_call_type yfs_RXYFSLink = {
1101 .deliver = yfs_deliver_fs_link,
1102 .destructor = afs_flat_call_destructor,
1108 int yfs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
1109 const char *name, u64 current_data_version)
1111 struct afs_vnode *dvnode = fc->vnode;
1112 struct afs_call *call;
1113 struct afs_net *net = afs_v2net(vnode);
1119 namesz = strlen(name);
1120 call = afs_alloc_flat_call(net, &yfs_RXYFSLink,
1122 sizeof(struct yfs_xdr_RPCFlags) +
1123 sizeof(struct yfs_xdr_YFSFid) +
1124 xdr_strlen(namesz) +
1125 sizeof(struct yfs_xdr_YFSFid),
1126 sizeof(struct yfs_xdr_YFSFetchStatus) +
1127 sizeof(struct yfs_xdr_YFSFetchStatus) +
1128 sizeof(struct yfs_xdr_YFSVolSync));
1132 call->key = fc->key;
1133 call->dvnode = dvnode;
1134 call->xvnode = vnode;
1135 call->expected_version = current_data_version + 1;
1137 /* marshall the parameters */
1139 bp = xdr_encode_u32(bp, YFSLINK);
1140 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1141 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1142 bp = xdr_encode_string(bp, name, namesz);
1143 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1144 yfs_check_req(call, bp);
1146 afs_use_fs_server(call, fc->cbi);
1147 trace_afs_make_fs_call1(call, &vnode->fid, name);
1148 afs_set_fc_call(call, fc);
1149 afs_make_call(&fc->ac, call, GFP_NOFS);
1150 return afs_wait_for_call_to_complete(call, &fc->ac);
1154 * Deliver reply data to a YFS.Symlink operation.
1156 static int yfs_deliver_fs_symlink(struct afs_call *call)
1158 struct afs_vnode *dvnode = call->dvnode;
1162 _enter("{%u}", call->unmarshall);
1164 ret = afs_transfer_reply(call);
1168 /* unmarshall the reply once we've received all of it */
1170 xdr_decode_YFSFid(&bp, call->out_fid);
1171 ret = yfs_decode_status(call, &bp, call->out_extra_status, NULL, NULL, NULL);
1174 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
1175 &call->expected_version, NULL);
1178 xdr_decode_YFSVolSync(&bp, NULL);
1180 _leave(" = 0 [done]");
1185 * YFS.Symlink operation type
1187 static const struct afs_call_type yfs_RXYFSSymlink = {
1188 .name = "YFS.Symlink",
1189 .op = yfs_FS_Symlink,
1190 .deliver = yfs_deliver_fs_symlink,
1191 .destructor = afs_flat_call_destructor,
1195 * Create a symbolic link.
1197 int yfs_fs_symlink(struct afs_fs_cursor *fc,
1199 const char *contents,
1200 u64 current_data_version,
1201 struct afs_fid *newfid,
1202 struct afs_file_status *newstatus)
1204 struct afs_vnode *dvnode = fc->vnode;
1205 struct afs_call *call;
1206 struct afs_net *net = afs_v2net(dvnode);
1207 size_t namesz, contents_sz;
1212 namesz = strlen(name);
1213 contents_sz = strlen(contents);
1214 call = afs_alloc_flat_call(net, &yfs_RXYFSSymlink,
1216 sizeof(struct yfs_xdr_RPCFlags) +
1217 sizeof(struct yfs_xdr_YFSFid) +
1218 xdr_strlen(namesz) +
1219 xdr_strlen(contents_sz) +
1220 sizeof(struct yfs_xdr_YFSStoreStatus),
1221 sizeof(struct yfs_xdr_YFSFid) +
1222 sizeof(struct yfs_xdr_YFSFetchStatus) +
1223 sizeof(struct yfs_xdr_YFSFetchStatus) +
1224 sizeof(struct yfs_xdr_YFSVolSync));
1228 call->key = fc->key;
1229 call->dvnode = dvnode;
1230 call->out_fid = newfid;
1231 call->out_extra_status = newstatus;
1232 call->expected_version = current_data_version + 1;
1234 /* marshall the parameters */
1236 bp = xdr_encode_u32(bp, YFSSYMLINK);
1237 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1238 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1239 bp = xdr_encode_string(bp, name, namesz);
1240 bp = xdr_encode_string(bp, contents, contents_sz);
1241 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
1242 yfs_check_req(call, bp);
1244 afs_use_fs_server(call, fc->cbi);
1245 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1246 afs_set_fc_call(call, fc);
1247 afs_make_call(&fc->ac, call, GFP_NOFS);
1248 return afs_wait_for_call_to_complete(call, &fc->ac);
1252 * Deliver reply data to a YFS.Rename operation.
1254 static int yfs_deliver_fs_rename(struct afs_call *call)
1256 struct afs_vnode *orig_dvnode = call->dvnode;
1257 struct afs_vnode *new_dvnode = call->xvnode;
1261 _enter("{%u}", call->unmarshall);
1263 ret = afs_transfer_reply(call);
1267 /* unmarshall the reply once we've received all of it */
1269 ret = yfs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1270 &call->expected_version, NULL);
1273 if (new_dvnode != orig_dvnode) {
1274 ret = yfs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1275 &call->expected_version_2, NULL);
1280 xdr_decode_YFSVolSync(&bp, NULL);
1281 _leave(" = 0 [done]");
1286 * YFS.Rename operation type
1288 static const struct afs_call_type yfs_RXYFSRename = {
1289 .name = "FS.Rename",
1290 .op = yfs_FS_Rename,
1291 .deliver = yfs_deliver_fs_rename,
1292 .destructor = afs_flat_call_destructor,
1296 * Rename a file or directory.
1298 int yfs_fs_rename(struct afs_fs_cursor *fc,
1299 const char *orig_name,
1300 struct afs_vnode *new_dvnode,
1301 const char *new_name,
1302 u64 current_orig_data_version,
1303 u64 current_new_data_version)
1305 struct afs_vnode *orig_dvnode = fc->vnode;
1306 struct afs_call *call;
1307 struct afs_net *net = afs_v2net(orig_dvnode);
1308 size_t o_namesz, n_namesz;
1313 o_namesz = strlen(orig_name);
1314 n_namesz = strlen(new_name);
1315 call = afs_alloc_flat_call(net, &yfs_RXYFSRename,
1317 sizeof(struct yfs_xdr_RPCFlags) +
1318 sizeof(struct yfs_xdr_YFSFid) +
1319 xdr_strlen(o_namesz) +
1320 sizeof(struct yfs_xdr_YFSFid) +
1321 xdr_strlen(n_namesz),
1322 sizeof(struct yfs_xdr_YFSFetchStatus) +
1323 sizeof(struct yfs_xdr_YFSFetchStatus) +
1324 sizeof(struct yfs_xdr_YFSVolSync));
1328 call->key = fc->key;
1329 call->dvnode = orig_dvnode;
1330 call->xvnode = new_dvnode;
1331 call->expected_version = current_orig_data_version + 1;
1332 call->expected_version_2 = current_new_data_version + 1;
1334 /* marshall the parameters */
1336 bp = xdr_encode_u32(bp, YFSRENAME);
1337 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1338 bp = xdr_encode_YFSFid(bp, &orig_dvnode->fid);
1339 bp = xdr_encode_string(bp, orig_name, o_namesz);
1340 bp = xdr_encode_YFSFid(bp, &new_dvnode->fid);
1341 bp = xdr_encode_string(bp, new_name, n_namesz);
1342 yfs_check_req(call, bp);
1344 afs_use_fs_server(call, fc->cbi);
1345 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1346 afs_set_fc_call(call, fc);
1347 afs_make_call(&fc->ac, call, GFP_NOFS);
1348 return afs_wait_for_call_to_complete(call, &fc->ac);
1352 * Deliver reply data to a YFS.StoreData64 operation.
1354 static int yfs_deliver_fs_store_data(struct afs_call *call)
1356 struct afs_vnode *vnode = call->xvnode;
1362 ret = afs_transfer_reply(call);
1366 /* unmarshall the reply once we've received all of it */
1368 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1369 &call->expected_version, NULL);
1372 xdr_decode_YFSVolSync(&bp, NULL);
1374 afs_pages_written_back(vnode, call);
1376 _leave(" = 0 [done]");
1381 * YFS.StoreData64 operation type.
1383 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1384 .name = "YFS.StoreData64",
1385 .op = yfs_FS_StoreData64,
1386 .deliver = yfs_deliver_fs_store_data,
1387 .destructor = afs_flat_call_destructor,
1391 * Store a set of pages to a large file.
1393 int yfs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1394 pgoff_t first, pgoff_t last,
1395 unsigned offset, unsigned to)
1397 struct afs_vnode *vnode = fc->vnode;
1398 struct afs_call *call;
1399 struct afs_net *net = afs_v2net(vnode);
1400 loff_t size, pos, i_size;
1403 _enter(",%x,{%llx:%llu},,",
1404 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1406 size = (loff_t)to - (loff_t)offset;
1408 size += (loff_t)(last - first) << PAGE_SHIFT;
1409 pos = (loff_t)first << PAGE_SHIFT;
1412 i_size = i_size_read(&vnode->vfs_inode);
1413 if (pos + size > i_size)
1414 i_size = size + pos;
1416 _debug("size %llx, at %llx, i_size %llx",
1417 (unsigned long long)size, (unsigned long long)pos,
1418 (unsigned long long)i_size);
1420 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64,
1423 sizeof(struct yfs_xdr_YFSFid) +
1424 sizeof(struct yfs_xdr_YFSStoreStatus) +
1425 sizeof(struct yfs_xdr_u64) * 3,
1426 sizeof(struct yfs_xdr_YFSFetchStatus) +
1427 sizeof(struct yfs_xdr_YFSVolSync));
1431 call->key = fc->key;
1432 call->mapping = mapping;
1433 call->xvnode = vnode;
1434 call->first = first;
1436 call->first_offset = offset;
1438 call->send_pages = true;
1439 call->expected_version = vnode->status.data_version + 1;
1441 /* marshall the parameters */
1443 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1444 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1445 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1446 bp = xdr_encode_YFSStoreStatus_mtime(bp, &vnode->vfs_inode.i_mtime);
1447 bp = xdr_encode_u64(bp, pos);
1448 bp = xdr_encode_u64(bp, size);
1449 bp = xdr_encode_u64(bp, i_size);
1450 yfs_check_req(call, bp);
1452 afs_use_fs_server(call, fc->cbi);
1453 trace_afs_make_fs_call(call, &vnode->fid);
1454 afs_set_fc_call(call, fc);
1455 afs_make_call(&fc->ac, call, GFP_NOFS);
1456 return afs_wait_for_call_to_complete(call, &fc->ac);
1460 * deliver reply data to an FS.StoreStatus
1462 static int yfs_deliver_fs_store_status(struct afs_call *call)
1464 struct afs_vnode *vnode = call->xvnode;
1470 ret = afs_transfer_reply(call);
1474 /* unmarshall the reply once we've received all of it */
1476 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1477 &call->expected_version, NULL);
1480 xdr_decode_YFSVolSync(&bp, NULL);
1482 _leave(" = 0 [done]");
1487 * YFS.StoreStatus operation type
1489 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1490 .name = "YFS.StoreStatus",
1491 .op = yfs_FS_StoreStatus,
1492 .deliver = yfs_deliver_fs_store_status,
1493 .destructor = afs_flat_call_destructor,
1496 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1497 .name = "YFS.StoreData64",
1498 .op = yfs_FS_StoreData64,
1499 .deliver = yfs_deliver_fs_store_status,
1500 .destructor = afs_flat_call_destructor,
1504 * Set the attributes on a file, using YFS.StoreData64 rather than
1505 * YFS.StoreStatus so as to alter the file size also.
1507 static int yfs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1509 struct afs_vnode *vnode = fc->vnode;
1510 struct afs_call *call;
1511 struct afs_net *net = afs_v2net(vnode);
1514 _enter(",%x,{%llx:%llu},,",
1515 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1517 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64_as_Status,
1518 sizeof(__be32) * 2 +
1519 sizeof(struct yfs_xdr_YFSFid) +
1520 sizeof(struct yfs_xdr_YFSStoreStatus) +
1521 sizeof(struct yfs_xdr_u64) * 3,
1522 sizeof(struct yfs_xdr_YFSFetchStatus) +
1523 sizeof(struct yfs_xdr_YFSVolSync));
1527 call->key = fc->key;
1528 call->xvnode = vnode;
1529 call->expected_version = vnode->status.data_version + 1;
1531 /* marshall the parameters */
1533 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1534 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1535 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1536 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1537 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1538 bp = xdr_encode_u64(bp, 0); /* size of write */
1539 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1540 yfs_check_req(call, bp);
1542 afs_use_fs_server(call, fc->cbi);
1543 trace_afs_make_fs_call(call, &vnode->fid);
1544 afs_set_fc_call(call, fc);
1545 afs_make_call(&fc->ac, call, GFP_NOFS);
1546 return afs_wait_for_call_to_complete(call, &fc->ac);
1550 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1551 * file size, and YFS.StoreStatus otherwise.
1553 int yfs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1555 struct afs_vnode *vnode = fc->vnode;
1556 struct afs_call *call;
1557 struct afs_net *net = afs_v2net(vnode);
1560 if (attr->ia_valid & ATTR_SIZE)
1561 return yfs_fs_setattr_size(fc, attr);
1563 _enter(",%x,{%llx:%llu},,",
1564 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1566 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
1567 sizeof(__be32) * 2 +
1568 sizeof(struct yfs_xdr_YFSFid) +
1569 sizeof(struct yfs_xdr_YFSStoreStatus),
1570 sizeof(struct yfs_xdr_YFSFetchStatus) +
1571 sizeof(struct yfs_xdr_YFSVolSync));
1575 call->key = fc->key;
1576 call->xvnode = vnode;
1577 call->expected_version = vnode->status.data_version;
1579 /* marshall the parameters */
1581 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1582 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1583 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1584 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1585 yfs_check_req(call, bp);
1587 afs_use_fs_server(call, fc->cbi);
1588 trace_afs_make_fs_call(call, &vnode->fid);
1589 afs_set_fc_call(call, fc);
1590 afs_make_call(&fc->ac, call, GFP_NOFS);
1591 return afs_wait_for_call_to_complete(call, &fc->ac);
1595 * Deliver reply data to a YFS.GetVolumeStatus operation.
1597 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1604 _enter("{%u}", call->unmarshall);
1606 switch (call->unmarshall) {
1609 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1611 /* Fall through - and extract the returned status record */
1613 _debug("extract status");
1614 ret = afs_extract_data(call, true);
1619 xdr_decode_YFSFetchVolumeStatus(&bp, call->out_volstatus);
1621 afs_extract_to_tmp(call);
1623 /* Fall through - and extract the volume name length */
1625 ret = afs_extract_data(call, true);
1629 call->count = ntohl(call->tmp);
1630 _debug("volname length: %u", call->count);
1631 if (call->count >= AFSNAMEMAX)
1632 return afs_protocol_error(call, -EBADMSG,
1633 afs_eproto_volname_len);
1634 size = (call->count + 3) & ~3; /* It's padded */
1635 afs_extract_to_buf(call, size);
1638 /* Fall through - and extract the volume name */
1640 _debug("extract volname");
1641 ret = afs_extract_data(call, true);
1647 _debug("volname '%s'", p);
1648 afs_extract_to_tmp(call);
1651 /* Fall through - and extract the offline message length */
1653 ret = afs_extract_data(call, true);
1657 call->count = ntohl(call->tmp);
1658 _debug("offline msg length: %u", call->count);
1659 if (call->count >= AFSNAMEMAX)
1660 return afs_protocol_error(call, -EBADMSG,
1661 afs_eproto_offline_msg_len);
1662 size = (call->count + 3) & ~3; /* It's padded */
1663 afs_extract_to_buf(call, size);
1666 /* Fall through - and extract the offline message */
1668 _debug("extract offline");
1669 ret = afs_extract_data(call, true);
1675 _debug("offline '%s'", p);
1677 afs_extract_to_tmp(call);
1680 /* Fall through - and extract the message of the day length */
1682 ret = afs_extract_data(call, true);
1686 call->count = ntohl(call->tmp);
1687 _debug("motd length: %u", call->count);
1688 if (call->count >= AFSNAMEMAX)
1689 return afs_protocol_error(call, -EBADMSG,
1690 afs_eproto_motd_len);
1691 size = (call->count + 3) & ~3; /* It's padded */
1692 afs_extract_to_buf(call, size);
1695 /* Fall through - and extract the message of the day */
1697 _debug("extract motd");
1698 ret = afs_extract_data(call, false);
1704 _debug("motd '%s'", p);
1713 _leave(" = 0 [done]");
1718 * YFS.GetVolumeStatus operation type
1720 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1721 .name = "YFS.GetVolumeStatus",
1722 .op = yfs_FS_GetVolumeStatus,
1723 .deliver = yfs_deliver_fs_get_volume_status,
1724 .destructor = afs_flat_call_destructor,
1728 * fetch the status of a volume
1730 int yfs_fs_get_volume_status(struct afs_fs_cursor *fc,
1731 struct afs_volume_status *vs)
1733 struct afs_vnode *vnode = fc->vnode;
1734 struct afs_call *call;
1735 struct afs_net *net = afs_v2net(vnode);
1740 call = afs_alloc_flat_call(net, &yfs_RXYFSGetVolumeStatus,
1741 sizeof(__be32) * 2 +
1742 sizeof(struct yfs_xdr_u64),
1744 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1750 call->key = fc->key;
1751 call->out_volstatus = vs;
1753 /* marshall the parameters */
1755 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1756 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1757 bp = xdr_encode_u64(bp, vnode->fid.vid);
1758 yfs_check_req(call, bp);
1760 afs_use_fs_server(call, fc->cbi);
1761 trace_afs_make_fs_call(call, &vnode->fid);
1762 afs_set_fc_call(call, fc);
1763 afs_make_call(&fc->ac, call, GFP_NOFS);
1764 return afs_wait_for_call_to_complete(call, &fc->ac);
1768 * Deliver reply data to operations that just return a file status and a volume
1771 static int yfs_deliver_status_and_volsync(struct afs_call *call)
1773 struct afs_vnode *vnode = call->xvnode;
1777 _enter("{%u}", call->unmarshall);
1779 ret = afs_transfer_reply(call);
1783 /* unmarshall the reply once we've received all of it */
1785 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1786 &call->expected_version, NULL);
1789 xdr_decode_YFSVolSync(&bp, NULL);
1791 _leave(" = 0 [done]");
1796 * YFS.SetLock operation type
1798 static const struct afs_call_type yfs_RXYFSSetLock = {
1799 .name = "YFS.SetLock",
1800 .op = yfs_FS_SetLock,
1801 .deliver = yfs_deliver_status_and_volsync,
1802 .done = afs_lock_op_done,
1803 .destructor = afs_flat_call_destructor,
1807 * YFS.ExtendLock operation type
1809 static const struct afs_call_type yfs_RXYFSExtendLock = {
1810 .name = "YFS.ExtendLock",
1811 .op = yfs_FS_ExtendLock,
1812 .deliver = yfs_deliver_status_and_volsync,
1813 .done = afs_lock_op_done,
1814 .destructor = afs_flat_call_destructor,
1818 * YFS.ReleaseLock operation type
1820 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1821 .name = "YFS.ReleaseLock",
1822 .op = yfs_FS_ReleaseLock,
1823 .deliver = yfs_deliver_status_and_volsync,
1824 .destructor = afs_flat_call_destructor,
1828 * Set a lock on a file
1830 int yfs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1832 struct afs_vnode *vnode = fc->vnode;
1833 struct afs_call *call;
1834 struct afs_net *net = afs_v2net(vnode);
1839 call = afs_alloc_flat_call(net, &yfs_RXYFSSetLock,
1840 sizeof(__be32) * 2 +
1841 sizeof(struct yfs_xdr_YFSFid) +
1843 sizeof(struct yfs_xdr_YFSFetchStatus) +
1844 sizeof(struct yfs_xdr_YFSVolSync));
1848 call->key = fc->key;
1849 call->xvnode = vnode;
1850 call->want_reply_time = true;
1852 /* marshall the parameters */
1854 bp = xdr_encode_u32(bp, YFSSETLOCK);
1855 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1856 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1857 bp = xdr_encode_u32(bp, type);
1858 yfs_check_req(call, bp);
1860 afs_use_fs_server(call, fc->cbi);
1861 trace_afs_make_fs_calli(call, &vnode->fid, type);
1862 afs_set_fc_call(call, fc);
1863 afs_make_call(&fc->ac, call, GFP_NOFS);
1864 return afs_wait_for_call_to_complete(call, &fc->ac);
1868 * extend a lock on a file
1870 int yfs_fs_extend_lock(struct afs_fs_cursor *fc)
1872 struct afs_vnode *vnode = fc->vnode;
1873 struct afs_call *call;
1874 struct afs_net *net = afs_v2net(vnode);
1879 call = afs_alloc_flat_call(net, &yfs_RXYFSExtendLock,
1880 sizeof(__be32) * 2 +
1881 sizeof(struct yfs_xdr_YFSFid),
1882 sizeof(struct yfs_xdr_YFSFetchStatus) +
1883 sizeof(struct yfs_xdr_YFSVolSync));
1887 call->key = fc->key;
1888 call->xvnode = vnode;
1889 call->want_reply_time = true;
1891 /* marshall the parameters */
1893 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1894 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1895 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1896 yfs_check_req(call, bp);
1898 afs_use_fs_server(call, fc->cbi);
1899 trace_afs_make_fs_call(call, &vnode->fid);
1900 afs_set_fc_call(call, fc);
1901 afs_make_call(&fc->ac, call, GFP_NOFS);
1902 return afs_wait_for_call_to_complete(call, &fc->ac);
1906 * release a lock on a file
1908 int yfs_fs_release_lock(struct afs_fs_cursor *fc)
1910 struct afs_vnode *vnode = fc->vnode;
1911 struct afs_call *call;
1912 struct afs_net *net = afs_v2net(vnode);
1917 call = afs_alloc_flat_call(net, &yfs_RXYFSReleaseLock,
1918 sizeof(__be32) * 2 +
1919 sizeof(struct yfs_xdr_YFSFid),
1920 sizeof(struct yfs_xdr_YFSFetchStatus) +
1921 sizeof(struct yfs_xdr_YFSVolSync));
1925 call->key = fc->key;
1926 call->xvnode = vnode;
1928 /* marshall the parameters */
1930 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1931 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1932 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1933 yfs_check_req(call, bp);
1935 afs_use_fs_server(call, fc->cbi);
1936 trace_afs_make_fs_call(call, &vnode->fid);
1937 afs_set_fc_call(call, fc);
1938 afs_make_call(&fc->ac, call, GFP_NOFS);
1939 return afs_wait_for_call_to_complete(call, &fc->ac);
1943 * Deliver reply data to an FS.FetchStatus with no vnode.
1945 static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1947 struct afs_file_status *status = call->out_extra_status;
1948 struct afs_callback *callback = call->out_cb;
1949 struct afs_volsync *volsync = call->out_volsync;
1953 ret = afs_transfer_reply(call);
1959 /* unmarshall the reply once we've received all of it */
1961 ret = yfs_decode_status(call, &bp, status, NULL,
1962 &call->expected_version, NULL);
1965 xdr_decode_YFSCallBack_raw(call, callback, &bp);
1966 xdr_decode_YFSVolSync(&bp, volsync);
1968 _leave(" = 0 [done]");
1973 * YFS.FetchStatus operation type
1975 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1976 .name = "YFS.FetchStatus",
1977 .op = yfs_FS_FetchStatus,
1978 .deliver = yfs_deliver_fs_fetch_status,
1979 .destructor = afs_flat_call_destructor,
1983 * Fetch the status information for a fid without needing a vnode handle.
1985 int yfs_fs_fetch_status(struct afs_fs_cursor *fc,
1986 struct afs_net *net,
1987 struct afs_fid *fid,
1988 struct afs_file_status *status,
1989 struct afs_callback *callback,
1990 struct afs_volsync *volsync)
1992 struct afs_call *call;
1995 _enter(",%x,{%llx:%llu},,",
1996 key_serial(fc->key), fid->vid, fid->vnode);
1998 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus,
1999 sizeof(__be32) * 2 +
2000 sizeof(struct yfs_xdr_YFSFid),
2001 sizeof(struct yfs_xdr_YFSFetchStatus) +
2002 sizeof(struct yfs_xdr_YFSCallBack) +
2003 sizeof(struct yfs_xdr_YFSVolSync));
2005 fc->ac.error = -ENOMEM;
2009 call->key = fc->key;
2010 call->out_extra_status = status;
2011 call->out_cb = callback;
2012 call->out_volsync = volsync;
2013 call->expected_version = 1; /* vnode->status.data_version */
2015 /* marshall the parameters */
2017 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
2018 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2019 bp = xdr_encode_YFSFid(bp, fid);
2020 yfs_check_req(call, bp);
2022 call->cb_break = fc->cb_break;
2023 afs_use_fs_server(call, fc->cbi);
2024 trace_afs_make_fs_call(call, fid);
2025 afs_set_fc_call(call, fc);
2026 afs_make_call(&fc->ac, call, GFP_NOFS);
2027 return afs_wait_for_call_to_complete(call, &fc->ac);
2031 * Deliver reply data to an YFS.InlineBulkStatus call
2033 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
2035 struct afs_file_status *statuses;
2036 struct afs_callback *callbacks;
2041 _enter("{%u}", call->unmarshall);
2043 switch (call->unmarshall) {
2045 afs_extract_to_tmp(call);
2048 /* Extract the file status count and array in two steps */
2051 _debug("extract status count");
2052 ret = afs_extract_data(call, true);
2056 tmp = ntohl(call->tmp);
2057 _debug("status count: %u/%u", tmp, call->count2);
2058 if (tmp != call->count2)
2059 return afs_protocol_error(call, -EBADMSG,
2060 afs_eproto_ibulkst_count);
2065 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
2069 _debug("extract status array %u", call->count);
2070 ret = afs_extract_data(call, true);
2075 statuses = call->out_extra_status;
2076 ret = yfs_decode_status(call, &bp, &statuses[call->count],
2082 if (call->count < call->count2)
2087 afs_extract_to_tmp(call);
2089 /* Extract the callback count and array in two steps */
2092 _debug("extract CB count");
2093 ret = afs_extract_data(call, true);
2097 tmp = ntohl(call->tmp);
2098 _debug("CB count: %u", tmp);
2099 if (tmp != call->count2)
2100 return afs_protocol_error(call, -EBADMSG,
2101 afs_eproto_ibulkst_cb_count);
2105 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
2109 _debug("extract CB array");
2110 ret = afs_extract_data(call, true);
2114 _debug("unmarshall CB array");
2116 callbacks = call->out_cb;
2117 xdr_decode_YFSCallBack_raw(call, &callbacks[call->count], &bp);
2119 if (call->count < call->count2)
2122 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
2127 ret = afs_extract_data(call, false);
2132 xdr_decode_YFSVolSync(&bp, call->out_volsync);
2141 _leave(" = 0 [done]");
2146 * FS.InlineBulkStatus operation type
2148 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
2149 .name = "YFS.InlineBulkStatus",
2150 .op = yfs_FS_InlineBulkStatus,
2151 .deliver = yfs_deliver_fs_inline_bulk_status,
2152 .destructor = afs_flat_call_destructor,
2156 * Fetch the status information for up to 1024 files
2158 int yfs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2159 struct afs_net *net,
2160 struct afs_fid *fids,
2161 struct afs_file_status *statuses,
2162 struct afs_callback *callbacks,
2163 unsigned int nr_fids,
2164 struct afs_volsync *volsync)
2166 struct afs_call *call;
2170 _enter(",%x,{%llx:%llu},%u",
2171 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2173 call = afs_alloc_flat_call(net, &yfs_RXYFSInlineBulkStatus,
2177 sizeof(struct yfs_xdr_YFSFid) * nr_fids,
2178 sizeof(struct yfs_xdr_YFSFetchStatus));
2180 fc->ac.error = -ENOMEM;
2184 call->key = fc->key;
2185 call->out_extra_status = statuses;
2186 call->out_cb = callbacks;
2187 call->out_volsync = volsync;
2188 call->count2 = nr_fids;
2190 /* marshall the parameters */
2192 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
2193 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
2194 bp = xdr_encode_u32(bp, nr_fids);
2195 for (i = 0; i < nr_fids; i++)
2196 bp = xdr_encode_YFSFid(bp, &fids[i]);
2197 yfs_check_req(call, bp);
2199 call->cb_break = fc->cb_break;
2200 afs_use_fs_server(call, fc->cbi);
2201 trace_afs_make_fs_call(call, &fids[0]);
2202 afs_set_fc_call(call, fc);
2203 afs_make_call(&fc->ac, call, GFP_NOFS);
2204 return afs_wait_for_call_to_complete(call, &fc->ac);
2208 * Deliver reply data to an YFS.FetchOpaqueACL.
2210 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
2212 struct afs_volsync *volsync = call->out_volsync;
2213 struct afs_vnode *vnode = call->xvnode;
2214 struct yfs_acl *yacl = call->out_yacl;
2215 struct afs_acl *acl;
2220 _enter("{%u}", call->unmarshall);
2222 switch (call->unmarshall) {
2224 afs_extract_to_tmp(call);
2227 /* Extract the file ACL length */
2229 ret = afs_extract_data(call, true);
2233 size = call->count2 = ntohl(call->tmp);
2234 size = round_up(size, 4);
2236 if (yacl->flags & YFS_ACL_WANT_ACL) {
2237 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2241 acl->size = call->count2;
2242 afs_extract_begin(call, acl->data, size);
2244 iov_iter_discard(&call->iter, READ, size);
2248 /* Extract the file ACL */
2250 ret = afs_extract_data(call, true);
2254 afs_extract_to_tmp(call);
2257 /* Extract the volume ACL length */
2259 ret = afs_extract_data(call, true);
2263 size = call->count2 = ntohl(call->tmp);
2264 size = round_up(size, 4);
2266 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
2267 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2270 yacl->vol_acl = acl;
2271 acl->size = call->count2;
2272 afs_extract_begin(call, acl->data, size);
2274 iov_iter_discard(&call->iter, READ, size);
2278 /* Extract the volume ACL */
2280 ret = afs_extract_data(call, true);
2284 afs_extract_to_buf(call,
2285 sizeof(__be32) * 2 +
2286 sizeof(struct yfs_xdr_YFSFetchStatus) +
2287 sizeof(struct yfs_xdr_YFSVolSync));
2290 /* extract the metadata */
2292 ret = afs_extract_data(call, false);
2297 yacl->inherit_flag = ntohl(*bp++);
2298 yacl->num_cleaned = ntohl(*bp++);
2299 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
2300 &call->expected_version, NULL);
2303 xdr_decode_YFSVolSync(&bp, volsync);
2311 _leave(" = 0 [done]");
2315 void yfs_free_opaque_acl(struct yfs_acl *yacl)
2319 kfree(yacl->vol_acl);
2325 * YFS.FetchOpaqueACL operation type
2327 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
2328 .name = "YFS.FetchOpaqueACL",
2329 .op = yfs_FS_FetchOpaqueACL,
2330 .deliver = yfs_deliver_fs_fetch_opaque_acl,
2331 .destructor = afs_flat_call_destructor,
2335 * Fetch the YFS advanced ACLs for a file.
2337 struct yfs_acl *yfs_fs_fetch_opaque_acl(struct afs_fs_cursor *fc,
2338 struct yfs_acl *yacl)
2340 struct afs_vnode *vnode = fc->vnode;
2341 struct afs_call *call;
2342 struct afs_net *net = afs_v2net(vnode);
2345 _enter(",%x,{%llx:%llu},,",
2346 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2348 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchOpaqueACL,
2349 sizeof(__be32) * 2 +
2350 sizeof(struct yfs_xdr_YFSFid),
2351 sizeof(__be32) * 2 +
2352 sizeof(struct yfs_xdr_YFSFetchStatus) +
2353 sizeof(struct yfs_xdr_YFSVolSync));
2355 fc->ac.error = -ENOMEM;
2356 return ERR_PTR(-ENOMEM);
2359 call->key = fc->key;
2360 call->out_yacl = yacl;
2361 call->xvnode = vnode;
2362 call->out_volsync = NULL; /* volsync */
2364 /* marshall the parameters */
2366 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
2367 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2368 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2369 yfs_check_req(call, bp);
2371 call->cb_break = fc->cb_break;
2372 afs_use_fs_server(call, fc->cbi);
2373 trace_afs_make_fs_call(call, &vnode->fid);
2374 afs_make_call(&fc->ac, call, GFP_KERNEL);
2375 return (struct yfs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2379 * YFS.StoreOpaqueACL2 operation type
2381 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
2382 .name = "YFS.StoreOpaqueACL2",
2383 .op = yfs_FS_StoreOpaqueACL2,
2384 .deliver = yfs_deliver_status_and_volsync,
2385 .destructor = afs_flat_call_destructor,
2389 * Fetch the YFS ACL for a file.
2391 int yfs_fs_store_opaque_acl2(struct afs_fs_cursor *fc, const struct afs_acl *acl)
2393 struct afs_vnode *vnode = fc->vnode;
2394 struct afs_call *call;
2395 struct afs_net *net = afs_v2net(vnode);
2399 _enter(",%x,{%llx:%llu},,",
2400 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2402 size = round_up(acl->size, 4);
2403 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
2404 sizeof(__be32) * 2 +
2405 sizeof(struct yfs_xdr_YFSFid) +
2406 sizeof(__be32) + size,
2407 sizeof(struct yfs_xdr_YFSFetchStatus) +
2408 sizeof(struct yfs_xdr_YFSVolSync));
2410 fc->ac.error = -ENOMEM;
2414 call->key = fc->key;
2415 call->xvnode = vnode;
2416 call->out_volsync = NULL;
2418 /* marshall the parameters */
2420 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
2421 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2422 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2423 bp = xdr_encode_u32(bp, acl->size);
2424 memcpy(bp, acl->data, acl->size);
2425 if (acl->size != size)
2426 memset((void *)bp + acl->size, 0, size - acl->size);
2427 yfs_check_req(call, bp);
2429 trace_afs_make_fs_call(call, &vnode->fid);
2430 afs_make_call(&fc->ac, call, GFP_KERNEL);
2431 return afs_wait_for_call_to_complete(call, &fc->ac);