1 /* YFS File Server client stubs
3 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/sched.h>
15 #include <linux/circ_buf.h>
16 #include <linux/iversion.h>
20 #include "protocol_yfs.h"
22 static const struct afs_fid afs_zero_fid;
24 static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
26 call->cbi = afs_get_cb_interest(cbi);
29 #define xdr_size(x) (sizeof(*x) / sizeof(__be32))
31 static void xdr_decode_YFSFid(const __be32 **_bp, struct afs_fid *fid)
33 const struct yfs_xdr_YFSFid *x = (const void *)*_bp;
35 fid->vid = xdr_to_u64(x->volume);
36 fid->vnode = xdr_to_u64(x->vnode.lo);
37 fid->vnode_hi = ntohl(x->vnode.hi);
38 fid->unique = ntohl(x->vnode.unique);
42 static __be32 *xdr_encode_u32(__be32 *bp, u32 n)
48 static __be32 *xdr_encode_u64(__be32 *bp, u64 n)
50 struct yfs_xdr_u64 *x = (void *)bp;
53 return bp + xdr_size(x);
56 static __be32 *xdr_encode_YFSFid(__be32 *bp, struct afs_fid *fid)
58 struct yfs_xdr_YFSFid *x = (void *)bp;
60 x->volume = u64_to_xdr(fid->vid);
61 x->vnode.lo = u64_to_xdr(fid->vnode);
62 x->vnode.hi = htonl(fid->vnode_hi);
63 x->vnode.unique = htonl(fid->unique);
64 return bp + xdr_size(x);
67 static size_t xdr_strlen(unsigned int len)
69 return sizeof(__be32) + round_up(len, sizeof(__be32));
72 static __be32 *xdr_encode_string(__be32 *bp, const char *p, unsigned int len)
74 bp = xdr_encode_u32(bp, len);
75 bp = memcpy(bp, p, len);
77 unsigned int pad = 4 - (len & 3);
79 memset((u8 *)bp + len, 0, pad);
83 return bp + len / sizeof(__be32);
86 static s64 linux_to_yfs_time(const struct timespec64 *t)
88 /* Convert to 100ns intervals. */
89 return (u64)t->tv_sec * 10000000 + t->tv_nsec/100;
92 static __be32 *xdr_encode_YFSStoreStatus_mode(__be32 *bp, mode_t mode)
94 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
96 x->mask = htonl(AFS_SET_MODE);
97 x->mode = htonl(mode & S_IALLUGO);
98 x->mtime_client = u64_to_xdr(0);
99 x->owner = u64_to_xdr(0);
100 x->group = u64_to_xdr(0);
101 return bp + xdr_size(x);
104 static __be32 *xdr_encode_YFSStoreStatus_mtime(__be32 *bp, const struct timespec64 *t)
106 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
107 s64 mtime = linux_to_yfs_time(t);
109 x->mask = htonl(AFS_SET_MTIME);
111 x->mtime_client = u64_to_xdr(mtime);
112 x->owner = u64_to_xdr(0);
113 x->group = u64_to_xdr(0);
114 return bp + xdr_size(x);
118 * Convert a signed 100ns-resolution 64-bit time into a timespec.
120 static struct timespec64 yfs_time_to_linux(s64 t)
122 struct timespec64 ts;
126 * Unfortunately can not use normal 64 bit division on 32 bit arch, but
127 * the alternative, do_div, does not work with negative numbers so have
128 * to special case them
132 ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100);
133 ts.tv_nsec = -ts.tv_nsec;
137 ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100;
144 static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr)
146 s64 t = xdr_to_u64(xdr);
148 return yfs_time_to_linux(t);
151 static void yfs_check_req(struct afs_call *call, __be32 *bp)
153 size_t len = (void *)bp - call->request;
155 if (len > call->request_size)
156 pr_err("kAFS: %s: Request buffer overflow (%zu>%u)\n",
157 call->type->name, len, call->request_size);
158 else if (len < call->request_size)
159 pr_warning("kAFS: %s: Request buffer underflow (%zu<%u)\n",
160 call->type->name, len, call->request_size);
164 * Dump a bad file status record.
166 static void xdr_dump_bad(const __be32 *bp)
171 pr_notice("YFS XDR: Bad status record\n");
172 for (i = 0; i < 5 * 4 * 4; i += 16) {
175 pr_notice("%03x: %08x %08x %08x %08x\n",
176 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
180 pr_notice("0x50: %08x\n", ntohl(x[0]));
184 * Decode a YFSFetchStatus block
186 static int xdr_decode_YFSFetchStatus(struct afs_call *call,
188 struct afs_file_status *status,
189 struct afs_vnode *vnode,
190 const afs_dataversion_t *expected_version,
191 struct afs_read *read_req)
193 const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
197 status->abort_code = ntohl(xdr->abort_code);
198 if (status->abort_code != 0) {
199 if (vnode && status->abort_code == VNOVNODE) {
200 set_bit(AFS_VNODE_DELETED, &vnode->flags);
202 __afs_break_callback(vnode);
207 type = ntohl(xdr->type);
211 case AFS_FTYPE_SYMLINK:
212 if (type != status->type &&
214 !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
215 pr_warning("Vnode %llx:%llx:%x changed type %u to %u\n",
228 #define EXTRACT_M4(FIELD) \
230 u32 x = ntohl(xdr->FIELD); \
231 if (status->FIELD != x) { \
232 flags |= AFS_VNODE_META_CHANGED; \
237 #define EXTRACT_M8(FIELD) \
239 u64 x = xdr_to_u64(xdr->FIELD); \
240 if (status->FIELD != x) { \
241 flags |= AFS_VNODE_META_CHANGED; \
246 #define EXTRACT_D8(FIELD) \
248 u64 x = xdr_to_u64(xdr->FIELD); \
249 if (status->FIELD != x) { \
250 flags |= AFS_VNODE_DATA_CHANGED; \
257 EXTRACT_D8(data_version);
262 EXTRACT_M4(caller_access); /* call ticket dependent */
263 EXTRACT_M4(anon_access);
265 status->mtime_client = xdr_to_time(xdr->mtime_client);
266 status->mtime_server = xdr_to_time(xdr->mtime_server);
267 status->lock_count = ntohl(xdr->lock_count);
270 read_req->data_version = status->data_version;
271 read_req->file_size = status->size;
274 *_bp += xdr_size(xdr);
277 if (test_bit(AFS_VNODE_UNSET, &vnode->flags))
278 flags |= AFS_VNODE_NOT_YET_SET;
279 afs_update_inode_from_status(vnode, status, expected_version,
287 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
291 * Decode the file status. We need to lock the target vnode if we're going to
292 * update its status so that stat() sees the attributes update atomically.
294 static int yfs_decode_status(struct afs_call *call,
296 struct afs_file_status *status,
297 struct afs_vnode *vnode,
298 const afs_dataversion_t *expected_version,
299 struct afs_read *read_req)
304 return xdr_decode_YFSFetchStatus(call, _bp, status, vnode,
305 expected_version, read_req);
307 write_seqlock(&vnode->cb_lock);
308 ret = xdr_decode_YFSFetchStatus(call, _bp, status, vnode,
309 expected_version, read_req);
310 write_sequnlock(&vnode->cb_lock);
314 static void xdr_decode_YFSCallBack_raw(struct afs_call *call,
315 struct afs_callback *cb,
318 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
321 cb_expiry = call->reply_time;
322 cb_expiry = ktime_add(cb_expiry, xdr_to_u64(x->expiration_time) * 100);
323 cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
324 cb->version = ntohl(x->version);
325 cb->type = ntohl(x->type);
331 * Decode a YFSCallBack block
333 static void xdr_decode_YFSCallBack(struct afs_call *call,
334 struct afs_vnode *vnode,
337 struct afs_cb_interest *old, *cbi = call->cbi;
338 struct afs_callback cb;
340 xdr_decode_YFSCallBack_raw(call, &cb, _bp);
342 write_seqlock(&vnode->cb_lock);
344 if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
345 vnode->cb_version = cb.version;
346 vnode->cb_type = cb.type;
347 vnode->cb_expires_at = cb.expires_at;
348 old = vnode->cb_interest;
349 if (old != call->cbi) {
350 vnode->cb_interest = cbi;
353 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
356 write_sequnlock(&vnode->cb_lock);
361 * Decode a YFSVolSync block
363 static void xdr_decode_YFSVolSync(const __be32 **_bp,
364 struct afs_volsync *volsync)
366 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
370 creation = xdr_to_u64(x->vol_creation_date);
371 do_div(creation, 10 * 1000 * 1000);
372 volsync->creation = creation;
379 * Encode the requested attributes into a YFSStoreStatus block
381 static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
383 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
384 s64 mtime = 0, owner = 0, group = 0;
385 u32 mask = 0, mode = 0;
388 if (attr->ia_valid & ATTR_MTIME) {
389 mask |= AFS_SET_MTIME;
390 mtime = linux_to_yfs_time(&attr->ia_mtime);
393 if (attr->ia_valid & ATTR_UID) {
394 mask |= AFS_SET_OWNER;
395 owner = from_kuid(&init_user_ns, attr->ia_uid);
398 if (attr->ia_valid & ATTR_GID) {
399 mask |= AFS_SET_GROUP;
400 group = from_kgid(&init_user_ns, attr->ia_gid);
403 if (attr->ia_valid & ATTR_MODE) {
404 mask |= AFS_SET_MODE;
405 mode = attr->ia_mode & S_IALLUGO;
408 x->mask = htonl(mask);
409 x->mode = htonl(mode);
410 x->mtime_client = u64_to_xdr(mtime);
411 x->owner = u64_to_xdr(owner);
412 x->group = u64_to_xdr(group);
413 return bp + xdr_size(x);
417 * Decode a YFSFetchVolumeStatus block.
419 static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
420 struct afs_volume_status *vs)
422 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
425 vs->vid = xdr_to_u64(x->vid);
426 vs->parent_id = xdr_to_u64(x->parent_id);
427 flags = ntohl(x->flags);
428 vs->online = flags & yfs_FVSOnline;
429 vs->in_service = flags & yfs_FVSInservice;
430 vs->blessed = flags & yfs_FVSBlessed;
431 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
432 vs->type = ntohl(x->type);
434 vs->max_quota = xdr_to_u64(x->max_quota);
435 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
436 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
437 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
438 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
439 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
440 *_bp += sizeof(*x) / sizeof(__be32);
444 * deliver reply data to an FS.FetchStatus
446 static int yfs_deliver_fs_fetch_status_vnode(struct afs_call *call)
448 struct afs_vnode *vnode = call->reply[0];
452 ret = afs_transfer_reply(call);
456 _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
458 /* unmarshall the reply once we've received all of it */
460 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
461 &call->expected_version, NULL);
464 xdr_decode_YFSCallBack(call, vnode, &bp);
465 xdr_decode_YFSVolSync(&bp, call->reply[1]);
467 _leave(" = 0 [done]");
472 * YFS.FetchStatus operation type
474 static const struct afs_call_type yfs_RXYFSFetchStatus_vnode = {
475 .name = "YFS.FetchStatus(vnode)",
476 .op = yfs_FS_FetchStatus,
477 .deliver = yfs_deliver_fs_fetch_status_vnode,
478 .destructor = afs_flat_call_destructor,
482 * Fetch the status information for a file.
484 int yfs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_volsync *volsync,
487 struct afs_vnode *vnode = fc->vnode;
488 struct afs_call *call;
489 struct afs_net *net = afs_v2net(vnode);
492 _enter(",%x,{%llx:%llu},,",
493 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
495 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus_vnode,
497 sizeof(struct yfs_xdr_YFSFid),
498 sizeof(struct yfs_xdr_YFSFetchStatus) +
499 sizeof(struct yfs_xdr_YFSCallBack) +
500 sizeof(struct yfs_xdr_YFSVolSync));
502 fc->ac.error = -ENOMEM;
507 call->reply[0] = vnode;
508 call->reply[1] = volsync;
509 call->expected_version = new_inode ? 1 : vnode->status.data_version;
511 /* marshall the parameters */
513 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
514 bp = xdr_encode_u32(bp, 0); /* RPC flags */
515 bp = xdr_encode_YFSFid(bp, &vnode->fid);
516 yfs_check_req(call, bp);
518 call->cb_break = fc->cb_break;
519 afs_use_fs_server(call, fc->cbi);
520 trace_afs_make_fs_call(call, &vnode->fid);
521 afs_set_fc_call(call, fc);
522 afs_make_call(&fc->ac, call, GFP_NOFS);
523 return afs_wait_for_call_to_complete(call, &fc->ac);
527 * Deliver reply data to an YFS.FetchData64.
529 static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
531 struct afs_vnode *vnode = call->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_set_fc_call(call, fc);
716 afs_make_call(&fc->ac, call, GFP_NOFS);
717 return afs_wait_for_call_to_complete(call, &fc->ac);
721 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
723 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
725 struct afs_vnode *vnode = call->reply[0];
729 _enter("{%u}", call->unmarshall);
731 ret = afs_transfer_reply(call);
735 /* unmarshall the reply once we've received all of it */
737 xdr_decode_YFSFid(&bp, call->reply[1]);
738 ret = yfs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
741 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
742 &call->expected_version, NULL);
745 xdr_decode_YFSCallBack_raw(call, call->reply[3], &bp);
746 xdr_decode_YFSVolSync(&bp, NULL);
748 _leave(" = 0 [done]");
753 * FS.CreateFile and FS.MakeDir operation type
755 static const struct afs_call_type afs_RXFSCreateFile = {
756 .name = "YFS.CreateFile",
757 .op = yfs_FS_CreateFile,
758 .deliver = yfs_deliver_fs_create_vnode,
759 .destructor = afs_flat_call_destructor,
765 int yfs_fs_create_file(struct afs_fs_cursor *fc,
768 u64 current_data_version,
769 struct afs_fid *newfid,
770 struct afs_file_status *newstatus,
771 struct afs_callback *newcb)
773 struct afs_vnode *vnode = fc->vnode;
774 struct afs_call *call;
775 struct afs_net *net = afs_v2net(vnode);
776 size_t namesz, reqsz, rplsz;
781 namesz = strlen(name);
782 reqsz = (sizeof(__be32) +
784 sizeof(struct yfs_xdr_YFSFid) +
786 sizeof(struct yfs_xdr_YFSStoreStatus) +
788 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
789 sizeof(struct yfs_xdr_YFSFetchStatus) +
790 sizeof(struct yfs_xdr_YFSFetchStatus) +
791 sizeof(struct yfs_xdr_YFSCallBack) +
792 sizeof(struct yfs_xdr_YFSVolSync));
794 call = afs_alloc_flat_call(net, &afs_RXFSCreateFile, reqsz, rplsz);
799 call->reply[0] = vnode;
800 call->reply[1] = newfid;
801 call->reply[2] = newstatus;
802 call->reply[3] = newcb;
803 call->expected_version = current_data_version + 1;
805 /* marshall the parameters */
807 bp = xdr_encode_u32(bp, YFSCREATEFILE);
808 bp = xdr_encode_u32(bp, 0); /* RPC flags */
809 bp = xdr_encode_YFSFid(bp, &vnode->fid);
810 bp = xdr_encode_string(bp, name, namesz);
811 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
812 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
813 yfs_check_req(call, bp);
815 afs_use_fs_server(call, fc->cbi);
816 trace_afs_make_fs_call1(call, &vnode->fid, name);
817 afs_set_fc_call(call, fc);
818 afs_make_call(&fc->ac, call, GFP_NOFS);
819 return afs_wait_for_call_to_complete(call, &fc->ac);
822 static const struct afs_call_type yfs_RXFSMakeDir = {
823 .name = "YFS.MakeDir",
824 .op = yfs_FS_MakeDir,
825 .deliver = yfs_deliver_fs_create_vnode,
826 .destructor = afs_flat_call_destructor,
832 int yfs_fs_make_dir(struct afs_fs_cursor *fc,
835 u64 current_data_version,
836 struct afs_fid *newfid,
837 struct afs_file_status *newstatus,
838 struct afs_callback *newcb)
840 struct afs_vnode *vnode = fc->vnode;
841 struct afs_call *call;
842 struct afs_net *net = afs_v2net(vnode);
843 size_t namesz, reqsz, rplsz;
848 namesz = strlen(name);
849 reqsz = (sizeof(__be32) +
850 sizeof(struct yfs_xdr_RPCFlags) +
851 sizeof(struct yfs_xdr_YFSFid) +
853 sizeof(struct yfs_xdr_YFSStoreStatus));
854 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
855 sizeof(struct yfs_xdr_YFSFetchStatus) +
856 sizeof(struct yfs_xdr_YFSFetchStatus) +
857 sizeof(struct yfs_xdr_YFSCallBack) +
858 sizeof(struct yfs_xdr_YFSVolSync));
860 call = afs_alloc_flat_call(net, &yfs_RXFSMakeDir, reqsz, rplsz);
865 call->reply[0] = vnode;
866 call->reply[1] = newfid;
867 call->reply[2] = newstatus;
868 call->reply[3] = newcb;
869 call->expected_version = current_data_version + 1;
871 /* marshall the parameters */
873 bp = xdr_encode_u32(bp, YFSMAKEDIR);
874 bp = xdr_encode_u32(bp, 0); /* RPC flags */
875 bp = xdr_encode_YFSFid(bp, &vnode->fid);
876 bp = xdr_encode_string(bp, name, namesz);
877 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
878 yfs_check_req(call, bp);
880 afs_use_fs_server(call, fc->cbi);
881 trace_afs_make_fs_call1(call, &vnode->fid, name);
882 afs_set_fc_call(call, fc);
883 afs_make_call(&fc->ac, call, GFP_NOFS);
884 return afs_wait_for_call_to_complete(call, &fc->ac);
888 * Deliver reply data to a YFS.RemoveFile2 operation.
890 static int yfs_deliver_fs_remove_file2(struct afs_call *call)
892 struct afs_vnode *dvnode = call->reply[0];
893 struct afs_vnode *vnode = call->reply[1];
898 _enter("{%u}", call->unmarshall);
900 ret = afs_transfer_reply(call);
904 /* unmarshall the reply once we've received all of it */
906 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
907 &call->expected_version, NULL);
911 xdr_decode_YFSFid(&bp, &fid);
912 ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
915 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
917 xdr_decode_YFSVolSync(&bp, NULL);
922 * YFS.RemoveFile2 operation type.
924 static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
925 .name = "YFS.RemoveFile2",
926 .op = yfs_FS_RemoveFile2,
927 .deliver = yfs_deliver_fs_remove_file2,
928 .destructor = afs_flat_call_destructor,
932 * Remove a file and retrieve new file status.
934 int yfs_fs_remove_file2(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
935 const char *name, u64 current_data_version)
937 struct afs_vnode *dvnode = fc->vnode;
938 struct afs_call *call;
939 struct afs_net *net = afs_v2net(dvnode);
945 namesz = strlen(name);
947 call = afs_alloc_flat_call(net, &yfs_RXYFSRemoveFile2,
949 sizeof(struct yfs_xdr_RPCFlags) +
950 sizeof(struct yfs_xdr_YFSFid) +
952 sizeof(struct yfs_xdr_YFSFetchStatus) +
953 sizeof(struct yfs_xdr_YFSFid) +
954 sizeof(struct yfs_xdr_YFSFetchStatus) +
955 sizeof(struct yfs_xdr_YFSVolSync));
960 call->reply[0] = dvnode;
961 call->reply[1] = vnode;
962 call->expected_version = current_data_version + 1;
964 /* marshall the parameters */
966 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
967 bp = xdr_encode_u32(bp, 0); /* RPC flags */
968 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
969 bp = xdr_encode_string(bp, name, namesz);
970 yfs_check_req(call, bp);
972 afs_use_fs_server(call, fc->cbi);
973 trace_afs_make_fs_call1(call, &dvnode->fid, name);
974 afs_set_fc_call(call, fc);
975 afs_make_call(&fc->ac, call, GFP_NOFS);
976 return afs_wait_for_call_to_complete(call, &fc->ac);
980 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
982 static int yfs_deliver_fs_remove(struct afs_call *call)
984 struct afs_vnode *dvnode = call->reply[0];
988 _enter("{%u}", call->unmarshall);
990 ret = afs_transfer_reply(call);
994 /* unmarshall the reply once we've received all of it */
996 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
997 &call->expected_version, NULL);
1001 xdr_decode_YFSVolSync(&bp, NULL);
1006 * FS.RemoveDir and FS.RemoveFile operation types.
1008 static const struct afs_call_type yfs_RXYFSRemoveFile = {
1009 .name = "YFS.RemoveFile",
1010 .op = yfs_FS_RemoveFile,
1011 .deliver = yfs_deliver_fs_remove,
1012 .destructor = afs_flat_call_destructor,
1015 static const struct afs_call_type yfs_RXYFSRemoveDir = {
1016 .name = "YFS.RemoveDir",
1017 .op = yfs_FS_RemoveDir,
1018 .deliver = yfs_deliver_fs_remove,
1019 .destructor = afs_flat_call_destructor,
1023 * remove a file or directory
1025 int yfs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
1026 const char *name, bool isdir, u64 current_data_version)
1028 struct afs_vnode *dvnode = fc->vnode;
1029 struct afs_call *call;
1030 struct afs_net *net = afs_v2net(dvnode);
1036 namesz = strlen(name);
1037 call = afs_alloc_flat_call(
1038 net, isdir ? &yfs_RXYFSRemoveDir : &yfs_RXYFSRemoveFile,
1040 sizeof(struct yfs_xdr_RPCFlags) +
1041 sizeof(struct yfs_xdr_YFSFid) +
1043 sizeof(struct yfs_xdr_YFSFetchStatus) +
1044 sizeof(struct yfs_xdr_YFSVolSync));
1048 call->key = fc->key;
1049 call->reply[0] = dvnode;
1050 call->reply[1] = vnode;
1051 call->expected_version = current_data_version + 1;
1053 /* marshall the parameters */
1055 bp = xdr_encode_u32(bp, isdir ? YFSREMOVEDIR : YFSREMOVEFILE);
1056 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1057 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1058 bp = xdr_encode_string(bp, name, namesz);
1059 yfs_check_req(call, bp);
1061 afs_use_fs_server(call, fc->cbi);
1062 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1063 afs_set_fc_call(call, fc);
1064 afs_make_call(&fc->ac, call, GFP_NOFS);
1065 return afs_wait_for_call_to_complete(call, &fc->ac);
1069 * Deliver reply data to a YFS.Link operation.
1071 static int yfs_deliver_fs_link(struct afs_call *call)
1073 struct afs_vnode *dvnode = call->reply[0], *vnode = call->reply[1];
1077 _enter("{%u}", call->unmarshall);
1079 ret = afs_transfer_reply(call);
1083 /* unmarshall the reply once we've received all of it */
1085 ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
1088 ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode,
1089 &call->expected_version, NULL);
1092 xdr_decode_YFSVolSync(&bp, NULL);
1093 _leave(" = 0 [done]");
1098 * YFS.Link operation type.
1100 static const struct afs_call_type yfs_RXYFSLink = {
1103 .deliver = yfs_deliver_fs_link,
1104 .destructor = afs_flat_call_destructor,
1110 int yfs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
1111 const char *name, u64 current_data_version)
1113 struct afs_vnode *dvnode = fc->vnode;
1114 struct afs_call *call;
1115 struct afs_net *net = afs_v2net(vnode);
1121 namesz = strlen(name);
1122 call = afs_alloc_flat_call(net, &yfs_RXYFSLink,
1124 sizeof(struct yfs_xdr_RPCFlags) +
1125 sizeof(struct yfs_xdr_YFSFid) +
1126 xdr_strlen(namesz) +
1127 sizeof(struct yfs_xdr_YFSFid),
1128 sizeof(struct yfs_xdr_YFSFetchStatus) +
1129 sizeof(struct yfs_xdr_YFSFetchStatus) +
1130 sizeof(struct yfs_xdr_YFSVolSync));
1134 call->key = fc->key;
1135 call->reply[0] = dvnode;
1136 call->reply[1] = vnode;
1137 call->expected_version = current_data_version + 1;
1139 /* marshall the parameters */
1141 bp = xdr_encode_u32(bp, YFSLINK);
1142 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1143 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1144 bp = xdr_encode_string(bp, name, namesz);
1145 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1146 yfs_check_req(call, bp);
1148 afs_use_fs_server(call, fc->cbi);
1149 trace_afs_make_fs_call1(call, &vnode->fid, name);
1150 afs_set_fc_call(call, fc);
1151 afs_make_call(&fc->ac, call, GFP_NOFS);
1152 return afs_wait_for_call_to_complete(call, &fc->ac);
1156 * Deliver reply data to a YFS.Symlink operation.
1158 static int yfs_deliver_fs_symlink(struct afs_call *call)
1160 struct afs_vnode *vnode = call->reply[0];
1164 _enter("{%u}", call->unmarshall);
1166 ret = afs_transfer_reply(call);
1170 /* unmarshall the reply once we've received all of it */
1172 xdr_decode_YFSFid(&bp, call->reply[1]);
1173 ret = yfs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
1176 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1177 &call->expected_version, NULL);
1180 xdr_decode_YFSVolSync(&bp, NULL);
1182 _leave(" = 0 [done]");
1187 * YFS.Symlink operation type
1189 static const struct afs_call_type yfs_RXYFSSymlink = {
1190 .name = "YFS.Symlink",
1191 .op = yfs_FS_Symlink,
1192 .deliver = yfs_deliver_fs_symlink,
1193 .destructor = afs_flat_call_destructor,
1197 * Create a symbolic link.
1199 int yfs_fs_symlink(struct afs_fs_cursor *fc,
1201 const char *contents,
1202 u64 current_data_version,
1203 struct afs_fid *newfid,
1204 struct afs_file_status *newstatus)
1206 struct afs_vnode *dvnode = fc->vnode;
1207 struct afs_call *call;
1208 struct afs_net *net = afs_v2net(dvnode);
1209 size_t namesz, contents_sz;
1214 namesz = strlen(name);
1215 contents_sz = strlen(contents);
1216 call = afs_alloc_flat_call(net, &yfs_RXYFSSymlink,
1218 sizeof(struct yfs_xdr_RPCFlags) +
1219 sizeof(struct yfs_xdr_YFSFid) +
1220 xdr_strlen(namesz) +
1221 xdr_strlen(contents_sz) +
1222 sizeof(struct yfs_xdr_YFSStoreStatus),
1223 sizeof(struct yfs_xdr_YFSFid) +
1224 sizeof(struct yfs_xdr_YFSFetchStatus) +
1225 sizeof(struct yfs_xdr_YFSFetchStatus) +
1226 sizeof(struct yfs_xdr_YFSVolSync));
1230 call->key = fc->key;
1231 call->reply[0] = dvnode;
1232 call->reply[1] = newfid;
1233 call->reply[2] = newstatus;
1234 call->expected_version = current_data_version + 1;
1236 /* marshall the parameters */
1238 bp = xdr_encode_u32(bp, YFSSYMLINK);
1239 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1240 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1241 bp = xdr_encode_string(bp, name, namesz);
1242 bp = xdr_encode_string(bp, contents, contents_sz);
1243 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
1244 yfs_check_req(call, bp);
1246 afs_use_fs_server(call, fc->cbi);
1247 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1248 afs_set_fc_call(call, fc);
1249 afs_make_call(&fc->ac, call, GFP_NOFS);
1250 return afs_wait_for_call_to_complete(call, &fc->ac);
1254 * Deliver reply data to a YFS.Rename operation.
1256 static int yfs_deliver_fs_rename(struct afs_call *call)
1258 struct afs_vnode *orig_dvnode = call->reply[0];
1259 struct afs_vnode *new_dvnode = call->reply[1];
1263 _enter("{%u}", call->unmarshall);
1265 ret = afs_transfer_reply(call);
1269 /* unmarshall the reply once we've received all of it */
1271 ret = yfs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1272 &call->expected_version, NULL);
1275 if (new_dvnode != orig_dvnode) {
1276 ret = yfs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1277 &call->expected_version_2, NULL);
1282 xdr_decode_YFSVolSync(&bp, NULL);
1283 _leave(" = 0 [done]");
1288 * YFS.Rename operation type
1290 static const struct afs_call_type yfs_RXYFSRename = {
1291 .name = "FS.Rename",
1292 .op = yfs_FS_Rename,
1293 .deliver = yfs_deliver_fs_rename,
1294 .destructor = afs_flat_call_destructor,
1298 * Rename a file or directory.
1300 int yfs_fs_rename(struct afs_fs_cursor *fc,
1301 const char *orig_name,
1302 struct afs_vnode *new_dvnode,
1303 const char *new_name,
1304 u64 current_orig_data_version,
1305 u64 current_new_data_version)
1307 struct afs_vnode *orig_dvnode = fc->vnode;
1308 struct afs_call *call;
1309 struct afs_net *net = afs_v2net(orig_dvnode);
1310 size_t o_namesz, n_namesz;
1315 o_namesz = strlen(orig_name);
1316 n_namesz = strlen(new_name);
1317 call = afs_alloc_flat_call(net, &yfs_RXYFSRename,
1319 sizeof(struct yfs_xdr_RPCFlags) +
1320 sizeof(struct yfs_xdr_YFSFid) +
1321 xdr_strlen(o_namesz) +
1322 sizeof(struct yfs_xdr_YFSFid) +
1323 xdr_strlen(n_namesz),
1324 sizeof(struct yfs_xdr_YFSFetchStatus) +
1325 sizeof(struct yfs_xdr_YFSFetchStatus) +
1326 sizeof(struct yfs_xdr_YFSVolSync));
1330 call->key = fc->key;
1331 call->reply[0] = orig_dvnode;
1332 call->reply[1] = new_dvnode;
1333 call->expected_version = current_orig_data_version + 1;
1334 call->expected_version_2 = current_new_data_version + 1;
1336 /* marshall the parameters */
1338 bp = xdr_encode_u32(bp, YFSRENAME);
1339 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1340 bp = xdr_encode_YFSFid(bp, &orig_dvnode->fid);
1341 bp = xdr_encode_string(bp, orig_name, o_namesz);
1342 bp = xdr_encode_YFSFid(bp, &new_dvnode->fid);
1343 bp = xdr_encode_string(bp, new_name, n_namesz);
1344 yfs_check_req(call, bp);
1346 afs_use_fs_server(call, fc->cbi);
1347 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1348 afs_set_fc_call(call, fc);
1349 afs_make_call(&fc->ac, call, GFP_NOFS);
1350 return afs_wait_for_call_to_complete(call, &fc->ac);
1354 * Deliver reply data to a YFS.StoreData64 operation.
1356 static int yfs_deliver_fs_store_data(struct afs_call *call)
1358 struct afs_vnode *vnode = call->reply[0];
1364 ret = afs_transfer_reply(call);
1368 /* unmarshall the reply once we've received all of it */
1370 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1371 &call->expected_version, NULL);
1374 xdr_decode_YFSVolSync(&bp, NULL);
1376 afs_pages_written_back(vnode, call);
1378 _leave(" = 0 [done]");
1383 * YFS.StoreData64 operation type.
1385 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1386 .name = "YFS.StoreData64",
1387 .op = yfs_FS_StoreData64,
1388 .deliver = yfs_deliver_fs_store_data,
1389 .destructor = afs_flat_call_destructor,
1393 * Store a set of pages to a large file.
1395 int yfs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1396 pgoff_t first, pgoff_t last,
1397 unsigned offset, unsigned to)
1399 struct afs_vnode *vnode = fc->vnode;
1400 struct afs_call *call;
1401 struct afs_net *net = afs_v2net(vnode);
1402 loff_t size, pos, i_size;
1405 _enter(",%x,{%llx:%llu},,",
1406 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1408 size = (loff_t)to - (loff_t)offset;
1410 size += (loff_t)(last - first) << PAGE_SHIFT;
1411 pos = (loff_t)first << PAGE_SHIFT;
1414 i_size = i_size_read(&vnode->vfs_inode);
1415 if (pos + size > i_size)
1416 i_size = size + pos;
1418 _debug("size %llx, at %llx, i_size %llx",
1419 (unsigned long long)size, (unsigned long long)pos,
1420 (unsigned long long)i_size);
1422 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64,
1425 sizeof(struct yfs_xdr_YFSFid) +
1426 sizeof(struct yfs_xdr_YFSStoreStatus) +
1427 sizeof(struct yfs_xdr_u64) * 3,
1428 sizeof(struct yfs_xdr_YFSFetchStatus) +
1429 sizeof(struct yfs_xdr_YFSVolSync));
1433 call->key = fc->key;
1434 call->mapping = mapping;
1435 call->reply[0] = vnode;
1436 call->first = first;
1438 call->first_offset = offset;
1440 call->send_pages = true;
1441 call->expected_version = vnode->status.data_version + 1;
1443 /* marshall the parameters */
1445 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1446 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1447 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1448 bp = xdr_encode_YFSStoreStatus_mtime(bp, &vnode->vfs_inode.i_mtime);
1449 bp = xdr_encode_u64(bp, pos);
1450 bp = xdr_encode_u64(bp, size);
1451 bp = xdr_encode_u64(bp, i_size);
1452 yfs_check_req(call, bp);
1454 afs_use_fs_server(call, fc->cbi);
1455 trace_afs_make_fs_call(call, &vnode->fid);
1456 afs_set_fc_call(call, fc);
1457 afs_make_call(&fc->ac, call, GFP_NOFS);
1458 return afs_wait_for_call_to_complete(call, &fc->ac);
1462 * deliver reply data to an FS.StoreStatus
1464 static int yfs_deliver_fs_store_status(struct afs_call *call)
1466 struct afs_vnode *vnode = call->reply[0];
1472 ret = afs_transfer_reply(call);
1476 /* unmarshall the reply once we've received all of it */
1478 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1479 &call->expected_version, NULL);
1482 xdr_decode_YFSVolSync(&bp, NULL);
1484 _leave(" = 0 [done]");
1489 * YFS.StoreStatus operation type
1491 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1492 .name = "YFS.StoreStatus",
1493 .op = yfs_FS_StoreStatus,
1494 .deliver = yfs_deliver_fs_store_status,
1495 .destructor = afs_flat_call_destructor,
1498 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1499 .name = "YFS.StoreData64",
1500 .op = yfs_FS_StoreData64,
1501 .deliver = yfs_deliver_fs_store_status,
1502 .destructor = afs_flat_call_destructor,
1506 * Set the attributes on a file, using YFS.StoreData64 rather than
1507 * YFS.StoreStatus so as to alter the file size also.
1509 static int yfs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1511 struct afs_vnode *vnode = fc->vnode;
1512 struct afs_call *call;
1513 struct afs_net *net = afs_v2net(vnode);
1516 _enter(",%x,{%llx:%llu},,",
1517 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1519 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64_as_Status,
1520 sizeof(__be32) * 2 +
1521 sizeof(struct yfs_xdr_YFSFid) +
1522 sizeof(struct yfs_xdr_YFSStoreStatus) +
1523 sizeof(struct yfs_xdr_u64) * 3,
1524 sizeof(struct yfs_xdr_YFSFetchStatus) +
1525 sizeof(struct yfs_xdr_YFSVolSync));
1529 call->key = fc->key;
1530 call->reply[0] = vnode;
1531 call->expected_version = vnode->status.data_version + 1;
1533 /* marshall the parameters */
1535 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1536 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1537 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1538 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1539 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1540 bp = xdr_encode_u64(bp, 0); /* size of write */
1541 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1542 yfs_check_req(call, bp);
1544 afs_use_fs_server(call, fc->cbi);
1545 trace_afs_make_fs_call(call, &vnode->fid);
1546 afs_set_fc_call(call, fc);
1547 afs_make_call(&fc->ac, call, GFP_NOFS);
1548 return afs_wait_for_call_to_complete(call, &fc->ac);
1552 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1553 * file size, and YFS.StoreStatus otherwise.
1555 int yfs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1557 struct afs_vnode *vnode = fc->vnode;
1558 struct afs_call *call;
1559 struct afs_net *net = afs_v2net(vnode);
1562 if (attr->ia_valid & ATTR_SIZE)
1563 return yfs_fs_setattr_size(fc, attr);
1565 _enter(",%x,{%llx:%llu},,",
1566 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1568 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
1569 sizeof(__be32) * 2 +
1570 sizeof(struct yfs_xdr_YFSFid) +
1571 sizeof(struct yfs_xdr_YFSStoreStatus),
1572 sizeof(struct yfs_xdr_YFSFetchStatus) +
1573 sizeof(struct yfs_xdr_YFSVolSync));
1577 call->key = fc->key;
1578 call->reply[0] = vnode;
1579 call->expected_version = vnode->status.data_version;
1581 /* marshall the parameters */
1583 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1584 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1585 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1586 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1587 yfs_check_req(call, bp);
1589 afs_use_fs_server(call, fc->cbi);
1590 trace_afs_make_fs_call(call, &vnode->fid);
1591 afs_set_fc_call(call, fc);
1592 afs_make_call(&fc->ac, call, GFP_NOFS);
1593 return afs_wait_for_call_to_complete(call, &fc->ac);
1597 * Deliver reply data to a YFS.GetVolumeStatus operation.
1599 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1606 _enter("{%u}", call->unmarshall);
1608 switch (call->unmarshall) {
1611 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1613 /* Fall through - and extract the returned status record */
1615 _debug("extract status");
1616 ret = afs_extract_data(call, true);
1621 xdr_decode_YFSFetchVolumeStatus(&bp, call->reply[1]);
1623 afs_extract_to_tmp(call);
1625 /* Fall through - and extract the volume name length */
1627 ret = afs_extract_data(call, true);
1631 call->count = ntohl(call->tmp);
1632 _debug("volname length: %u", call->count);
1633 if (call->count >= AFSNAMEMAX)
1634 return afs_protocol_error(call, -EBADMSG,
1635 afs_eproto_volname_len);
1636 size = (call->count + 3) & ~3; /* It's padded */
1637 afs_extract_begin(call, call->reply[2], size);
1640 /* Fall through - and extract the volume name */
1642 _debug("extract volname");
1643 ret = afs_extract_data(call, true);
1649 _debug("volname '%s'", p);
1650 afs_extract_to_tmp(call);
1653 /* Fall through - and extract the offline message length */
1655 ret = afs_extract_data(call, true);
1659 call->count = ntohl(call->tmp);
1660 _debug("offline msg length: %u", call->count);
1661 if (call->count >= AFSNAMEMAX)
1662 return afs_protocol_error(call, -EBADMSG,
1663 afs_eproto_offline_msg_len);
1664 size = (call->count + 3) & ~3; /* It's padded */
1665 afs_extract_begin(call, call->reply[2], size);
1668 /* Fall through - and extract the offline message */
1670 _debug("extract offline");
1671 ret = afs_extract_data(call, true);
1677 _debug("offline '%s'", p);
1679 afs_extract_to_tmp(call);
1682 /* Fall through - and extract the message of the day length */
1684 ret = afs_extract_data(call, true);
1688 call->count = ntohl(call->tmp);
1689 _debug("motd length: %u", call->count);
1690 if (call->count >= AFSNAMEMAX)
1691 return afs_protocol_error(call, -EBADMSG,
1692 afs_eproto_motd_len);
1693 size = (call->count + 3) & ~3; /* It's padded */
1694 afs_extract_begin(call, call->reply[2], size);
1697 /* Fall through - and extract the message of the day */
1699 _debug("extract motd");
1700 ret = afs_extract_data(call, false);
1706 _debug("motd '%s'", p);
1715 _leave(" = 0 [done]");
1720 * Destroy a YFS.GetVolumeStatus call.
1722 static void yfs_get_volume_status_call_destructor(struct afs_call *call)
1724 kfree(call->reply[2]);
1725 call->reply[2] = NULL;
1726 afs_flat_call_destructor(call);
1730 * YFS.GetVolumeStatus operation type
1732 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1733 .name = "YFS.GetVolumeStatus",
1734 .op = yfs_FS_GetVolumeStatus,
1735 .deliver = yfs_deliver_fs_get_volume_status,
1736 .destructor = yfs_get_volume_status_call_destructor,
1740 * fetch the status of a volume
1742 int yfs_fs_get_volume_status(struct afs_fs_cursor *fc,
1743 struct afs_volume_status *vs)
1745 struct afs_vnode *vnode = fc->vnode;
1746 struct afs_call *call;
1747 struct afs_net *net = afs_v2net(vnode);
1753 tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1757 call = afs_alloc_flat_call(net, &yfs_RXYFSGetVolumeStatus,
1758 sizeof(__be32) * 2 +
1759 sizeof(struct yfs_xdr_u64),
1760 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1767 call->key = fc->key;
1768 call->reply[0] = vnode;
1769 call->reply[1] = vs;
1770 call->reply[2] = tmpbuf;
1772 /* marshall the parameters */
1774 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1775 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1776 bp = xdr_encode_u64(bp, vnode->fid.vid);
1777 yfs_check_req(call, bp);
1779 afs_use_fs_server(call, fc->cbi);
1780 trace_afs_make_fs_call(call, &vnode->fid);
1781 afs_set_fc_call(call, fc);
1782 afs_make_call(&fc->ac, call, GFP_NOFS);
1783 return afs_wait_for_call_to_complete(call, &fc->ac);
1787 * Deliver reply data to operations that just return a file status and a volume
1790 static int yfs_deliver_status_and_volsync(struct afs_call *call)
1792 struct afs_vnode *vnode = call->reply[0];
1796 _enter("{%u}", call->unmarshall);
1798 ret = afs_transfer_reply(call);
1802 /* unmarshall the reply once we've received all of it */
1804 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
1805 &call->expected_version, NULL);
1808 xdr_decode_YFSVolSync(&bp, NULL);
1810 _leave(" = 0 [done]");
1815 * YFS.SetLock operation type
1817 static const struct afs_call_type yfs_RXYFSSetLock = {
1818 .name = "YFS.SetLock",
1819 .op = yfs_FS_SetLock,
1820 .deliver = yfs_deliver_status_and_volsync,
1821 .done = afs_lock_op_done,
1822 .destructor = afs_flat_call_destructor,
1826 * YFS.ExtendLock operation type
1828 static const struct afs_call_type yfs_RXYFSExtendLock = {
1829 .name = "YFS.ExtendLock",
1830 .op = yfs_FS_ExtendLock,
1831 .deliver = yfs_deliver_status_and_volsync,
1832 .done = afs_lock_op_done,
1833 .destructor = afs_flat_call_destructor,
1837 * YFS.ReleaseLock operation type
1839 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1840 .name = "YFS.ReleaseLock",
1841 .op = yfs_FS_ReleaseLock,
1842 .deliver = yfs_deliver_status_and_volsync,
1843 .destructor = afs_flat_call_destructor,
1847 * Set a lock on a file
1849 int yfs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1851 struct afs_vnode *vnode = fc->vnode;
1852 struct afs_call *call;
1853 struct afs_net *net = afs_v2net(vnode);
1858 call = afs_alloc_flat_call(net, &yfs_RXYFSSetLock,
1859 sizeof(__be32) * 2 +
1860 sizeof(struct yfs_xdr_YFSFid) +
1862 sizeof(struct yfs_xdr_YFSFetchStatus) +
1863 sizeof(struct yfs_xdr_YFSVolSync));
1867 call->key = fc->key;
1868 call->reply[0] = vnode;
1869 call->want_reply_time = true;
1871 /* marshall the parameters */
1873 bp = xdr_encode_u32(bp, YFSSETLOCK);
1874 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1875 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1876 bp = xdr_encode_u32(bp, type);
1877 yfs_check_req(call, bp);
1879 afs_use_fs_server(call, fc->cbi);
1880 trace_afs_make_fs_calli(call, &vnode->fid, type);
1881 afs_set_fc_call(call, fc);
1882 afs_make_call(&fc->ac, call, GFP_NOFS);
1883 return afs_wait_for_call_to_complete(call, &fc->ac);
1887 * extend a lock on a file
1889 int yfs_fs_extend_lock(struct afs_fs_cursor *fc)
1891 struct afs_vnode *vnode = fc->vnode;
1892 struct afs_call *call;
1893 struct afs_net *net = afs_v2net(vnode);
1898 call = afs_alloc_flat_call(net, &yfs_RXYFSExtendLock,
1899 sizeof(__be32) * 2 +
1900 sizeof(struct yfs_xdr_YFSFid),
1901 sizeof(struct yfs_xdr_YFSFetchStatus) +
1902 sizeof(struct yfs_xdr_YFSVolSync));
1906 call->key = fc->key;
1907 call->reply[0] = vnode;
1908 call->want_reply_time = true;
1910 /* marshall the parameters */
1912 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1913 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1914 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1915 yfs_check_req(call, bp);
1917 afs_use_fs_server(call, fc->cbi);
1918 trace_afs_make_fs_call(call, &vnode->fid);
1919 afs_set_fc_call(call, fc);
1920 afs_make_call(&fc->ac, call, GFP_NOFS);
1921 return afs_wait_for_call_to_complete(call, &fc->ac);
1925 * release a lock on a file
1927 int yfs_fs_release_lock(struct afs_fs_cursor *fc)
1929 struct afs_vnode *vnode = fc->vnode;
1930 struct afs_call *call;
1931 struct afs_net *net = afs_v2net(vnode);
1936 call = afs_alloc_flat_call(net, &yfs_RXYFSReleaseLock,
1937 sizeof(__be32) * 2 +
1938 sizeof(struct yfs_xdr_YFSFid),
1939 sizeof(struct yfs_xdr_YFSFetchStatus) +
1940 sizeof(struct yfs_xdr_YFSVolSync));
1944 call->key = fc->key;
1945 call->reply[0] = vnode;
1947 /* marshall the parameters */
1949 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1950 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1951 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1952 yfs_check_req(call, bp);
1954 afs_use_fs_server(call, fc->cbi);
1955 trace_afs_make_fs_call(call, &vnode->fid);
1956 afs_set_fc_call(call, fc);
1957 afs_make_call(&fc->ac, call, GFP_NOFS);
1958 return afs_wait_for_call_to_complete(call, &fc->ac);
1962 * Deliver reply data to an FS.FetchStatus with no vnode.
1964 static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1966 struct afs_file_status *status = call->reply[1];
1967 struct afs_callback *callback = call->reply[2];
1968 struct afs_volsync *volsync = call->reply[3];
1969 struct afs_vnode *vnode = call->reply[0];
1973 ret = afs_transfer_reply(call);
1977 _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
1979 /* unmarshall the reply once we've received all of it */
1981 ret = yfs_decode_status(call, &bp, status, vnode,
1982 &call->expected_version, NULL);
1985 xdr_decode_YFSCallBack_raw(call, callback, &bp);
1986 xdr_decode_YFSVolSync(&bp, volsync);
1988 _leave(" = 0 [done]");
1993 * YFS.FetchStatus operation type
1995 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1996 .name = "YFS.FetchStatus",
1997 .op = yfs_FS_FetchStatus,
1998 .deliver = yfs_deliver_fs_fetch_status,
1999 .destructor = afs_flat_call_destructor,
2003 * Fetch the status information for a fid without needing a vnode handle.
2005 int yfs_fs_fetch_status(struct afs_fs_cursor *fc,
2006 struct afs_net *net,
2007 struct afs_fid *fid,
2008 struct afs_file_status *status,
2009 struct afs_callback *callback,
2010 struct afs_volsync *volsync)
2012 struct afs_call *call;
2015 _enter(",%x,{%llx:%llu},,",
2016 key_serial(fc->key), fid->vid, fid->vnode);
2018 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus,
2019 sizeof(__be32) * 2 +
2020 sizeof(struct yfs_xdr_YFSFid),
2021 sizeof(struct yfs_xdr_YFSFetchStatus) +
2022 sizeof(struct yfs_xdr_YFSCallBack) +
2023 sizeof(struct yfs_xdr_YFSVolSync));
2025 fc->ac.error = -ENOMEM;
2029 call->key = fc->key;
2030 call->reply[0] = NULL; /* vnode for fid[0] */
2031 call->reply[1] = status;
2032 call->reply[2] = callback;
2033 call->reply[3] = volsync;
2034 call->expected_version = 1; /* vnode->status.data_version */
2036 /* marshall the parameters */
2038 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
2039 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2040 bp = xdr_encode_YFSFid(bp, fid);
2041 yfs_check_req(call, bp);
2043 call->cb_break = fc->cb_break;
2044 afs_use_fs_server(call, fc->cbi);
2045 trace_afs_make_fs_call(call, fid);
2046 afs_set_fc_call(call, fc);
2047 afs_make_call(&fc->ac, call, GFP_NOFS);
2048 return afs_wait_for_call_to_complete(call, &fc->ac);
2052 * Deliver reply data to an YFS.InlineBulkStatus call
2054 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
2056 struct afs_file_status *statuses;
2057 struct afs_callback *callbacks;
2062 _enter("{%u}", call->unmarshall);
2064 switch (call->unmarshall) {
2066 afs_extract_to_tmp(call);
2069 /* Extract the file status count and array in two steps */
2072 _debug("extract status count");
2073 ret = afs_extract_data(call, true);
2077 tmp = ntohl(call->tmp);
2078 _debug("status count: %u/%u", tmp, call->count2);
2079 if (tmp != call->count2)
2080 return afs_protocol_error(call, -EBADMSG,
2081 afs_eproto_ibulkst_count);
2086 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
2090 _debug("extract status array %u", call->count);
2091 ret = afs_extract_data(call, true);
2096 statuses = call->reply[1];
2097 ret = yfs_decode_status(call, &bp, &statuses[call->count],
2103 if (call->count < call->count2)
2108 afs_extract_to_tmp(call);
2110 /* Extract the callback count and array in two steps */
2113 _debug("extract CB count");
2114 ret = afs_extract_data(call, true);
2118 tmp = ntohl(call->tmp);
2119 _debug("CB count: %u", tmp);
2120 if (tmp != call->count2)
2121 return afs_protocol_error(call, -EBADMSG,
2122 afs_eproto_ibulkst_cb_count);
2126 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
2130 _debug("extract CB array");
2131 ret = afs_extract_data(call, true);
2135 _debug("unmarshall CB array");
2137 callbacks = call->reply[2];
2138 xdr_decode_YFSCallBack_raw(call, &callbacks[call->count], &bp);
2140 if (call->count < call->count2)
2143 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
2148 ret = afs_extract_data(call, false);
2153 xdr_decode_YFSVolSync(&bp, call->reply[3]);
2162 _leave(" = 0 [done]");
2167 * FS.InlineBulkStatus operation type
2169 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
2170 .name = "YFS.InlineBulkStatus",
2171 .op = yfs_FS_InlineBulkStatus,
2172 .deliver = yfs_deliver_fs_inline_bulk_status,
2173 .destructor = afs_flat_call_destructor,
2177 * Fetch the status information for up to 1024 files
2179 int yfs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2180 struct afs_net *net,
2181 struct afs_fid *fids,
2182 struct afs_file_status *statuses,
2183 struct afs_callback *callbacks,
2184 unsigned int nr_fids,
2185 struct afs_volsync *volsync)
2187 struct afs_call *call;
2191 _enter(",%x,{%llx:%llu},%u",
2192 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2194 call = afs_alloc_flat_call(net, &yfs_RXYFSInlineBulkStatus,
2198 sizeof(struct yfs_xdr_YFSFid) * nr_fids,
2199 sizeof(struct yfs_xdr_YFSFetchStatus));
2201 fc->ac.error = -ENOMEM;
2205 call->key = fc->key;
2206 call->reply[1] = statuses;
2207 call->reply[2] = callbacks;
2208 call->reply[3] = volsync;
2209 call->count2 = nr_fids;
2211 /* marshall the parameters */
2213 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
2214 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
2215 bp = xdr_encode_u32(bp, nr_fids);
2216 for (i = 0; i < nr_fids; i++)
2217 bp = xdr_encode_YFSFid(bp, &fids[i]);
2218 yfs_check_req(call, bp);
2220 call->cb_break = fc->cb_break;
2221 afs_use_fs_server(call, fc->cbi);
2222 trace_afs_make_fs_call(call, &fids[0]);
2223 afs_set_fc_call(call, fc);
2224 afs_make_call(&fc->ac, call, GFP_NOFS);
2225 return afs_wait_for_call_to_complete(call, &fc->ac);
2229 * Deliver reply data to an YFS.FetchOpaqueACL.
2231 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
2233 struct afs_volsync *volsync = call->reply[2];
2234 struct afs_vnode *vnode = call->reply[1];
2235 struct yfs_acl *yacl = call->reply[0];
2236 struct afs_acl *acl;
2241 _enter("{%u}", call->unmarshall);
2243 switch (call->unmarshall) {
2245 afs_extract_to_tmp(call);
2248 /* Extract the file ACL length */
2250 ret = afs_extract_data(call, true);
2254 size = call->count2 = ntohl(call->tmp);
2255 size = round_up(size, 4);
2257 if (yacl->flags & YFS_ACL_WANT_ACL) {
2258 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2262 acl->size = call->count2;
2263 afs_extract_begin(call, acl->data, size);
2265 iov_iter_discard(&call->iter, READ, size);
2269 /* Extract the file ACL */
2271 ret = afs_extract_data(call, true);
2275 afs_extract_to_tmp(call);
2278 /* Extract the volume ACL length */
2280 ret = afs_extract_data(call, true);
2284 size = call->count2 = ntohl(call->tmp);
2285 size = round_up(size, 4);
2287 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
2288 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2291 yacl->vol_acl = acl;
2292 acl->size = call->count2;
2293 afs_extract_begin(call, acl->data, size);
2295 iov_iter_discard(&call->iter, READ, size);
2299 /* Extract the volume ACL */
2301 ret = afs_extract_data(call, true);
2305 afs_extract_to_buf(call,
2306 sizeof(__be32) * 2 +
2307 sizeof(struct yfs_xdr_YFSFetchStatus) +
2308 sizeof(struct yfs_xdr_YFSVolSync));
2311 /* extract the metadata */
2313 ret = afs_extract_data(call, false);
2318 yacl->inherit_flag = ntohl(*bp++);
2319 yacl->num_cleaned = ntohl(*bp++);
2320 ret = yfs_decode_status(call, &bp, &vnode->status, vnode,
2321 &call->expected_version, NULL);
2324 xdr_decode_YFSVolSync(&bp, volsync);
2332 _leave(" = 0 [done]");
2336 void yfs_free_opaque_acl(struct yfs_acl *yacl)
2340 kfree(yacl->vol_acl);
2346 * YFS.FetchOpaqueACL operation type
2348 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
2349 .name = "YFS.FetchOpaqueACL",
2350 .op = yfs_FS_FetchOpaqueACL,
2351 .deliver = yfs_deliver_fs_fetch_opaque_acl,
2352 .destructor = afs_flat_call_destructor,
2356 * Fetch the YFS advanced ACLs for a file.
2358 struct yfs_acl *yfs_fs_fetch_opaque_acl(struct afs_fs_cursor *fc,
2359 struct yfs_acl *yacl)
2361 struct afs_vnode *vnode = fc->vnode;
2362 struct afs_call *call;
2363 struct afs_net *net = afs_v2net(vnode);
2366 _enter(",%x,{%llx:%llu},,",
2367 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2369 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchOpaqueACL,
2370 sizeof(__be32) * 2 +
2371 sizeof(struct yfs_xdr_YFSFid),
2372 sizeof(__be32) * 2 +
2373 sizeof(struct yfs_xdr_YFSFetchStatus) +
2374 sizeof(struct yfs_xdr_YFSVolSync));
2376 fc->ac.error = -ENOMEM;
2377 return ERR_PTR(-ENOMEM);
2380 call->key = fc->key;
2381 call->reply[0] = yacl;
2382 call->reply[1] = vnode;
2383 call->reply[2] = NULL; /* volsync */
2385 /* marshall the parameters */
2387 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
2388 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2389 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2390 yfs_check_req(call, bp);
2392 call->cb_break = fc->cb_break;
2393 afs_use_fs_server(call, fc->cbi);
2394 trace_afs_make_fs_call(call, &vnode->fid);
2395 afs_make_call(&fc->ac, call, GFP_KERNEL);
2396 return (struct yfs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2400 * YFS.StoreOpaqueACL2 operation type
2402 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
2403 .name = "YFS.StoreOpaqueACL2",
2404 .op = yfs_FS_StoreOpaqueACL2,
2405 .deliver = yfs_deliver_status_and_volsync,
2406 .destructor = afs_flat_call_destructor,
2410 * Fetch the YFS ACL for a file.
2412 int yfs_fs_store_opaque_acl2(struct afs_fs_cursor *fc, const struct afs_acl *acl)
2414 struct afs_vnode *vnode = fc->vnode;
2415 struct afs_call *call;
2416 struct afs_net *net = afs_v2net(vnode);
2420 _enter(",%x,{%llx:%llu},,",
2421 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2423 size = round_up(acl->size, 4);
2424 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
2425 sizeof(__be32) * 2 +
2426 sizeof(struct yfs_xdr_YFSFid) +
2427 sizeof(__be32) + size,
2428 sizeof(struct yfs_xdr_YFSFetchStatus) +
2429 sizeof(struct yfs_xdr_YFSVolSync));
2431 fc->ac.error = -ENOMEM;
2435 call->key = fc->key;
2436 call->reply[0] = vnode;
2437 call->reply[2] = NULL; /* volsync */
2439 /* marshall the parameters */
2441 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
2442 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2443 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2444 bp = xdr_encode_u32(bp, acl->size);
2445 memcpy(bp, acl->data, acl->size);
2446 if (acl->size != size)
2447 memset((void *)bp + acl->size, 0, size - acl->size);
2448 yfs_check_req(call, bp);
2450 trace_afs_make_fs_call(call, &vnode->fid);
2451 afs_make_call(&fc->ac, call, GFP_KERNEL);
2452 return afs_wait_for_call_to_complete(call, &fc->ac);