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 /* 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->reply[1]);
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 struct afs_read *req = call->reply[2];
658 afs_flat_call_destructor(call);
662 * YFS.FetchData64 operation type
664 static const struct afs_call_type yfs_RXYFSFetchData64 = {
665 .name = "YFS.FetchData64",
666 .op = yfs_FS_FetchData64,
667 .deliver = yfs_deliver_fs_fetch_data64,
668 .destructor = yfs_fetch_data_destructor,
672 * Fetch data from a file.
674 int yfs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
676 struct afs_vnode *vnode = fc->vnode;
677 struct afs_call *call;
678 struct afs_net *net = afs_v2net(vnode);
681 _enter(",%x,{%llx:%llu},%llx,%llx",
682 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode,
685 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchData64,
687 sizeof(struct yfs_xdr_YFSFid) +
688 sizeof(struct yfs_xdr_u64) * 2,
689 sizeof(struct yfs_xdr_YFSFetchStatus) +
690 sizeof(struct yfs_xdr_YFSCallBack) +
691 sizeof(struct yfs_xdr_YFSVolSync));
696 call->reply[0] = vnode;
697 call->reply[1] = NULL; /* volsync */
698 call->reply[2] = req;
699 call->expected_version = vnode->status.data_version;
700 call->want_reply_time = true;
702 /* marshall the parameters */
704 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
705 bp = xdr_encode_u32(bp, 0); /* RPC flags */
706 bp = xdr_encode_YFSFid(bp, &vnode->fid);
707 bp = xdr_encode_u64(bp, req->pos);
708 bp = xdr_encode_u64(bp, req->len);
709 yfs_check_req(call, bp);
711 refcount_inc(&req->usage);
712 call->cb_break = fc->cb_break;
713 afs_use_fs_server(call, fc->cbi);
714 trace_afs_make_fs_call(call, &vnode->fid);
715 afs_make_call(&fc->ac, call, GFP_NOFS);
716 return afs_wait_for_call_to_complete(call, &fc->ac);
720 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
722 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
724 struct afs_vnode *vnode = call->reply[0];
728 _enter("{%u}", call->unmarshall);
730 ret = afs_transfer_reply(call);
734 /* unmarshall the reply once we've received all of it */
736 xdr_decode_YFSFid(&bp, call->reply[1]);
737 ret = yfs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
740 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
741 &call->expected_version, NULL);
744 xdr_decode_YFSCallBack_raw(&bp, call->reply[3]);
745 xdr_decode_YFSVolSync(&bp, NULL);
747 _leave(" = 0 [done]");
752 * FS.CreateFile and FS.MakeDir operation type
754 static const struct afs_call_type afs_RXFSCreateFile = {
755 .name = "YFS.CreateFile",
756 .op = yfs_FS_CreateFile,
757 .deliver = yfs_deliver_fs_create_vnode,
758 .destructor = afs_flat_call_destructor,
764 int yfs_fs_create_file(struct afs_fs_cursor *fc,
767 u64 current_data_version,
768 struct afs_fid *newfid,
769 struct afs_file_status *newstatus,
770 struct afs_callback *newcb)
772 struct afs_vnode *vnode = fc->vnode;
773 struct afs_call *call;
774 struct afs_net *net = afs_v2net(vnode);
775 size_t namesz, reqsz, rplsz;
780 namesz = strlen(name);
781 reqsz = (sizeof(__be32) +
783 sizeof(struct yfs_xdr_YFSFid) +
785 sizeof(struct yfs_xdr_YFSStoreStatus) +
787 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
788 sizeof(struct yfs_xdr_YFSFetchStatus) +
789 sizeof(struct yfs_xdr_YFSFetchStatus) +
790 sizeof(struct yfs_xdr_YFSCallBack) +
791 sizeof(struct yfs_xdr_YFSVolSync));
793 call = afs_alloc_flat_call(net, &afs_RXFSCreateFile, reqsz, rplsz);
798 call->reply[0] = vnode;
799 call->reply[1] = newfid;
800 call->reply[2] = newstatus;
801 call->reply[3] = newcb;
802 call->expected_version = current_data_version + 1;
804 /* marshall the parameters */
806 bp = xdr_encode_u32(bp, YFSCREATEFILE);
807 bp = xdr_encode_u32(bp, 0); /* RPC flags */
808 bp = xdr_encode_YFSFid(bp, &vnode->fid);
809 bp = xdr_encode_string(bp, name, namesz);
810 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
811 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
812 yfs_check_req(call, bp);
814 afs_use_fs_server(call, fc->cbi);
815 trace_afs_make_fs_call1(call, &vnode->fid, name);
816 afs_make_call(&fc->ac, call, GFP_NOFS);
817 return afs_wait_for_call_to_complete(call, &fc->ac);
820 static const struct afs_call_type yfs_RXFSMakeDir = {
821 .name = "YFS.MakeDir",
822 .op = yfs_FS_MakeDir,
823 .deliver = yfs_deliver_fs_create_vnode,
824 .destructor = afs_flat_call_destructor,
830 int yfs_fs_make_dir(struct afs_fs_cursor *fc,
833 u64 current_data_version,
834 struct afs_fid *newfid,
835 struct afs_file_status *newstatus,
836 struct afs_callback *newcb)
838 struct afs_vnode *vnode = fc->vnode;
839 struct afs_call *call;
840 struct afs_net *net = afs_v2net(vnode);
841 size_t namesz, reqsz, rplsz;
846 namesz = strlen(name);
847 reqsz = (sizeof(__be32) +
848 sizeof(struct yfs_xdr_RPCFlags) +
849 sizeof(struct yfs_xdr_YFSFid) +
851 sizeof(struct yfs_xdr_YFSStoreStatus));
852 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
853 sizeof(struct yfs_xdr_YFSFetchStatus) +
854 sizeof(struct yfs_xdr_YFSFetchStatus) +
855 sizeof(struct yfs_xdr_YFSCallBack) +
856 sizeof(struct yfs_xdr_YFSVolSync));
858 call = afs_alloc_flat_call(net, &yfs_RXFSMakeDir, reqsz, rplsz);
863 call->reply[0] = vnode;
864 call->reply[1] = newfid;
865 call->reply[2] = newstatus;
866 call->reply[3] = newcb;
867 call->expected_version = current_data_version + 1;
869 /* marshall the parameters */
871 bp = xdr_encode_u32(bp, YFSMAKEDIR);
872 bp = xdr_encode_u32(bp, 0); /* RPC flags */
873 bp = xdr_encode_YFSFid(bp, &vnode->fid);
874 bp = xdr_encode_string(bp, name, namesz);
875 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
876 yfs_check_req(call, bp);
878 afs_use_fs_server(call, fc->cbi);
879 trace_afs_make_fs_call1(call, &vnode->fid, name);
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->reply[0];
890 struct afs_vnode *vnode = call->reply[1];
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->reply[0] = dvnode;
958 call->reply[1] = 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_make_call(&fc->ac, call, GFP_NOFS);
972 return afs_wait_for_call_to_complete(call, &fc->ac);
976 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
978 static int yfs_deliver_fs_remove(struct afs_call *call)
980 struct afs_vnode *dvnode = call->reply[0];
984 _enter("{%u}", call->unmarshall);
986 ret = afs_transfer_reply(call);
990 /* unmarshall the reply once we've received all of it */
992 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
993 &call->expected_version, NULL);
997 xdr_decode_YFSVolSync(&bp, NULL);
1002 * FS.RemoveDir and FS.RemoveFile operation types.
1004 static const struct afs_call_type yfs_RXYFSRemoveFile = {
1005 .name = "YFS.RemoveFile",
1006 .op = yfs_FS_RemoveFile,
1007 .deliver = yfs_deliver_fs_remove,
1008 .destructor = afs_flat_call_destructor,
1011 static const struct afs_call_type yfs_RXYFSRemoveDir = {
1012 .name = "YFS.RemoveDir",
1013 .op = yfs_FS_RemoveDir,
1014 .deliver = yfs_deliver_fs_remove,
1015 .destructor = afs_flat_call_destructor,
1019 * remove a file or directory
1021 int yfs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
1022 const char *name, bool isdir, u64 current_data_version)
1024 struct afs_vnode *dvnode = fc->vnode;
1025 struct afs_call *call;
1026 struct afs_net *net = afs_v2net(dvnode);
1032 namesz = strlen(name);
1033 call = afs_alloc_flat_call(
1034 net, isdir ? &yfs_RXYFSRemoveDir : &yfs_RXYFSRemoveFile,
1036 sizeof(struct yfs_xdr_RPCFlags) +
1037 sizeof(struct yfs_xdr_YFSFid) +
1039 sizeof(struct yfs_xdr_YFSFetchStatus) +
1040 sizeof(struct yfs_xdr_YFSVolSync));
1044 call->key = fc->key;
1045 call->reply[0] = dvnode;
1046 call->reply[1] = vnode;
1047 call->expected_version = current_data_version + 1;
1049 /* marshall the parameters */
1051 bp = xdr_encode_u32(bp, isdir ? YFSREMOVEDIR : YFSREMOVEFILE);
1052 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1053 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1054 bp = xdr_encode_string(bp, name, namesz);
1055 yfs_check_req(call, bp);
1057 afs_use_fs_server(call, fc->cbi);
1058 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1059 afs_make_call(&fc->ac, call, GFP_NOFS);
1060 return afs_wait_for_call_to_complete(call, &fc->ac);
1064 * Deliver reply data to a YFS.Link operation.
1066 static int yfs_deliver_fs_link(struct afs_call *call)
1068 struct afs_vnode *dvnode = call->reply[0], *vnode = call->reply[1];
1072 _enter("{%u}", call->unmarshall);
1074 ret = afs_transfer_reply(call);
1078 /* unmarshall the reply once we've received all of it */
1080 ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
1083 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
1084 &call->expected_version, NULL);
1087 xdr_decode_YFSVolSync(&bp, NULL);
1088 _leave(" = 0 [done]");
1093 * YFS.Link operation type.
1095 static const struct afs_call_type yfs_RXYFSLink = {
1098 .deliver = yfs_deliver_fs_link,
1099 .destructor = afs_flat_call_destructor,
1105 int yfs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
1106 const char *name, u64 current_data_version)
1108 struct afs_vnode *dvnode = fc->vnode;
1109 struct afs_call *call;
1110 struct afs_net *net = afs_v2net(vnode);
1116 namesz = strlen(name);
1117 call = afs_alloc_flat_call(net, &yfs_RXYFSLink,
1119 sizeof(struct yfs_xdr_RPCFlags) +
1120 sizeof(struct yfs_xdr_YFSFid) +
1121 xdr_strlen(namesz) +
1122 sizeof(struct yfs_xdr_YFSFid),
1123 sizeof(struct yfs_xdr_YFSFetchStatus) +
1124 sizeof(struct yfs_xdr_YFSFetchStatus) +
1125 sizeof(struct yfs_xdr_YFSVolSync));
1129 call->key = fc->key;
1130 call->reply[0] = dvnode;
1131 call->reply[1] = vnode;
1132 call->expected_version = current_data_version + 1;
1134 /* marshall the parameters */
1136 bp = xdr_encode_u32(bp, YFSLINK);
1137 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1138 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1139 bp = xdr_encode_string(bp, name, namesz);
1140 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1141 yfs_check_req(call, bp);
1143 afs_use_fs_server(call, fc->cbi);
1144 trace_afs_make_fs_call1(call, &vnode->fid, name);
1145 afs_make_call(&fc->ac, call, GFP_NOFS);
1146 return afs_wait_for_call_to_complete(call, &fc->ac);
1150 * Deliver reply data to a YFS.Symlink operation.
1152 static int yfs_deliver_fs_symlink(struct afs_call *call)
1154 struct afs_vnode *vnode = call->reply[0];
1158 _enter("{%u}", call->unmarshall);
1160 ret = afs_transfer_reply(call);
1164 /* unmarshall the reply once we've received all of it */
1166 xdr_decode_YFSFid(&bp, call->reply[1]);
1167 ret = yfs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
1170 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1171 &call->expected_version, NULL);
1174 xdr_decode_YFSVolSync(&bp, NULL);
1176 _leave(" = 0 [done]");
1181 * YFS.Symlink operation type
1183 static const struct afs_call_type yfs_RXYFSSymlink = {
1184 .name = "YFS.Symlink",
1185 .op = yfs_FS_Symlink,
1186 .deliver = yfs_deliver_fs_symlink,
1187 .destructor = afs_flat_call_destructor,
1191 * Create a symbolic link.
1193 int yfs_fs_symlink(struct afs_fs_cursor *fc,
1195 const char *contents,
1196 u64 current_data_version,
1197 struct afs_fid *newfid,
1198 struct afs_file_status *newstatus)
1200 struct afs_vnode *dvnode = fc->vnode;
1201 struct afs_call *call;
1202 struct afs_net *net = afs_v2net(dvnode);
1203 size_t namesz, contents_sz;
1208 namesz = strlen(name);
1209 contents_sz = strlen(contents);
1210 call = afs_alloc_flat_call(net, &yfs_RXYFSSymlink,
1212 sizeof(struct yfs_xdr_RPCFlags) +
1213 sizeof(struct yfs_xdr_YFSFid) +
1214 xdr_strlen(namesz) +
1215 xdr_strlen(contents_sz) +
1216 sizeof(struct yfs_xdr_YFSStoreStatus),
1217 sizeof(struct yfs_xdr_YFSFid) +
1218 sizeof(struct yfs_xdr_YFSFetchStatus) +
1219 sizeof(struct yfs_xdr_YFSFetchStatus) +
1220 sizeof(struct yfs_xdr_YFSVolSync));
1224 call->key = fc->key;
1225 call->reply[0] = dvnode;
1226 call->reply[1] = newfid;
1227 call->reply[2] = newstatus;
1228 call->expected_version = current_data_version + 1;
1230 /* marshall the parameters */
1232 bp = xdr_encode_u32(bp, YFSSYMLINK);
1233 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1234 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1235 bp = xdr_encode_string(bp, name, namesz);
1236 bp = xdr_encode_string(bp, contents, contents_sz);
1237 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
1238 yfs_check_req(call, bp);
1240 afs_use_fs_server(call, fc->cbi);
1241 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1242 afs_make_call(&fc->ac, call, GFP_NOFS);
1243 return afs_wait_for_call_to_complete(call, &fc->ac);
1247 * Deliver reply data to a YFS.Rename operation.
1249 static int yfs_deliver_fs_rename(struct afs_call *call)
1251 struct afs_vnode *orig_dvnode = call->reply[0];
1252 struct afs_vnode *new_dvnode = call->reply[1];
1256 _enter("{%u}", call->unmarshall);
1258 ret = afs_transfer_reply(call);
1262 /* unmarshall the reply once we've received all of it */
1264 ret = yfs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1265 &call->expected_version, NULL);
1268 if (new_dvnode != orig_dvnode) {
1269 ret = yfs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1270 &call->expected_version_2, NULL);
1275 xdr_decode_YFSVolSync(&bp, NULL);
1276 _leave(" = 0 [done]");
1281 * YFS.Rename operation type
1283 static const struct afs_call_type yfs_RXYFSRename = {
1284 .name = "FS.Rename",
1285 .op = yfs_FS_Rename,
1286 .deliver = yfs_deliver_fs_rename,
1287 .destructor = afs_flat_call_destructor,
1291 * Rename a file or directory.
1293 int yfs_fs_rename(struct afs_fs_cursor *fc,
1294 const char *orig_name,
1295 struct afs_vnode *new_dvnode,
1296 const char *new_name,
1297 u64 current_orig_data_version,
1298 u64 current_new_data_version)
1300 struct afs_vnode *orig_dvnode = fc->vnode;
1301 struct afs_call *call;
1302 struct afs_net *net = afs_v2net(orig_dvnode);
1303 size_t o_namesz, n_namesz;
1308 o_namesz = strlen(orig_name);
1309 n_namesz = strlen(new_name);
1310 call = afs_alloc_flat_call(net, &yfs_RXYFSRename,
1312 sizeof(struct yfs_xdr_RPCFlags) +
1313 sizeof(struct yfs_xdr_YFSFid) +
1314 xdr_strlen(o_namesz) +
1315 sizeof(struct yfs_xdr_YFSFid) +
1316 xdr_strlen(n_namesz),
1317 sizeof(struct yfs_xdr_YFSFetchStatus) +
1318 sizeof(struct yfs_xdr_YFSFetchStatus) +
1319 sizeof(struct yfs_xdr_YFSVolSync));
1323 call->key = fc->key;
1324 call->reply[0] = orig_dvnode;
1325 call->reply[1] = new_dvnode;
1326 call->expected_version = current_orig_data_version + 1;
1327 call->expected_version_2 = current_new_data_version + 1;
1329 /* marshall the parameters */
1331 bp = xdr_encode_u32(bp, YFSRENAME);
1332 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1333 bp = xdr_encode_YFSFid(bp, &orig_dvnode->fid);
1334 bp = xdr_encode_string(bp, orig_name, o_namesz);
1335 bp = xdr_encode_YFSFid(bp, &new_dvnode->fid);
1336 bp = xdr_encode_string(bp, new_name, n_namesz);
1337 yfs_check_req(call, bp);
1339 afs_use_fs_server(call, fc->cbi);
1340 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1341 afs_make_call(&fc->ac, call, GFP_NOFS);
1342 return afs_wait_for_call_to_complete(call, &fc->ac);
1346 * Deliver reply data to a YFS.StoreData64 operation.
1348 static int yfs_deliver_fs_store_data(struct afs_call *call)
1350 struct afs_vnode *vnode = call->reply[0];
1356 ret = afs_transfer_reply(call);
1360 /* unmarshall the reply once we've received all of it */
1362 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1363 &call->expected_version, NULL);
1366 xdr_decode_YFSVolSync(&bp, NULL);
1368 afs_pages_written_back(vnode, call);
1370 _leave(" = 0 [done]");
1375 * YFS.StoreData64 operation type.
1377 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1378 .name = "YFS.StoreData64",
1379 .op = yfs_FS_StoreData64,
1380 .deliver = yfs_deliver_fs_store_data,
1381 .destructor = afs_flat_call_destructor,
1385 * Store a set of pages to a large file.
1387 int yfs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1388 pgoff_t first, pgoff_t last,
1389 unsigned offset, unsigned to)
1391 struct afs_vnode *vnode = fc->vnode;
1392 struct afs_call *call;
1393 struct afs_net *net = afs_v2net(vnode);
1394 loff_t size, pos, i_size;
1397 _enter(",%x,{%llx:%llu},,",
1398 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1400 size = (loff_t)to - (loff_t)offset;
1402 size += (loff_t)(last - first) << PAGE_SHIFT;
1403 pos = (loff_t)first << PAGE_SHIFT;
1406 i_size = i_size_read(&vnode->vfs_inode);
1407 if (pos + size > i_size)
1408 i_size = size + pos;
1410 _debug("size %llx, at %llx, i_size %llx",
1411 (unsigned long long)size, (unsigned long long)pos,
1412 (unsigned long long)i_size);
1414 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64,
1417 sizeof(struct yfs_xdr_YFSFid) +
1418 sizeof(struct yfs_xdr_YFSStoreStatus) +
1419 sizeof(struct yfs_xdr_u64) * 3,
1420 sizeof(struct yfs_xdr_YFSFetchStatus) +
1421 sizeof(struct yfs_xdr_YFSVolSync));
1425 call->key = fc->key;
1426 call->mapping = mapping;
1427 call->reply[0] = vnode;
1428 call->first = first;
1430 call->first_offset = offset;
1432 call->send_pages = true;
1433 call->expected_version = vnode->status.data_version + 1;
1435 /* marshall the parameters */
1437 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1438 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1439 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1440 bp = xdr_encode_YFSStoreStatus_mtime(bp, &vnode->vfs_inode.i_mtime);
1441 bp = xdr_encode_u64(bp, pos);
1442 bp = xdr_encode_u64(bp, size);
1443 bp = xdr_encode_u64(bp, i_size);
1444 yfs_check_req(call, bp);
1446 afs_use_fs_server(call, fc->cbi);
1447 trace_afs_make_fs_call(call, &vnode->fid);
1448 afs_make_call(&fc->ac, call, GFP_NOFS);
1449 return afs_wait_for_call_to_complete(call, &fc->ac);
1453 * deliver reply data to an FS.StoreStatus
1455 static int yfs_deliver_fs_store_status(struct afs_call *call)
1457 struct afs_vnode *vnode = call->reply[0];
1463 ret = afs_transfer_reply(call);
1467 /* unmarshall the reply once we've received all of it */
1469 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1470 &call->expected_version, NULL);
1473 xdr_decode_YFSVolSync(&bp, NULL);
1475 _leave(" = 0 [done]");
1480 * YFS.StoreStatus operation type
1482 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1483 .name = "YFS.StoreStatus",
1484 .op = yfs_FS_StoreStatus,
1485 .deliver = yfs_deliver_fs_store_status,
1486 .destructor = afs_flat_call_destructor,
1489 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1490 .name = "YFS.StoreData64",
1491 .op = yfs_FS_StoreData64,
1492 .deliver = yfs_deliver_fs_store_status,
1493 .destructor = afs_flat_call_destructor,
1497 * Set the attributes on a file, using YFS.StoreData64 rather than
1498 * YFS.StoreStatus so as to alter the file size also.
1500 static int yfs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1502 struct afs_vnode *vnode = fc->vnode;
1503 struct afs_call *call;
1504 struct afs_net *net = afs_v2net(vnode);
1507 _enter(",%x,{%llx:%llu},,",
1508 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1510 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64_as_Status,
1511 sizeof(__be32) * 2 +
1512 sizeof(struct yfs_xdr_YFSFid) +
1513 sizeof(struct yfs_xdr_YFSStoreStatus) +
1514 sizeof(struct yfs_xdr_u64) * 3,
1515 sizeof(struct yfs_xdr_YFSFetchStatus) +
1516 sizeof(struct yfs_xdr_YFSVolSync));
1520 call->key = fc->key;
1521 call->reply[0] = vnode;
1522 call->expected_version = vnode->status.data_version + 1;
1524 /* marshall the parameters */
1526 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1527 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1528 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1529 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1530 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1531 bp = xdr_encode_u64(bp, 0); /* size of write */
1532 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1533 yfs_check_req(call, bp);
1535 afs_use_fs_server(call, fc->cbi);
1536 trace_afs_make_fs_call(call, &vnode->fid);
1537 afs_make_call(&fc->ac, call, GFP_NOFS);
1538 return afs_wait_for_call_to_complete(call, &fc->ac);
1542 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1543 * file size, and YFS.StoreStatus otherwise.
1545 int yfs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1547 struct afs_vnode *vnode = fc->vnode;
1548 struct afs_call *call;
1549 struct afs_net *net = afs_v2net(vnode);
1552 if (attr->ia_valid & ATTR_SIZE)
1553 return yfs_fs_setattr_size(fc, attr);
1555 _enter(",%x,{%llx:%llu},,",
1556 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1558 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
1559 sizeof(__be32) * 2 +
1560 sizeof(struct yfs_xdr_YFSFid) +
1561 sizeof(struct yfs_xdr_YFSStoreStatus),
1562 sizeof(struct yfs_xdr_YFSFetchStatus) +
1563 sizeof(struct yfs_xdr_YFSVolSync));
1567 call->key = fc->key;
1568 call->reply[0] = vnode;
1569 call->expected_version = vnode->status.data_version;
1571 /* marshall the parameters */
1573 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1574 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1575 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1576 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1577 yfs_check_req(call, bp);
1579 afs_use_fs_server(call, fc->cbi);
1580 trace_afs_make_fs_call(call, &vnode->fid);
1581 afs_make_call(&fc->ac, call, GFP_NOFS);
1582 return afs_wait_for_call_to_complete(call, &fc->ac);
1586 * Deliver reply data to a YFS.GetVolumeStatus operation.
1588 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1595 _enter("{%u}", call->unmarshall);
1597 switch (call->unmarshall) {
1600 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1602 /* Fall through - and extract the returned status record */
1604 _debug("extract status");
1605 ret = afs_extract_data(call, true);
1610 xdr_decode_YFSFetchVolumeStatus(&bp, call->reply[1]);
1612 afs_extract_to_tmp(call);
1614 /* Fall through - and extract the volume name length */
1616 ret = afs_extract_data(call, true);
1620 call->count = ntohl(call->tmp);
1621 _debug("volname length: %u", call->count);
1622 if (call->count >= AFSNAMEMAX)
1623 return afs_protocol_error(call, -EBADMSG,
1624 afs_eproto_volname_len);
1625 size = (call->count + 3) & ~3; /* It's padded */
1626 afs_extract_begin(call, call->reply[2], size);
1629 /* Fall through - and extract the volume name */
1631 _debug("extract volname");
1632 ret = afs_extract_data(call, true);
1638 _debug("volname '%s'", p);
1639 afs_extract_to_tmp(call);
1642 /* Fall through - and extract the offline message length */
1644 ret = afs_extract_data(call, true);
1648 call->count = ntohl(call->tmp);
1649 _debug("offline msg length: %u", call->count);
1650 if (call->count >= AFSNAMEMAX)
1651 return afs_protocol_error(call, -EBADMSG,
1652 afs_eproto_offline_msg_len);
1653 size = (call->count + 3) & ~3; /* It's padded */
1654 afs_extract_begin(call, call->reply[2], size);
1657 /* Fall through - and extract the offline message */
1659 _debug("extract offline");
1660 ret = afs_extract_data(call, true);
1666 _debug("offline '%s'", p);
1668 afs_extract_to_tmp(call);
1671 /* Fall through - and extract the message of the day length */
1673 ret = afs_extract_data(call, true);
1677 call->count = ntohl(call->tmp);
1678 _debug("motd length: %u", call->count);
1679 if (call->count >= AFSNAMEMAX)
1680 return afs_protocol_error(call, -EBADMSG,
1681 afs_eproto_motd_len);
1682 size = (call->count + 3) & ~3; /* It's padded */
1683 afs_extract_begin(call, call->reply[2], size);
1686 /* Fall through - and extract the message of the day */
1688 _debug("extract motd");
1689 ret = afs_extract_data(call, false);
1695 _debug("motd '%s'", p);
1704 _leave(" = 0 [done]");
1709 * Destroy a YFS.GetVolumeStatus call.
1711 static void yfs_get_volume_status_call_destructor(struct afs_call *call)
1713 kfree(call->reply[2]);
1714 call->reply[2] = NULL;
1715 afs_flat_call_destructor(call);
1719 * YFS.GetVolumeStatus operation type
1721 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1722 .name = "YFS.GetVolumeStatus",
1723 .op = yfs_FS_GetVolumeStatus,
1724 .deliver = yfs_deliver_fs_get_volume_status,
1725 .destructor = yfs_get_volume_status_call_destructor,
1729 * fetch the status of a volume
1731 int yfs_fs_get_volume_status(struct afs_fs_cursor *fc,
1732 struct afs_volume_status *vs)
1734 struct afs_vnode *vnode = fc->vnode;
1735 struct afs_call *call;
1736 struct afs_net *net = afs_v2net(vnode);
1742 tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1746 call = afs_alloc_flat_call(net, &yfs_RXYFSGetVolumeStatus,
1747 sizeof(__be32) * 2 +
1748 sizeof(struct yfs_xdr_u64),
1749 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1756 call->key = fc->key;
1757 call->reply[0] = vnode;
1758 call->reply[1] = vs;
1759 call->reply[2] = tmpbuf;
1761 /* marshall the parameters */
1763 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1764 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1765 bp = xdr_encode_u64(bp, vnode->fid.vid);
1766 yfs_check_req(call, bp);
1768 afs_use_fs_server(call, fc->cbi);
1769 trace_afs_make_fs_call(call, &vnode->fid);
1770 afs_make_call(&fc->ac, call, GFP_NOFS);
1771 return afs_wait_for_call_to_complete(call, &fc->ac);
1775 * Deliver reply data to operations that just return a file status and a volume
1778 static int yfs_deliver_status_and_volsync(struct afs_call *call)
1780 struct afs_vnode *vnode = call->reply[0];
1784 _enter("{%u}", call->unmarshall);
1786 ret = afs_transfer_reply(call);
1790 /* unmarshall the reply once we've received all of it */
1792 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1793 &call->expected_version, NULL);
1796 xdr_decode_YFSVolSync(&bp, NULL);
1798 _leave(" = 0 [done]");
1803 * YFS.SetLock operation type
1805 static const struct afs_call_type yfs_RXYFSSetLock = {
1806 .name = "YFS.SetLock",
1807 .op = yfs_FS_SetLock,
1808 .deliver = yfs_deliver_status_and_volsync,
1809 .done = afs_lock_op_done,
1810 .destructor = afs_flat_call_destructor,
1814 * YFS.ExtendLock operation type
1816 static const struct afs_call_type yfs_RXYFSExtendLock = {
1817 .name = "YFS.ExtendLock",
1818 .op = yfs_FS_ExtendLock,
1819 .deliver = yfs_deliver_status_and_volsync,
1820 .done = afs_lock_op_done,
1821 .destructor = afs_flat_call_destructor,
1825 * YFS.ReleaseLock operation type
1827 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1828 .name = "YFS.ReleaseLock",
1829 .op = yfs_FS_ReleaseLock,
1830 .deliver = yfs_deliver_status_and_volsync,
1831 .destructor = afs_flat_call_destructor,
1835 * Set a lock on a file
1837 int yfs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1839 struct afs_vnode *vnode = fc->vnode;
1840 struct afs_call *call;
1841 struct afs_net *net = afs_v2net(vnode);
1846 call = afs_alloc_flat_call(net, &yfs_RXYFSSetLock,
1847 sizeof(__be32) * 2 +
1848 sizeof(struct yfs_xdr_YFSFid) +
1850 sizeof(struct yfs_xdr_YFSFetchStatus) +
1851 sizeof(struct yfs_xdr_YFSVolSync));
1855 call->key = fc->key;
1856 call->reply[0] = vnode;
1857 call->want_reply_time = true;
1859 /* marshall the parameters */
1861 bp = xdr_encode_u32(bp, YFSSETLOCK);
1862 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1863 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1864 bp = xdr_encode_u32(bp, type);
1865 yfs_check_req(call, bp);
1867 afs_use_fs_server(call, fc->cbi);
1868 trace_afs_make_fs_calli(call, &vnode->fid, type);
1869 afs_make_call(&fc->ac, call, GFP_NOFS);
1870 return afs_wait_for_call_to_complete(call, &fc->ac);
1874 * extend a lock on a file
1876 int yfs_fs_extend_lock(struct afs_fs_cursor *fc)
1878 struct afs_vnode *vnode = fc->vnode;
1879 struct afs_call *call;
1880 struct afs_net *net = afs_v2net(vnode);
1885 call = afs_alloc_flat_call(net, &yfs_RXYFSExtendLock,
1886 sizeof(__be32) * 2 +
1887 sizeof(struct yfs_xdr_YFSFid),
1888 sizeof(struct yfs_xdr_YFSFetchStatus) +
1889 sizeof(struct yfs_xdr_YFSVolSync));
1893 call->key = fc->key;
1894 call->reply[0] = vnode;
1895 call->want_reply_time = true;
1897 /* marshall the parameters */
1899 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1900 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1901 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1902 yfs_check_req(call, bp);
1904 afs_use_fs_server(call, fc->cbi);
1905 trace_afs_make_fs_call(call, &vnode->fid);
1906 afs_make_call(&fc->ac, call, GFP_NOFS);
1907 return afs_wait_for_call_to_complete(call, &fc->ac);
1911 * release a lock on a file
1913 int yfs_fs_release_lock(struct afs_fs_cursor *fc)
1915 struct afs_vnode *vnode = fc->vnode;
1916 struct afs_call *call;
1917 struct afs_net *net = afs_v2net(vnode);
1922 call = afs_alloc_flat_call(net, &yfs_RXYFSReleaseLock,
1923 sizeof(__be32) * 2 +
1924 sizeof(struct yfs_xdr_YFSFid),
1925 sizeof(struct yfs_xdr_YFSFetchStatus) +
1926 sizeof(struct yfs_xdr_YFSVolSync));
1930 call->key = fc->key;
1931 call->reply[0] = vnode;
1933 /* marshall the parameters */
1935 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1936 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1937 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1938 yfs_check_req(call, bp);
1940 afs_use_fs_server(call, fc->cbi);
1941 trace_afs_make_fs_call(call, &vnode->fid);
1942 afs_make_call(&fc->ac, call, GFP_NOFS);
1943 return afs_wait_for_call_to_complete(call, &fc->ac);
1947 * Deliver reply data to an FS.FetchStatus with no vnode.
1949 static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1951 struct afs_file_status *status = call->reply[1];
1952 struct afs_callback *callback = call->reply[2];
1953 struct afs_volsync *volsync = call->reply[3];
1954 struct afs_vnode *vnode = call->reply[0];
1958 ret = afs_transfer_reply(call);
1962 _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
1964 /* unmarshall the reply once we've received all of it */
1966 ret = yfs_decode_status(call, &bp, status, vnode,
1967 &call->expected_version, NULL);
1970 xdr_decode_YFSCallBack_raw(&bp, callback);
1971 xdr_decode_YFSVolSync(&bp, volsync);
1973 _leave(" = 0 [done]");
1978 * YFS.FetchStatus operation type
1980 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1981 .name = "YFS.FetchStatus",
1982 .op = yfs_FS_FetchStatus,
1983 .deliver = yfs_deliver_fs_fetch_status,
1984 .destructor = afs_flat_call_destructor,
1988 * Fetch the status information for a fid without needing a vnode handle.
1990 int yfs_fs_fetch_status(struct afs_fs_cursor *fc,
1991 struct afs_net *net,
1992 struct afs_fid *fid,
1993 struct afs_file_status *status,
1994 struct afs_callback *callback,
1995 struct afs_volsync *volsync)
1997 struct afs_call *call;
2000 _enter(",%x,{%llx:%llu},,",
2001 key_serial(fc->key), fid->vid, fid->vnode);
2003 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus,
2004 sizeof(__be32) * 2 +
2005 sizeof(struct yfs_xdr_YFSFid),
2006 sizeof(struct yfs_xdr_YFSFetchStatus) +
2007 sizeof(struct yfs_xdr_YFSCallBack) +
2008 sizeof(struct yfs_xdr_YFSVolSync));
2010 fc->ac.error = -ENOMEM;
2014 call->key = fc->key;
2015 call->reply[0] = NULL; /* vnode for fid[0] */
2016 call->reply[1] = status;
2017 call->reply[2] = callback;
2018 call->reply[3] = volsync;
2019 call->expected_version = 1; /* vnode->status.data_version */
2021 /* marshall the parameters */
2023 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
2024 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2025 bp = xdr_encode_YFSFid(bp, fid);
2026 yfs_check_req(call, bp);
2028 call->cb_break = fc->cb_break;
2029 afs_use_fs_server(call, fc->cbi);
2030 trace_afs_make_fs_call(call, fid);
2031 afs_make_call(&fc->ac, call, GFP_NOFS);
2032 return afs_wait_for_call_to_complete(call, &fc->ac);
2036 * Deliver reply data to an YFS.InlineBulkStatus call
2038 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
2040 struct afs_file_status *statuses;
2041 struct afs_callback *callbacks;
2042 struct afs_vnode *vnode = call->reply[0];
2047 _enter("{%u}", call->unmarshall);
2049 switch (call->unmarshall) {
2051 afs_extract_to_tmp(call);
2054 /* Extract the file status count and array in two steps */
2057 _debug("extract status count");
2058 ret = afs_extract_data(call, true);
2062 tmp = ntohl(call->tmp);
2063 _debug("status count: %u/%u", tmp, call->count2);
2064 if (tmp != call->count2)
2065 return afs_protocol_error(call, -EBADMSG,
2066 afs_eproto_ibulkst_count);
2071 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
2075 _debug("extract status array %u", call->count);
2076 ret = afs_extract_data(call, true);
2081 statuses = call->reply[1];
2082 ret = yfs_decode_status(call, &bp, &statuses[call->count],
2083 call->count == 0 ? vnode : NULL,
2089 if (call->count < call->count2)
2094 afs_extract_to_tmp(call);
2096 /* Extract the callback count and array in two steps */
2099 _debug("extract CB count");
2100 ret = afs_extract_data(call, true);
2104 tmp = ntohl(call->tmp);
2105 _debug("CB count: %u", tmp);
2106 if (tmp != call->count2)
2107 return afs_protocol_error(call, -EBADMSG,
2108 afs_eproto_ibulkst_cb_count);
2112 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
2116 _debug("extract CB array");
2117 ret = afs_extract_data(call, true);
2121 _debug("unmarshall CB array");
2123 callbacks = call->reply[2];
2124 xdr_decode_YFSCallBack_raw(&bp, &callbacks[call->count]);
2125 statuses = call->reply[1];
2126 if (call->count == 0 && vnode && statuses[0].abort_code == 0) {
2128 xdr_decode_YFSCallBack(call, vnode, &bp);
2131 if (call->count < call->count2)
2134 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
2139 ret = afs_extract_data(call, false);
2144 xdr_decode_YFSVolSync(&bp, call->reply[3]);
2153 _leave(" = 0 [done]");
2158 * FS.InlineBulkStatus operation type
2160 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
2161 .name = "YFS.InlineBulkStatus",
2162 .op = yfs_FS_InlineBulkStatus,
2163 .deliver = yfs_deliver_fs_inline_bulk_status,
2164 .destructor = afs_flat_call_destructor,
2168 * Fetch the status information for up to 1024 files
2170 int yfs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2171 struct afs_net *net,
2172 struct afs_fid *fids,
2173 struct afs_file_status *statuses,
2174 struct afs_callback *callbacks,
2175 unsigned int nr_fids,
2176 struct afs_volsync *volsync)
2178 struct afs_call *call;
2182 _enter(",%x,{%llx:%llu},%u",
2183 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2185 call = afs_alloc_flat_call(net, &yfs_RXYFSInlineBulkStatus,
2189 sizeof(struct yfs_xdr_YFSFid) * nr_fids,
2190 sizeof(struct yfs_xdr_YFSFetchStatus));
2192 fc->ac.error = -ENOMEM;
2196 call->key = fc->key;
2197 call->reply[0] = NULL; /* vnode for fid[0] */
2198 call->reply[1] = statuses;
2199 call->reply[2] = callbacks;
2200 call->reply[3] = volsync;
2201 call->count2 = nr_fids;
2203 /* marshall the parameters */
2205 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
2206 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
2207 bp = xdr_encode_u32(bp, nr_fids);
2208 for (i = 0; i < nr_fids; i++)
2209 bp = xdr_encode_YFSFid(bp, &fids[i]);
2210 yfs_check_req(call, bp);
2212 call->cb_break = fc->cb_break;
2213 afs_use_fs_server(call, fc->cbi);
2214 trace_afs_make_fs_call(call, &fids[0]);
2215 afs_make_call(&fc->ac, call, GFP_NOFS);
2216 return afs_wait_for_call_to_complete(call, &fc->ac);
2220 * Deliver reply data to an YFS.FetchOpaqueACL.
2222 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
2224 struct afs_volsync *volsync = call->reply[2];
2225 struct afs_vnode *vnode = call->reply[1];
2226 struct yfs_acl *yacl = call->reply[0];
2227 struct afs_acl *acl;
2232 _enter("{%u}", call->unmarshall);
2234 switch (call->unmarshall) {
2236 afs_extract_to_tmp(call);
2239 /* Extract the file ACL length */
2241 ret = afs_extract_data(call, true);
2245 size = call->count2 = ntohl(call->tmp);
2246 size = round_up(size, 4);
2248 if (yacl->flags & YFS_ACL_WANT_ACL) {
2249 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2253 acl->size = call->count2;
2254 afs_extract_begin(call, acl->data, size);
2256 iov_iter_discard(&call->iter, READ, size);
2260 /* Extract the file ACL */
2262 ret = afs_extract_data(call, true);
2266 afs_extract_to_tmp(call);
2269 /* Extract the volume ACL length */
2271 ret = afs_extract_data(call, true);
2275 size = call->count2 = ntohl(call->tmp);
2276 size = round_up(size, 4);
2278 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
2279 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2282 yacl->vol_acl = acl;
2283 acl->size = call->count2;
2284 afs_extract_begin(call, acl->data, size);
2286 iov_iter_discard(&call->iter, READ, size);
2290 /* Extract the volume ACL */
2292 ret = afs_extract_data(call, true);
2296 afs_extract_to_buf(call,
2297 sizeof(__be32) * 2 +
2298 sizeof(struct yfs_xdr_YFSFetchStatus) +
2299 sizeof(struct yfs_xdr_YFSVolSync));
2302 /* extract the metadata */
2304 ret = afs_extract_data(call, false);
2309 yacl->inherit_flag = ntohl(*bp++);
2310 yacl->num_cleaned = ntohl(*bp++);
2311 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
2312 &call->expected_version, NULL);
2315 xdr_decode_YFSVolSync(&bp, volsync);
2323 _leave(" = 0 [done]");
2327 void yfs_free_opaque_acl(struct yfs_acl *yacl)
2331 kfree(yacl->vol_acl);
2336 static void yfs_destroy_fs_fetch_opaque_acl(struct afs_call *call)
2338 yfs_free_opaque_acl(call->reply[0]);
2339 afs_flat_call_destructor(call);
2343 * YFS.FetchOpaqueACL operation type
2345 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
2346 .name = "YFS.FetchOpaqueACL",
2347 .op = yfs_FS_FetchOpaqueACL,
2348 .deliver = yfs_deliver_fs_fetch_opaque_acl,
2349 .destructor = yfs_destroy_fs_fetch_opaque_acl,
2353 * Fetch the YFS advanced ACLs for a file.
2355 struct yfs_acl *yfs_fs_fetch_opaque_acl(struct afs_fs_cursor *fc,
2358 struct afs_vnode *vnode = fc->vnode;
2359 struct afs_call *call;
2360 struct yfs_acl *yacl;
2361 struct afs_net *net = afs_v2net(vnode);
2364 _enter(",%x,{%llx:%llu},,",
2365 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2367 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchOpaqueACL,
2368 sizeof(__be32) * 2 +
2369 sizeof(struct yfs_xdr_YFSFid),
2370 sizeof(__be32) * 2 +
2371 sizeof(struct yfs_xdr_YFSFetchStatus) +
2372 sizeof(struct yfs_xdr_YFSVolSync));
2376 yacl = kzalloc(sizeof(struct yfs_acl), GFP_KERNEL);
2380 yacl->flags = flags;
2381 call->key = fc->key;
2382 call->reply[0] = yacl;
2383 call->reply[1] = vnode;
2384 call->reply[2] = NULL; /* volsync */
2385 call->ret_reply0 = true;
2387 /* marshall the parameters */
2389 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
2390 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2391 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2392 yfs_check_req(call, bp);
2394 call->cb_break = fc->cb_break;
2395 afs_use_fs_server(call, fc->cbi);
2396 trace_afs_make_fs_call(call, &vnode->fid);
2397 afs_make_call(&fc->ac, call, GFP_KERNEL);
2398 return (struct yfs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2403 fc->ac.error = -ENOMEM;
2404 return ERR_PTR(-ENOMEM);
2408 * YFS.StoreOpaqueACL2 operation type
2410 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
2411 .name = "YFS.StoreOpaqueACL2",
2412 .op = yfs_FS_StoreOpaqueACL2,
2413 .deliver = yfs_deliver_status_and_volsync,
2414 .destructor = afs_flat_call_destructor,
2418 * Fetch the YFS ACL for a file.
2420 int yfs_fs_store_opaque_acl2(struct afs_fs_cursor *fc, const struct afs_acl *acl)
2422 struct afs_vnode *vnode = fc->vnode;
2423 struct afs_call *call;
2424 struct afs_net *net = afs_v2net(vnode);
2428 _enter(",%x,{%llx:%llu},,",
2429 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2431 size = round_up(acl->size, 4);
2432 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
2433 sizeof(__be32) * 2 +
2434 sizeof(struct yfs_xdr_YFSFid) +
2435 sizeof(__be32) + size,
2436 sizeof(struct yfs_xdr_YFSFetchStatus) +
2437 sizeof(struct yfs_xdr_YFSVolSync));
2439 fc->ac.error = -ENOMEM;
2443 call->key = fc->key;
2444 call->reply[0] = vnode;
2445 call->reply[2] = NULL; /* volsync */
2447 /* marshall the parameters */
2449 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
2450 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2451 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2452 bp = xdr_encode_u32(bp, acl->size);
2453 memcpy(bp, acl->data, acl->size);
2454 if (acl->size != size)
2455 memset((void *)bp + acl->size, 0, size - acl->size);
2456 yfs_check_req(call, bp);
2458 trace_afs_make_fs_call(call, &vnode->fid);
2459 afs_make_call(&fc->ac, call, GFP_KERNEL);
2460 return afs_wait_for_call_to_complete(call, &fc->ac);