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;
699 /* marshall the parameters */
701 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
702 bp = xdr_encode_u32(bp, 0); /* RPC flags */
703 bp = xdr_encode_YFSFid(bp, &vnode->fid);
704 bp = xdr_encode_u64(bp, req->pos);
705 bp = xdr_encode_u64(bp, req->len);
706 yfs_check_req(call, bp);
708 refcount_inc(&req->usage);
709 call->cb_break = fc->cb_break;
710 afs_use_fs_server(call, fc->cbi);
711 trace_afs_make_fs_call(call, &vnode->fid);
712 afs_set_fc_call(call, fc);
713 afs_make_call(&fc->ac, call, GFP_NOFS);
714 return afs_wait_for_call_to_complete(call, &fc->ac);
718 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
720 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
722 struct afs_vnode *dvnode = call->dvnode;
726 _enter("{%u}", call->unmarshall);
728 ret = afs_transfer_reply(call);
732 /* unmarshall the reply once we've received all of it */
734 xdr_decode_YFSFid(&bp, call->out_fid);
735 ret = yfs_decode_status(call, &bp, call->out_extra_status, NULL, NULL, NULL);
738 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
739 &call->expected_version, NULL);
742 xdr_decode_YFSCallBack_raw(call, call->out_cb, &bp);
743 xdr_decode_YFSVolSync(&bp, NULL);
745 _leave(" = 0 [done]");
750 * FS.CreateFile and FS.MakeDir operation type
752 static const struct afs_call_type afs_RXFSCreateFile = {
753 .name = "YFS.CreateFile",
754 .op = yfs_FS_CreateFile,
755 .deliver = yfs_deliver_fs_create_vnode,
756 .destructor = afs_flat_call_destructor,
762 int yfs_fs_create_file(struct afs_fs_cursor *fc,
765 u64 current_data_version,
766 struct afs_fid *newfid,
767 struct afs_file_status *newstatus,
768 struct afs_callback *newcb)
770 struct afs_vnode *dvnode = fc->vnode;
771 struct afs_call *call;
772 struct afs_net *net = afs_v2net(dvnode);
773 size_t namesz, reqsz, rplsz;
778 namesz = strlen(name);
779 reqsz = (sizeof(__be32) +
781 sizeof(struct yfs_xdr_YFSFid) +
783 sizeof(struct yfs_xdr_YFSStoreStatus) +
785 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
786 sizeof(struct yfs_xdr_YFSFetchStatus) +
787 sizeof(struct yfs_xdr_YFSFetchStatus) +
788 sizeof(struct yfs_xdr_YFSCallBack) +
789 sizeof(struct yfs_xdr_YFSVolSync));
791 call = afs_alloc_flat_call(net, &afs_RXFSCreateFile, reqsz, rplsz);
796 call->dvnode = dvnode;
797 call->out_fid = newfid;
798 call->out_extra_status = newstatus;
799 call->out_cb = newcb;
800 call->expected_version = current_data_version + 1;
802 /* marshall the parameters */
804 bp = xdr_encode_u32(bp, YFSCREATEFILE);
805 bp = xdr_encode_u32(bp, 0); /* RPC flags */
806 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
807 bp = xdr_encode_string(bp, name, namesz);
808 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
809 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
810 yfs_check_req(call, bp);
812 afs_use_fs_server(call, fc->cbi);
813 trace_afs_make_fs_call1(call, &dvnode->fid, name);
814 afs_set_fc_call(call, fc);
815 afs_make_call(&fc->ac, call, GFP_NOFS);
816 return afs_wait_for_call_to_complete(call, &fc->ac);
819 static const struct afs_call_type yfs_RXFSMakeDir = {
820 .name = "YFS.MakeDir",
821 .op = yfs_FS_MakeDir,
822 .deliver = yfs_deliver_fs_create_vnode,
823 .destructor = afs_flat_call_destructor,
829 int yfs_fs_make_dir(struct afs_fs_cursor *fc,
832 u64 current_data_version,
833 struct afs_fid *newfid,
834 struct afs_file_status *newstatus,
835 struct afs_callback *newcb)
837 struct afs_vnode *dvnode = fc->vnode;
838 struct afs_call *call;
839 struct afs_net *net = afs_v2net(dvnode);
840 size_t namesz, reqsz, rplsz;
845 namesz = strlen(name);
846 reqsz = (sizeof(__be32) +
847 sizeof(struct yfs_xdr_RPCFlags) +
848 sizeof(struct yfs_xdr_YFSFid) +
850 sizeof(struct yfs_xdr_YFSStoreStatus));
851 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
852 sizeof(struct yfs_xdr_YFSFetchStatus) +
853 sizeof(struct yfs_xdr_YFSFetchStatus) +
854 sizeof(struct yfs_xdr_YFSCallBack) +
855 sizeof(struct yfs_xdr_YFSVolSync));
857 call = afs_alloc_flat_call(net, &yfs_RXFSMakeDir, reqsz, rplsz);
862 call->dvnode = dvnode;
863 call->out_fid = newfid;
864 call->out_extra_status = newstatus;
865 call->out_cb = newcb;
866 call->expected_version = current_data_version + 1;
868 /* marshall the parameters */
870 bp = xdr_encode_u32(bp, YFSMAKEDIR);
871 bp = xdr_encode_u32(bp, 0); /* RPC flags */
872 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
873 bp = xdr_encode_string(bp, name, namesz);
874 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
875 yfs_check_req(call, bp);
877 afs_use_fs_server(call, fc->cbi);
878 trace_afs_make_fs_call1(call, &dvnode->fid, name);
879 afs_set_fc_call(call, fc);
880 afs_make_call(&fc->ac, call, GFP_NOFS);
881 return afs_wait_for_call_to_complete(call, &fc->ac);
885 * Deliver reply data to a YFS.RemoveFile2 operation.
887 static int yfs_deliver_fs_remove_file2(struct afs_call *call)
889 struct afs_vnode *dvnode = call->dvnode;
890 struct afs_vnode *vnode = call->xvnode;
895 _enter("{%u}", call->unmarshall);
897 ret = afs_transfer_reply(call);
901 /* unmarshall the reply once we've received all of it */
903 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
904 &call->expected_version, NULL);
908 xdr_decode_YFSFid(&bp, &fid);
909 ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
912 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
914 xdr_decode_YFSVolSync(&bp, NULL);
919 * YFS.RemoveFile2 operation type.
921 static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
922 .name = "YFS.RemoveFile2",
923 .op = yfs_FS_RemoveFile2,
924 .deliver = yfs_deliver_fs_remove_file2,
925 .destructor = afs_flat_call_destructor,
929 * Remove a file and retrieve new file status.
931 int yfs_fs_remove_file2(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
932 const char *name, u64 current_data_version)
934 struct afs_vnode *dvnode = fc->vnode;
935 struct afs_call *call;
936 struct afs_net *net = afs_v2net(dvnode);
942 namesz = strlen(name);
944 call = afs_alloc_flat_call(net, &yfs_RXYFSRemoveFile2,
946 sizeof(struct yfs_xdr_RPCFlags) +
947 sizeof(struct yfs_xdr_YFSFid) +
949 sizeof(struct yfs_xdr_YFSFetchStatus) +
950 sizeof(struct yfs_xdr_YFSFid) +
951 sizeof(struct yfs_xdr_YFSFetchStatus) +
952 sizeof(struct yfs_xdr_YFSVolSync));
957 call->dvnode = dvnode;
958 call->xvnode = vnode;
959 call->expected_version = current_data_version + 1;
961 /* marshall the parameters */
963 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
964 bp = xdr_encode_u32(bp, 0); /* RPC flags */
965 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
966 bp = xdr_encode_string(bp, name, namesz);
967 yfs_check_req(call, bp);
969 afs_use_fs_server(call, fc->cbi);
970 trace_afs_make_fs_call1(call, &dvnode->fid, name);
971 afs_set_fc_call(call, fc);
972 afs_make_call(&fc->ac, call, GFP_NOFS);
973 return afs_wait_for_call_to_complete(call, &fc->ac);
977 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
979 static int yfs_deliver_fs_remove(struct afs_call *call)
981 struct afs_vnode *dvnode = call->dvnode;
985 _enter("{%u}", call->unmarshall);
987 ret = afs_transfer_reply(call);
991 /* unmarshall the reply once we've received all of it */
993 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
994 &call->expected_version, NULL);
998 xdr_decode_YFSVolSync(&bp, NULL);
1003 * FS.RemoveDir and FS.RemoveFile operation types.
1005 static const struct afs_call_type yfs_RXYFSRemoveFile = {
1006 .name = "YFS.RemoveFile",
1007 .op = yfs_FS_RemoveFile,
1008 .deliver = yfs_deliver_fs_remove,
1009 .destructor = afs_flat_call_destructor,
1012 static const struct afs_call_type yfs_RXYFSRemoveDir = {
1013 .name = "YFS.RemoveDir",
1014 .op = yfs_FS_RemoveDir,
1015 .deliver = yfs_deliver_fs_remove,
1016 .destructor = afs_flat_call_destructor,
1020 * remove a file or directory
1022 int yfs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
1023 const char *name, bool isdir, u64 current_data_version)
1025 struct afs_vnode *dvnode = fc->vnode;
1026 struct afs_call *call;
1027 struct afs_net *net = afs_v2net(dvnode);
1033 namesz = strlen(name);
1034 call = afs_alloc_flat_call(
1035 net, isdir ? &yfs_RXYFSRemoveDir : &yfs_RXYFSRemoveFile,
1037 sizeof(struct yfs_xdr_RPCFlags) +
1038 sizeof(struct yfs_xdr_YFSFid) +
1040 sizeof(struct yfs_xdr_YFSFetchStatus) +
1041 sizeof(struct yfs_xdr_YFSVolSync));
1045 call->key = fc->key;
1046 call->dvnode = dvnode;
1047 call->xvnode = vnode;
1048 call->expected_version = current_data_version + 1;
1050 /* marshall the parameters */
1052 bp = xdr_encode_u32(bp, isdir ? YFSREMOVEDIR : YFSREMOVEFILE);
1053 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1054 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1055 bp = xdr_encode_string(bp, name, namesz);
1056 yfs_check_req(call, bp);
1058 afs_use_fs_server(call, fc->cbi);
1059 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1060 afs_set_fc_call(call, fc);
1061 afs_make_call(&fc->ac, call, GFP_NOFS);
1062 return afs_wait_for_call_to_complete(call, &fc->ac);
1066 * Deliver reply data to a YFS.Link operation.
1068 static int yfs_deliver_fs_link(struct afs_call *call)
1070 struct afs_vnode *dvnode = call->dvnode, *vnode = call->xvnode;
1074 _enter("{%u}", call->unmarshall);
1076 ret = afs_transfer_reply(call);
1080 /* unmarshall the reply once we've received all of it */
1082 ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
1085 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
1086 &call->expected_version, NULL);
1089 xdr_decode_YFSVolSync(&bp, NULL);
1090 _leave(" = 0 [done]");
1095 * YFS.Link operation type.
1097 static const struct afs_call_type yfs_RXYFSLink = {
1100 .deliver = yfs_deliver_fs_link,
1101 .destructor = afs_flat_call_destructor,
1107 int yfs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
1108 const char *name, u64 current_data_version)
1110 struct afs_vnode *dvnode = fc->vnode;
1111 struct afs_call *call;
1112 struct afs_net *net = afs_v2net(vnode);
1118 namesz = strlen(name);
1119 call = afs_alloc_flat_call(net, &yfs_RXYFSLink,
1121 sizeof(struct yfs_xdr_RPCFlags) +
1122 sizeof(struct yfs_xdr_YFSFid) +
1123 xdr_strlen(namesz) +
1124 sizeof(struct yfs_xdr_YFSFid),
1125 sizeof(struct yfs_xdr_YFSFetchStatus) +
1126 sizeof(struct yfs_xdr_YFSFetchStatus) +
1127 sizeof(struct yfs_xdr_YFSVolSync));
1131 call->key = fc->key;
1132 call->dvnode = dvnode;
1133 call->xvnode = vnode;
1134 call->expected_version = current_data_version + 1;
1136 /* marshall the parameters */
1138 bp = xdr_encode_u32(bp, YFSLINK);
1139 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1140 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1141 bp = xdr_encode_string(bp, name, namesz);
1142 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1143 yfs_check_req(call, bp);
1145 afs_use_fs_server(call, fc->cbi);
1146 trace_afs_make_fs_call1(call, &vnode->fid, name);
1147 afs_set_fc_call(call, fc);
1148 afs_make_call(&fc->ac, call, GFP_NOFS);
1149 return afs_wait_for_call_to_complete(call, &fc->ac);
1153 * Deliver reply data to a YFS.Symlink operation.
1155 static int yfs_deliver_fs_symlink(struct afs_call *call)
1157 struct afs_vnode *dvnode = call->dvnode;
1161 _enter("{%u}", call->unmarshall);
1163 ret = afs_transfer_reply(call);
1167 /* unmarshall the reply once we've received all of it */
1169 xdr_decode_YFSFid(&bp, call->out_fid);
1170 ret = yfs_decode_status(call, &bp, call->out_extra_status, NULL, NULL, NULL);
1173 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
1174 &call->expected_version, NULL);
1177 xdr_decode_YFSVolSync(&bp, NULL);
1179 _leave(" = 0 [done]");
1184 * YFS.Symlink operation type
1186 static const struct afs_call_type yfs_RXYFSSymlink = {
1187 .name = "YFS.Symlink",
1188 .op = yfs_FS_Symlink,
1189 .deliver = yfs_deliver_fs_symlink,
1190 .destructor = afs_flat_call_destructor,
1194 * Create a symbolic link.
1196 int yfs_fs_symlink(struct afs_fs_cursor *fc,
1198 const char *contents,
1199 u64 current_data_version,
1200 struct afs_fid *newfid,
1201 struct afs_file_status *newstatus)
1203 struct afs_vnode *dvnode = fc->vnode;
1204 struct afs_call *call;
1205 struct afs_net *net = afs_v2net(dvnode);
1206 size_t namesz, contents_sz;
1211 namesz = strlen(name);
1212 contents_sz = strlen(contents);
1213 call = afs_alloc_flat_call(net, &yfs_RXYFSSymlink,
1215 sizeof(struct yfs_xdr_RPCFlags) +
1216 sizeof(struct yfs_xdr_YFSFid) +
1217 xdr_strlen(namesz) +
1218 xdr_strlen(contents_sz) +
1219 sizeof(struct yfs_xdr_YFSStoreStatus),
1220 sizeof(struct yfs_xdr_YFSFid) +
1221 sizeof(struct yfs_xdr_YFSFetchStatus) +
1222 sizeof(struct yfs_xdr_YFSFetchStatus) +
1223 sizeof(struct yfs_xdr_YFSVolSync));
1227 call->key = fc->key;
1228 call->dvnode = dvnode;
1229 call->out_fid = newfid;
1230 call->out_extra_status = newstatus;
1231 call->expected_version = current_data_version + 1;
1233 /* marshall the parameters */
1235 bp = xdr_encode_u32(bp, YFSSYMLINK);
1236 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1237 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1238 bp = xdr_encode_string(bp, name, namesz);
1239 bp = xdr_encode_string(bp, contents, contents_sz);
1240 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
1241 yfs_check_req(call, bp);
1243 afs_use_fs_server(call, fc->cbi);
1244 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1245 afs_set_fc_call(call, fc);
1246 afs_make_call(&fc->ac, call, GFP_NOFS);
1247 return afs_wait_for_call_to_complete(call, &fc->ac);
1251 * Deliver reply data to a YFS.Rename operation.
1253 static int yfs_deliver_fs_rename(struct afs_call *call)
1255 struct afs_vnode *orig_dvnode = call->dvnode;
1256 struct afs_vnode *new_dvnode = call->xvnode;
1260 _enter("{%u}", call->unmarshall);
1262 ret = afs_transfer_reply(call);
1266 /* unmarshall the reply once we've received all of it */
1268 ret = yfs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1269 &call->expected_version, NULL);
1272 if (new_dvnode != orig_dvnode) {
1273 ret = yfs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1274 &call->expected_version_2, NULL);
1279 xdr_decode_YFSVolSync(&bp, NULL);
1280 _leave(" = 0 [done]");
1285 * YFS.Rename operation type
1287 static const struct afs_call_type yfs_RXYFSRename = {
1288 .name = "FS.Rename",
1289 .op = yfs_FS_Rename,
1290 .deliver = yfs_deliver_fs_rename,
1291 .destructor = afs_flat_call_destructor,
1295 * Rename a file or directory.
1297 int yfs_fs_rename(struct afs_fs_cursor *fc,
1298 const char *orig_name,
1299 struct afs_vnode *new_dvnode,
1300 const char *new_name,
1301 u64 current_orig_data_version,
1302 u64 current_new_data_version)
1304 struct afs_vnode *orig_dvnode = fc->vnode;
1305 struct afs_call *call;
1306 struct afs_net *net = afs_v2net(orig_dvnode);
1307 size_t o_namesz, n_namesz;
1312 o_namesz = strlen(orig_name);
1313 n_namesz = strlen(new_name);
1314 call = afs_alloc_flat_call(net, &yfs_RXYFSRename,
1316 sizeof(struct yfs_xdr_RPCFlags) +
1317 sizeof(struct yfs_xdr_YFSFid) +
1318 xdr_strlen(o_namesz) +
1319 sizeof(struct yfs_xdr_YFSFid) +
1320 xdr_strlen(n_namesz),
1321 sizeof(struct yfs_xdr_YFSFetchStatus) +
1322 sizeof(struct yfs_xdr_YFSFetchStatus) +
1323 sizeof(struct yfs_xdr_YFSVolSync));
1327 call->key = fc->key;
1328 call->dvnode = orig_dvnode;
1329 call->xvnode = new_dvnode;
1330 call->expected_version = current_orig_data_version + 1;
1331 call->expected_version_2 = current_new_data_version + 1;
1333 /* marshall the parameters */
1335 bp = xdr_encode_u32(bp, YFSRENAME);
1336 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1337 bp = xdr_encode_YFSFid(bp, &orig_dvnode->fid);
1338 bp = xdr_encode_string(bp, orig_name, o_namesz);
1339 bp = xdr_encode_YFSFid(bp, &new_dvnode->fid);
1340 bp = xdr_encode_string(bp, new_name, n_namesz);
1341 yfs_check_req(call, bp);
1343 afs_use_fs_server(call, fc->cbi);
1344 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1345 afs_set_fc_call(call, fc);
1346 afs_make_call(&fc->ac, call, GFP_NOFS);
1347 return afs_wait_for_call_to_complete(call, &fc->ac);
1351 * Deliver reply data to a YFS.StoreData64 operation.
1353 static int yfs_deliver_fs_store_data(struct afs_call *call)
1355 struct afs_vnode *vnode = call->xvnode;
1361 ret = afs_transfer_reply(call);
1365 /* unmarshall the reply once we've received all of it */
1367 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1368 &call->expected_version, NULL);
1371 xdr_decode_YFSVolSync(&bp, NULL);
1373 afs_pages_written_back(vnode, call);
1375 _leave(" = 0 [done]");
1380 * YFS.StoreData64 operation type.
1382 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1383 .name = "YFS.StoreData64",
1384 .op = yfs_FS_StoreData64,
1385 .deliver = yfs_deliver_fs_store_data,
1386 .destructor = afs_flat_call_destructor,
1390 * Store a set of pages to a large file.
1392 int yfs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1393 pgoff_t first, pgoff_t last,
1394 unsigned offset, unsigned to)
1396 struct afs_vnode *vnode = fc->vnode;
1397 struct afs_call *call;
1398 struct afs_net *net = afs_v2net(vnode);
1399 loff_t size, pos, i_size;
1402 _enter(",%x,{%llx:%llu},,",
1403 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1405 size = (loff_t)to - (loff_t)offset;
1407 size += (loff_t)(last - first) << PAGE_SHIFT;
1408 pos = (loff_t)first << PAGE_SHIFT;
1411 i_size = i_size_read(&vnode->vfs_inode);
1412 if (pos + size > i_size)
1413 i_size = size + pos;
1415 _debug("size %llx, at %llx, i_size %llx",
1416 (unsigned long long)size, (unsigned long long)pos,
1417 (unsigned long long)i_size);
1419 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64,
1422 sizeof(struct yfs_xdr_YFSFid) +
1423 sizeof(struct yfs_xdr_YFSStoreStatus) +
1424 sizeof(struct yfs_xdr_u64) * 3,
1425 sizeof(struct yfs_xdr_YFSFetchStatus) +
1426 sizeof(struct yfs_xdr_YFSVolSync));
1430 call->key = fc->key;
1431 call->mapping = mapping;
1432 call->xvnode = vnode;
1433 call->first = first;
1435 call->first_offset = offset;
1437 call->send_pages = true;
1438 call->expected_version = vnode->status.data_version + 1;
1440 /* marshall the parameters */
1442 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1443 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1444 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1445 bp = xdr_encode_YFSStoreStatus_mtime(bp, &vnode->vfs_inode.i_mtime);
1446 bp = xdr_encode_u64(bp, pos);
1447 bp = xdr_encode_u64(bp, size);
1448 bp = xdr_encode_u64(bp, i_size);
1449 yfs_check_req(call, bp);
1451 afs_use_fs_server(call, fc->cbi);
1452 trace_afs_make_fs_call(call, &vnode->fid);
1453 afs_set_fc_call(call, fc);
1454 afs_make_call(&fc->ac, call, GFP_NOFS);
1455 return afs_wait_for_call_to_complete(call, &fc->ac);
1459 * deliver reply data to an FS.StoreStatus
1461 static int yfs_deliver_fs_store_status(struct afs_call *call)
1463 struct afs_vnode *vnode = call->xvnode;
1469 ret = afs_transfer_reply(call);
1473 /* unmarshall the reply once we've received all of it */
1475 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1476 &call->expected_version, NULL);
1479 xdr_decode_YFSVolSync(&bp, NULL);
1481 _leave(" = 0 [done]");
1486 * YFS.StoreStatus operation type
1488 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1489 .name = "YFS.StoreStatus",
1490 .op = yfs_FS_StoreStatus,
1491 .deliver = yfs_deliver_fs_store_status,
1492 .destructor = afs_flat_call_destructor,
1495 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1496 .name = "YFS.StoreData64",
1497 .op = yfs_FS_StoreData64,
1498 .deliver = yfs_deliver_fs_store_status,
1499 .destructor = afs_flat_call_destructor,
1503 * Set the attributes on a file, using YFS.StoreData64 rather than
1504 * YFS.StoreStatus so as to alter the file size also.
1506 static int yfs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1508 struct afs_vnode *vnode = fc->vnode;
1509 struct afs_call *call;
1510 struct afs_net *net = afs_v2net(vnode);
1513 _enter(",%x,{%llx:%llu},,",
1514 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1516 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64_as_Status,
1517 sizeof(__be32) * 2 +
1518 sizeof(struct yfs_xdr_YFSFid) +
1519 sizeof(struct yfs_xdr_YFSStoreStatus) +
1520 sizeof(struct yfs_xdr_u64) * 3,
1521 sizeof(struct yfs_xdr_YFSFetchStatus) +
1522 sizeof(struct yfs_xdr_YFSVolSync));
1526 call->key = fc->key;
1527 call->xvnode = vnode;
1528 call->expected_version = vnode->status.data_version + 1;
1530 /* marshall the parameters */
1532 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1533 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1534 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1535 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1536 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1537 bp = xdr_encode_u64(bp, 0); /* size of write */
1538 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1539 yfs_check_req(call, bp);
1541 afs_use_fs_server(call, fc->cbi);
1542 trace_afs_make_fs_call(call, &vnode->fid);
1543 afs_set_fc_call(call, fc);
1544 afs_make_call(&fc->ac, call, GFP_NOFS);
1545 return afs_wait_for_call_to_complete(call, &fc->ac);
1549 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1550 * file size, and YFS.StoreStatus otherwise.
1552 int yfs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1554 struct afs_vnode *vnode = fc->vnode;
1555 struct afs_call *call;
1556 struct afs_net *net = afs_v2net(vnode);
1559 if (attr->ia_valid & ATTR_SIZE)
1560 return yfs_fs_setattr_size(fc, attr);
1562 _enter(",%x,{%llx:%llu},,",
1563 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1565 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
1566 sizeof(__be32) * 2 +
1567 sizeof(struct yfs_xdr_YFSFid) +
1568 sizeof(struct yfs_xdr_YFSStoreStatus),
1569 sizeof(struct yfs_xdr_YFSFetchStatus) +
1570 sizeof(struct yfs_xdr_YFSVolSync));
1574 call->key = fc->key;
1575 call->xvnode = vnode;
1576 call->expected_version = vnode->status.data_version;
1578 /* marshall the parameters */
1580 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1581 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1582 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1583 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1584 yfs_check_req(call, bp);
1586 afs_use_fs_server(call, fc->cbi);
1587 trace_afs_make_fs_call(call, &vnode->fid);
1588 afs_set_fc_call(call, fc);
1589 afs_make_call(&fc->ac, call, GFP_NOFS);
1590 return afs_wait_for_call_to_complete(call, &fc->ac);
1594 * Deliver reply data to a YFS.GetVolumeStatus operation.
1596 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1603 _enter("{%u}", call->unmarshall);
1605 switch (call->unmarshall) {
1608 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1610 /* Fall through - and extract the returned status record */
1612 _debug("extract status");
1613 ret = afs_extract_data(call, true);
1618 xdr_decode_YFSFetchVolumeStatus(&bp, call->out_volstatus);
1620 afs_extract_to_tmp(call);
1622 /* Fall through - and extract the volume name length */
1624 ret = afs_extract_data(call, true);
1628 call->count = ntohl(call->tmp);
1629 _debug("volname length: %u", call->count);
1630 if (call->count >= AFSNAMEMAX)
1631 return afs_protocol_error(call, -EBADMSG,
1632 afs_eproto_volname_len);
1633 size = (call->count + 3) & ~3; /* It's padded */
1634 afs_extract_to_buf(call, size);
1637 /* Fall through - and extract the volume name */
1639 _debug("extract volname");
1640 ret = afs_extract_data(call, true);
1646 _debug("volname '%s'", p);
1647 afs_extract_to_tmp(call);
1650 /* Fall through - and extract the offline message length */
1652 ret = afs_extract_data(call, true);
1656 call->count = ntohl(call->tmp);
1657 _debug("offline msg length: %u", call->count);
1658 if (call->count >= AFSNAMEMAX)
1659 return afs_protocol_error(call, -EBADMSG,
1660 afs_eproto_offline_msg_len);
1661 size = (call->count + 3) & ~3; /* It's padded */
1662 afs_extract_to_buf(call, size);
1665 /* Fall through - and extract the offline message */
1667 _debug("extract offline");
1668 ret = afs_extract_data(call, true);
1674 _debug("offline '%s'", p);
1676 afs_extract_to_tmp(call);
1679 /* Fall through - and extract the message of the day length */
1681 ret = afs_extract_data(call, true);
1685 call->count = ntohl(call->tmp);
1686 _debug("motd length: %u", call->count);
1687 if (call->count >= AFSNAMEMAX)
1688 return afs_protocol_error(call, -EBADMSG,
1689 afs_eproto_motd_len);
1690 size = (call->count + 3) & ~3; /* It's padded */
1691 afs_extract_to_buf(call, size);
1694 /* Fall through - and extract the message of the day */
1696 _debug("extract motd");
1697 ret = afs_extract_data(call, false);
1703 _debug("motd '%s'", p);
1712 _leave(" = 0 [done]");
1717 * YFS.GetVolumeStatus operation type
1719 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1720 .name = "YFS.GetVolumeStatus",
1721 .op = yfs_FS_GetVolumeStatus,
1722 .deliver = yfs_deliver_fs_get_volume_status,
1723 .destructor = afs_flat_call_destructor,
1727 * fetch the status of a volume
1729 int yfs_fs_get_volume_status(struct afs_fs_cursor *fc,
1730 struct afs_volume_status *vs)
1732 struct afs_vnode *vnode = fc->vnode;
1733 struct afs_call *call;
1734 struct afs_net *net = afs_v2net(vnode);
1739 call = afs_alloc_flat_call(net, &yfs_RXYFSGetVolumeStatus,
1740 sizeof(__be32) * 2 +
1741 sizeof(struct yfs_xdr_u64),
1743 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1749 call->key = fc->key;
1750 call->out_volstatus = vs;
1752 /* marshall the parameters */
1754 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1755 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1756 bp = xdr_encode_u64(bp, vnode->fid.vid);
1757 yfs_check_req(call, bp);
1759 afs_use_fs_server(call, fc->cbi);
1760 trace_afs_make_fs_call(call, &vnode->fid);
1761 afs_set_fc_call(call, fc);
1762 afs_make_call(&fc->ac, call, GFP_NOFS);
1763 return afs_wait_for_call_to_complete(call, &fc->ac);
1767 * Deliver reply data to operations that just return a file status and a volume
1770 static int yfs_deliver_status_and_volsync(struct afs_call *call)
1772 struct afs_vnode *vnode = call->xvnode;
1776 _enter("{%u}", call->unmarshall);
1778 ret = afs_transfer_reply(call);
1782 /* unmarshall the reply once we've received all of it */
1784 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1785 &call->expected_version, NULL);
1788 xdr_decode_YFSVolSync(&bp, NULL);
1790 _leave(" = 0 [done]");
1795 * YFS.SetLock operation type
1797 static const struct afs_call_type yfs_RXYFSSetLock = {
1798 .name = "YFS.SetLock",
1799 .op = yfs_FS_SetLock,
1800 .deliver = yfs_deliver_status_and_volsync,
1801 .done = afs_lock_op_done,
1802 .destructor = afs_flat_call_destructor,
1806 * YFS.ExtendLock operation type
1808 static const struct afs_call_type yfs_RXYFSExtendLock = {
1809 .name = "YFS.ExtendLock",
1810 .op = yfs_FS_ExtendLock,
1811 .deliver = yfs_deliver_status_and_volsync,
1812 .done = afs_lock_op_done,
1813 .destructor = afs_flat_call_destructor,
1817 * YFS.ReleaseLock operation type
1819 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1820 .name = "YFS.ReleaseLock",
1821 .op = yfs_FS_ReleaseLock,
1822 .deliver = yfs_deliver_status_and_volsync,
1823 .destructor = afs_flat_call_destructor,
1827 * Set a lock on a file
1829 int yfs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1831 struct afs_vnode *vnode = fc->vnode;
1832 struct afs_call *call;
1833 struct afs_net *net = afs_v2net(vnode);
1838 call = afs_alloc_flat_call(net, &yfs_RXYFSSetLock,
1839 sizeof(__be32) * 2 +
1840 sizeof(struct yfs_xdr_YFSFid) +
1842 sizeof(struct yfs_xdr_YFSFetchStatus) +
1843 sizeof(struct yfs_xdr_YFSVolSync));
1847 call->key = fc->key;
1848 call->xvnode = vnode;
1850 /* marshall the parameters */
1852 bp = xdr_encode_u32(bp, YFSSETLOCK);
1853 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1854 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1855 bp = xdr_encode_u32(bp, type);
1856 yfs_check_req(call, bp);
1858 afs_use_fs_server(call, fc->cbi);
1859 trace_afs_make_fs_calli(call, &vnode->fid, type);
1860 afs_set_fc_call(call, fc);
1861 afs_make_call(&fc->ac, call, GFP_NOFS);
1862 return afs_wait_for_call_to_complete(call, &fc->ac);
1866 * extend a lock on a file
1868 int yfs_fs_extend_lock(struct afs_fs_cursor *fc)
1870 struct afs_vnode *vnode = fc->vnode;
1871 struct afs_call *call;
1872 struct afs_net *net = afs_v2net(vnode);
1877 call = afs_alloc_flat_call(net, &yfs_RXYFSExtendLock,
1878 sizeof(__be32) * 2 +
1879 sizeof(struct yfs_xdr_YFSFid),
1880 sizeof(struct yfs_xdr_YFSFetchStatus) +
1881 sizeof(struct yfs_xdr_YFSVolSync));
1885 call->key = fc->key;
1886 call->xvnode = vnode;
1888 /* marshall the parameters */
1890 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1891 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1892 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1893 yfs_check_req(call, bp);
1895 afs_use_fs_server(call, fc->cbi);
1896 trace_afs_make_fs_call(call, &vnode->fid);
1897 afs_set_fc_call(call, fc);
1898 afs_make_call(&fc->ac, call, GFP_NOFS);
1899 return afs_wait_for_call_to_complete(call, &fc->ac);
1903 * release a lock on a file
1905 int yfs_fs_release_lock(struct afs_fs_cursor *fc)
1907 struct afs_vnode *vnode = fc->vnode;
1908 struct afs_call *call;
1909 struct afs_net *net = afs_v2net(vnode);
1914 call = afs_alloc_flat_call(net, &yfs_RXYFSReleaseLock,
1915 sizeof(__be32) * 2 +
1916 sizeof(struct yfs_xdr_YFSFid),
1917 sizeof(struct yfs_xdr_YFSFetchStatus) +
1918 sizeof(struct yfs_xdr_YFSVolSync));
1922 call->key = fc->key;
1923 call->xvnode = vnode;
1925 /* marshall the parameters */
1927 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1928 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1929 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1930 yfs_check_req(call, bp);
1932 afs_use_fs_server(call, fc->cbi);
1933 trace_afs_make_fs_call(call, &vnode->fid);
1934 afs_set_fc_call(call, fc);
1935 afs_make_call(&fc->ac, call, GFP_NOFS);
1936 return afs_wait_for_call_to_complete(call, &fc->ac);
1940 * Deliver reply data to an FS.FetchStatus with no vnode.
1942 static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1944 struct afs_file_status *status = call->out_extra_status;
1945 struct afs_callback *callback = call->out_cb;
1946 struct afs_volsync *volsync = call->out_volsync;
1950 ret = afs_transfer_reply(call);
1956 /* unmarshall the reply once we've received all of it */
1958 ret = yfs_decode_status(call, &bp, status, NULL,
1959 &call->expected_version, NULL);
1962 xdr_decode_YFSCallBack_raw(call, callback, &bp);
1963 xdr_decode_YFSVolSync(&bp, volsync);
1965 _leave(" = 0 [done]");
1970 * YFS.FetchStatus operation type
1972 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1973 .name = "YFS.FetchStatus",
1974 .op = yfs_FS_FetchStatus,
1975 .deliver = yfs_deliver_fs_fetch_status,
1976 .destructor = afs_flat_call_destructor,
1980 * Fetch the status information for a fid without needing a vnode handle.
1982 int yfs_fs_fetch_status(struct afs_fs_cursor *fc,
1983 struct afs_net *net,
1984 struct afs_fid *fid,
1985 struct afs_file_status *status,
1986 struct afs_callback *callback,
1987 struct afs_volsync *volsync)
1989 struct afs_call *call;
1992 _enter(",%x,{%llx:%llu},,",
1993 key_serial(fc->key), fid->vid, fid->vnode);
1995 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus,
1996 sizeof(__be32) * 2 +
1997 sizeof(struct yfs_xdr_YFSFid),
1998 sizeof(struct yfs_xdr_YFSFetchStatus) +
1999 sizeof(struct yfs_xdr_YFSCallBack) +
2000 sizeof(struct yfs_xdr_YFSVolSync));
2002 fc->ac.error = -ENOMEM;
2006 call->key = fc->key;
2007 call->out_extra_status = status;
2008 call->out_cb = callback;
2009 call->out_volsync = volsync;
2010 call->expected_version = 1; /* vnode->status.data_version */
2012 /* marshall the parameters */
2014 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
2015 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2016 bp = xdr_encode_YFSFid(bp, fid);
2017 yfs_check_req(call, bp);
2019 call->cb_break = fc->cb_break;
2020 afs_use_fs_server(call, fc->cbi);
2021 trace_afs_make_fs_call(call, fid);
2022 afs_set_fc_call(call, fc);
2023 afs_make_call(&fc->ac, call, GFP_NOFS);
2024 return afs_wait_for_call_to_complete(call, &fc->ac);
2028 * Deliver reply data to an YFS.InlineBulkStatus call
2030 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
2032 struct afs_status_cb *scb;
2037 _enter("{%u}", call->unmarshall);
2039 switch (call->unmarshall) {
2041 afs_extract_to_tmp(call);
2044 /* Extract the file status count and array in two steps */
2047 _debug("extract status count");
2048 ret = afs_extract_data(call, true);
2052 tmp = ntohl(call->tmp);
2053 _debug("status count: %u/%u", tmp, call->count2);
2054 if (tmp != call->count2)
2055 return afs_protocol_error(call, -EBADMSG,
2056 afs_eproto_ibulkst_count);
2061 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
2065 _debug("extract status array %u", call->count);
2066 ret = afs_extract_data(call, true);
2071 scb = &call->out_scb[call->count];
2072 ret = yfs_decode_status(call, &bp, &scb->status,
2078 if (call->count < call->count2)
2083 afs_extract_to_tmp(call);
2085 /* Extract the callback count and array in two steps */
2088 _debug("extract CB count");
2089 ret = afs_extract_data(call, true);
2093 tmp = ntohl(call->tmp);
2094 _debug("CB count: %u", tmp);
2095 if (tmp != call->count2)
2096 return afs_protocol_error(call, -EBADMSG,
2097 afs_eproto_ibulkst_cb_count);
2101 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
2105 _debug("extract CB array");
2106 ret = afs_extract_data(call, true);
2110 _debug("unmarshall CB array");
2112 scb = &call->out_scb[call->count];
2113 xdr_decode_YFSCallBack_raw(call, &scb->callback, &bp);
2114 scb->have_cb = true;
2116 if (call->count < call->count2)
2119 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
2124 ret = afs_extract_data(call, false);
2129 xdr_decode_YFSVolSync(&bp, call->out_volsync);
2138 _leave(" = 0 [done]");
2143 * FS.InlineBulkStatus operation type
2145 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
2146 .name = "YFS.InlineBulkStatus",
2147 .op = yfs_FS_InlineBulkStatus,
2148 .deliver = yfs_deliver_fs_inline_bulk_status,
2149 .destructor = afs_flat_call_destructor,
2153 * Fetch the status information for up to 1024 files
2155 int yfs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2156 struct afs_net *net,
2157 struct afs_fid *fids,
2158 struct afs_status_cb *statuses,
2159 unsigned int nr_fids,
2160 struct afs_volsync *volsync)
2162 struct afs_call *call;
2166 _enter(",%x,{%llx:%llu},%u",
2167 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2169 call = afs_alloc_flat_call(net, &yfs_RXYFSInlineBulkStatus,
2173 sizeof(struct yfs_xdr_YFSFid) * nr_fids,
2174 sizeof(struct yfs_xdr_YFSFetchStatus));
2176 fc->ac.error = -ENOMEM;
2180 call->key = fc->key;
2181 call->out_scb = statuses;
2182 call->out_volsync = volsync;
2183 call->count2 = nr_fids;
2185 /* marshall the parameters */
2187 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
2188 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
2189 bp = xdr_encode_u32(bp, nr_fids);
2190 for (i = 0; i < nr_fids; i++)
2191 bp = xdr_encode_YFSFid(bp, &fids[i]);
2192 yfs_check_req(call, bp);
2194 call->cb_break = fc->cb_break;
2195 afs_use_fs_server(call, fc->cbi);
2196 trace_afs_make_fs_call(call, &fids[0]);
2197 afs_set_fc_call(call, fc);
2198 afs_make_call(&fc->ac, call, GFP_NOFS);
2199 return afs_wait_for_call_to_complete(call, &fc->ac);
2203 * Deliver reply data to an YFS.FetchOpaqueACL.
2205 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
2207 struct afs_volsync *volsync = call->out_volsync;
2208 struct afs_vnode *vnode = call->xvnode;
2209 struct yfs_acl *yacl = call->out_yacl;
2210 struct afs_acl *acl;
2215 _enter("{%u}", call->unmarshall);
2217 switch (call->unmarshall) {
2219 afs_extract_to_tmp(call);
2222 /* Extract the file ACL length */
2224 ret = afs_extract_data(call, true);
2228 size = call->count2 = ntohl(call->tmp);
2229 size = round_up(size, 4);
2231 if (yacl->flags & YFS_ACL_WANT_ACL) {
2232 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2236 acl->size = call->count2;
2237 afs_extract_begin(call, acl->data, size);
2239 iov_iter_discard(&call->iter, READ, size);
2243 /* Extract the file ACL */
2245 ret = afs_extract_data(call, true);
2249 afs_extract_to_tmp(call);
2252 /* Extract the volume ACL length */
2254 ret = afs_extract_data(call, true);
2258 size = call->count2 = ntohl(call->tmp);
2259 size = round_up(size, 4);
2261 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
2262 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2265 yacl->vol_acl = acl;
2266 acl->size = call->count2;
2267 afs_extract_begin(call, acl->data, size);
2269 iov_iter_discard(&call->iter, READ, size);
2273 /* Extract the volume ACL */
2275 ret = afs_extract_data(call, true);
2279 afs_extract_to_buf(call,
2280 sizeof(__be32) * 2 +
2281 sizeof(struct yfs_xdr_YFSFetchStatus) +
2282 sizeof(struct yfs_xdr_YFSVolSync));
2285 /* extract the metadata */
2287 ret = afs_extract_data(call, false);
2292 yacl->inherit_flag = ntohl(*bp++);
2293 yacl->num_cleaned = ntohl(*bp++);
2294 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
2295 &call->expected_version, NULL);
2298 xdr_decode_YFSVolSync(&bp, volsync);
2306 _leave(" = 0 [done]");
2310 void yfs_free_opaque_acl(struct yfs_acl *yacl)
2314 kfree(yacl->vol_acl);
2320 * YFS.FetchOpaqueACL operation type
2322 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
2323 .name = "YFS.FetchOpaqueACL",
2324 .op = yfs_FS_FetchOpaqueACL,
2325 .deliver = yfs_deliver_fs_fetch_opaque_acl,
2326 .destructor = afs_flat_call_destructor,
2330 * Fetch the YFS advanced ACLs for a file.
2332 struct yfs_acl *yfs_fs_fetch_opaque_acl(struct afs_fs_cursor *fc,
2333 struct yfs_acl *yacl)
2335 struct afs_vnode *vnode = fc->vnode;
2336 struct afs_call *call;
2337 struct afs_net *net = afs_v2net(vnode);
2340 _enter(",%x,{%llx:%llu},,",
2341 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2343 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchOpaqueACL,
2344 sizeof(__be32) * 2 +
2345 sizeof(struct yfs_xdr_YFSFid),
2346 sizeof(__be32) * 2 +
2347 sizeof(struct yfs_xdr_YFSFetchStatus) +
2348 sizeof(struct yfs_xdr_YFSVolSync));
2350 fc->ac.error = -ENOMEM;
2351 return ERR_PTR(-ENOMEM);
2354 call->key = fc->key;
2355 call->out_yacl = yacl;
2356 call->xvnode = vnode;
2357 call->out_volsync = NULL; /* volsync */
2359 /* marshall the parameters */
2361 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
2362 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2363 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2364 yfs_check_req(call, bp);
2366 call->cb_break = fc->cb_break;
2367 afs_use_fs_server(call, fc->cbi);
2368 trace_afs_make_fs_call(call, &vnode->fid);
2369 afs_make_call(&fc->ac, call, GFP_KERNEL);
2370 return (struct yfs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2374 * YFS.StoreOpaqueACL2 operation type
2376 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
2377 .name = "YFS.StoreOpaqueACL2",
2378 .op = yfs_FS_StoreOpaqueACL2,
2379 .deliver = yfs_deliver_status_and_volsync,
2380 .destructor = afs_flat_call_destructor,
2384 * Fetch the YFS ACL for a file.
2386 int yfs_fs_store_opaque_acl2(struct afs_fs_cursor *fc, const struct afs_acl *acl)
2388 struct afs_vnode *vnode = fc->vnode;
2389 struct afs_call *call;
2390 struct afs_net *net = afs_v2net(vnode);
2394 _enter(",%x,{%llx:%llu},,",
2395 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2397 size = round_up(acl->size, 4);
2398 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
2399 sizeof(__be32) * 2 +
2400 sizeof(struct yfs_xdr_YFSFid) +
2401 sizeof(__be32) + size,
2402 sizeof(struct yfs_xdr_YFSFetchStatus) +
2403 sizeof(struct yfs_xdr_YFSVolSync));
2405 fc->ac.error = -ENOMEM;
2409 call->key = fc->key;
2410 call->xvnode = vnode;
2411 call->out_volsync = NULL;
2413 /* marshall the parameters */
2415 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
2416 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2417 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2418 bp = xdr_encode_u32(bp, acl->size);
2419 memcpy(bp, acl->data, acl->size);
2420 if (acl->size != size)
2421 memset((void *)bp + acl->size, 0, size - acl->size);
2422 yfs_check_req(call, bp);
2424 trace_afs_make_fs_call(call, &vnode->fid);
2425 afs_make_call(&fc->ac, call, GFP_KERNEL);
2426 return afs_wait_for_call_to_complete(call, &fc->ac);