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);
315 * Decode a YFSCallBack block
317 static void xdr_decode_YFSCallBack(struct afs_call *call,
318 struct afs_vnode *vnode,
321 struct yfs_xdr_YFSCallBack *xdr = (void *)*_bp;
322 struct afs_cb_interest *old, *cbi = call->cbi;
325 write_seqlock(&vnode->cb_lock);
327 if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
328 cb_expiry = xdr_to_u64(xdr->expiration_time);
329 do_div(cb_expiry, 10 * 1000 * 1000);
330 vnode->cb_version = ntohl(xdr->version);
331 vnode->cb_type = ntohl(xdr->type);
332 vnode->cb_expires_at = cb_expiry + ktime_get_real_seconds();
333 old = vnode->cb_interest;
334 if (old != call->cbi) {
335 vnode->cb_interest = cbi;
338 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
341 write_sequnlock(&vnode->cb_lock);
343 *_bp += xdr_size(xdr);
346 static void xdr_decode_YFSCallBack_raw(const __be32 **_bp,
347 struct afs_callback *cb)
349 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
352 cb_expiry = xdr_to_u64(x->expiration_time);
353 do_div(cb_expiry, 10 * 1000 * 1000);
354 cb->version = ntohl(x->version);
355 cb->type = ntohl(x->type);
356 cb->expires_at = cb_expiry + ktime_get_real_seconds();
362 * Decode a YFSVolSync block
364 static void xdr_decode_YFSVolSync(const __be32 **_bp,
365 struct afs_volsync *volsync)
367 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
371 creation = xdr_to_u64(x->vol_creation_date);
372 do_div(creation, 10 * 1000 * 1000);
373 volsync->creation = creation;
380 * Encode the requested attributes into a YFSStoreStatus block
382 static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
384 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
385 s64 mtime = 0, owner = 0, group = 0;
386 u32 mask = 0, mode = 0;
389 if (attr->ia_valid & ATTR_MTIME) {
390 mask |= AFS_SET_MTIME;
391 mtime = linux_to_yfs_time(&attr->ia_mtime);
394 if (attr->ia_valid & ATTR_UID) {
395 mask |= AFS_SET_OWNER;
396 owner = from_kuid(&init_user_ns, attr->ia_uid);
399 if (attr->ia_valid & ATTR_GID) {
400 mask |= AFS_SET_GROUP;
401 group = from_kgid(&init_user_ns, attr->ia_gid);
404 if (attr->ia_valid & ATTR_MODE) {
405 mask |= AFS_SET_MODE;
406 mode = attr->ia_mode & S_IALLUGO;
409 x->mask = htonl(mask);
410 x->mode = htonl(mode);
411 x->mtime_client = u64_to_xdr(mtime);
412 x->owner = u64_to_xdr(owner);
413 x->group = u64_to_xdr(group);
414 return bp + xdr_size(x);
418 * Decode a YFSFetchVolumeStatus block.
420 static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
421 struct afs_volume_status *vs)
423 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
426 vs->vid = xdr_to_u64(x->vid);
427 vs->parent_id = xdr_to_u64(x->parent_id);
428 flags = ntohl(x->flags);
429 vs->online = flags & yfs_FVSOnline;
430 vs->in_service = flags & yfs_FVSInservice;
431 vs->blessed = flags & yfs_FVSBlessed;
432 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
433 vs->type = ntohl(x->type);
435 vs->max_quota = xdr_to_u64(x->max_quota);
436 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
437 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
438 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
439 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
440 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
441 *_bp += sizeof(*x) / sizeof(__be32);
445 * deliver reply data to an FS.FetchStatus
447 static int yfs_deliver_fs_fetch_status_vnode(struct afs_call *call)
449 struct afs_vnode *vnode = call->reply[0];
453 ret = afs_transfer_reply(call);
457 _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
459 /* unmarshall the reply once we've received all of it */
461 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
462 &call->expected_version, NULL);
465 xdr_decode_YFSCallBack(call, vnode, &bp);
466 xdr_decode_YFSVolSync(&bp, call->reply[1]);
468 _leave(" = 0 [done]");
473 * YFS.FetchStatus operation type
475 static const struct afs_call_type yfs_RXYFSFetchStatus_vnode = {
476 .name = "YFS.FetchStatus(vnode)",
477 .op = yfs_FS_FetchStatus,
478 .deliver = yfs_deliver_fs_fetch_status_vnode,
479 .destructor = afs_flat_call_destructor,
483 * Fetch the status information for a file.
485 int yfs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_volsync *volsync,
488 struct afs_vnode *vnode = fc->vnode;
489 struct afs_call *call;
490 struct afs_net *net = afs_v2net(vnode);
493 _enter(",%x,{%llx:%llu},,",
494 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
496 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus_vnode,
498 sizeof(struct yfs_xdr_YFSFid),
499 sizeof(struct yfs_xdr_YFSFetchStatus) +
500 sizeof(struct yfs_xdr_YFSCallBack) +
501 sizeof(struct yfs_xdr_YFSVolSync));
503 fc->ac.error = -ENOMEM;
508 call->reply[0] = vnode;
509 call->reply[1] = volsync;
510 call->expected_version = new_inode ? 1 : vnode->status.data_version;
512 /* marshall the parameters */
514 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
515 bp = xdr_encode_u32(bp, 0); /* RPC flags */
516 bp = xdr_encode_YFSFid(bp, &vnode->fid);
517 yfs_check_req(call, bp);
519 call->cb_break = fc->cb_break;
520 afs_use_fs_server(call, fc->cbi);
521 trace_afs_make_fs_call(call, &vnode->fid);
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->reply[0];
532 struct afs_read *req = call->reply[2];
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 /* 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 /* 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;
603 _debug("extract discard %zu/%llu",
604 iov_iter_count(&call->iter), req->actual_len - req->len);
606 ret = afs_extract_data(call, true);
611 call->unmarshall = 4;
612 afs_extract_to_buf(call,
613 sizeof(struct yfs_xdr_YFSFetchStatus) +
614 sizeof(struct yfs_xdr_YFSCallBack) +
615 sizeof(struct yfs_xdr_YFSVolSync));
617 /* extract the metadata */
619 ret = afs_extract_data(call, false);
624 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
625 &vnode->status.data_version, req);
628 xdr_decode_YFSCallBack(call, vnode, &bp);
629 xdr_decode_YFSVolSync(&bp, call->reply[1]);
637 for (; req->index < req->nr_pages; req->index++) {
638 if (req->offset < PAGE_SIZE)
639 zero_user_segment(req->pages[req->index],
640 req->offset, PAGE_SIZE);
642 req->page_done(call, req);
646 _leave(" = 0 [done]");
650 static void yfs_fetch_data_destructor(struct afs_call *call)
652 struct afs_read *req = call->reply[2];
655 afs_flat_call_destructor(call);
659 * YFS.FetchData64 operation type
661 static const struct afs_call_type yfs_RXYFSFetchData64 = {
662 .name = "YFS.FetchData64",
663 .op = yfs_FS_FetchData64,
664 .deliver = yfs_deliver_fs_fetch_data64,
665 .destructor = yfs_fetch_data_destructor,
669 * Fetch data from a file.
671 int yfs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
673 struct afs_vnode *vnode = fc->vnode;
674 struct afs_call *call;
675 struct afs_net *net = afs_v2net(vnode);
678 _enter(",%x,{%llx:%llu},%llx,%llx",
679 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode,
682 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchData64,
684 sizeof(struct yfs_xdr_YFSFid) +
685 sizeof(struct yfs_xdr_u64) * 2,
686 sizeof(struct yfs_xdr_YFSFetchStatus) +
687 sizeof(struct yfs_xdr_YFSCallBack) +
688 sizeof(struct yfs_xdr_YFSVolSync));
693 call->reply[0] = vnode;
694 call->reply[1] = NULL; /* volsync */
695 call->reply[2] = req;
696 call->expected_version = vnode->status.data_version;
697 call->want_reply_time = true;
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_make_call(&fc->ac, call, GFP_NOFS);
713 return afs_wait_for_call_to_complete(call, &fc->ac);
717 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
719 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
721 struct afs_vnode *vnode = call->reply[0];
725 _enter("{%u}", call->unmarshall);
727 ret = afs_transfer_reply(call);
731 /* unmarshall the reply once we've received all of it */
733 xdr_decode_YFSFid(&bp, call->reply[1]);
734 ret = yfs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
737 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
738 &call->expected_version, NULL);
741 xdr_decode_YFSCallBack_raw(&bp, call->reply[3]);
742 xdr_decode_YFSVolSync(&bp, NULL);
744 _leave(" = 0 [done]");
749 * FS.CreateFile and FS.MakeDir operation type
751 static const struct afs_call_type afs_RXFSCreateFile = {
752 .name = "YFS.CreateFile",
753 .op = yfs_FS_CreateFile,
754 .deliver = yfs_deliver_fs_create_vnode,
755 .destructor = afs_flat_call_destructor,
761 int yfs_fs_create_file(struct afs_fs_cursor *fc,
764 u64 current_data_version,
765 struct afs_fid *newfid,
766 struct afs_file_status *newstatus,
767 struct afs_callback *newcb)
769 struct afs_vnode *vnode = fc->vnode;
770 struct afs_call *call;
771 struct afs_net *net = afs_v2net(vnode);
772 size_t namesz, reqsz, rplsz;
777 namesz = strlen(name);
778 reqsz = (sizeof(__be32) +
780 sizeof(struct yfs_xdr_YFSFid) +
782 sizeof(struct yfs_xdr_YFSStoreStatus) +
784 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
785 sizeof(struct yfs_xdr_YFSFetchStatus) +
786 sizeof(struct yfs_xdr_YFSFetchStatus) +
787 sizeof(struct yfs_xdr_YFSCallBack) +
788 sizeof(struct yfs_xdr_YFSVolSync));
790 call = afs_alloc_flat_call(net, &afs_RXFSCreateFile, reqsz, rplsz);
795 call->reply[0] = vnode;
796 call->reply[1] = newfid;
797 call->reply[2] = newstatus;
798 call->reply[3] = newcb;
799 call->expected_version = current_data_version + 1;
801 /* marshall the parameters */
803 bp = xdr_encode_u32(bp, YFSCREATEFILE);
804 bp = xdr_encode_u32(bp, 0); /* RPC flags */
805 bp = xdr_encode_YFSFid(bp, &vnode->fid);
806 bp = xdr_encode_string(bp, name, namesz);
807 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
808 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
809 yfs_check_req(call, bp);
811 afs_use_fs_server(call, fc->cbi);
812 trace_afs_make_fs_call1(call, &vnode->fid, name);
813 afs_make_call(&fc->ac, call, GFP_NOFS);
814 return afs_wait_for_call_to_complete(call, &fc->ac);
817 static const struct afs_call_type yfs_RXFSMakeDir = {
818 .name = "YFS.MakeDir",
819 .op = yfs_FS_MakeDir,
820 .deliver = yfs_deliver_fs_create_vnode,
821 .destructor = afs_flat_call_destructor,
827 int yfs_fs_make_dir(struct afs_fs_cursor *fc,
830 u64 current_data_version,
831 struct afs_fid *newfid,
832 struct afs_file_status *newstatus,
833 struct afs_callback *newcb)
835 struct afs_vnode *vnode = fc->vnode;
836 struct afs_call *call;
837 struct afs_net *net = afs_v2net(vnode);
838 size_t namesz, reqsz, rplsz;
843 namesz = strlen(name);
844 reqsz = (sizeof(__be32) +
845 sizeof(struct yfs_xdr_RPCFlags) +
846 sizeof(struct yfs_xdr_YFSFid) +
848 sizeof(struct yfs_xdr_YFSStoreStatus));
849 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
850 sizeof(struct yfs_xdr_YFSFetchStatus) +
851 sizeof(struct yfs_xdr_YFSFetchStatus) +
852 sizeof(struct yfs_xdr_YFSCallBack) +
853 sizeof(struct yfs_xdr_YFSVolSync));
855 call = afs_alloc_flat_call(net, &yfs_RXFSMakeDir, reqsz, rplsz);
860 call->reply[0] = vnode;
861 call->reply[1] = newfid;
862 call->reply[2] = newstatus;
863 call->reply[3] = newcb;
864 call->expected_version = current_data_version + 1;
866 /* marshall the parameters */
868 bp = xdr_encode_u32(bp, YFSMAKEDIR);
869 bp = xdr_encode_u32(bp, 0); /* RPC flags */
870 bp = xdr_encode_YFSFid(bp, &vnode->fid);
871 bp = xdr_encode_string(bp, name, namesz);
872 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
873 yfs_check_req(call, bp);
875 afs_use_fs_server(call, fc->cbi);
876 trace_afs_make_fs_call1(call, &vnode->fid, name);
877 afs_make_call(&fc->ac, call, GFP_NOFS);
878 return afs_wait_for_call_to_complete(call, &fc->ac);
882 * Deliver reply data to a YFS.RemoveFile2 operation.
884 static int yfs_deliver_fs_remove_file2(struct afs_call *call)
886 struct afs_vnode *dvnode = call->reply[0];
887 struct afs_vnode *vnode = call->reply[1];
892 _enter("{%u}", call->unmarshall);
894 ret = afs_transfer_reply(call);
898 /* unmarshall the reply once we've received all of it */
900 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
901 &call->expected_version, NULL);
905 xdr_decode_YFSFid(&bp, &fid);
906 ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
909 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
911 xdr_decode_YFSVolSync(&bp, NULL);
916 * YFS.RemoveFile2 operation type.
918 static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
919 .name = "YFS.RemoveFile2",
920 .op = yfs_FS_RemoveFile2,
921 .deliver = yfs_deliver_fs_remove_file2,
922 .destructor = afs_flat_call_destructor,
926 * Remove a file and retrieve new file status.
928 int yfs_fs_remove_file2(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
929 const char *name, u64 current_data_version)
931 struct afs_vnode *dvnode = fc->vnode;
932 struct afs_call *call;
933 struct afs_net *net = afs_v2net(dvnode);
939 namesz = strlen(name);
941 call = afs_alloc_flat_call(net, &yfs_RXYFSRemoveFile2,
943 sizeof(struct yfs_xdr_RPCFlags) +
944 sizeof(struct yfs_xdr_YFSFid) +
946 sizeof(struct yfs_xdr_YFSFetchStatus) +
947 sizeof(struct yfs_xdr_YFSFid) +
948 sizeof(struct yfs_xdr_YFSFetchStatus) +
949 sizeof(struct yfs_xdr_YFSVolSync));
954 call->reply[0] = dvnode;
955 call->reply[1] = vnode;
956 call->expected_version = current_data_version + 1;
958 /* marshall the parameters */
960 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
961 bp = xdr_encode_u32(bp, 0); /* RPC flags */
962 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
963 bp = xdr_encode_string(bp, name, namesz);
964 yfs_check_req(call, bp);
966 afs_use_fs_server(call, fc->cbi);
967 trace_afs_make_fs_call1(call, &dvnode->fid, name);
968 afs_make_call(&fc->ac, call, GFP_NOFS);
969 return afs_wait_for_call_to_complete(call, &fc->ac);
973 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
975 static int yfs_deliver_fs_remove(struct afs_call *call)
977 struct afs_vnode *dvnode = call->reply[0];
981 _enter("{%u}", call->unmarshall);
983 ret = afs_transfer_reply(call);
987 /* unmarshall the reply once we've received all of it */
989 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
990 &call->expected_version, NULL);
994 xdr_decode_YFSVolSync(&bp, NULL);
999 * FS.RemoveDir and FS.RemoveFile operation types.
1001 static const struct afs_call_type yfs_RXYFSRemoveFile = {
1002 .name = "YFS.RemoveFile",
1003 .op = yfs_FS_RemoveFile,
1004 .deliver = yfs_deliver_fs_remove,
1005 .destructor = afs_flat_call_destructor,
1008 static const struct afs_call_type yfs_RXYFSRemoveDir = {
1009 .name = "YFS.RemoveDir",
1010 .op = yfs_FS_RemoveDir,
1011 .deliver = yfs_deliver_fs_remove,
1012 .destructor = afs_flat_call_destructor,
1016 * remove a file or directory
1018 int yfs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
1019 const char *name, bool isdir, u64 current_data_version)
1021 struct afs_vnode *dvnode = fc->vnode;
1022 struct afs_call *call;
1023 struct afs_net *net = afs_v2net(dvnode);
1029 namesz = strlen(name);
1030 call = afs_alloc_flat_call(
1031 net, isdir ? &yfs_RXYFSRemoveDir : &yfs_RXYFSRemoveFile,
1033 sizeof(struct yfs_xdr_RPCFlags) +
1034 sizeof(struct yfs_xdr_YFSFid) +
1036 sizeof(struct yfs_xdr_YFSFetchStatus) +
1037 sizeof(struct yfs_xdr_YFSVolSync));
1041 call->key = fc->key;
1042 call->reply[0] = dvnode;
1043 call->reply[1] = vnode;
1044 call->expected_version = current_data_version + 1;
1046 /* marshall the parameters */
1048 bp = xdr_encode_u32(bp, isdir ? YFSREMOVEDIR : YFSREMOVEFILE);
1049 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1050 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1051 bp = xdr_encode_string(bp, name, namesz);
1052 yfs_check_req(call, bp);
1054 afs_use_fs_server(call, fc->cbi);
1055 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1056 afs_make_call(&fc->ac, call, GFP_NOFS);
1057 return afs_wait_for_call_to_complete(call, &fc->ac);
1061 * Deliver reply data to a YFS.Link operation.
1063 static int yfs_deliver_fs_link(struct afs_call *call)
1065 struct afs_vnode *dvnode = call->reply[0], *vnode = call->reply[1];
1069 _enter("{%u}", call->unmarshall);
1071 ret = afs_transfer_reply(call);
1075 /* unmarshall the reply once we've received all of it */
1077 ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
1080 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
1081 &call->expected_version, NULL);
1084 xdr_decode_YFSVolSync(&bp, NULL);
1085 _leave(" = 0 [done]");
1090 * YFS.Link operation type.
1092 static const struct afs_call_type yfs_RXYFSLink = {
1095 .deliver = yfs_deliver_fs_link,
1096 .destructor = afs_flat_call_destructor,
1102 int yfs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
1103 const char *name, u64 current_data_version)
1105 struct afs_vnode *dvnode = fc->vnode;
1106 struct afs_call *call;
1107 struct afs_net *net = afs_v2net(vnode);
1113 namesz = strlen(name);
1114 call = afs_alloc_flat_call(net, &yfs_RXYFSLink,
1116 sizeof(struct yfs_xdr_RPCFlags) +
1117 sizeof(struct yfs_xdr_YFSFid) +
1118 xdr_strlen(namesz) +
1119 sizeof(struct yfs_xdr_YFSFid),
1120 sizeof(struct yfs_xdr_YFSFetchStatus) +
1121 sizeof(struct yfs_xdr_YFSFetchStatus) +
1122 sizeof(struct yfs_xdr_YFSVolSync));
1126 call->key = fc->key;
1127 call->reply[0] = dvnode;
1128 call->reply[1] = vnode;
1129 call->expected_version = current_data_version + 1;
1131 /* marshall the parameters */
1133 bp = xdr_encode_u32(bp, YFSLINK);
1134 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1135 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1136 bp = xdr_encode_string(bp, name, namesz);
1137 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1138 yfs_check_req(call, bp);
1140 afs_use_fs_server(call, fc->cbi);
1141 trace_afs_make_fs_call1(call, &vnode->fid, name);
1142 afs_make_call(&fc->ac, call, GFP_NOFS);
1143 return afs_wait_for_call_to_complete(call, &fc->ac);
1147 * Deliver reply data to a YFS.Symlink operation.
1149 static int yfs_deliver_fs_symlink(struct afs_call *call)
1151 struct afs_vnode *vnode = call->reply[0];
1155 _enter("{%u}", call->unmarshall);
1157 ret = afs_transfer_reply(call);
1161 /* unmarshall the reply once we've received all of it */
1163 xdr_decode_YFSFid(&bp, call->reply[1]);
1164 ret = yfs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
1167 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1168 &call->expected_version, NULL);
1171 xdr_decode_YFSVolSync(&bp, NULL);
1173 _leave(" = 0 [done]");
1178 * YFS.Symlink operation type
1180 static const struct afs_call_type yfs_RXYFSSymlink = {
1181 .name = "YFS.Symlink",
1182 .op = yfs_FS_Symlink,
1183 .deliver = yfs_deliver_fs_symlink,
1184 .destructor = afs_flat_call_destructor,
1188 * Create a symbolic link.
1190 int yfs_fs_symlink(struct afs_fs_cursor *fc,
1192 const char *contents,
1193 u64 current_data_version,
1194 struct afs_fid *newfid,
1195 struct afs_file_status *newstatus)
1197 struct afs_vnode *dvnode = fc->vnode;
1198 struct afs_call *call;
1199 struct afs_net *net = afs_v2net(dvnode);
1200 size_t namesz, contents_sz;
1205 namesz = strlen(name);
1206 contents_sz = strlen(contents);
1207 call = afs_alloc_flat_call(net, &yfs_RXYFSSymlink,
1209 sizeof(struct yfs_xdr_RPCFlags) +
1210 sizeof(struct yfs_xdr_YFSFid) +
1211 xdr_strlen(namesz) +
1212 xdr_strlen(contents_sz) +
1213 sizeof(struct yfs_xdr_YFSStoreStatus),
1214 sizeof(struct yfs_xdr_YFSFid) +
1215 sizeof(struct yfs_xdr_YFSFetchStatus) +
1216 sizeof(struct yfs_xdr_YFSFetchStatus) +
1217 sizeof(struct yfs_xdr_YFSVolSync));
1221 call->key = fc->key;
1222 call->reply[0] = dvnode;
1223 call->reply[1] = newfid;
1224 call->reply[2] = newstatus;
1225 call->expected_version = current_data_version + 1;
1227 /* marshall the parameters */
1229 bp = xdr_encode_u32(bp, YFSSYMLINK);
1230 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1231 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1232 bp = xdr_encode_string(bp, name, namesz);
1233 bp = xdr_encode_string(bp, contents, contents_sz);
1234 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
1235 yfs_check_req(call, bp);
1237 afs_use_fs_server(call, fc->cbi);
1238 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1239 afs_make_call(&fc->ac, call, GFP_NOFS);
1240 return afs_wait_for_call_to_complete(call, &fc->ac);
1244 * Deliver reply data to a YFS.Rename operation.
1246 static int yfs_deliver_fs_rename(struct afs_call *call)
1248 struct afs_vnode *orig_dvnode = call->reply[0];
1249 struct afs_vnode *new_dvnode = call->reply[1];
1253 _enter("{%u}", call->unmarshall);
1255 ret = afs_transfer_reply(call);
1259 /* unmarshall the reply once we've received all of it */
1261 ret = yfs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1262 &call->expected_version, NULL);
1265 if (new_dvnode != orig_dvnode) {
1266 ret = yfs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1267 &call->expected_version_2, NULL);
1272 xdr_decode_YFSVolSync(&bp, NULL);
1273 _leave(" = 0 [done]");
1278 * YFS.Rename operation type
1280 static const struct afs_call_type yfs_RXYFSRename = {
1281 .name = "FS.Rename",
1282 .op = yfs_FS_Rename,
1283 .deliver = yfs_deliver_fs_rename,
1284 .destructor = afs_flat_call_destructor,
1288 * Rename a file or directory.
1290 int yfs_fs_rename(struct afs_fs_cursor *fc,
1291 const char *orig_name,
1292 struct afs_vnode *new_dvnode,
1293 const char *new_name,
1294 u64 current_orig_data_version,
1295 u64 current_new_data_version)
1297 struct afs_vnode *orig_dvnode = fc->vnode;
1298 struct afs_call *call;
1299 struct afs_net *net = afs_v2net(orig_dvnode);
1300 size_t o_namesz, n_namesz;
1305 o_namesz = strlen(orig_name);
1306 n_namesz = strlen(new_name);
1307 call = afs_alloc_flat_call(net, &yfs_RXYFSRename,
1309 sizeof(struct yfs_xdr_RPCFlags) +
1310 sizeof(struct yfs_xdr_YFSFid) +
1311 xdr_strlen(o_namesz) +
1312 sizeof(struct yfs_xdr_YFSFid) +
1313 xdr_strlen(n_namesz),
1314 sizeof(struct yfs_xdr_YFSFetchStatus) +
1315 sizeof(struct yfs_xdr_YFSFetchStatus) +
1316 sizeof(struct yfs_xdr_YFSVolSync));
1320 call->key = fc->key;
1321 call->reply[0] = orig_dvnode;
1322 call->reply[1] = new_dvnode;
1323 call->expected_version = current_orig_data_version + 1;
1324 call->expected_version_2 = current_new_data_version + 1;
1326 /* marshall the parameters */
1328 bp = xdr_encode_u32(bp, YFSRENAME);
1329 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1330 bp = xdr_encode_YFSFid(bp, &orig_dvnode->fid);
1331 bp = xdr_encode_string(bp, orig_name, o_namesz);
1332 bp = xdr_encode_YFSFid(bp, &new_dvnode->fid);
1333 bp = xdr_encode_string(bp, new_name, n_namesz);
1334 yfs_check_req(call, bp);
1336 afs_use_fs_server(call, fc->cbi);
1337 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1338 afs_make_call(&fc->ac, call, GFP_NOFS);
1339 return afs_wait_for_call_to_complete(call, &fc->ac);
1343 * Deliver reply data to a YFS.StoreData64 operation.
1345 static int yfs_deliver_fs_store_data(struct afs_call *call)
1347 struct afs_vnode *vnode = call->reply[0];
1353 ret = afs_transfer_reply(call);
1357 /* unmarshall the reply once we've received all of it */
1359 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1360 &call->expected_version, NULL);
1363 xdr_decode_YFSVolSync(&bp, NULL);
1365 afs_pages_written_back(vnode, call);
1367 _leave(" = 0 [done]");
1372 * YFS.StoreData64 operation type.
1374 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1375 .name = "YFS.StoreData64",
1376 .op = yfs_FS_StoreData64,
1377 .deliver = yfs_deliver_fs_store_data,
1378 .destructor = afs_flat_call_destructor,
1382 * Store a set of pages to a large file.
1384 int yfs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1385 pgoff_t first, pgoff_t last,
1386 unsigned offset, unsigned to)
1388 struct afs_vnode *vnode = fc->vnode;
1389 struct afs_call *call;
1390 struct afs_net *net = afs_v2net(vnode);
1391 loff_t size, pos, i_size;
1394 _enter(",%x,{%llx:%llu},,",
1395 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1397 size = (loff_t)to - (loff_t)offset;
1399 size += (loff_t)(last - first) << PAGE_SHIFT;
1400 pos = (loff_t)first << PAGE_SHIFT;
1403 i_size = i_size_read(&vnode->vfs_inode);
1404 if (pos + size > i_size)
1405 i_size = size + pos;
1407 _debug("size %llx, at %llx, i_size %llx",
1408 (unsigned long long)size, (unsigned long long)pos,
1409 (unsigned long long)i_size);
1411 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64,
1414 sizeof(struct yfs_xdr_YFSFid) +
1415 sizeof(struct yfs_xdr_YFSStoreStatus) +
1416 sizeof(struct yfs_xdr_u64) * 3,
1417 sizeof(struct yfs_xdr_YFSFetchStatus) +
1418 sizeof(struct yfs_xdr_YFSVolSync));
1422 call->key = fc->key;
1423 call->mapping = mapping;
1424 call->reply[0] = vnode;
1425 call->first = first;
1427 call->first_offset = offset;
1429 call->send_pages = true;
1430 call->expected_version = vnode->status.data_version + 1;
1432 /* marshall the parameters */
1434 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1435 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1436 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1437 bp = xdr_encode_YFSStoreStatus_mtime(bp, &vnode->vfs_inode.i_mtime);
1438 bp = xdr_encode_u64(bp, pos);
1439 bp = xdr_encode_u64(bp, size);
1440 bp = xdr_encode_u64(bp, i_size);
1441 yfs_check_req(call, bp);
1443 afs_use_fs_server(call, fc->cbi);
1444 trace_afs_make_fs_call(call, &vnode->fid);
1445 afs_make_call(&fc->ac, call, GFP_NOFS);
1446 return afs_wait_for_call_to_complete(call, &fc->ac);
1450 * deliver reply data to an FS.StoreStatus
1452 static int yfs_deliver_fs_store_status(struct afs_call *call)
1454 struct afs_vnode *vnode = call->reply[0];
1460 ret = afs_transfer_reply(call);
1464 /* unmarshall the reply once we've received all of it */
1466 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1467 &call->expected_version, NULL);
1470 xdr_decode_YFSVolSync(&bp, NULL);
1472 _leave(" = 0 [done]");
1477 * YFS.StoreStatus operation type
1479 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1480 .name = "YFS.StoreStatus",
1481 .op = yfs_FS_StoreStatus,
1482 .deliver = yfs_deliver_fs_store_status,
1483 .destructor = afs_flat_call_destructor,
1486 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1487 .name = "YFS.StoreData64",
1488 .op = yfs_FS_StoreData64,
1489 .deliver = yfs_deliver_fs_store_status,
1490 .destructor = afs_flat_call_destructor,
1494 * Set the attributes on a file, using YFS.StoreData64 rather than
1495 * YFS.StoreStatus so as to alter the file size also.
1497 static int yfs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1499 struct afs_vnode *vnode = fc->vnode;
1500 struct afs_call *call;
1501 struct afs_net *net = afs_v2net(vnode);
1504 _enter(",%x,{%llx:%llu},,",
1505 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1507 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64_as_Status,
1508 sizeof(__be32) * 2 +
1509 sizeof(struct yfs_xdr_YFSFid) +
1510 sizeof(struct yfs_xdr_YFSStoreStatus) +
1511 sizeof(struct yfs_xdr_u64) * 3,
1512 sizeof(struct yfs_xdr_YFSFetchStatus) +
1513 sizeof(struct yfs_xdr_YFSVolSync));
1517 call->key = fc->key;
1518 call->reply[0] = vnode;
1519 call->expected_version = vnode->status.data_version + 1;
1521 /* marshall the parameters */
1523 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1524 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1525 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1526 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1527 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1528 bp = xdr_encode_u64(bp, 0); /* size of write */
1529 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1530 yfs_check_req(call, bp);
1532 afs_use_fs_server(call, fc->cbi);
1533 trace_afs_make_fs_call(call, &vnode->fid);
1534 afs_make_call(&fc->ac, call, GFP_NOFS);
1535 return afs_wait_for_call_to_complete(call, &fc->ac);
1539 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1540 * file size, and YFS.StoreStatus otherwise.
1542 int yfs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1544 struct afs_vnode *vnode = fc->vnode;
1545 struct afs_call *call;
1546 struct afs_net *net = afs_v2net(vnode);
1549 if (attr->ia_valid & ATTR_SIZE)
1550 return yfs_fs_setattr_size(fc, attr);
1552 _enter(",%x,{%llx:%llu},,",
1553 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1555 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
1556 sizeof(__be32) * 2 +
1557 sizeof(struct yfs_xdr_YFSFid) +
1558 sizeof(struct yfs_xdr_YFSStoreStatus),
1559 sizeof(struct yfs_xdr_YFSFetchStatus) +
1560 sizeof(struct yfs_xdr_YFSVolSync));
1564 call->key = fc->key;
1565 call->reply[0] = vnode;
1566 call->expected_version = vnode->status.data_version;
1568 /* marshall the parameters */
1570 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1571 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1572 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1573 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1574 yfs_check_req(call, bp);
1576 afs_use_fs_server(call, fc->cbi);
1577 trace_afs_make_fs_call(call, &vnode->fid);
1578 afs_make_call(&fc->ac, call, GFP_NOFS);
1579 return afs_wait_for_call_to_complete(call, &fc->ac);
1583 * Deliver reply data to a YFS.GetVolumeStatus operation.
1585 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1592 _enter("{%u}", call->unmarshall);
1594 switch (call->unmarshall) {
1597 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1599 /* extract the returned status record */
1601 _debug("extract status");
1602 ret = afs_extract_data(call, true);
1607 xdr_decode_YFSFetchVolumeStatus(&bp, call->reply[1]);
1609 afs_extract_to_tmp(call);
1611 /* extract the volume name length */
1613 ret = afs_extract_data(call, true);
1617 call->count = ntohl(call->tmp);
1618 _debug("volname length: %u", call->count);
1619 if (call->count >= AFSNAMEMAX)
1620 return afs_protocol_error(call, -EBADMSG,
1621 afs_eproto_volname_len);
1622 size = (call->count + 3) & ~3; /* It's padded */
1623 afs_extract_begin(call, call->reply[2], size);
1626 /* extract the volume name */
1628 _debug("extract volname");
1629 ret = afs_extract_data(call, true);
1635 _debug("volname '%s'", p);
1636 afs_extract_to_tmp(call);
1639 /* extract the offline message length */
1641 ret = afs_extract_data(call, true);
1645 call->count = ntohl(call->tmp);
1646 _debug("offline msg length: %u", call->count);
1647 if (call->count >= AFSNAMEMAX)
1648 return afs_protocol_error(call, -EBADMSG,
1649 afs_eproto_offline_msg_len);
1650 size = (call->count + 3) & ~3; /* It's padded */
1651 afs_extract_begin(call, call->reply[2], size);
1654 /* extract the offline message */
1656 _debug("extract offline");
1657 ret = afs_extract_data(call, true);
1663 _debug("offline '%s'", p);
1665 afs_extract_to_tmp(call);
1668 /* extract the message of the day length */
1670 ret = afs_extract_data(call, true);
1674 call->count = ntohl(call->tmp);
1675 _debug("motd length: %u", call->count);
1676 if (call->count >= AFSNAMEMAX)
1677 return afs_protocol_error(call, -EBADMSG,
1678 afs_eproto_motd_len);
1679 size = (call->count + 3) & ~3; /* It's padded */
1680 afs_extract_begin(call, call->reply[2], size);
1683 /* extract the message of the day */
1685 _debug("extract motd");
1686 ret = afs_extract_data(call, false);
1692 _debug("motd '%s'", p);
1700 _leave(" = 0 [done]");
1705 * Destroy a YFS.GetVolumeStatus call.
1707 static void yfs_get_volume_status_call_destructor(struct afs_call *call)
1709 kfree(call->reply[2]);
1710 call->reply[2] = NULL;
1711 afs_flat_call_destructor(call);
1715 * YFS.GetVolumeStatus operation type
1717 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1718 .name = "YFS.GetVolumeStatus",
1719 .op = yfs_FS_GetVolumeStatus,
1720 .deliver = yfs_deliver_fs_get_volume_status,
1721 .destructor = yfs_get_volume_status_call_destructor,
1725 * fetch the status of a volume
1727 int yfs_fs_get_volume_status(struct afs_fs_cursor *fc,
1728 struct afs_volume_status *vs)
1730 struct afs_vnode *vnode = fc->vnode;
1731 struct afs_call *call;
1732 struct afs_net *net = afs_v2net(vnode);
1738 tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1742 call = afs_alloc_flat_call(net, &yfs_RXYFSGetVolumeStatus,
1743 sizeof(__be32) * 2 +
1744 sizeof(struct yfs_xdr_u64),
1745 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1752 call->key = fc->key;
1753 call->reply[0] = vnode;
1754 call->reply[1] = vs;
1755 call->reply[2] = tmpbuf;
1757 /* marshall the parameters */
1759 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1760 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1761 bp = xdr_encode_u64(bp, vnode->fid.vid);
1762 yfs_check_req(call, bp);
1764 afs_use_fs_server(call, fc->cbi);
1765 trace_afs_make_fs_call(call, &vnode->fid);
1766 afs_make_call(&fc->ac, call, GFP_NOFS);
1767 return afs_wait_for_call_to_complete(call, &fc->ac);
1771 * Deliver reply data to operations that just return a file status and a volume
1774 static int yfs_deliver_status_and_volsync(struct afs_call *call)
1776 struct afs_vnode *vnode = call->reply[0];
1780 _enter("{%u}", call->unmarshall);
1782 ret = afs_transfer_reply(call);
1786 /* unmarshall the reply once we've received all of it */
1788 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1789 &call->expected_version, NULL);
1792 xdr_decode_YFSVolSync(&bp, NULL);
1794 _leave(" = 0 [done]");
1799 * YFS.SetLock operation type
1801 static const struct afs_call_type yfs_RXYFSSetLock = {
1802 .name = "YFS.SetLock",
1803 .op = yfs_FS_SetLock,
1804 .deliver = yfs_deliver_status_and_volsync,
1805 .done = afs_lock_op_done,
1806 .destructor = afs_flat_call_destructor,
1810 * YFS.ExtendLock operation type
1812 static const struct afs_call_type yfs_RXYFSExtendLock = {
1813 .name = "YFS.ExtendLock",
1814 .op = yfs_FS_ExtendLock,
1815 .deliver = yfs_deliver_status_and_volsync,
1816 .done = afs_lock_op_done,
1817 .destructor = afs_flat_call_destructor,
1821 * YFS.ReleaseLock operation type
1823 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1824 .name = "YFS.ReleaseLock",
1825 .op = yfs_FS_ReleaseLock,
1826 .deliver = yfs_deliver_status_and_volsync,
1827 .destructor = afs_flat_call_destructor,
1831 * Set a lock on a file
1833 int yfs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1835 struct afs_vnode *vnode = fc->vnode;
1836 struct afs_call *call;
1837 struct afs_net *net = afs_v2net(vnode);
1842 call = afs_alloc_flat_call(net, &yfs_RXYFSSetLock,
1843 sizeof(__be32) * 2 +
1844 sizeof(struct yfs_xdr_YFSFid) +
1846 sizeof(struct yfs_xdr_YFSFetchStatus) +
1847 sizeof(struct yfs_xdr_YFSVolSync));
1851 call->key = fc->key;
1852 call->reply[0] = vnode;
1853 call->want_reply_time = true;
1855 /* marshall the parameters */
1857 bp = xdr_encode_u32(bp, YFSSETLOCK);
1858 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1859 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1860 bp = xdr_encode_u32(bp, type);
1861 yfs_check_req(call, bp);
1863 afs_use_fs_server(call, fc->cbi);
1864 trace_afs_make_fs_calli(call, &vnode->fid, type);
1865 afs_make_call(&fc->ac, call, GFP_NOFS);
1866 return afs_wait_for_call_to_complete(call, &fc->ac);
1870 * extend a lock on a file
1872 int yfs_fs_extend_lock(struct afs_fs_cursor *fc)
1874 struct afs_vnode *vnode = fc->vnode;
1875 struct afs_call *call;
1876 struct afs_net *net = afs_v2net(vnode);
1881 call = afs_alloc_flat_call(net, &yfs_RXYFSExtendLock,
1882 sizeof(__be32) * 2 +
1883 sizeof(struct yfs_xdr_YFSFid),
1884 sizeof(struct yfs_xdr_YFSFetchStatus) +
1885 sizeof(struct yfs_xdr_YFSVolSync));
1889 call->key = fc->key;
1890 call->reply[0] = vnode;
1891 call->want_reply_time = true;
1893 /* marshall the parameters */
1895 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1896 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1897 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1898 yfs_check_req(call, bp);
1900 afs_use_fs_server(call, fc->cbi);
1901 trace_afs_make_fs_call(call, &vnode->fid);
1902 afs_make_call(&fc->ac, call, GFP_NOFS);
1903 return afs_wait_for_call_to_complete(call, &fc->ac);
1907 * release a lock on a file
1909 int yfs_fs_release_lock(struct afs_fs_cursor *fc)
1911 struct afs_vnode *vnode = fc->vnode;
1912 struct afs_call *call;
1913 struct afs_net *net = afs_v2net(vnode);
1918 call = afs_alloc_flat_call(net, &yfs_RXYFSReleaseLock,
1919 sizeof(__be32) * 2 +
1920 sizeof(struct yfs_xdr_YFSFid),
1921 sizeof(struct yfs_xdr_YFSFetchStatus) +
1922 sizeof(struct yfs_xdr_YFSVolSync));
1926 call->key = fc->key;
1927 call->reply[0] = vnode;
1929 /* marshall the parameters */
1931 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1932 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1933 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1934 yfs_check_req(call, bp);
1936 afs_use_fs_server(call, fc->cbi);
1937 trace_afs_make_fs_call(call, &vnode->fid);
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->reply[1];
1948 struct afs_callback *callback = call->reply[2];
1949 struct afs_volsync *volsync = call->reply[3];
1950 struct afs_vnode *vnode = call->reply[0];
1954 ret = afs_transfer_reply(call);
1958 _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
1960 /* unmarshall the reply once we've received all of it */
1962 ret = yfs_decode_status(call, &bp, status, vnode,
1963 &call->expected_version, NULL);
1966 xdr_decode_YFSCallBack_raw(&bp, callback);
1967 xdr_decode_YFSVolSync(&bp, volsync);
1969 _leave(" = 0 [done]");
1974 * YFS.FetchStatus operation type
1976 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1977 .name = "YFS.FetchStatus",
1978 .op = yfs_FS_FetchStatus,
1979 .deliver = yfs_deliver_fs_fetch_status,
1980 .destructor = afs_flat_call_destructor,
1984 * Fetch the status information for a fid without needing a vnode handle.
1986 int yfs_fs_fetch_status(struct afs_fs_cursor *fc,
1987 struct afs_net *net,
1988 struct afs_fid *fid,
1989 struct afs_file_status *status,
1990 struct afs_callback *callback,
1991 struct afs_volsync *volsync)
1993 struct afs_call *call;
1996 _enter(",%x,{%llx:%llu},,",
1997 key_serial(fc->key), fid->vid, fid->vnode);
1999 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus,
2000 sizeof(__be32) * 2 +
2001 sizeof(struct yfs_xdr_YFSFid),
2002 sizeof(struct yfs_xdr_YFSFetchStatus) +
2003 sizeof(struct yfs_xdr_YFSCallBack) +
2004 sizeof(struct yfs_xdr_YFSVolSync));
2006 fc->ac.error = -ENOMEM;
2010 call->key = fc->key;
2011 call->reply[0] = NULL; /* vnode for fid[0] */
2012 call->reply[1] = status;
2013 call->reply[2] = callback;
2014 call->reply[3] = volsync;
2015 call->expected_version = 1; /* vnode->status.data_version */
2017 /* marshall the parameters */
2019 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
2020 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2021 bp = xdr_encode_YFSFid(bp, fid);
2022 yfs_check_req(call, bp);
2024 call->cb_break = fc->cb_break;
2025 afs_use_fs_server(call, fc->cbi);
2026 trace_afs_make_fs_call(call, fid);
2027 afs_make_call(&fc->ac, call, GFP_NOFS);
2028 return afs_wait_for_call_to_complete(call, &fc->ac);
2032 * Deliver reply data to an YFS.InlineBulkStatus call
2034 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
2036 struct afs_file_status *statuses;
2037 struct afs_callback *callbacks;
2038 struct afs_vnode *vnode = call->reply[0];
2043 _enter("{%u}", call->unmarshall);
2045 switch (call->unmarshall) {
2047 afs_extract_to_tmp(call);
2050 /* Extract the file status count and array in two steps */
2052 _debug("extract status count");
2053 ret = afs_extract_data(call, true);
2057 tmp = ntohl(call->tmp);
2058 _debug("status count: %u/%u", tmp, call->count2);
2059 if (tmp != call->count2)
2060 return afs_protocol_error(call, -EBADMSG,
2061 afs_eproto_ibulkst_count);
2066 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->reply[1];
2076 ret = yfs_decode_status(call, &bp, &statuses[call->count],
2077 call->count == 0 ? vnode : NULL,
2083 if (call->count < call->count2)
2088 afs_extract_to_tmp(call);
2090 /* 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));
2108 _debug("extract CB array");
2109 ret = afs_extract_data(call, true);
2113 _debug("unmarshall CB array");
2115 callbacks = call->reply[2];
2116 xdr_decode_YFSCallBack_raw(&bp, &callbacks[call->count]);
2117 statuses = call->reply[1];
2118 if (call->count == 0 && vnode && statuses[0].abort_code == 0) {
2120 xdr_decode_YFSCallBack(call, vnode, &bp);
2123 if (call->count < call->count2)
2126 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
2130 ret = afs_extract_data(call, false);
2135 xdr_decode_YFSVolSync(&bp, call->reply[3]);
2143 _leave(" = 0 [done]");
2148 * FS.InlineBulkStatus operation type
2150 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
2151 .name = "YFS.InlineBulkStatus",
2152 .op = yfs_FS_InlineBulkStatus,
2153 .deliver = yfs_deliver_fs_inline_bulk_status,
2154 .destructor = afs_flat_call_destructor,
2158 * Fetch the status information for up to 1024 files
2160 int yfs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2161 struct afs_net *net,
2162 struct afs_fid *fids,
2163 struct afs_file_status *statuses,
2164 struct afs_callback *callbacks,
2165 unsigned int nr_fids,
2166 struct afs_volsync *volsync)
2168 struct afs_call *call;
2172 _enter(",%x,{%llx:%llu},%u",
2173 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2175 call = afs_alloc_flat_call(net, &yfs_RXYFSInlineBulkStatus,
2179 sizeof(struct yfs_xdr_YFSFid) * nr_fids,
2180 sizeof(struct yfs_xdr_YFSFetchStatus));
2182 fc->ac.error = -ENOMEM;
2186 call->key = fc->key;
2187 call->reply[0] = NULL; /* vnode for fid[0] */
2188 call->reply[1] = statuses;
2189 call->reply[2] = callbacks;
2190 call->reply[3] = volsync;
2191 call->count2 = nr_fids;
2193 /* marshall the parameters */
2195 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
2196 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
2197 bp = xdr_encode_u32(bp, nr_fids);
2198 for (i = 0; i < nr_fids; i++)
2199 bp = xdr_encode_YFSFid(bp, &fids[i]);
2200 yfs_check_req(call, bp);
2202 call->cb_break = fc->cb_break;
2203 afs_use_fs_server(call, fc->cbi);
2204 trace_afs_make_fs_call(call, &fids[0]);
2205 afs_make_call(&fc->ac, call, GFP_NOFS);
2206 return afs_wait_for_call_to_complete(call, &fc->ac);
2210 * Deliver reply data to an YFS.FetchOpaqueACL.
2212 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
2214 struct afs_volsync *volsync = call->reply[2];
2215 struct afs_vnode *vnode = call->reply[1];
2216 struct yfs_acl *yacl = call->reply[0];
2217 struct afs_acl *acl;
2222 _enter("{%u}", call->unmarshall);
2224 switch (call->unmarshall) {
2226 afs_extract_to_tmp(call);
2229 /* Extract the file ACL length */
2231 ret = afs_extract_data(call, true);
2235 size = call->count2 = ntohl(call->tmp);
2236 size = round_up(size, 4);
2238 if (yacl->flags & YFS_ACL_WANT_ACL) {
2239 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2243 acl->size = call->count2;
2244 afs_extract_begin(call, acl->data, size);
2246 iov_iter_discard(&call->iter, READ, size);
2250 /* Extract the file ACL */
2252 ret = afs_extract_data(call, true);
2256 afs_extract_to_tmp(call);
2259 /* Extract the volume ACL length */
2261 ret = afs_extract_data(call, true);
2265 size = call->count2 = ntohl(call->tmp);
2266 size = round_up(size, 4);
2268 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
2269 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2272 yacl->vol_acl = acl;
2273 acl->size = call->count2;
2274 afs_extract_begin(call, acl->data, size);
2276 iov_iter_discard(&call->iter, READ, size);
2280 /* Extract the volume ACL */
2282 ret = afs_extract_data(call, true);
2286 afs_extract_to_buf(call,
2287 sizeof(__be32) * 2 +
2288 sizeof(struct yfs_xdr_YFSFetchStatus) +
2289 sizeof(struct yfs_xdr_YFSVolSync));
2292 /* extract the metadata */
2294 ret = afs_extract_data(call, false);
2299 yacl->inherit_flag = ntohl(*bp++);
2300 yacl->num_cleaned = ntohl(*bp++);
2301 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
2302 &call->expected_version, NULL);
2305 xdr_decode_YFSVolSync(&bp, volsync);
2313 _leave(" = 0 [done]");
2317 void yfs_free_opaque_acl(struct yfs_acl *yacl)
2321 kfree(yacl->vol_acl);
2326 static void yfs_destroy_fs_fetch_opaque_acl(struct afs_call *call)
2328 yfs_free_opaque_acl(call->reply[0]);
2329 afs_flat_call_destructor(call);
2333 * YFS.FetchOpaqueACL operation type
2335 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
2336 .name = "YFS.FetchOpaqueACL",
2337 .op = yfs_FS_FetchOpaqueACL,
2338 .deliver = yfs_deliver_fs_fetch_opaque_acl,
2339 .destructor = yfs_destroy_fs_fetch_opaque_acl,
2343 * Fetch the YFS advanced ACLs for a file.
2345 struct yfs_acl *yfs_fs_fetch_opaque_acl(struct afs_fs_cursor *fc,
2348 struct afs_vnode *vnode = fc->vnode;
2349 struct afs_call *call;
2350 struct yfs_acl *yacl;
2351 struct afs_net *net = afs_v2net(vnode);
2354 _enter(",%x,{%llx:%llu},,",
2355 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2357 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchOpaqueACL,
2358 sizeof(__be32) * 2 +
2359 sizeof(struct yfs_xdr_YFSFid),
2360 sizeof(__be32) * 2 +
2361 sizeof(struct yfs_xdr_YFSFetchStatus) +
2362 sizeof(struct yfs_xdr_YFSVolSync));
2366 yacl = kzalloc(sizeof(struct yfs_acl), GFP_KERNEL);
2370 yacl->flags = flags;
2371 call->key = fc->key;
2372 call->reply[0] = yacl;
2373 call->reply[1] = vnode;
2374 call->reply[2] = NULL; /* volsync */
2375 call->ret_reply0 = true;
2377 /* marshall the parameters */
2379 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
2380 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2381 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2382 yfs_check_req(call, bp);
2384 call->cb_break = fc->cb_break;
2385 afs_use_fs_server(call, fc->cbi);
2386 trace_afs_make_fs_call(call, &vnode->fid);
2387 afs_make_call(&fc->ac, call, GFP_KERNEL);
2388 return (struct yfs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2393 fc->ac.error = -ENOMEM;
2394 return ERR_PTR(-ENOMEM);
2398 * YFS.StoreOpaqueACL2 operation type
2400 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
2401 .name = "YFS.StoreOpaqueACL2",
2402 .op = yfs_FS_StoreOpaqueACL2,
2403 .deliver = yfs_deliver_status_and_volsync,
2404 .destructor = afs_flat_call_destructor,
2408 * Fetch the YFS ACL for a file.
2410 int yfs_fs_store_opaque_acl2(struct afs_fs_cursor *fc, const struct afs_acl *acl)
2412 struct afs_vnode *vnode = fc->vnode;
2413 struct afs_call *call;
2414 struct afs_net *net = afs_v2net(vnode);
2418 _enter(",%x,{%llx:%llu},,",
2419 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2421 size = round_up(acl->size, 4);
2422 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
2423 sizeof(__be32) * 2 +
2424 sizeof(struct yfs_xdr_YFSFid) +
2425 sizeof(__be32) + size,
2426 sizeof(struct yfs_xdr_YFSFetchStatus) +
2427 sizeof(struct yfs_xdr_YFSVolSync));
2429 fc->ac.error = -ENOMEM;
2433 call->key = fc->key;
2434 call->reply[0] = vnode;
2435 call->reply[2] = NULL; /* volsync */
2437 /* marshall the parameters */
2439 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
2440 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2441 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2442 bp = xdr_encode_u32(bp, acl->size);
2443 memcpy(bp, acl->data, acl->size);
2444 if (acl->size != size)
2445 memset((void *)bp + acl->size, 0, size - acl->size);
2446 yfs_check_req(call, bp);
2448 trace_afs_make_fs_call(call, &vnode->fid);
2449 afs_make_call(&fc->ac, call, GFP_KERNEL);
2450 return afs_wait_for_call_to_complete(call, &fc->ac);