1 /* AFS File Server client stubs
3 * Copyright (C) 2002, 2007 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 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);
472 afs_make_call(&fc->ac, call, GFP_NOFS);
473 return afs_wait_for_call_to_complete(call, &fc->ac);
477 * deliver reply data to an FS.FetchData
479 static int afs_deliver_fs_fetch_data(struct afs_call *call)
481 struct afs_vnode *vnode = call->reply[0];
482 struct afs_read *req = call->reply[2];
487 _enter("{%u,%zu/%llu}",
488 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
490 switch (call->unmarshall) {
494 req->offset = req->pos & (PAGE_SIZE - 1);
496 if (call->operation_ID == FSFETCHDATA64) {
497 afs_extract_to_tmp64(call);
499 call->tmp_u = htonl(0);
500 afs_extract_to_tmp(call);
503 /* extract the returned data length */
505 _debug("extract data length");
506 ret = afs_extract_data(call, true);
510 req->actual_len = be64_to_cpu(call->tmp64);
511 _debug("DATA length: %llu", req->actual_len);
512 req->remain = min(req->len, req->actual_len);
513 if (req->remain == 0)
519 ASSERTCMP(req->index, <, req->nr_pages);
520 if (req->remain > PAGE_SIZE - req->offset)
521 size = PAGE_SIZE - req->offset;
524 call->bvec[0].bv_len = size;
525 call->bvec[0].bv_offset = req->offset;
526 call->bvec[0].bv_page = req->pages[req->index];
527 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
528 ASSERTCMP(size, <=, PAGE_SIZE);
530 /* extract the returned data */
532 _debug("extract data %zu/%llu",
533 iov_iter_count(&call->iter), req->remain);
535 ret = afs_extract_data(call, true);
538 req->remain -= call->bvec[0].bv_len;
539 req->offset += call->bvec[0].bv_len;
540 ASSERTCMP(req->offset, <=, PAGE_SIZE);
541 if (req->offset == PAGE_SIZE) {
544 req->page_done(call, req);
550 ASSERTCMP(req->remain, ==, 0);
551 if (req->actual_len <= req->len)
554 /* Discard any excess data the server gave us */
555 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
556 call->unmarshall = 3;
558 _debug("extract discard %zu/%llu",
559 iov_iter_count(&call->iter), req->actual_len - req->len);
561 ret = afs_extract_data(call, true);
566 call->unmarshall = 4;
567 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
569 /* extract the metadata */
571 ret = afs_extract_data(call, false);
576 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
577 &vnode->status.data_version, req);
580 xdr_decode_AFSCallBack(call, vnode, &bp);
581 xdr_decode_AFSVolSync(&bp, call->reply[1]);
589 for (; req->index < req->nr_pages; req->index++) {
590 if (req->offset < PAGE_SIZE)
591 zero_user_segment(req->pages[req->index],
592 req->offset, PAGE_SIZE);
594 req->page_done(call, req);
598 _leave(" = 0 [done]");
602 static void afs_fetch_data_destructor(struct afs_call *call)
604 struct afs_read *req = call->reply[2];
607 afs_flat_call_destructor(call);
611 * FS.FetchData operation type
613 static const struct afs_call_type afs_RXFSFetchData = {
614 .name = "FS.FetchData",
615 .op = afs_FS_FetchData,
616 .deliver = afs_deliver_fs_fetch_data,
617 .destructor = afs_fetch_data_destructor,
620 static const struct afs_call_type afs_RXFSFetchData64 = {
621 .name = "FS.FetchData64",
622 .op = afs_FS_FetchData64,
623 .deliver = afs_deliver_fs_fetch_data,
624 .destructor = afs_fetch_data_destructor,
628 * fetch data from a very large file
630 static int afs_fs_fetch_data64(struct afs_fs_cursor *fc, struct afs_read *req)
632 struct afs_vnode *vnode = fc->vnode;
633 struct afs_call *call;
634 struct afs_net *net = afs_v2net(vnode);
639 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
644 call->reply[0] = vnode;
645 call->reply[1] = NULL; /* volsync */
646 call->reply[2] = req;
647 call->expected_version = vnode->status.data_version;
648 call->want_reply_time = true;
650 /* marshall the parameters */
652 bp[0] = htonl(FSFETCHDATA64);
653 bp[1] = htonl(vnode->fid.vid);
654 bp[2] = htonl(vnode->fid.vnode);
655 bp[3] = htonl(vnode->fid.unique);
656 bp[4] = htonl(upper_32_bits(req->pos));
657 bp[5] = htonl(lower_32_bits(req->pos));
659 bp[7] = htonl(lower_32_bits(req->len));
661 refcount_inc(&req->usage);
662 call->cb_break = fc->cb_break;
663 afs_use_fs_server(call, fc->cbi);
664 trace_afs_make_fs_call(call, &vnode->fid);
665 afs_make_call(&fc->ac, call, GFP_NOFS);
666 return afs_wait_for_call_to_complete(call, &fc->ac);
670 * fetch data from a file
672 int afs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
674 struct afs_vnode *vnode = fc->vnode;
675 struct afs_call *call;
676 struct afs_net *net = afs_v2net(vnode);
679 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
680 return yfs_fs_fetch_data(fc, req);
682 if (upper_32_bits(req->pos) ||
683 upper_32_bits(req->len) ||
684 upper_32_bits(req->pos + req->len))
685 return afs_fs_fetch_data64(fc, req);
689 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
694 call->reply[0] = vnode;
695 call->reply[1] = NULL; /* volsync */
696 call->reply[2] = req;
697 call->expected_version = vnode->status.data_version;
698 call->want_reply_time = true;
700 /* marshall the parameters */
702 bp[0] = htonl(FSFETCHDATA);
703 bp[1] = htonl(vnode->fid.vid);
704 bp[2] = htonl(vnode->fid.vnode);
705 bp[3] = htonl(vnode->fid.unique);
706 bp[4] = htonl(lower_32_bits(req->pos));
707 bp[5] = htonl(lower_32_bits(req->len));
709 refcount_inc(&req->usage);
710 call->cb_break = fc->cb_break;
711 afs_use_fs_server(call, fc->cbi);
712 trace_afs_make_fs_call(call, &vnode->fid);
713 afs_make_call(&fc->ac, call, GFP_NOFS);
714 return afs_wait_for_call_to_complete(call, &fc->ac);
718 * deliver reply data to an FS.CreateFile or an FS.MakeDir
720 static int afs_deliver_fs_create_vnode(struct afs_call *call)
722 struct afs_vnode *vnode = call->reply[0];
726 _enter("{%u}", call->unmarshall);
728 ret = afs_transfer_reply(call);
732 /* unmarshall the reply once we've received all of it */
734 xdr_decode_AFSFid(&bp, call->reply[1]);
735 ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
738 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
739 &call->expected_version, NULL);
742 xdr_decode_AFSCallBack_raw(call, &bp, call->reply[3]);
743 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
745 _leave(" = 0 [done]");
750 * FS.CreateFile and FS.MakeDir operation type
752 static const struct afs_call_type afs_RXFSCreateFile = {
753 .name = "FS.CreateFile",
754 .op = afs_FS_CreateFile,
755 .deliver = afs_deliver_fs_create_vnode,
756 .destructor = afs_flat_call_destructor,
759 static const struct afs_call_type afs_RXFSMakeDir = {
760 .name = "FS.MakeDir",
761 .op = afs_FS_MakeDir,
762 .deliver = afs_deliver_fs_create_vnode,
763 .destructor = afs_flat_call_destructor,
767 * create a file or make a directory
769 int afs_fs_create(struct afs_fs_cursor *fc,
772 u64 current_data_version,
773 struct afs_fid *newfid,
774 struct afs_file_status *newstatus,
775 struct afs_callback *newcb)
777 struct afs_vnode *vnode = fc->vnode;
778 struct afs_call *call;
779 struct afs_net *net = afs_v2net(vnode);
780 size_t namesz, reqsz, padsz;
783 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
785 return yfs_fs_make_dir(fc, name, mode, current_data_version,
786 newfid, newstatus, newcb);
788 return yfs_fs_create_file(fc, name, mode, current_data_version,
789 newfid, newstatus, newcb);
794 namesz = strlen(name);
795 padsz = (4 - (namesz & 3)) & 3;
796 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
798 call = afs_alloc_flat_call(
799 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
800 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
805 call->reply[0] = vnode;
806 call->reply[1] = newfid;
807 call->reply[2] = newstatus;
808 call->reply[3] = newcb;
809 call->expected_version = current_data_version + 1;
810 call->want_reply_time = true;
812 /* marshall the parameters */
814 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
815 *bp++ = htonl(vnode->fid.vid);
816 *bp++ = htonl(vnode->fid.vnode);
817 *bp++ = htonl(vnode->fid.unique);
818 *bp++ = htonl(namesz);
819 memcpy(bp, name, namesz);
820 bp = (void *) bp + namesz;
822 memset(bp, 0, padsz);
823 bp = (void *) bp + padsz;
825 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
826 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
827 *bp++ = 0; /* owner */
828 *bp++ = 0; /* group */
829 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
830 *bp++ = 0; /* segment size */
832 afs_use_fs_server(call, fc->cbi);
833 trace_afs_make_fs_call1(call, &vnode->fid, name);
834 afs_make_call(&fc->ac, call, GFP_NOFS);
835 return afs_wait_for_call_to_complete(call, &fc->ac);
839 * deliver reply data to an FS.RemoveFile or FS.RemoveDir
841 static int afs_deliver_fs_remove(struct afs_call *call)
843 struct afs_vnode *vnode = call->reply[0];
847 _enter("{%u}", call->unmarshall);
849 ret = afs_transfer_reply(call);
853 /* unmarshall the reply once we've received all of it */
855 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
856 &call->expected_version, NULL);
859 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
861 _leave(" = 0 [done]");
866 * FS.RemoveDir/FS.RemoveFile operation type
868 static const struct afs_call_type afs_RXFSRemoveFile = {
869 .name = "FS.RemoveFile",
870 .op = afs_FS_RemoveFile,
871 .deliver = afs_deliver_fs_remove,
872 .destructor = afs_flat_call_destructor,
875 static const struct afs_call_type afs_RXFSRemoveDir = {
876 .name = "FS.RemoveDir",
877 .op = afs_FS_RemoveDir,
878 .deliver = afs_deliver_fs_remove,
879 .destructor = afs_flat_call_destructor,
883 * remove a file or directory
885 int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
886 const char *name, bool isdir, u64 current_data_version)
888 struct afs_vnode *dvnode = fc->vnode;
889 struct afs_call *call;
890 struct afs_net *net = afs_v2net(dvnode);
891 size_t namesz, reqsz, padsz;
894 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
895 return yfs_fs_remove(fc, vnode, name, isdir, current_data_version);
899 namesz = strlen(name);
900 padsz = (4 - (namesz & 3)) & 3;
901 reqsz = (5 * 4) + namesz + padsz;
903 call = afs_alloc_flat_call(
904 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
905 reqsz, (21 + 6) * 4);
910 call->reply[0] = dvnode;
911 call->reply[1] = vnode;
912 call->expected_version = current_data_version + 1;
914 /* marshall the parameters */
916 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
917 *bp++ = htonl(dvnode->fid.vid);
918 *bp++ = htonl(dvnode->fid.vnode);
919 *bp++ = htonl(dvnode->fid.unique);
920 *bp++ = htonl(namesz);
921 memcpy(bp, name, namesz);
922 bp = (void *) bp + namesz;
924 memset(bp, 0, padsz);
925 bp = (void *) bp + padsz;
928 afs_use_fs_server(call, fc->cbi);
929 trace_afs_make_fs_call1(call, &dvnode->fid, name);
930 afs_make_call(&fc->ac, call, GFP_NOFS);
931 return afs_wait_for_call_to_complete(call, &fc->ac);
935 * deliver reply data to an FS.Link
937 static int afs_deliver_fs_link(struct afs_call *call)
939 struct afs_vnode *dvnode = call->reply[0], *vnode = call->reply[1];
943 _enter("{%u}", call->unmarshall);
945 ret = afs_transfer_reply(call);
949 /* unmarshall the reply once we've received all of it */
951 ret = afs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
954 ret = afs_decode_status(call, &bp, &dvnode->status, dvnode,
955 &call->expected_version, NULL);
958 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
960 _leave(" = 0 [done]");
965 * FS.Link operation type
967 static const struct afs_call_type afs_RXFSLink = {
970 .deliver = afs_deliver_fs_link,
971 .destructor = afs_flat_call_destructor,
977 int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
978 const char *name, u64 current_data_version)
980 struct afs_vnode *dvnode = fc->vnode;
981 struct afs_call *call;
982 struct afs_net *net = afs_v2net(vnode);
983 size_t namesz, reqsz, padsz;
986 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
987 return yfs_fs_link(fc, vnode, name, current_data_version);
991 namesz = strlen(name);
992 padsz = (4 - (namesz & 3)) & 3;
993 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
995 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
1000 call->reply[0] = dvnode;
1001 call->reply[1] = vnode;
1002 call->expected_version = current_data_version + 1;
1004 /* marshall the parameters */
1006 *bp++ = htonl(FSLINK);
1007 *bp++ = htonl(dvnode->fid.vid);
1008 *bp++ = htonl(dvnode->fid.vnode);
1009 *bp++ = htonl(dvnode->fid.unique);
1010 *bp++ = htonl(namesz);
1011 memcpy(bp, name, namesz);
1012 bp = (void *) bp + namesz;
1014 memset(bp, 0, padsz);
1015 bp = (void *) bp + padsz;
1017 *bp++ = htonl(vnode->fid.vid);
1018 *bp++ = htonl(vnode->fid.vnode);
1019 *bp++ = htonl(vnode->fid.unique);
1021 afs_use_fs_server(call, fc->cbi);
1022 trace_afs_make_fs_call1(call, &vnode->fid, name);
1023 afs_make_call(&fc->ac, call, GFP_NOFS);
1024 return afs_wait_for_call_to_complete(call, &fc->ac);
1028 * deliver reply data to an FS.Symlink
1030 static int afs_deliver_fs_symlink(struct afs_call *call)
1032 struct afs_vnode *vnode = call->reply[0];
1036 _enter("{%u}", call->unmarshall);
1038 ret = afs_transfer_reply(call);
1042 /* unmarshall the reply once we've received all of it */
1044 xdr_decode_AFSFid(&bp, call->reply[1]);
1045 ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
1048 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1049 &call->expected_version, NULL);
1052 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1054 _leave(" = 0 [done]");
1059 * FS.Symlink operation type
1061 static const struct afs_call_type afs_RXFSSymlink = {
1062 .name = "FS.Symlink",
1063 .op = afs_FS_Symlink,
1064 .deliver = afs_deliver_fs_symlink,
1065 .destructor = afs_flat_call_destructor,
1069 * create a symbolic link
1071 int afs_fs_symlink(struct afs_fs_cursor *fc,
1073 const char *contents,
1074 u64 current_data_version,
1075 struct afs_fid *newfid,
1076 struct afs_file_status *newstatus)
1078 struct afs_vnode *vnode = fc->vnode;
1079 struct afs_call *call;
1080 struct afs_net *net = afs_v2net(vnode);
1081 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
1084 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1085 return yfs_fs_symlink(fc, name, contents, current_data_version,
1090 namesz = strlen(name);
1091 padsz = (4 - (namesz & 3)) & 3;
1093 c_namesz = strlen(contents);
1094 c_padsz = (4 - (c_namesz & 3)) & 3;
1096 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
1098 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
1099 (3 + 21 + 21 + 6) * 4);
1103 call->key = fc->key;
1104 call->reply[0] = vnode;
1105 call->reply[1] = newfid;
1106 call->reply[2] = newstatus;
1107 call->expected_version = current_data_version + 1;
1109 /* marshall the parameters */
1111 *bp++ = htonl(FSSYMLINK);
1112 *bp++ = htonl(vnode->fid.vid);
1113 *bp++ = htonl(vnode->fid.vnode);
1114 *bp++ = htonl(vnode->fid.unique);
1115 *bp++ = htonl(namesz);
1116 memcpy(bp, name, namesz);
1117 bp = (void *) bp + namesz;
1119 memset(bp, 0, padsz);
1120 bp = (void *) bp + padsz;
1122 *bp++ = htonl(c_namesz);
1123 memcpy(bp, contents, c_namesz);
1124 bp = (void *) bp + c_namesz;
1126 memset(bp, 0, c_padsz);
1127 bp = (void *) bp + c_padsz;
1129 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
1130 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1131 *bp++ = 0; /* owner */
1132 *bp++ = 0; /* group */
1133 *bp++ = htonl(S_IRWXUGO); /* unix mode */
1134 *bp++ = 0; /* segment size */
1136 afs_use_fs_server(call, fc->cbi);
1137 trace_afs_make_fs_call1(call, &vnode->fid, name);
1138 afs_make_call(&fc->ac, call, GFP_NOFS);
1139 return afs_wait_for_call_to_complete(call, &fc->ac);
1143 * deliver reply data to an FS.Rename
1145 static int afs_deliver_fs_rename(struct afs_call *call)
1147 struct afs_vnode *orig_dvnode = call->reply[0], *new_dvnode = call->reply[1];
1151 _enter("{%u}", call->unmarshall);
1153 ret = afs_transfer_reply(call);
1157 /* unmarshall the reply once we've received all of it */
1159 ret = afs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1160 &call->expected_version, NULL);
1163 if (new_dvnode != orig_dvnode) {
1164 ret = afs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1165 &call->expected_version_2, NULL);
1169 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1171 _leave(" = 0 [done]");
1176 * FS.Rename operation type
1178 static const struct afs_call_type afs_RXFSRename = {
1179 .name = "FS.Rename",
1180 .op = afs_FS_Rename,
1181 .deliver = afs_deliver_fs_rename,
1182 .destructor = afs_flat_call_destructor,
1186 * create a symbolic link
1188 int afs_fs_rename(struct afs_fs_cursor *fc,
1189 const char *orig_name,
1190 struct afs_vnode *new_dvnode,
1191 const char *new_name,
1192 u64 current_orig_data_version,
1193 u64 current_new_data_version)
1195 struct afs_vnode *orig_dvnode = fc->vnode;
1196 struct afs_call *call;
1197 struct afs_net *net = afs_v2net(orig_dvnode);
1198 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1201 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1202 return yfs_fs_rename(fc, orig_name,
1203 new_dvnode, new_name,
1204 current_orig_data_version,
1205 current_new_data_version);
1209 o_namesz = strlen(orig_name);
1210 o_padsz = (4 - (o_namesz & 3)) & 3;
1212 n_namesz = strlen(new_name);
1213 n_padsz = (4 - (n_namesz & 3)) & 3;
1216 4 + o_namesz + o_padsz +
1218 4 + n_namesz + n_padsz;
1220 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1224 call->key = fc->key;
1225 call->reply[0] = orig_dvnode;
1226 call->reply[1] = new_dvnode;
1227 call->expected_version = current_orig_data_version + 1;
1228 call->expected_version_2 = current_new_data_version + 1;
1230 /* marshall the parameters */
1232 *bp++ = htonl(FSRENAME);
1233 *bp++ = htonl(orig_dvnode->fid.vid);
1234 *bp++ = htonl(orig_dvnode->fid.vnode);
1235 *bp++ = htonl(orig_dvnode->fid.unique);
1236 *bp++ = htonl(o_namesz);
1237 memcpy(bp, orig_name, o_namesz);
1238 bp = (void *) bp + o_namesz;
1240 memset(bp, 0, o_padsz);
1241 bp = (void *) bp + o_padsz;
1244 *bp++ = htonl(new_dvnode->fid.vid);
1245 *bp++ = htonl(new_dvnode->fid.vnode);
1246 *bp++ = htonl(new_dvnode->fid.unique);
1247 *bp++ = htonl(n_namesz);
1248 memcpy(bp, new_name, n_namesz);
1249 bp = (void *) bp + n_namesz;
1251 memset(bp, 0, n_padsz);
1252 bp = (void *) bp + n_padsz;
1255 afs_use_fs_server(call, fc->cbi);
1256 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1257 afs_make_call(&fc->ac, call, GFP_NOFS);
1258 return afs_wait_for_call_to_complete(call, &fc->ac);
1262 * deliver reply data to an FS.StoreData
1264 static int afs_deliver_fs_store_data(struct afs_call *call)
1266 struct afs_vnode *vnode = call->reply[0];
1272 ret = afs_transfer_reply(call);
1276 /* unmarshall the reply once we've received all of it */
1278 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1279 &call->expected_version, NULL);
1282 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1284 afs_pages_written_back(vnode, call);
1286 _leave(" = 0 [done]");
1291 * FS.StoreData operation type
1293 static const struct afs_call_type afs_RXFSStoreData = {
1294 .name = "FS.StoreData",
1295 .op = afs_FS_StoreData,
1296 .deliver = afs_deliver_fs_store_data,
1297 .destructor = afs_flat_call_destructor,
1300 static const struct afs_call_type afs_RXFSStoreData64 = {
1301 .name = "FS.StoreData64",
1302 .op = afs_FS_StoreData64,
1303 .deliver = afs_deliver_fs_store_data,
1304 .destructor = afs_flat_call_destructor,
1308 * store a set of pages to a very large file
1310 static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1311 struct address_space *mapping,
1312 pgoff_t first, pgoff_t last,
1313 unsigned offset, unsigned to,
1314 loff_t size, loff_t pos, loff_t i_size)
1316 struct afs_vnode *vnode = fc->vnode;
1317 struct afs_call *call;
1318 struct afs_net *net = afs_v2net(vnode);
1321 _enter(",%x,{%llx:%llu},,",
1322 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1324 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
1325 (4 + 6 + 3 * 2) * 4,
1330 call->key = fc->key;
1331 call->mapping = mapping;
1332 call->reply[0] = vnode;
1333 call->first = first;
1335 call->first_offset = offset;
1337 call->send_pages = true;
1338 call->expected_version = vnode->status.data_version + 1;
1340 /* marshall the parameters */
1342 *bp++ = htonl(FSSTOREDATA64);
1343 *bp++ = htonl(vnode->fid.vid);
1344 *bp++ = htonl(vnode->fid.vnode);
1345 *bp++ = htonl(vnode->fid.unique);
1347 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1348 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1349 *bp++ = 0; /* owner */
1350 *bp++ = 0; /* group */
1351 *bp++ = 0; /* unix mode */
1352 *bp++ = 0; /* segment size */
1354 *bp++ = htonl(pos >> 32);
1355 *bp++ = htonl((u32) pos);
1356 *bp++ = htonl(size >> 32);
1357 *bp++ = htonl((u32) size);
1358 *bp++ = htonl(i_size >> 32);
1359 *bp++ = htonl((u32) i_size);
1361 trace_afs_make_fs_call(call, &vnode->fid);
1362 afs_make_call(&fc->ac, call, GFP_NOFS);
1363 return afs_wait_for_call_to_complete(call, &fc->ac);
1367 * store a set of pages
1369 int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1370 pgoff_t first, pgoff_t last,
1371 unsigned offset, unsigned to)
1373 struct afs_vnode *vnode = fc->vnode;
1374 struct afs_call *call;
1375 struct afs_net *net = afs_v2net(vnode);
1376 loff_t size, pos, i_size;
1379 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1380 return yfs_fs_store_data(fc, mapping, first, last, offset, to);
1382 _enter(",%x,{%llx:%llu},,",
1383 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1385 size = (loff_t)to - (loff_t)offset;
1387 size += (loff_t)(last - first) << PAGE_SHIFT;
1388 pos = (loff_t)first << PAGE_SHIFT;
1391 i_size = i_size_read(&vnode->vfs_inode);
1392 if (pos + size > i_size)
1393 i_size = size + pos;
1395 _debug("size %llx, at %llx, i_size %llx",
1396 (unsigned long long) size, (unsigned long long) pos,
1397 (unsigned long long) i_size);
1399 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1400 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
1403 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1409 call->key = fc->key;
1410 call->mapping = mapping;
1411 call->reply[0] = vnode;
1412 call->first = first;
1414 call->first_offset = offset;
1416 call->send_pages = true;
1417 call->expected_version = vnode->status.data_version + 1;
1419 /* marshall the parameters */
1421 *bp++ = htonl(FSSTOREDATA);
1422 *bp++ = htonl(vnode->fid.vid);
1423 *bp++ = htonl(vnode->fid.vnode);
1424 *bp++ = htonl(vnode->fid.unique);
1426 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1427 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1428 *bp++ = 0; /* owner */
1429 *bp++ = 0; /* group */
1430 *bp++ = 0; /* unix mode */
1431 *bp++ = 0; /* segment size */
1434 *bp++ = htonl(size);
1435 *bp++ = htonl(i_size);
1437 afs_use_fs_server(call, fc->cbi);
1438 trace_afs_make_fs_call(call, &vnode->fid);
1439 afs_make_call(&fc->ac, call, GFP_NOFS);
1440 return afs_wait_for_call_to_complete(call, &fc->ac);
1444 * deliver reply data to an FS.StoreStatus
1446 static int afs_deliver_fs_store_status(struct afs_call *call)
1448 struct afs_vnode *vnode = call->reply[0];
1454 ret = afs_transfer_reply(call);
1458 /* unmarshall the reply once we've received all of it */
1460 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1461 &call->expected_version, NULL);
1464 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1466 _leave(" = 0 [done]");
1471 * FS.StoreStatus operation type
1473 static const struct afs_call_type afs_RXFSStoreStatus = {
1474 .name = "FS.StoreStatus",
1475 .op = afs_FS_StoreStatus,
1476 .deliver = afs_deliver_fs_store_status,
1477 .destructor = afs_flat_call_destructor,
1480 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1481 .name = "FS.StoreData",
1482 .op = afs_FS_StoreData,
1483 .deliver = afs_deliver_fs_store_status,
1484 .destructor = afs_flat_call_destructor,
1487 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1488 .name = "FS.StoreData64",
1489 .op = afs_FS_StoreData64,
1490 .deliver = afs_deliver_fs_store_status,
1491 .destructor = afs_flat_call_destructor,
1495 * set the attributes on a very large file, using FS.StoreData rather than
1496 * FS.StoreStatus so as to alter the file size also
1498 static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr)
1500 struct afs_vnode *vnode = fc->vnode;
1501 struct afs_call *call;
1502 struct afs_net *net = afs_v2net(vnode);
1505 _enter(",%x,{%llx:%llu},,",
1506 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1508 ASSERT(attr->ia_valid & ATTR_SIZE);
1510 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
1511 (4 + 6 + 3 * 2) * 4,
1516 call->key = fc->key;
1517 call->reply[0] = vnode;
1518 call->expected_version = vnode->status.data_version + 1;
1520 /* marshall the parameters */
1522 *bp++ = htonl(FSSTOREDATA64);
1523 *bp++ = htonl(vnode->fid.vid);
1524 *bp++ = htonl(vnode->fid.vnode);
1525 *bp++ = htonl(vnode->fid.unique);
1527 xdr_encode_AFS_StoreStatus(&bp, attr);
1529 *bp++ = htonl(attr->ia_size >> 32); /* position of start of write */
1530 *bp++ = htonl((u32) attr->ia_size);
1531 *bp++ = 0; /* size of write */
1533 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1534 *bp++ = htonl((u32) attr->ia_size);
1536 afs_use_fs_server(call, fc->cbi);
1537 trace_afs_make_fs_call(call, &vnode->fid);
1538 afs_make_call(&fc->ac, call, GFP_NOFS);
1539 return afs_wait_for_call_to_complete(call, &fc->ac);
1543 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1544 * so as to alter the file size also
1546 static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1548 struct afs_vnode *vnode = fc->vnode;
1549 struct afs_call *call;
1550 struct afs_net *net = afs_v2net(vnode);
1553 _enter(",%x,{%llx:%llu},,",
1554 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1556 ASSERT(attr->ia_valid & ATTR_SIZE);
1557 if (attr->ia_size >> 32)
1558 return afs_fs_setattr_size64(fc, attr);
1560 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1566 call->key = fc->key;
1567 call->reply[0] = vnode;
1568 call->expected_version = vnode->status.data_version + 1;
1570 /* marshall the parameters */
1572 *bp++ = htonl(FSSTOREDATA);
1573 *bp++ = htonl(vnode->fid.vid);
1574 *bp++ = htonl(vnode->fid.vnode);
1575 *bp++ = htonl(vnode->fid.unique);
1577 xdr_encode_AFS_StoreStatus(&bp, attr);
1579 *bp++ = htonl(attr->ia_size); /* position of start of write */
1580 *bp++ = 0; /* size of write */
1581 *bp++ = htonl(attr->ia_size); /* new file length */
1583 afs_use_fs_server(call, fc->cbi);
1584 trace_afs_make_fs_call(call, &vnode->fid);
1585 afs_make_call(&fc->ac, call, GFP_NOFS);
1586 return afs_wait_for_call_to_complete(call, &fc->ac);
1590 * set the attributes on a file, using FS.StoreData if there's a change in file
1591 * size, and FS.StoreStatus otherwise
1593 int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1595 struct afs_vnode *vnode = fc->vnode;
1596 struct afs_call *call;
1597 struct afs_net *net = afs_v2net(vnode);
1600 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1601 return yfs_fs_setattr(fc, attr);
1603 if (attr->ia_valid & ATTR_SIZE)
1604 return afs_fs_setattr_size(fc, attr);
1606 _enter(",%x,{%llx:%llu},,",
1607 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1609 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1615 call->key = fc->key;
1616 call->reply[0] = vnode;
1617 call->expected_version = vnode->status.data_version;
1619 /* marshall the parameters */
1621 *bp++ = htonl(FSSTORESTATUS);
1622 *bp++ = htonl(vnode->fid.vid);
1623 *bp++ = htonl(vnode->fid.vnode);
1624 *bp++ = htonl(vnode->fid.unique);
1626 xdr_encode_AFS_StoreStatus(&bp, attr);
1628 afs_use_fs_server(call, fc->cbi);
1629 trace_afs_make_fs_call(call, &vnode->fid);
1630 afs_make_call(&fc->ac, call, GFP_NOFS);
1631 return afs_wait_for_call_to_complete(call, &fc->ac);
1635 * deliver reply data to an FS.GetVolumeStatus
1637 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1644 _enter("{%u}", call->unmarshall);
1646 switch (call->unmarshall) {
1649 afs_extract_to_buf(call, 12 * 4);
1651 /* extract the returned status record */
1653 _debug("extract status");
1654 ret = afs_extract_data(call, true);
1659 xdr_decode_AFSFetchVolumeStatus(&bp, call->reply[1]);
1661 afs_extract_to_tmp(call);
1663 /* extract the volume name length */
1665 ret = afs_extract_data(call, true);
1669 call->count = ntohl(call->tmp);
1670 _debug("volname length: %u", call->count);
1671 if (call->count >= AFSNAMEMAX)
1672 return afs_protocol_error(call, -EBADMSG,
1673 afs_eproto_volname_len);
1674 size = (call->count + 3) & ~3; /* It's padded */
1675 afs_extract_begin(call, call->reply[2], size);
1678 /* extract the volume name */
1680 _debug("extract volname");
1681 ret = afs_extract_data(call, true);
1687 _debug("volname '%s'", p);
1688 afs_extract_to_tmp(call);
1691 /* extract the offline message length */
1693 ret = afs_extract_data(call, true);
1697 call->count = ntohl(call->tmp);
1698 _debug("offline msg length: %u", call->count);
1699 if (call->count >= AFSNAMEMAX)
1700 return afs_protocol_error(call, -EBADMSG,
1701 afs_eproto_offline_msg_len);
1702 size = (call->count + 3) & ~3; /* It's padded */
1703 afs_extract_begin(call, call->reply[2], size);
1706 /* extract the offline message */
1708 _debug("extract offline");
1709 ret = afs_extract_data(call, true);
1715 _debug("offline '%s'", p);
1717 afs_extract_to_tmp(call);
1720 /* extract the message of the day length */
1722 ret = afs_extract_data(call, true);
1726 call->count = ntohl(call->tmp);
1727 _debug("motd length: %u", call->count);
1728 if (call->count >= AFSNAMEMAX)
1729 return afs_protocol_error(call, -EBADMSG,
1730 afs_eproto_motd_len);
1731 size = (call->count + 3) & ~3; /* It's padded */
1732 afs_extract_begin(call, call->reply[2], size);
1735 /* extract the message of the day */
1737 _debug("extract motd");
1738 ret = afs_extract_data(call, false);
1744 _debug("motd '%s'", p);
1752 _leave(" = 0 [done]");
1757 * destroy an FS.GetVolumeStatus call
1759 static void afs_get_volume_status_call_destructor(struct afs_call *call)
1761 kfree(call->reply[2]);
1762 call->reply[2] = NULL;
1763 afs_flat_call_destructor(call);
1767 * FS.GetVolumeStatus operation type
1769 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1770 .name = "FS.GetVolumeStatus",
1771 .op = afs_FS_GetVolumeStatus,
1772 .deliver = afs_deliver_fs_get_volume_status,
1773 .destructor = afs_get_volume_status_call_destructor,
1777 * fetch the status of a volume
1779 int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1780 struct afs_volume_status *vs)
1782 struct afs_vnode *vnode = fc->vnode;
1783 struct afs_call *call;
1784 struct afs_net *net = afs_v2net(vnode);
1788 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1789 return yfs_fs_get_volume_status(fc, vs);
1793 tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1797 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
1803 call->key = fc->key;
1804 call->reply[0] = vnode;
1805 call->reply[1] = vs;
1806 call->reply[2] = tmpbuf;
1808 /* marshall the parameters */
1810 bp[0] = htonl(FSGETVOLUMESTATUS);
1811 bp[1] = htonl(vnode->fid.vid);
1813 afs_use_fs_server(call, fc->cbi);
1814 trace_afs_make_fs_call(call, &vnode->fid);
1815 afs_make_call(&fc->ac, call, GFP_NOFS);
1816 return afs_wait_for_call_to_complete(call, &fc->ac);
1820 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1822 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1827 _enter("{%u}", call->unmarshall);
1829 ret = afs_transfer_reply(call);
1833 /* unmarshall the reply once we've received all of it */
1835 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1837 _leave(" = 0 [done]");
1842 * FS.SetLock operation type
1844 static const struct afs_call_type afs_RXFSSetLock = {
1845 .name = "FS.SetLock",
1846 .op = afs_FS_SetLock,
1847 .deliver = afs_deliver_fs_xxxx_lock,
1848 .done = afs_lock_op_done,
1849 .destructor = afs_flat_call_destructor,
1853 * FS.ExtendLock operation type
1855 static const struct afs_call_type afs_RXFSExtendLock = {
1856 .name = "FS.ExtendLock",
1857 .op = afs_FS_ExtendLock,
1858 .deliver = afs_deliver_fs_xxxx_lock,
1859 .done = afs_lock_op_done,
1860 .destructor = afs_flat_call_destructor,
1864 * FS.ReleaseLock operation type
1866 static const struct afs_call_type afs_RXFSReleaseLock = {
1867 .name = "FS.ReleaseLock",
1868 .op = afs_FS_ReleaseLock,
1869 .deliver = afs_deliver_fs_xxxx_lock,
1870 .destructor = afs_flat_call_destructor,
1874 * Set a lock on a file
1876 int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1878 struct afs_vnode *vnode = fc->vnode;
1879 struct afs_call *call;
1880 struct afs_net *net = afs_v2net(vnode);
1883 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1884 return yfs_fs_set_lock(fc, type);
1888 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1892 call->key = fc->key;
1893 call->reply[0] = vnode;
1894 call->want_reply_time = true;
1896 /* marshall the parameters */
1898 *bp++ = htonl(FSSETLOCK);
1899 *bp++ = htonl(vnode->fid.vid);
1900 *bp++ = htonl(vnode->fid.vnode);
1901 *bp++ = htonl(vnode->fid.unique);
1902 *bp++ = htonl(type);
1904 afs_use_fs_server(call, fc->cbi);
1905 trace_afs_make_fs_calli(call, &vnode->fid, type);
1906 afs_make_call(&fc->ac, call, GFP_NOFS);
1907 return afs_wait_for_call_to_complete(call, &fc->ac);
1911 * extend a lock on a file
1913 int afs_fs_extend_lock(struct afs_fs_cursor *fc)
1915 struct afs_vnode *vnode = fc->vnode;
1916 struct afs_call *call;
1917 struct afs_net *net = afs_v2net(vnode);
1920 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1921 return yfs_fs_extend_lock(fc);
1925 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1929 call->key = fc->key;
1930 call->reply[0] = vnode;
1931 call->want_reply_time = true;
1933 /* marshall the parameters */
1935 *bp++ = htonl(FSEXTENDLOCK);
1936 *bp++ = htonl(vnode->fid.vid);
1937 *bp++ = htonl(vnode->fid.vnode);
1938 *bp++ = htonl(vnode->fid.unique);
1940 afs_use_fs_server(call, fc->cbi);
1941 trace_afs_make_fs_call(call, &vnode->fid);
1942 afs_make_call(&fc->ac, call, GFP_NOFS);
1943 return afs_wait_for_call_to_complete(call, &fc->ac);
1947 * release a lock on a file
1949 int afs_fs_release_lock(struct afs_fs_cursor *fc)
1951 struct afs_vnode *vnode = fc->vnode;
1952 struct afs_call *call;
1953 struct afs_net *net = afs_v2net(vnode);
1956 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1957 return yfs_fs_release_lock(fc);
1961 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1965 call->key = fc->key;
1966 call->reply[0] = vnode;
1968 /* marshall the parameters */
1970 *bp++ = htonl(FSRELEASELOCK);
1971 *bp++ = htonl(vnode->fid.vid);
1972 *bp++ = htonl(vnode->fid.vnode);
1973 *bp++ = htonl(vnode->fid.unique);
1975 afs_use_fs_server(call, fc->cbi);
1976 trace_afs_make_fs_call(call, &vnode->fid);
1977 afs_make_call(&fc->ac, call, GFP_NOFS);
1978 return afs_wait_for_call_to_complete(call, &fc->ac);
1982 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1984 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1986 return afs_transfer_reply(call);
1990 * FS.GiveUpAllCallBacks operation type
1992 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1993 .name = "FS.GiveUpAllCallBacks",
1994 .op = afs_FS_GiveUpAllCallBacks,
1995 .deliver = afs_deliver_fs_give_up_all_callbacks,
1996 .destructor = afs_flat_call_destructor,
2000 * Flush all the callbacks we have on a server.
2002 int afs_fs_give_up_all_callbacks(struct afs_net *net,
2003 struct afs_server *server,
2004 struct afs_addr_cursor *ac,
2007 struct afs_call *call;
2012 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
2018 /* marshall the parameters */
2020 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
2022 /* Can't take a ref on server */
2023 afs_make_call(ac, call, GFP_NOFS);
2024 return afs_wait_for_call_to_complete(call, ac);
2028 * Deliver reply data to an FS.GetCapabilities operation.
2030 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
2035 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
2037 switch (call->unmarshall) {
2039 afs_extract_to_tmp(call);
2042 /* Extract the capabilities word count */
2044 ret = afs_extract_data(call, true);
2048 count = ntohl(call->tmp);
2050 call->count = count;
2051 call->count2 = count;
2052 iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
2055 /* Extract capabilities words */
2057 ret = afs_extract_data(call, false);
2061 /* TODO: Examine capabilities */
2067 _leave(" = 0 [done]");
2071 static void afs_destroy_fs_get_capabilities(struct afs_call *call)
2073 struct afs_server *server = call->reply[0];
2075 afs_put_server(call->net, server);
2076 afs_flat_call_destructor(call);
2080 * FS.GetCapabilities operation type
2082 static const struct afs_call_type afs_RXFSGetCapabilities = {
2083 .name = "FS.GetCapabilities",
2084 .op = afs_FS_GetCapabilities,
2085 .deliver = afs_deliver_fs_get_capabilities,
2086 .done = afs_fileserver_probe_result,
2087 .destructor = afs_destroy_fs_get_capabilities,
2091 * Probe a fileserver for the capabilities that it supports. This can
2092 * return up to 196 words.
2094 struct afs_call *afs_fs_get_capabilities(struct afs_net *net,
2095 struct afs_server *server,
2096 struct afs_addr_cursor *ac,
2098 unsigned int server_index)
2100 struct afs_call *call;
2105 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
2107 return ERR_PTR(-ENOMEM);
2110 call->reply[0] = afs_get_server(server);
2111 call->reply[1] = (void *)(long)server_index;
2112 call->upgrade = true;
2113 call->want_reply_time = true;
2116 /* marshall the parameters */
2118 *bp++ = htonl(FSGETCAPABILITIES);
2120 /* Can't take a ref on server */
2121 trace_afs_make_fs_call(call, NULL);
2122 afs_make_call(ac, call, GFP_NOFS);
2127 * Deliver reply data to an FS.FetchStatus with no vnode.
2129 static int afs_deliver_fs_fetch_status(struct afs_call *call)
2131 struct afs_file_status *status = call->reply[1];
2132 struct afs_callback *callback = call->reply[2];
2133 struct afs_volsync *volsync = call->reply[3];
2134 struct afs_fid *fid = call->reply[0];
2138 ret = afs_transfer_reply(call);
2142 _enter("{%llx:%llu}", fid->vid, fid->vnode);
2144 /* unmarshall the reply once we've received all of it */
2146 ret = afs_decode_status(call, &bp, status, NULL,
2147 &call->expected_version, NULL);
2150 xdr_decode_AFSCallBack_raw(call, &bp, callback);
2151 xdr_decode_AFSVolSync(&bp, volsync);
2153 _leave(" = 0 [done]");
2158 * FS.FetchStatus operation type
2160 static const struct afs_call_type afs_RXFSFetchStatus = {
2161 .name = "FS.FetchStatus",
2162 .op = afs_FS_FetchStatus,
2163 .deliver = afs_deliver_fs_fetch_status,
2164 .destructor = afs_flat_call_destructor,
2168 * Fetch the status information for a fid without needing a vnode handle.
2170 int afs_fs_fetch_status(struct afs_fs_cursor *fc,
2171 struct afs_net *net,
2172 struct afs_fid *fid,
2173 struct afs_file_status *status,
2174 struct afs_callback *callback,
2175 struct afs_volsync *volsync)
2177 struct afs_call *call;
2180 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2181 return yfs_fs_fetch_status(fc, net, fid, status, callback, volsync);
2183 _enter(",%x,{%llx:%llu},,",
2184 key_serial(fc->key), fid->vid, fid->vnode);
2186 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
2188 fc->ac.error = -ENOMEM;
2192 call->key = fc->key;
2193 call->reply[0] = fid;
2194 call->reply[1] = status;
2195 call->reply[2] = callback;
2196 call->reply[3] = volsync;
2197 call->expected_version = 1; /* vnode->status.data_version */
2198 call->want_reply_time = true;
2200 /* marshall the parameters */
2202 bp[0] = htonl(FSFETCHSTATUS);
2203 bp[1] = htonl(fid->vid);
2204 bp[2] = htonl(fid->vnode);
2205 bp[3] = htonl(fid->unique);
2207 call->cb_break = fc->cb_break;
2208 afs_use_fs_server(call, fc->cbi);
2209 trace_afs_make_fs_call(call, fid);
2210 afs_make_call(&fc->ac, call, GFP_NOFS);
2211 return afs_wait_for_call_to_complete(call, &fc->ac);
2215 * Deliver reply data to an FS.InlineBulkStatus call
2217 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2219 struct afs_file_status *statuses;
2220 struct afs_callback *callbacks;
2221 struct afs_vnode *vnode = call->reply[0];
2226 _enter("{%u}", call->unmarshall);
2228 switch (call->unmarshall) {
2230 afs_extract_to_tmp(call);
2233 /* Extract the file status count and array in two steps */
2235 _debug("extract status count");
2236 ret = afs_extract_data(call, true);
2240 tmp = ntohl(call->tmp);
2241 _debug("status count: %u/%u", tmp, call->count2);
2242 if (tmp != call->count2)
2243 return afs_protocol_error(call, -EBADMSG,
2244 afs_eproto_ibulkst_count);
2249 afs_extract_to_buf(call, 21 * sizeof(__be32));
2252 _debug("extract status array %u", call->count);
2253 ret = afs_extract_data(call, true);
2258 statuses = call->reply[1];
2259 ret = afs_decode_status(call, &bp, &statuses[call->count],
2260 call->count == 0 ? vnode : NULL,
2266 if (call->count < call->count2)
2271 afs_extract_to_tmp(call);
2273 /* Extract the callback count and array in two steps */
2275 _debug("extract CB count");
2276 ret = afs_extract_data(call, true);
2280 tmp = ntohl(call->tmp);
2281 _debug("CB count: %u", tmp);
2282 if (tmp != call->count2)
2283 return afs_protocol_error(call, -EBADMSG,
2284 afs_eproto_ibulkst_cb_count);
2288 afs_extract_to_buf(call, 3 * sizeof(__be32));
2291 _debug("extract CB array");
2292 ret = afs_extract_data(call, true);
2296 _debug("unmarshall CB array");
2298 callbacks = call->reply[2];
2299 callbacks[call->count].version = ntohl(bp[0]);
2300 callbacks[call->count].expires_at = xdr_decode_expiry(call, ntohl(bp[1]));
2301 callbacks[call->count].type = ntohl(bp[2]);
2302 statuses = call->reply[1];
2303 if (call->count == 0 && vnode && statuses[0].abort_code == 0)
2304 xdr_decode_AFSCallBack(call, vnode, &bp);
2306 if (call->count < call->count2)
2309 afs_extract_to_buf(call, 6 * sizeof(__be32));
2313 ret = afs_extract_data(call, false);
2318 xdr_decode_AFSVolSync(&bp, call->reply[3]);
2326 _leave(" = 0 [done]");
2331 * FS.InlineBulkStatus operation type
2333 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2334 .name = "FS.InlineBulkStatus",
2335 .op = afs_FS_InlineBulkStatus,
2336 .deliver = afs_deliver_fs_inline_bulk_status,
2337 .destructor = afs_flat_call_destructor,
2341 * Fetch the status information for up to 50 files
2343 int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2344 struct afs_net *net,
2345 struct afs_fid *fids,
2346 struct afs_file_status *statuses,
2347 struct afs_callback *callbacks,
2348 unsigned int nr_fids,
2349 struct afs_volsync *volsync)
2351 struct afs_call *call;
2355 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2356 return yfs_fs_inline_bulk_status(fc, net, fids, statuses, callbacks,
2359 _enter(",%x,{%llx:%llu},%u",
2360 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2362 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2363 (2 + nr_fids * 3) * 4,
2366 fc->ac.error = -ENOMEM;
2370 call->key = fc->key;
2371 call->reply[0] = NULL; /* vnode for fid[0] */
2372 call->reply[1] = statuses;
2373 call->reply[2] = callbacks;
2374 call->reply[3] = volsync;
2375 call->count2 = nr_fids;
2376 call->want_reply_time = true;
2378 /* marshall the parameters */
2380 *bp++ = htonl(FSINLINEBULKSTATUS);
2381 *bp++ = htonl(nr_fids);
2382 for (i = 0; i < nr_fids; i++) {
2383 *bp++ = htonl(fids[i].vid);
2384 *bp++ = htonl(fids[i].vnode);
2385 *bp++ = htonl(fids[i].unique);
2388 call->cb_break = fc->cb_break;
2389 afs_use_fs_server(call, fc->cbi);
2390 trace_afs_make_fs_call(call, &fids[0]);
2391 afs_make_call(&fc->ac, call, GFP_NOFS);
2392 return afs_wait_for_call_to_complete(call, &fc->ac);
2396 * deliver reply data to an FS.FetchACL
2398 static int afs_deliver_fs_fetch_acl(struct afs_call *call)
2400 struct afs_vnode *vnode = call->reply[1];
2401 struct afs_acl *acl;
2406 _enter("{%u}", call->unmarshall);
2408 switch (call->unmarshall) {
2410 afs_extract_to_tmp(call);
2413 /* extract the returned data length */
2415 ret = afs_extract_data(call, true);
2419 size = call->count2 = ntohl(call->tmp);
2420 size = round_up(size, 4);
2422 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2425 call->reply[0] = acl;
2426 acl->size = call->count2;
2427 afs_extract_begin(call, acl->data, size);
2430 /* extract the returned data */
2432 ret = afs_extract_data(call, true);
2436 afs_extract_to_buf(call, (21 + 6) * 4);
2439 /* extract the metadata */
2441 ret = afs_extract_data(call, false);
2446 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
2447 &vnode->status.data_version, NULL);
2450 xdr_decode_AFSVolSync(&bp, call->reply[2]);
2458 _leave(" = 0 [done]");
2462 static void afs_destroy_fs_fetch_acl(struct afs_call *call)
2464 kfree(call->reply[0]);
2465 afs_flat_call_destructor(call);
2469 * FS.FetchACL operation type
2471 static const struct afs_call_type afs_RXFSFetchACL = {
2472 .name = "FS.FetchACL",
2473 .op = afs_FS_FetchACL,
2474 .deliver = afs_deliver_fs_fetch_acl,
2475 .destructor = afs_destroy_fs_fetch_acl,
2479 * Fetch the ACL for a file.
2481 struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc)
2483 struct afs_vnode *vnode = fc->vnode;
2484 struct afs_call *call;
2485 struct afs_net *net = afs_v2net(vnode);
2488 _enter(",%x,{%llx:%llu},,",
2489 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2491 call = afs_alloc_flat_call(net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2493 fc->ac.error = -ENOMEM;
2494 return ERR_PTR(-ENOMEM);
2497 call->key = fc->key;
2498 call->reply[0] = NULL;
2499 call->reply[1] = vnode;
2500 call->reply[2] = NULL; /* volsync */
2501 call->ret_reply0 = true;
2503 /* marshall the parameters */
2505 bp[0] = htonl(FSFETCHACL);
2506 bp[1] = htonl(vnode->fid.vid);
2507 bp[2] = htonl(vnode->fid.vnode);
2508 bp[3] = htonl(vnode->fid.unique);
2510 call->cb_break = fc->cb_break;
2511 afs_use_fs_server(call, fc->cbi);
2512 trace_afs_make_fs_call(call, &vnode->fid);
2513 afs_make_call(&fc->ac, call, GFP_KERNEL);
2514 return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);