1 /* AFS File Server client stubs
3 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, 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);
30 * decode an AFSFid block
32 static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
34 const __be32 *bp = *_bp;
36 fid->vid = ntohl(*bp++);
37 fid->vnode = ntohl(*bp++);
38 fid->unique = ntohl(*bp++);
43 * Dump a bad file status record.
45 static void xdr_dump_bad(const __be32 *bp)
50 pr_notice("AFS XDR: Bad status record\n");
51 for (i = 0; i < 5 * 4 * 4; i += 16) {
54 pr_notice("%03x: %08x %08x %08x %08x\n",
55 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
59 pr_notice("0x50: %08x\n", ntohl(x[0]));
63 * Update the core inode struct from a returned status record.
65 void afs_update_inode_from_status(struct afs_vnode *vnode,
66 struct afs_file_status *status,
67 const afs_dataversion_t *expected_version,
73 t = status->mtime_client;
74 vnode->vfs_inode.i_ctime = t;
75 vnode->vfs_inode.i_mtime = t;
76 vnode->vfs_inode.i_atime = t;
78 if (flags & (AFS_VNODE_META_CHANGED | AFS_VNODE_NOT_YET_SET)) {
79 vnode->vfs_inode.i_uid = make_kuid(&init_user_ns, status->owner);
80 vnode->vfs_inode.i_gid = make_kgid(&init_user_ns, status->group);
81 set_nlink(&vnode->vfs_inode, status->nlink);
83 mode = vnode->vfs_inode.i_mode;
87 vnode->vfs_inode.i_mode = mode;
90 if (!(flags & AFS_VNODE_NOT_YET_SET)) {
91 if (expected_version &&
92 *expected_version != status->data_version) {
93 _debug("vnode modified %llx on {%llx:%llu} [exp %llx]",
94 (unsigned long long) status->data_version,
95 vnode->fid.vid, vnode->fid.vnode,
96 (unsigned long long) *expected_version);
97 vnode->invalid_before = status->data_version;
98 if (vnode->status.type == AFS_FTYPE_DIR) {
99 if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
100 afs_stat_v(vnode, n_inval);
102 set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags);
104 } else if (vnode->status.type == AFS_FTYPE_DIR) {
105 /* Expected directory change is handled elsewhere so
106 * that we can locally edit the directory and save on a
109 if (test_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
110 flags &= ~AFS_VNODE_DATA_CHANGED;
114 if (flags & (AFS_VNODE_DATA_CHANGED | AFS_VNODE_NOT_YET_SET)) {
115 inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
116 i_size_write(&vnode->vfs_inode, status->size);
121 * decode an AFSFetchStatus block
123 static int xdr_decode_AFSFetchStatus(struct afs_call *call,
125 struct afs_file_status *status,
126 struct afs_vnode *vnode,
127 const afs_dataversion_t *expected_version,
128 struct afs_read *read_req)
130 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
131 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
132 u64 data_version, size;
133 u32 type, abort_code;
136 abort_code = ntohl(xdr->abort_code);
138 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
139 if (xdr->if_version == htonl(0) &&
142 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
143 * whereby it doesn't set the interface version in the error
146 status->abort_code = abort_code;
150 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
154 if (abort_code != 0 && inline_error) {
155 status->abort_code = abort_code;
159 type = ntohl(xdr->type);
163 case AFS_FTYPE_SYMLINK:
164 if (type != status->type &&
166 !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
167 pr_warning("Vnode %llx:%llx:%x changed type %u to %u\n",
180 #define EXTRACT_M(FIELD) \
182 u32 x = ntohl(xdr->FIELD); \
183 if (status->FIELD != x) { \
184 flags |= AFS_VNODE_META_CHANGED; \
192 EXTRACT_M(caller_access); /* call ticket dependent */
193 EXTRACT_M(anon_access);
197 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
198 status->mtime_client.tv_nsec = 0;
199 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
200 status->mtime_server.tv_nsec = 0;
201 status->lock_count = ntohl(xdr->lock_count);
203 size = (u64)ntohl(xdr->size_lo);
204 size |= (u64)ntohl(xdr->size_hi) << 32;
207 data_version = (u64)ntohl(xdr->data_version_lo);
208 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
209 if (data_version != status->data_version) {
210 status->data_version = data_version;
211 flags |= AFS_VNODE_DATA_CHANGED;
215 read_req->data_version = data_version;
216 read_req->file_size = size;
219 *_bp = (const void *)*_bp + sizeof(*xdr);
222 if (test_bit(AFS_VNODE_UNSET, &vnode->flags))
223 flags |= AFS_VNODE_NOT_YET_SET;
224 afs_update_inode_from_status(vnode, status, expected_version,
232 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
236 * Decode the file status. We need to lock the target vnode if we're going to
237 * update its status so that stat() sees the attributes update atomically.
239 static int afs_decode_status(struct afs_call *call,
241 struct afs_file_status *status,
242 struct afs_vnode *vnode,
243 const afs_dataversion_t *expected_version,
244 struct afs_read *read_req)
249 return xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
250 expected_version, read_req);
252 write_seqlock(&vnode->cb_lock);
253 ret = xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
254 expected_version, read_req);
255 write_sequnlock(&vnode->cb_lock);
260 * decode an AFSCallBack block
262 static void xdr_decode_AFSCallBack(struct afs_call *call,
263 struct afs_vnode *vnode,
266 struct afs_cb_interest *old, *cbi = call->cbi;
267 const __be32 *bp = *_bp;
270 write_seqlock(&vnode->cb_lock);
272 if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
273 vnode->cb_version = ntohl(*bp++);
274 cb_expiry = ntohl(*bp++);
275 vnode->cb_type = ntohl(*bp++);
276 vnode->cb_expires_at = cb_expiry + ktime_get_real_seconds();
277 old = vnode->cb_interest;
278 if (old != call->cbi) {
279 vnode->cb_interest = cbi;
282 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
287 write_sequnlock(&vnode->cb_lock);
292 static ktime_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
294 return ktime_add_ns(call->reply_time, expiry * NSEC_PER_SEC);
297 static void xdr_decode_AFSCallBack_raw(struct afs_call *call,
299 struct afs_callback *cb)
301 const __be32 *bp = *_bp;
303 cb->version = ntohl(*bp++);
304 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
305 cb->type = ntohl(*bp++);
310 * decode an AFSVolSync block
312 static void xdr_decode_AFSVolSync(const __be32 **_bp,
313 struct afs_volsync *volsync)
315 const __be32 *bp = *_bp;
318 creation = ntohl(*bp++);
327 volsync->creation = creation;
331 * encode the requested attributes into an AFSStoreStatus block
333 static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
336 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
339 if (attr->ia_valid & ATTR_MTIME) {
340 mask |= AFS_SET_MTIME;
341 mtime = attr->ia_mtime.tv_sec;
344 if (attr->ia_valid & ATTR_UID) {
345 mask |= AFS_SET_OWNER;
346 owner = from_kuid(&init_user_ns, attr->ia_uid);
349 if (attr->ia_valid & ATTR_GID) {
350 mask |= AFS_SET_GROUP;
351 group = from_kgid(&init_user_ns, attr->ia_gid);
354 if (attr->ia_valid & ATTR_MODE) {
355 mask |= AFS_SET_MODE;
356 mode = attr->ia_mode & S_IALLUGO;
360 *bp++ = htonl(mtime);
361 *bp++ = htonl(owner);
362 *bp++ = htonl(group);
364 *bp++ = 0; /* segment size */
369 * decode an AFSFetchVolumeStatus block
371 static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
372 struct afs_volume_status *vs)
374 const __be32 *bp = *_bp;
376 vs->vid = ntohl(*bp++);
377 vs->parent_id = ntohl(*bp++);
378 vs->online = ntohl(*bp++);
379 vs->in_service = ntohl(*bp++);
380 vs->blessed = ntohl(*bp++);
381 vs->needs_salvage = ntohl(*bp++);
382 vs->type = ntohl(*bp++);
383 vs->min_quota = ntohl(*bp++);
384 vs->max_quota = ntohl(*bp++);
385 vs->blocks_in_use = ntohl(*bp++);
386 vs->part_blocks_avail = ntohl(*bp++);
387 vs->part_max_blocks = ntohl(*bp++);
388 vs->vol_copy_date = 0;
389 vs->vol_backup_date = 0;
394 * deliver reply data to an FS.FetchStatus
396 static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
398 struct afs_vnode *vnode = call->reply[0];
402 ret = afs_transfer_reply(call);
406 _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
408 /* unmarshall the reply once we've received all of it */
410 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
411 &call->expected_version, NULL);
414 xdr_decode_AFSCallBack(call, vnode, &bp);
415 xdr_decode_AFSVolSync(&bp, call->reply[1]);
417 _leave(" = 0 [done]");
422 * FS.FetchStatus operation type
424 static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
425 .name = "FS.FetchStatus(vnode)",
426 .op = afs_FS_FetchStatus,
427 .deliver = afs_deliver_fs_fetch_status_vnode,
428 .destructor = afs_flat_call_destructor,
432 * fetch the status information for a file
434 int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_volsync *volsync,
437 struct afs_vnode *vnode = fc->vnode;
438 struct afs_call *call;
439 struct afs_net *net = afs_v2net(vnode);
442 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
443 return yfs_fs_fetch_file_status(fc, volsync, new_inode);
445 _enter(",%x,{%llx:%llu},,",
446 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
448 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
449 16, (21 + 3 + 6) * 4);
451 fc->ac.error = -ENOMEM;
456 call->reply[0] = vnode;
457 call->reply[1] = volsync;
458 call->expected_version = new_inode ? 1 : vnode->status.data_version;
459 call->want_reply_time = true;
461 /* marshall the parameters */
463 bp[0] = htonl(FSFETCHSTATUS);
464 bp[1] = htonl(vnode->fid.vid);
465 bp[2] = htonl(vnode->fid.vnode);
466 bp[3] = htonl(vnode->fid.unique);
468 call->cb_break = fc->cb_break;
469 afs_use_fs_server(call, fc->cbi);
470 trace_afs_make_fs_call(call, &vnode->fid);
471 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
475 * deliver reply data to an FS.FetchData
477 static int afs_deliver_fs_fetch_data(struct afs_call *call)
479 struct afs_vnode *vnode = call->reply[0];
480 struct afs_read *req = call->reply[2];
485 _enter("{%u,%zu/%llu}",
486 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
488 switch (call->unmarshall) {
492 req->offset = req->pos & (PAGE_SIZE - 1);
494 if (call->operation_ID == FSFETCHDATA64) {
495 afs_extract_to_tmp64(call);
497 call->tmp_u = htonl(0);
498 afs_extract_to_tmp(call);
501 /* extract the returned data length */
503 _debug("extract data length");
504 ret = afs_extract_data(call, true);
508 req->actual_len = be64_to_cpu(call->tmp64);
509 _debug("DATA length: %llu", req->actual_len);
510 req->remain = min(req->len, req->actual_len);
511 if (req->remain == 0)
517 ASSERTCMP(req->index, <, req->nr_pages);
518 if (req->remain > PAGE_SIZE - req->offset)
519 size = PAGE_SIZE - req->offset;
522 call->bvec[0].bv_len = size;
523 call->bvec[0].bv_offset = req->offset;
524 call->bvec[0].bv_page = req->pages[req->index];
525 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
526 ASSERTCMP(size, <=, PAGE_SIZE);
528 /* extract the returned data */
530 _debug("extract data %zu/%llu",
531 iov_iter_count(&call->iter), req->remain);
533 ret = afs_extract_data(call, true);
536 req->remain -= call->bvec[0].bv_len;
537 req->offset += call->bvec[0].bv_len;
538 ASSERTCMP(req->offset, <=, PAGE_SIZE);
539 if (req->offset == PAGE_SIZE) {
542 req->page_done(call, req);
548 ASSERTCMP(req->remain, ==, 0);
549 if (req->actual_len <= req->len)
552 /* Discard any excess data the server gave us */
553 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
554 call->unmarshall = 3;
556 _debug("extract discard %zu/%llu",
557 iov_iter_count(&call->iter), req->actual_len - req->len);
559 ret = afs_extract_data(call, true);
564 call->unmarshall = 4;
565 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
567 /* extract the metadata */
569 ret = afs_extract_data(call, false);
574 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
575 &vnode->status.data_version, req);
578 xdr_decode_AFSCallBack(call, vnode, &bp);
579 xdr_decode_AFSVolSync(&bp, call->reply[1]);
587 for (; req->index < req->nr_pages; req->index++) {
588 if (req->offset < PAGE_SIZE)
589 zero_user_segment(req->pages[req->index],
590 req->offset, PAGE_SIZE);
592 req->page_done(call, req);
596 _leave(" = 0 [done]");
600 static void afs_fetch_data_destructor(struct afs_call *call)
602 struct afs_read *req = call->reply[2];
605 afs_flat_call_destructor(call);
609 * FS.FetchData operation type
611 static const struct afs_call_type afs_RXFSFetchData = {
612 .name = "FS.FetchData",
613 .op = afs_FS_FetchData,
614 .deliver = afs_deliver_fs_fetch_data,
615 .destructor = afs_fetch_data_destructor,
618 static const struct afs_call_type afs_RXFSFetchData64 = {
619 .name = "FS.FetchData64",
620 .op = afs_FS_FetchData64,
621 .deliver = afs_deliver_fs_fetch_data,
622 .destructor = afs_fetch_data_destructor,
626 * fetch data from a very large file
628 static int afs_fs_fetch_data64(struct afs_fs_cursor *fc, struct afs_read *req)
630 struct afs_vnode *vnode = fc->vnode;
631 struct afs_call *call;
632 struct afs_net *net = afs_v2net(vnode);
637 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
642 call->reply[0] = vnode;
643 call->reply[1] = NULL; /* volsync */
644 call->reply[2] = req;
645 call->expected_version = vnode->status.data_version;
646 call->want_reply_time = true;
648 /* marshall the parameters */
650 bp[0] = htonl(FSFETCHDATA64);
651 bp[1] = htonl(vnode->fid.vid);
652 bp[2] = htonl(vnode->fid.vnode);
653 bp[3] = htonl(vnode->fid.unique);
654 bp[4] = htonl(upper_32_bits(req->pos));
655 bp[5] = htonl(lower_32_bits(req->pos));
657 bp[7] = htonl(lower_32_bits(req->len));
659 refcount_inc(&req->usage);
660 call->cb_break = fc->cb_break;
661 afs_use_fs_server(call, fc->cbi);
662 trace_afs_make_fs_call(call, &vnode->fid);
663 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
667 * fetch data from a file
669 int afs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
671 struct afs_vnode *vnode = fc->vnode;
672 struct afs_call *call;
673 struct afs_net *net = afs_v2net(vnode);
676 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
677 return yfs_fs_fetch_data(fc, req);
679 if (upper_32_bits(req->pos) ||
680 upper_32_bits(req->len) ||
681 upper_32_bits(req->pos + req->len))
682 return afs_fs_fetch_data64(fc, req);
686 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
691 call->reply[0] = vnode;
692 call->reply[1] = NULL; /* volsync */
693 call->reply[2] = req;
694 call->expected_version = vnode->status.data_version;
695 call->want_reply_time = true;
697 /* marshall the parameters */
699 bp[0] = htonl(FSFETCHDATA);
700 bp[1] = htonl(vnode->fid.vid);
701 bp[2] = htonl(vnode->fid.vnode);
702 bp[3] = htonl(vnode->fid.unique);
703 bp[4] = htonl(lower_32_bits(req->pos));
704 bp[5] = htonl(lower_32_bits(req->len));
706 refcount_inc(&req->usage);
707 call->cb_break = fc->cb_break;
708 afs_use_fs_server(call, fc->cbi);
709 trace_afs_make_fs_call(call, &vnode->fid);
710 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
714 * deliver reply data to an FS.CreateFile or an FS.MakeDir
716 static int afs_deliver_fs_create_vnode(struct afs_call *call)
718 struct afs_vnode *vnode = call->reply[0];
722 _enter("{%u}", call->unmarshall);
724 ret = afs_transfer_reply(call);
728 /* unmarshall the reply once we've received all of it */
730 xdr_decode_AFSFid(&bp, call->reply[1]);
731 ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
734 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
735 &call->expected_version, NULL);
738 xdr_decode_AFSCallBack_raw(call, &bp, call->reply[3]);
739 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
741 _leave(" = 0 [done]");
746 * FS.CreateFile and FS.MakeDir operation type
748 static const struct afs_call_type afs_RXFSCreateFile = {
749 .name = "FS.CreateFile",
750 .op = afs_FS_CreateFile,
751 .deliver = afs_deliver_fs_create_vnode,
752 .destructor = afs_flat_call_destructor,
755 static const struct afs_call_type afs_RXFSMakeDir = {
756 .name = "FS.MakeDir",
757 .op = afs_FS_MakeDir,
758 .deliver = afs_deliver_fs_create_vnode,
759 .destructor = afs_flat_call_destructor,
763 * create a file or make a directory
765 int afs_fs_create(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, padsz;
779 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
781 return yfs_fs_make_dir(fc, name, mode, current_data_version,
782 newfid, newstatus, newcb);
784 return yfs_fs_create_file(fc, name, mode, current_data_version,
785 newfid, newstatus, newcb);
790 namesz = strlen(name);
791 padsz = (4 - (namesz & 3)) & 3;
792 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
794 call = afs_alloc_flat_call(
795 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
796 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
801 call->reply[0] = vnode;
802 call->reply[1] = newfid;
803 call->reply[2] = newstatus;
804 call->reply[3] = newcb;
805 call->expected_version = current_data_version + 1;
806 call->want_reply_time = true;
808 /* marshall the parameters */
810 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
811 *bp++ = htonl(vnode->fid.vid);
812 *bp++ = htonl(vnode->fid.vnode);
813 *bp++ = htonl(vnode->fid.unique);
814 *bp++ = htonl(namesz);
815 memcpy(bp, name, namesz);
816 bp = (void *) bp + namesz;
818 memset(bp, 0, padsz);
819 bp = (void *) bp + padsz;
821 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
822 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
823 *bp++ = 0; /* owner */
824 *bp++ = 0; /* group */
825 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
826 *bp++ = 0; /* segment size */
828 afs_use_fs_server(call, fc->cbi);
829 trace_afs_make_fs_call(call, &vnode->fid);
830 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
834 * deliver reply data to an FS.RemoveFile or FS.RemoveDir
836 static int afs_deliver_fs_remove(struct afs_call *call)
838 struct afs_vnode *vnode = call->reply[0];
842 _enter("{%u}", call->unmarshall);
844 ret = afs_transfer_reply(call);
848 /* unmarshall the reply once we've received all of it */
850 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
851 &call->expected_version, NULL);
854 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
856 _leave(" = 0 [done]");
861 * FS.RemoveDir/FS.RemoveFile operation type
863 static const struct afs_call_type afs_RXFSRemoveFile = {
864 .name = "FS.RemoveFile",
865 .op = afs_FS_RemoveFile,
866 .deliver = afs_deliver_fs_remove,
867 .destructor = afs_flat_call_destructor,
870 static const struct afs_call_type afs_RXFSRemoveDir = {
871 .name = "FS.RemoveDir",
872 .op = afs_FS_RemoveDir,
873 .deliver = afs_deliver_fs_remove,
874 .destructor = afs_flat_call_destructor,
878 * remove a file or directory
880 int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
881 const char *name, bool isdir, u64 current_data_version)
883 struct afs_vnode *dvnode = fc->vnode;
884 struct afs_call *call;
885 struct afs_net *net = afs_v2net(dvnode);
886 size_t namesz, reqsz, padsz;
889 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
890 return yfs_fs_remove(fc, vnode, name, isdir, current_data_version);
894 namesz = strlen(name);
895 padsz = (4 - (namesz & 3)) & 3;
896 reqsz = (5 * 4) + namesz + padsz;
898 call = afs_alloc_flat_call(
899 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
900 reqsz, (21 + 6) * 4);
905 call->reply[0] = dvnode;
906 call->reply[1] = vnode;
907 call->expected_version = current_data_version + 1;
909 /* marshall the parameters */
911 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
912 *bp++ = htonl(dvnode->fid.vid);
913 *bp++ = htonl(dvnode->fid.vnode);
914 *bp++ = htonl(dvnode->fid.unique);
915 *bp++ = htonl(namesz);
916 memcpy(bp, name, namesz);
917 bp = (void *) bp + namesz;
919 memset(bp, 0, padsz);
920 bp = (void *) bp + padsz;
923 afs_use_fs_server(call, fc->cbi);
924 trace_afs_make_fs_call(call, &dvnode->fid);
925 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
929 * deliver reply data to an FS.Link
931 static int afs_deliver_fs_link(struct afs_call *call)
933 struct afs_vnode *dvnode = call->reply[0], *vnode = call->reply[1];
937 _enter("{%u}", call->unmarshall);
939 ret = afs_transfer_reply(call);
943 /* unmarshall the reply once we've received all of it */
945 ret = afs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
948 ret = afs_decode_status(call, &bp, &dvnode->status, dvnode,
949 &call->expected_version, NULL);
952 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
954 _leave(" = 0 [done]");
959 * FS.Link operation type
961 static const struct afs_call_type afs_RXFSLink = {
964 .deliver = afs_deliver_fs_link,
965 .destructor = afs_flat_call_destructor,
971 int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
972 const char *name, u64 current_data_version)
974 struct afs_vnode *dvnode = fc->vnode;
975 struct afs_call *call;
976 struct afs_net *net = afs_v2net(vnode);
977 size_t namesz, reqsz, padsz;
980 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
981 return yfs_fs_link(fc, vnode, name, current_data_version);
985 namesz = strlen(name);
986 padsz = (4 - (namesz & 3)) & 3;
987 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
989 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
994 call->reply[0] = dvnode;
995 call->reply[1] = vnode;
996 call->expected_version = current_data_version + 1;
998 /* marshall the parameters */
1000 *bp++ = htonl(FSLINK);
1001 *bp++ = htonl(dvnode->fid.vid);
1002 *bp++ = htonl(dvnode->fid.vnode);
1003 *bp++ = htonl(dvnode->fid.unique);
1004 *bp++ = htonl(namesz);
1005 memcpy(bp, name, namesz);
1006 bp = (void *) bp + namesz;
1008 memset(bp, 0, padsz);
1009 bp = (void *) bp + padsz;
1011 *bp++ = htonl(vnode->fid.vid);
1012 *bp++ = htonl(vnode->fid.vnode);
1013 *bp++ = htonl(vnode->fid.unique);
1015 afs_use_fs_server(call, fc->cbi);
1016 trace_afs_make_fs_call(call, &vnode->fid);
1017 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1021 * deliver reply data to an FS.Symlink
1023 static int afs_deliver_fs_symlink(struct afs_call *call)
1025 struct afs_vnode *vnode = call->reply[0];
1029 _enter("{%u}", call->unmarshall);
1031 ret = afs_transfer_reply(call);
1035 /* unmarshall the reply once we've received all of it */
1037 xdr_decode_AFSFid(&bp, call->reply[1]);
1038 ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
1041 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1042 &call->expected_version, NULL);
1045 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1047 _leave(" = 0 [done]");
1052 * FS.Symlink operation type
1054 static const struct afs_call_type afs_RXFSSymlink = {
1055 .name = "FS.Symlink",
1056 .op = afs_FS_Symlink,
1057 .deliver = afs_deliver_fs_symlink,
1058 .destructor = afs_flat_call_destructor,
1062 * create a symbolic link
1064 int afs_fs_symlink(struct afs_fs_cursor *fc,
1066 const char *contents,
1067 u64 current_data_version,
1068 struct afs_fid *newfid,
1069 struct afs_file_status *newstatus)
1071 struct afs_vnode *vnode = fc->vnode;
1072 struct afs_call *call;
1073 struct afs_net *net = afs_v2net(vnode);
1074 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
1077 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1078 return yfs_fs_symlink(fc, name, contents, current_data_version,
1083 namesz = strlen(name);
1084 padsz = (4 - (namesz & 3)) & 3;
1086 c_namesz = strlen(contents);
1087 c_padsz = (4 - (c_namesz & 3)) & 3;
1089 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
1091 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
1092 (3 + 21 + 21 + 6) * 4);
1096 call->key = fc->key;
1097 call->reply[0] = vnode;
1098 call->reply[1] = newfid;
1099 call->reply[2] = newstatus;
1100 call->expected_version = current_data_version + 1;
1102 /* marshall the parameters */
1104 *bp++ = htonl(FSSYMLINK);
1105 *bp++ = htonl(vnode->fid.vid);
1106 *bp++ = htonl(vnode->fid.vnode);
1107 *bp++ = htonl(vnode->fid.unique);
1108 *bp++ = htonl(namesz);
1109 memcpy(bp, name, namesz);
1110 bp = (void *) bp + namesz;
1112 memset(bp, 0, padsz);
1113 bp = (void *) bp + padsz;
1115 *bp++ = htonl(c_namesz);
1116 memcpy(bp, contents, c_namesz);
1117 bp = (void *) bp + c_namesz;
1119 memset(bp, 0, c_padsz);
1120 bp = (void *) bp + c_padsz;
1122 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
1123 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1124 *bp++ = 0; /* owner */
1125 *bp++ = 0; /* group */
1126 *bp++ = htonl(S_IRWXUGO); /* unix mode */
1127 *bp++ = 0; /* segment size */
1129 afs_use_fs_server(call, fc->cbi);
1130 trace_afs_make_fs_call(call, &vnode->fid);
1131 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1135 * deliver reply data to an FS.Rename
1137 static int afs_deliver_fs_rename(struct afs_call *call)
1139 struct afs_vnode *orig_dvnode = call->reply[0], *new_dvnode = call->reply[1];
1143 _enter("{%u}", call->unmarshall);
1145 ret = afs_transfer_reply(call);
1149 /* unmarshall the reply once we've received all of it */
1151 ret = afs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1152 &call->expected_version, NULL);
1155 if (new_dvnode != orig_dvnode) {
1156 ret = afs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1157 &call->expected_version_2, NULL);
1161 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1163 _leave(" = 0 [done]");
1168 * FS.Rename operation type
1170 static const struct afs_call_type afs_RXFSRename = {
1171 .name = "FS.Rename",
1172 .op = afs_FS_Rename,
1173 .deliver = afs_deliver_fs_rename,
1174 .destructor = afs_flat_call_destructor,
1178 * create a symbolic link
1180 int afs_fs_rename(struct afs_fs_cursor *fc,
1181 const char *orig_name,
1182 struct afs_vnode *new_dvnode,
1183 const char *new_name,
1184 u64 current_orig_data_version,
1185 u64 current_new_data_version)
1187 struct afs_vnode *orig_dvnode = fc->vnode;
1188 struct afs_call *call;
1189 struct afs_net *net = afs_v2net(orig_dvnode);
1190 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1193 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1194 return yfs_fs_rename(fc, orig_name,
1195 new_dvnode, new_name,
1196 current_orig_data_version,
1197 current_new_data_version);
1201 o_namesz = strlen(orig_name);
1202 o_padsz = (4 - (o_namesz & 3)) & 3;
1204 n_namesz = strlen(new_name);
1205 n_padsz = (4 - (n_namesz & 3)) & 3;
1208 4 + o_namesz + o_padsz +
1210 4 + n_namesz + n_padsz;
1212 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1216 call->key = fc->key;
1217 call->reply[0] = orig_dvnode;
1218 call->reply[1] = new_dvnode;
1219 call->expected_version = current_orig_data_version + 1;
1220 call->expected_version_2 = current_new_data_version + 1;
1222 /* marshall the parameters */
1224 *bp++ = htonl(FSRENAME);
1225 *bp++ = htonl(orig_dvnode->fid.vid);
1226 *bp++ = htonl(orig_dvnode->fid.vnode);
1227 *bp++ = htonl(orig_dvnode->fid.unique);
1228 *bp++ = htonl(o_namesz);
1229 memcpy(bp, orig_name, o_namesz);
1230 bp = (void *) bp + o_namesz;
1232 memset(bp, 0, o_padsz);
1233 bp = (void *) bp + o_padsz;
1236 *bp++ = htonl(new_dvnode->fid.vid);
1237 *bp++ = htonl(new_dvnode->fid.vnode);
1238 *bp++ = htonl(new_dvnode->fid.unique);
1239 *bp++ = htonl(n_namesz);
1240 memcpy(bp, new_name, n_namesz);
1241 bp = (void *) bp + n_namesz;
1243 memset(bp, 0, n_padsz);
1244 bp = (void *) bp + n_padsz;
1247 afs_use_fs_server(call, fc->cbi);
1248 trace_afs_make_fs_call(call, &orig_dvnode->fid);
1249 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1253 * deliver reply data to an FS.StoreData
1255 static int afs_deliver_fs_store_data(struct afs_call *call)
1257 struct afs_vnode *vnode = call->reply[0];
1263 ret = afs_transfer_reply(call);
1267 /* unmarshall the reply once we've received all of it */
1269 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1270 &call->expected_version, NULL);
1273 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1275 afs_pages_written_back(vnode, call);
1277 _leave(" = 0 [done]");
1282 * FS.StoreData operation type
1284 static const struct afs_call_type afs_RXFSStoreData = {
1285 .name = "FS.StoreData",
1286 .op = afs_FS_StoreData,
1287 .deliver = afs_deliver_fs_store_data,
1288 .destructor = afs_flat_call_destructor,
1291 static const struct afs_call_type afs_RXFSStoreData64 = {
1292 .name = "FS.StoreData64",
1293 .op = afs_FS_StoreData64,
1294 .deliver = afs_deliver_fs_store_data,
1295 .destructor = afs_flat_call_destructor,
1299 * store a set of pages to a very large file
1301 static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1302 struct address_space *mapping,
1303 pgoff_t first, pgoff_t last,
1304 unsigned offset, unsigned to,
1305 loff_t size, loff_t pos, loff_t i_size)
1307 struct afs_vnode *vnode = fc->vnode;
1308 struct afs_call *call;
1309 struct afs_net *net = afs_v2net(vnode);
1312 _enter(",%x,{%llx:%llu},,",
1313 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1315 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
1316 (4 + 6 + 3 * 2) * 4,
1321 call->key = fc->key;
1322 call->mapping = mapping;
1323 call->reply[0] = vnode;
1324 call->first = first;
1326 call->first_offset = offset;
1328 call->send_pages = true;
1329 call->expected_version = vnode->status.data_version + 1;
1331 /* marshall the parameters */
1333 *bp++ = htonl(FSSTOREDATA64);
1334 *bp++ = htonl(vnode->fid.vid);
1335 *bp++ = htonl(vnode->fid.vnode);
1336 *bp++ = htonl(vnode->fid.unique);
1338 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1339 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1340 *bp++ = 0; /* owner */
1341 *bp++ = 0; /* group */
1342 *bp++ = 0; /* unix mode */
1343 *bp++ = 0; /* segment size */
1345 *bp++ = htonl(pos >> 32);
1346 *bp++ = htonl((u32) pos);
1347 *bp++ = htonl(size >> 32);
1348 *bp++ = htonl((u32) size);
1349 *bp++ = htonl(i_size >> 32);
1350 *bp++ = htonl((u32) i_size);
1352 trace_afs_make_fs_call(call, &vnode->fid);
1353 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1357 * store a set of pages
1359 int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1360 pgoff_t first, pgoff_t last,
1361 unsigned offset, unsigned to)
1363 struct afs_vnode *vnode = fc->vnode;
1364 struct afs_call *call;
1365 struct afs_net *net = afs_v2net(vnode);
1366 loff_t size, pos, i_size;
1369 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1370 return yfs_fs_store_data(fc, mapping, first, last, offset, to);
1372 _enter(",%x,{%llx:%llu},,",
1373 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1375 size = (loff_t)to - (loff_t)offset;
1377 size += (loff_t)(last - first) << PAGE_SHIFT;
1378 pos = (loff_t)first << PAGE_SHIFT;
1381 i_size = i_size_read(&vnode->vfs_inode);
1382 if (pos + size > i_size)
1383 i_size = size + pos;
1385 _debug("size %llx, at %llx, i_size %llx",
1386 (unsigned long long) size, (unsigned long long) pos,
1387 (unsigned long long) i_size);
1389 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1390 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
1393 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1399 call->key = fc->key;
1400 call->mapping = mapping;
1401 call->reply[0] = vnode;
1402 call->first = first;
1404 call->first_offset = offset;
1406 call->send_pages = true;
1407 call->expected_version = vnode->status.data_version + 1;
1409 /* marshall the parameters */
1411 *bp++ = htonl(FSSTOREDATA);
1412 *bp++ = htonl(vnode->fid.vid);
1413 *bp++ = htonl(vnode->fid.vnode);
1414 *bp++ = htonl(vnode->fid.unique);
1416 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1417 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1418 *bp++ = 0; /* owner */
1419 *bp++ = 0; /* group */
1420 *bp++ = 0; /* unix mode */
1421 *bp++ = 0; /* segment size */
1424 *bp++ = htonl(size);
1425 *bp++ = htonl(i_size);
1427 afs_use_fs_server(call, fc->cbi);
1428 trace_afs_make_fs_call(call, &vnode->fid);
1429 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1433 * deliver reply data to an FS.StoreStatus
1435 static int afs_deliver_fs_store_status(struct afs_call *call)
1437 struct afs_vnode *vnode = call->reply[0];
1443 ret = afs_transfer_reply(call);
1447 /* unmarshall the reply once we've received all of it */
1449 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1450 &call->expected_version, NULL);
1453 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1455 _leave(" = 0 [done]");
1460 * FS.StoreStatus operation type
1462 static const struct afs_call_type afs_RXFSStoreStatus = {
1463 .name = "FS.StoreStatus",
1464 .op = afs_FS_StoreStatus,
1465 .deliver = afs_deliver_fs_store_status,
1466 .destructor = afs_flat_call_destructor,
1469 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1470 .name = "FS.StoreData",
1471 .op = afs_FS_StoreData,
1472 .deliver = afs_deliver_fs_store_status,
1473 .destructor = afs_flat_call_destructor,
1476 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1477 .name = "FS.StoreData64",
1478 .op = afs_FS_StoreData64,
1479 .deliver = afs_deliver_fs_store_status,
1480 .destructor = afs_flat_call_destructor,
1484 * set the attributes on a very large file, using FS.StoreData rather than
1485 * FS.StoreStatus so as to alter the file size also
1487 static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr)
1489 struct afs_vnode *vnode = fc->vnode;
1490 struct afs_call *call;
1491 struct afs_net *net = afs_v2net(vnode);
1494 _enter(",%x,{%llx:%llu},,",
1495 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1497 ASSERT(attr->ia_valid & ATTR_SIZE);
1499 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
1500 (4 + 6 + 3 * 2) * 4,
1505 call->key = fc->key;
1506 call->reply[0] = vnode;
1507 call->expected_version = vnode->status.data_version + 1;
1509 /* marshall the parameters */
1511 *bp++ = htonl(FSSTOREDATA64);
1512 *bp++ = htonl(vnode->fid.vid);
1513 *bp++ = htonl(vnode->fid.vnode);
1514 *bp++ = htonl(vnode->fid.unique);
1516 xdr_encode_AFS_StoreStatus(&bp, attr);
1518 *bp++ = 0; /* position of start of write */
1520 *bp++ = 0; /* size of write */
1522 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1523 *bp++ = htonl((u32) attr->ia_size);
1525 afs_use_fs_server(call, fc->cbi);
1526 trace_afs_make_fs_call(call, &vnode->fid);
1527 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1531 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1532 * so as to alter the file size also
1534 static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1536 struct afs_vnode *vnode = fc->vnode;
1537 struct afs_call *call;
1538 struct afs_net *net = afs_v2net(vnode);
1541 _enter(",%x,{%llx:%llu},,",
1542 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1544 ASSERT(attr->ia_valid & ATTR_SIZE);
1545 if (attr->ia_size >> 32)
1546 return afs_fs_setattr_size64(fc, attr);
1548 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1554 call->key = fc->key;
1555 call->reply[0] = vnode;
1556 call->expected_version = vnode->status.data_version + 1;
1558 /* marshall the parameters */
1560 *bp++ = htonl(FSSTOREDATA);
1561 *bp++ = htonl(vnode->fid.vid);
1562 *bp++ = htonl(vnode->fid.vnode);
1563 *bp++ = htonl(vnode->fid.unique);
1565 xdr_encode_AFS_StoreStatus(&bp, attr);
1567 *bp++ = 0; /* position of start of write */
1568 *bp++ = 0; /* size of write */
1569 *bp++ = htonl(attr->ia_size); /* new file length */
1571 afs_use_fs_server(call, fc->cbi);
1572 trace_afs_make_fs_call(call, &vnode->fid);
1573 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1577 * set the attributes on a file, using FS.StoreData if there's a change in file
1578 * size, and FS.StoreStatus otherwise
1580 int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1582 struct afs_vnode *vnode = fc->vnode;
1583 struct afs_call *call;
1584 struct afs_net *net = afs_v2net(vnode);
1587 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1588 return yfs_fs_setattr(fc, attr);
1590 if (attr->ia_valid & ATTR_SIZE)
1591 return afs_fs_setattr_size(fc, attr);
1593 _enter(",%x,{%llx:%llu},,",
1594 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1596 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1602 call->key = fc->key;
1603 call->reply[0] = vnode;
1604 call->expected_version = vnode->status.data_version;
1606 /* marshall the parameters */
1608 *bp++ = htonl(FSSTORESTATUS);
1609 *bp++ = htonl(vnode->fid.vid);
1610 *bp++ = htonl(vnode->fid.vnode);
1611 *bp++ = htonl(vnode->fid.unique);
1613 xdr_encode_AFS_StoreStatus(&bp, attr);
1615 afs_use_fs_server(call, fc->cbi);
1616 trace_afs_make_fs_call(call, &vnode->fid);
1617 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1621 * deliver reply data to an FS.GetVolumeStatus
1623 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1630 _enter("{%u}", call->unmarshall);
1632 switch (call->unmarshall) {
1635 afs_extract_to_buf(call, 12 * 4);
1637 /* extract the returned status record */
1639 _debug("extract status");
1640 ret = afs_extract_data(call, true);
1645 xdr_decode_AFSFetchVolumeStatus(&bp, call->reply[1]);
1647 afs_extract_to_tmp(call);
1649 /* extract the volume name length */
1651 ret = afs_extract_data(call, true);
1655 call->count = ntohl(call->tmp);
1656 _debug("volname length: %u", call->count);
1657 if (call->count >= AFSNAMEMAX)
1658 return afs_protocol_error(call, -EBADMSG,
1659 afs_eproto_volname_len);
1660 size = (call->count + 3) & ~3; /* It's padded */
1661 afs_extract_begin(call, call->reply[2], size);
1664 /* extract the volume name */
1666 _debug("extract volname");
1667 ret = afs_extract_data(call, true);
1673 _debug("volname '%s'", p);
1674 afs_extract_to_tmp(call);
1677 /* extract the offline message length */
1679 ret = afs_extract_data(call, true);
1683 call->count = ntohl(call->tmp);
1684 _debug("offline msg length: %u", call->count);
1685 if (call->count >= AFSNAMEMAX)
1686 return afs_protocol_error(call, -EBADMSG,
1687 afs_eproto_offline_msg_len);
1688 size = (call->count + 3) & ~3; /* It's padded */
1689 afs_extract_begin(call, call->reply[2], size);
1692 /* extract the offline message */
1694 _debug("extract offline");
1695 ret = afs_extract_data(call, true);
1701 _debug("offline '%s'", p);
1703 afs_extract_to_tmp(call);
1706 /* extract the message of the day length */
1708 ret = afs_extract_data(call, true);
1712 call->count = ntohl(call->tmp);
1713 _debug("motd length: %u", call->count);
1714 if (call->count >= AFSNAMEMAX)
1715 return afs_protocol_error(call, -EBADMSG,
1716 afs_eproto_motd_len);
1717 size = (call->count + 3) & ~3; /* It's padded */
1718 afs_extract_begin(call, call->reply[2], size);
1721 /* extract the message of the day */
1723 _debug("extract motd");
1724 ret = afs_extract_data(call, false);
1730 _debug("motd '%s'", p);
1738 _leave(" = 0 [done]");
1743 * destroy an FS.GetVolumeStatus call
1745 static void afs_get_volume_status_call_destructor(struct afs_call *call)
1747 kfree(call->reply[2]);
1748 call->reply[2] = NULL;
1749 afs_flat_call_destructor(call);
1753 * FS.GetVolumeStatus operation type
1755 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1756 .name = "FS.GetVolumeStatus",
1757 .op = afs_FS_GetVolumeStatus,
1758 .deliver = afs_deliver_fs_get_volume_status,
1759 .destructor = afs_get_volume_status_call_destructor,
1763 * fetch the status of a volume
1765 int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1766 struct afs_volume_status *vs)
1768 struct afs_vnode *vnode = fc->vnode;
1769 struct afs_call *call;
1770 struct afs_net *net = afs_v2net(vnode);
1774 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1775 return yfs_fs_get_volume_status(fc, vs);
1779 tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1783 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
1789 call->key = fc->key;
1790 call->reply[0] = vnode;
1791 call->reply[1] = vs;
1792 call->reply[2] = tmpbuf;
1794 /* marshall the parameters */
1796 bp[0] = htonl(FSGETVOLUMESTATUS);
1797 bp[1] = htonl(vnode->fid.vid);
1799 afs_use_fs_server(call, fc->cbi);
1800 trace_afs_make_fs_call(call, &vnode->fid);
1801 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1805 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1807 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1812 _enter("{%u}", call->unmarshall);
1814 ret = afs_transfer_reply(call);
1818 /* unmarshall the reply once we've received all of it */
1820 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1822 _leave(" = 0 [done]");
1827 * FS.SetLock operation type
1829 static const struct afs_call_type afs_RXFSSetLock = {
1830 .name = "FS.SetLock",
1831 .op = afs_FS_SetLock,
1832 .deliver = afs_deliver_fs_xxxx_lock,
1833 .destructor = afs_flat_call_destructor,
1837 * FS.ExtendLock operation type
1839 static const struct afs_call_type afs_RXFSExtendLock = {
1840 .name = "FS.ExtendLock",
1841 .op = afs_FS_ExtendLock,
1842 .deliver = afs_deliver_fs_xxxx_lock,
1843 .destructor = afs_flat_call_destructor,
1847 * FS.ReleaseLock operation type
1849 static const struct afs_call_type afs_RXFSReleaseLock = {
1850 .name = "FS.ReleaseLock",
1851 .op = afs_FS_ReleaseLock,
1852 .deliver = afs_deliver_fs_xxxx_lock,
1853 .destructor = afs_flat_call_destructor,
1857 * Set a lock on a file
1859 int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1861 struct afs_vnode *vnode = fc->vnode;
1862 struct afs_call *call;
1863 struct afs_net *net = afs_v2net(vnode);
1866 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1867 return yfs_fs_set_lock(fc, type);
1871 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1875 call->key = fc->key;
1876 call->reply[0] = vnode;
1878 /* marshall the parameters */
1880 *bp++ = htonl(FSSETLOCK);
1881 *bp++ = htonl(vnode->fid.vid);
1882 *bp++ = htonl(vnode->fid.vnode);
1883 *bp++ = htonl(vnode->fid.unique);
1884 *bp++ = htonl(type);
1886 afs_use_fs_server(call, fc->cbi);
1887 trace_afs_make_fs_call(call, &vnode->fid);
1888 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1892 * extend a lock on a file
1894 int afs_fs_extend_lock(struct afs_fs_cursor *fc)
1896 struct afs_vnode *vnode = fc->vnode;
1897 struct afs_call *call;
1898 struct afs_net *net = afs_v2net(vnode);
1901 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1902 return yfs_fs_extend_lock(fc);
1906 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1910 call->key = fc->key;
1911 call->reply[0] = vnode;
1913 /* marshall the parameters */
1915 *bp++ = htonl(FSEXTENDLOCK);
1916 *bp++ = htonl(vnode->fid.vid);
1917 *bp++ = htonl(vnode->fid.vnode);
1918 *bp++ = htonl(vnode->fid.unique);
1920 afs_use_fs_server(call, fc->cbi);
1921 trace_afs_make_fs_call(call, &vnode->fid);
1922 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1926 * release a lock on a file
1928 int afs_fs_release_lock(struct afs_fs_cursor *fc)
1930 struct afs_vnode *vnode = fc->vnode;
1931 struct afs_call *call;
1932 struct afs_net *net = afs_v2net(vnode);
1935 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1936 return yfs_fs_release_lock(fc);
1940 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1944 call->key = fc->key;
1945 call->reply[0] = vnode;
1947 /* marshall the parameters */
1949 *bp++ = htonl(FSRELEASELOCK);
1950 *bp++ = htonl(vnode->fid.vid);
1951 *bp++ = htonl(vnode->fid.vnode);
1952 *bp++ = htonl(vnode->fid.unique);
1954 afs_use_fs_server(call, fc->cbi);
1955 trace_afs_make_fs_call(call, &vnode->fid);
1956 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1960 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1962 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1964 return afs_transfer_reply(call);
1968 * FS.GiveUpAllCallBacks operation type
1970 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1971 .name = "FS.GiveUpAllCallBacks",
1972 .op = afs_FS_GiveUpAllCallBacks,
1973 .deliver = afs_deliver_fs_give_up_all_callbacks,
1974 .destructor = afs_flat_call_destructor,
1978 * Flush all the callbacks we have on a server.
1980 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1981 struct afs_server *server,
1982 struct afs_addr_cursor *ac,
1985 struct afs_call *call;
1990 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1996 /* marshall the parameters */
1998 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
2000 /* Can't take a ref on server */
2001 return afs_make_call(ac, call, GFP_NOFS, false);
2005 * Deliver reply data to an FS.GetCapabilities operation.
2007 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
2012 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
2014 switch (call->unmarshall) {
2016 afs_extract_to_tmp(call);
2019 /* Extract the capabilities word count */
2021 ret = afs_extract_data(call, true);
2025 count = ntohl(call->tmp);
2027 call->count = count;
2028 call->count2 = count;
2029 iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
2032 /* Extract capabilities words */
2034 ret = afs_extract_data(call, false);
2038 /* TODO: Examine capabilities */
2044 _leave(" = 0 [done]");
2048 static void afs_destroy_fs_get_capabilities(struct afs_call *call)
2050 struct afs_server *server = call->reply[0];
2052 afs_put_server(call->net, server);
2053 afs_flat_call_destructor(call);
2057 * FS.GetCapabilities operation type
2059 static const struct afs_call_type afs_RXFSGetCapabilities = {
2060 .name = "FS.GetCapabilities",
2061 .op = afs_FS_GetCapabilities,
2062 .deliver = afs_deliver_fs_get_capabilities,
2063 .done = afs_fileserver_probe_result,
2064 .destructor = afs_destroy_fs_get_capabilities,
2068 * Probe a fileserver for the capabilities that it supports. This can
2069 * return up to 196 words.
2071 int afs_fs_get_capabilities(struct afs_net *net,
2072 struct afs_server *server,
2073 struct afs_addr_cursor *ac,
2075 unsigned int server_index,
2078 struct afs_call *call;
2083 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
2088 call->reply[0] = afs_get_server(server);
2089 call->reply[1] = (void *)(long)server_index;
2090 call->upgrade = true;
2091 call->want_reply_time = true;
2093 /* marshall the parameters */
2095 *bp++ = htonl(FSGETCAPABILITIES);
2097 /* Can't take a ref on server */
2098 trace_afs_make_fs_call(call, NULL);
2099 return afs_make_call(ac, call, GFP_NOFS, async);
2103 * Deliver reply data to an FS.FetchStatus with no vnode.
2105 static int afs_deliver_fs_fetch_status(struct afs_call *call)
2107 struct afs_file_status *status = call->reply[1];
2108 struct afs_callback *callback = call->reply[2];
2109 struct afs_volsync *volsync = call->reply[3];
2110 struct afs_fid *fid = call->reply[0];
2114 ret = afs_transfer_reply(call);
2118 _enter("{%llx:%llu}", fid->vid, fid->vnode);
2120 /* unmarshall the reply once we've received all of it */
2122 ret = afs_decode_status(call, &bp, status, NULL,
2123 &call->expected_version, NULL);
2126 xdr_decode_AFSCallBack_raw(call, &bp, callback);
2127 xdr_decode_AFSVolSync(&bp, volsync);
2129 _leave(" = 0 [done]");
2134 * FS.FetchStatus operation type
2136 static const struct afs_call_type afs_RXFSFetchStatus = {
2137 .name = "FS.FetchStatus",
2138 .op = afs_FS_FetchStatus,
2139 .deliver = afs_deliver_fs_fetch_status,
2140 .destructor = afs_flat_call_destructor,
2144 * Fetch the status information for a fid without needing a vnode handle.
2146 int afs_fs_fetch_status(struct afs_fs_cursor *fc,
2147 struct afs_net *net,
2148 struct afs_fid *fid,
2149 struct afs_file_status *status,
2150 struct afs_callback *callback,
2151 struct afs_volsync *volsync)
2153 struct afs_call *call;
2156 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2157 return yfs_fs_fetch_status(fc, net, fid, status, callback, volsync);
2159 _enter(",%x,{%llx:%llu},,",
2160 key_serial(fc->key), fid->vid, fid->vnode);
2162 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
2164 fc->ac.error = -ENOMEM;
2168 call->key = fc->key;
2169 call->reply[0] = fid;
2170 call->reply[1] = status;
2171 call->reply[2] = callback;
2172 call->reply[3] = volsync;
2173 call->expected_version = 1; /* vnode->status.data_version */
2174 call->want_reply_time = true;
2176 /* marshall the parameters */
2178 bp[0] = htonl(FSFETCHSTATUS);
2179 bp[1] = htonl(fid->vid);
2180 bp[2] = htonl(fid->vnode);
2181 bp[3] = htonl(fid->unique);
2183 call->cb_break = fc->cb_break;
2184 afs_use_fs_server(call, fc->cbi);
2185 trace_afs_make_fs_call(call, fid);
2186 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
2190 * Deliver reply data to an FS.InlineBulkStatus call
2192 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2194 struct afs_file_status *statuses;
2195 struct afs_callback *callbacks;
2196 struct afs_vnode *vnode = call->reply[0];
2201 _enter("{%u}", call->unmarshall);
2203 switch (call->unmarshall) {
2205 afs_extract_to_tmp(call);
2208 /* Extract the file status count and array in two steps */
2210 _debug("extract status count");
2211 ret = afs_extract_data(call, true);
2215 tmp = ntohl(call->tmp);
2216 _debug("status count: %u/%u", tmp, call->count2);
2217 if (tmp != call->count2)
2218 return afs_protocol_error(call, -EBADMSG,
2219 afs_eproto_ibulkst_count);
2224 afs_extract_to_buf(call, 21 * sizeof(__be32));
2227 _debug("extract status array %u", call->count);
2228 ret = afs_extract_data(call, true);
2233 statuses = call->reply[1];
2234 ret = afs_decode_status(call, &bp, &statuses[call->count],
2235 call->count == 0 ? vnode : NULL,
2241 if (call->count < call->count2)
2246 afs_extract_to_tmp(call);
2248 /* Extract the callback count and array in two steps */
2250 _debug("extract CB count");
2251 ret = afs_extract_data(call, true);
2255 tmp = ntohl(call->tmp);
2256 _debug("CB count: %u", tmp);
2257 if (tmp != call->count2)
2258 return afs_protocol_error(call, -EBADMSG,
2259 afs_eproto_ibulkst_cb_count);
2263 afs_extract_to_buf(call, 3 * sizeof(__be32));
2266 _debug("extract CB array");
2267 ret = afs_extract_data(call, true);
2271 _debug("unmarshall CB array");
2273 callbacks = call->reply[2];
2274 callbacks[call->count].version = ntohl(bp[0]);
2275 callbacks[call->count].expires_at = xdr_decode_expiry(call, ntohl(bp[1]));
2276 callbacks[call->count].type = ntohl(bp[2]);
2277 statuses = call->reply[1];
2278 if (call->count == 0 && vnode && statuses[0].abort_code == 0)
2279 xdr_decode_AFSCallBack(call, vnode, &bp);
2281 if (call->count < call->count2)
2284 afs_extract_to_buf(call, 6 * sizeof(__be32));
2288 ret = afs_extract_data(call, false);
2293 xdr_decode_AFSVolSync(&bp, call->reply[3]);
2301 _leave(" = 0 [done]");
2306 * FS.InlineBulkStatus operation type
2308 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2309 .name = "FS.InlineBulkStatus",
2310 .op = afs_FS_InlineBulkStatus,
2311 .deliver = afs_deliver_fs_inline_bulk_status,
2312 .destructor = afs_flat_call_destructor,
2316 * Fetch the status information for up to 50 files
2318 int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2319 struct afs_net *net,
2320 struct afs_fid *fids,
2321 struct afs_file_status *statuses,
2322 struct afs_callback *callbacks,
2323 unsigned int nr_fids,
2324 struct afs_volsync *volsync)
2326 struct afs_call *call;
2330 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2331 return yfs_fs_inline_bulk_status(fc, net, fids, statuses, callbacks,
2334 _enter(",%x,{%llx:%llu},%u",
2335 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2337 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2338 (2 + nr_fids * 3) * 4,
2341 fc->ac.error = -ENOMEM;
2345 call->key = fc->key;
2346 call->reply[0] = NULL; /* vnode for fid[0] */
2347 call->reply[1] = statuses;
2348 call->reply[2] = callbacks;
2349 call->reply[3] = volsync;
2350 call->count2 = nr_fids;
2351 call->want_reply_time = true;
2353 /* marshall the parameters */
2355 *bp++ = htonl(FSINLINEBULKSTATUS);
2356 *bp++ = htonl(nr_fids);
2357 for (i = 0; i < nr_fids; i++) {
2358 *bp++ = htonl(fids[i].vid);
2359 *bp++ = htonl(fids[i].vnode);
2360 *bp++ = htonl(fids[i].unique);
2363 call->cb_break = fc->cb_break;
2364 afs_use_fs_server(call, fc->cbi);
2365 trace_afs_make_fs_call(call, &fids[0]);
2366 return afs_make_call(&fc->ac, call, GFP_NOFS, false);