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>
21 static const struct afs_fid afs_zero_fid;
23 static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
25 call->cbi = afs_get_cb_interest(cbi);
29 * decode an AFSFid block
31 static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
33 const __be32 *bp = *_bp;
35 fid->vid = ntohl(*bp++);
36 fid->vnode = ntohl(*bp++);
37 fid->unique = ntohl(*bp++);
42 * Dump a bad file status record.
44 static void xdr_dump_bad(const __be32 *bp)
49 pr_notice("AFS XDR: Bad status record\n");
50 for (i = 0; i < 5 * 4 * 4; i += 16) {
53 pr_notice("%03x: %08x %08x %08x %08x\n",
54 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
58 pr_notice("0x50: %08x\n", ntohl(x[0]));
62 * Update the core inode struct from a returned status record.
64 void afs_update_inode_from_status(struct afs_vnode *vnode,
65 struct afs_file_status *status,
66 const afs_dataversion_t *expected_version,
72 t.tv_sec = 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 {%x:%u} [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 %x:%x:%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 = ntohl(xdr->mtime_client);
198 status->mtime_server = ntohl(xdr->mtime_server);
199 status->lock_count = ntohl(xdr->lock_count);
201 size = (u64)ntohl(xdr->size_lo);
202 size |= (u64)ntohl(xdr->size_hi) << 32;
205 data_version = (u64)ntohl(xdr->data_version_lo);
206 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
207 if (data_version != status->data_version) {
208 status->data_version = data_version;
209 flags |= AFS_VNODE_DATA_CHANGED;
213 read_req->data_version = data_version;
214 read_req->file_size = size;
217 *_bp = (const void *)*_bp + sizeof(*xdr);
220 if (test_bit(AFS_VNODE_UNSET, &vnode->flags))
221 flags |= AFS_VNODE_NOT_YET_SET;
222 afs_update_inode_from_status(vnode, status, expected_version,
230 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
234 * Decode the file status. We need to lock the target vnode if we're going to
235 * update its status so that stat() sees the attributes update atomically.
237 static int afs_decode_status(struct afs_call *call,
239 struct afs_file_status *status,
240 struct afs_vnode *vnode,
241 const afs_dataversion_t *expected_version,
242 struct afs_read *read_req)
247 return xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
248 expected_version, read_req);
250 write_seqlock(&vnode->cb_lock);
251 ret = xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
252 expected_version, read_req);
253 write_sequnlock(&vnode->cb_lock);
258 * decode an AFSCallBack block
260 static void xdr_decode_AFSCallBack(struct afs_call *call,
261 struct afs_vnode *vnode,
264 struct afs_cb_interest *old, *cbi = call->cbi;
265 const __be32 *bp = *_bp;
268 write_seqlock(&vnode->cb_lock);
270 if (call->cb_break == afs_cb_break_sum(vnode, cbi)) {
271 vnode->cb_version = ntohl(*bp++);
272 cb_expiry = ntohl(*bp++);
273 vnode->cb_type = ntohl(*bp++);
274 vnode->cb_expires_at = cb_expiry + ktime_get_real_seconds();
275 old = vnode->cb_interest;
276 if (old != call->cbi) {
277 vnode->cb_interest = cbi;
280 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
285 write_sequnlock(&vnode->cb_lock);
290 static void xdr_decode_AFSCallBack_raw(const __be32 **_bp,
291 struct afs_callback *cb)
293 const __be32 *bp = *_bp;
295 cb->version = ntohl(*bp++);
296 cb->expiry = ntohl(*bp++);
297 cb->type = ntohl(*bp++);
302 * decode an AFSVolSync block
304 static void xdr_decode_AFSVolSync(const __be32 **_bp,
305 struct afs_volsync *volsync)
307 const __be32 *bp = *_bp;
309 volsync->creation = ntohl(*bp++);
319 * encode the requested attributes into an AFSStoreStatus block
321 static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
324 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
327 if (attr->ia_valid & ATTR_MTIME) {
328 mask |= AFS_SET_MTIME;
329 mtime = attr->ia_mtime.tv_sec;
332 if (attr->ia_valid & ATTR_UID) {
333 mask |= AFS_SET_OWNER;
334 owner = from_kuid(&init_user_ns, attr->ia_uid);
337 if (attr->ia_valid & ATTR_GID) {
338 mask |= AFS_SET_GROUP;
339 group = from_kgid(&init_user_ns, attr->ia_gid);
342 if (attr->ia_valid & ATTR_MODE) {
343 mask |= AFS_SET_MODE;
344 mode = attr->ia_mode & S_IALLUGO;
348 *bp++ = htonl(mtime);
349 *bp++ = htonl(owner);
350 *bp++ = htonl(group);
352 *bp++ = 0; /* segment size */
357 * decode an AFSFetchVolumeStatus block
359 static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
360 struct afs_volume_status *vs)
362 const __be32 *bp = *_bp;
364 vs->vid = ntohl(*bp++);
365 vs->parent_id = ntohl(*bp++);
366 vs->online = ntohl(*bp++);
367 vs->in_service = ntohl(*bp++);
368 vs->blessed = ntohl(*bp++);
369 vs->needs_salvage = ntohl(*bp++);
370 vs->type = ntohl(*bp++);
371 vs->min_quota = ntohl(*bp++);
372 vs->max_quota = ntohl(*bp++);
373 vs->blocks_in_use = ntohl(*bp++);
374 vs->part_blocks_avail = ntohl(*bp++);
375 vs->part_max_blocks = ntohl(*bp++);
380 * deliver reply data to an FS.FetchStatus
382 static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
384 struct afs_vnode *vnode = call->reply[0];
388 ret = afs_transfer_reply(call);
392 _enter("{%x:%u}", vnode->fid.vid, vnode->fid.vnode);
394 /* unmarshall the reply once we've received all of it */
396 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
397 &call->expected_version, NULL);
400 xdr_decode_AFSCallBack(call, vnode, &bp);
402 xdr_decode_AFSVolSync(&bp, call->reply[1]);
404 _leave(" = 0 [done]");
409 * FS.FetchStatus operation type
411 static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
412 .name = "FS.FetchStatus(vnode)",
413 .op = afs_FS_FetchStatus,
414 .deliver = afs_deliver_fs_fetch_status_vnode,
415 .destructor = afs_flat_call_destructor,
419 * fetch the status information for a file
421 int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_volsync *volsync,
424 struct afs_vnode *vnode = fc->vnode;
425 struct afs_call *call;
426 struct afs_net *net = afs_v2net(vnode);
429 _enter(",%x,{%x:%u},,",
430 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
432 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
433 16, (21 + 3 + 6) * 4);
435 fc->ac.error = -ENOMEM;
440 call->reply[0] = vnode;
441 call->reply[1] = volsync;
442 call->expected_version = new_inode ? 1 : vnode->status.data_version;
444 /* marshall the parameters */
446 bp[0] = htonl(FSFETCHSTATUS);
447 bp[1] = htonl(vnode->fid.vid);
448 bp[2] = htonl(vnode->fid.vnode);
449 bp[3] = htonl(vnode->fid.unique);
451 call->cb_break = fc->cb_break;
452 afs_use_fs_server(call, fc->cbi);
453 trace_afs_make_fs_call(call, &vnode->fid);
454 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
458 * deliver reply data to an FS.FetchData
460 static int afs_deliver_fs_fetch_data(struct afs_call *call)
462 struct afs_vnode *vnode = call->reply[0];
463 struct afs_read *req = call->reply[2];
468 _enter("{%u,%zu/%llu}",
469 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
471 switch (call->unmarshall) {
475 req->offset = req->pos & (PAGE_SIZE - 1);
477 if (call->operation_ID == FSFETCHDATA64) {
478 afs_extract_to_tmp64(call);
480 call->tmp_u = htonl(0);
481 afs_extract_to_tmp(call);
484 /* extract the returned data length */
486 _debug("extract data length");
487 ret = afs_extract_data(call, true);
491 req->actual_len = be64_to_cpu(call->tmp64);
492 _debug("DATA length: %llu", req->actual_len);
493 req->remain = min(req->len, req->actual_len);
494 if (req->remain == 0)
500 ASSERTCMP(req->index, <, req->nr_pages);
501 if (req->remain > PAGE_SIZE - req->offset)
502 size = PAGE_SIZE - req->offset;
505 call->bvec[0].bv_len = size;
506 call->bvec[0].bv_offset = req->offset;
507 call->bvec[0].bv_page = req->pages[req->index];
508 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
509 ASSERTCMP(size, <=, PAGE_SIZE);
511 /* extract the returned data */
513 _debug("extract data %zu/%llu",
514 iov_iter_count(&call->iter), req->remain);
516 ret = afs_extract_data(call, true);
519 req->remain -= call->bvec[0].bv_len;
520 req->offset += call->bvec[0].bv_len;
521 ASSERTCMP(req->offset, <=, PAGE_SIZE);
522 if (req->offset == PAGE_SIZE) {
525 req->page_done(call, req);
531 ASSERTCMP(req->remain, ==, 0);
532 if (req->actual_len <= req->len)
535 /* Discard any excess data the server gave us */
536 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
537 call->unmarshall = 3;
539 _debug("extract discard %zu/%llu",
540 iov_iter_count(&call->iter), req->actual_len - req->len);
542 ret = afs_extract_data(call, true);
547 call->unmarshall = 4;
548 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
550 /* extract the metadata */
552 ret = afs_extract_data(call, false);
557 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
558 &vnode->status.data_version, req);
561 xdr_decode_AFSCallBack(call, vnode, &bp);
563 xdr_decode_AFSVolSync(&bp, call->reply[1]);
571 for (; req->index < req->nr_pages; req->index++) {
572 if (req->offset < PAGE_SIZE)
573 zero_user_segment(req->pages[req->index],
574 req->offset, PAGE_SIZE);
576 req->page_done(call, req);
580 _leave(" = 0 [done]");
584 static void afs_fetch_data_destructor(struct afs_call *call)
586 struct afs_read *req = call->reply[2];
589 afs_flat_call_destructor(call);
593 * FS.FetchData operation type
595 static const struct afs_call_type afs_RXFSFetchData = {
596 .name = "FS.FetchData",
597 .op = afs_FS_FetchData,
598 .deliver = afs_deliver_fs_fetch_data,
599 .destructor = afs_fetch_data_destructor,
602 static const struct afs_call_type afs_RXFSFetchData64 = {
603 .name = "FS.FetchData64",
604 .op = afs_FS_FetchData64,
605 .deliver = afs_deliver_fs_fetch_data,
606 .destructor = afs_fetch_data_destructor,
610 * fetch data from a very large file
612 static int afs_fs_fetch_data64(struct afs_fs_cursor *fc, struct afs_read *req)
614 struct afs_vnode *vnode = fc->vnode;
615 struct afs_call *call;
616 struct afs_net *net = afs_v2net(vnode);
621 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
626 call->reply[0] = vnode;
627 call->reply[1] = NULL; /* volsync */
628 call->reply[2] = req;
629 call->expected_version = vnode->status.data_version;
631 /* marshall the parameters */
633 bp[0] = htonl(FSFETCHDATA64);
634 bp[1] = htonl(vnode->fid.vid);
635 bp[2] = htonl(vnode->fid.vnode);
636 bp[3] = htonl(vnode->fid.unique);
637 bp[4] = htonl(upper_32_bits(req->pos));
638 bp[5] = htonl(lower_32_bits(req->pos));
640 bp[7] = htonl(lower_32_bits(req->len));
642 refcount_inc(&req->usage);
643 call->cb_break = fc->cb_break;
644 afs_use_fs_server(call, fc->cbi);
645 trace_afs_make_fs_call(call, &vnode->fid);
646 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
650 * fetch data from a file
652 int afs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
654 struct afs_vnode *vnode = fc->vnode;
655 struct afs_call *call;
656 struct afs_net *net = afs_v2net(vnode);
659 if (upper_32_bits(req->pos) ||
660 upper_32_bits(req->len) ||
661 upper_32_bits(req->pos + req->len))
662 return afs_fs_fetch_data64(fc, req);
666 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
671 call->reply[0] = vnode;
672 call->reply[1] = NULL; /* volsync */
673 call->reply[2] = req;
674 call->expected_version = vnode->status.data_version;
676 /* marshall the parameters */
678 bp[0] = htonl(FSFETCHDATA);
679 bp[1] = htonl(vnode->fid.vid);
680 bp[2] = htonl(vnode->fid.vnode);
681 bp[3] = htonl(vnode->fid.unique);
682 bp[4] = htonl(lower_32_bits(req->pos));
683 bp[5] = htonl(lower_32_bits(req->len));
685 refcount_inc(&req->usage);
686 call->cb_break = fc->cb_break;
687 afs_use_fs_server(call, fc->cbi);
688 trace_afs_make_fs_call(call, &vnode->fid);
689 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
693 * deliver reply data to an FS.CreateFile or an FS.MakeDir
695 static int afs_deliver_fs_create_vnode(struct afs_call *call)
697 struct afs_vnode *vnode = call->reply[0];
701 _enter("{%u}", call->unmarshall);
703 ret = afs_transfer_reply(call);
707 /* unmarshall the reply once we've received all of it */
709 xdr_decode_AFSFid(&bp, call->reply[1]);
710 ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
713 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
714 &call->expected_version, NULL);
717 xdr_decode_AFSCallBack_raw(&bp, call->reply[3]);
718 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
720 _leave(" = 0 [done]");
725 * FS.CreateFile and FS.MakeDir operation type
727 static const struct afs_call_type afs_RXFSCreateFile = {
728 .name = "FS.CreateFile",
729 .op = afs_FS_CreateFile,
730 .deliver = afs_deliver_fs_create_vnode,
731 .destructor = afs_flat_call_destructor,
734 static const struct afs_call_type afs_RXFSMakeDir = {
735 .name = "FS.MakeDir",
736 .op = afs_FS_MakeDir,
737 .deliver = afs_deliver_fs_create_vnode,
738 .destructor = afs_flat_call_destructor,
742 * create a file or make a directory
744 int afs_fs_create(struct afs_fs_cursor *fc,
747 u64 current_data_version,
748 struct afs_fid *newfid,
749 struct afs_file_status *newstatus,
750 struct afs_callback *newcb)
752 struct afs_vnode *vnode = fc->vnode;
753 struct afs_call *call;
754 struct afs_net *net = afs_v2net(vnode);
755 size_t namesz, reqsz, padsz;
760 namesz = strlen(name);
761 padsz = (4 - (namesz & 3)) & 3;
762 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
764 call = afs_alloc_flat_call(
765 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
766 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
771 call->reply[0] = vnode;
772 call->reply[1] = newfid;
773 call->reply[2] = newstatus;
774 call->reply[3] = newcb;
775 call->expected_version = current_data_version + 1;
777 /* marshall the parameters */
779 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
780 *bp++ = htonl(vnode->fid.vid);
781 *bp++ = htonl(vnode->fid.vnode);
782 *bp++ = htonl(vnode->fid.unique);
783 *bp++ = htonl(namesz);
784 memcpy(bp, name, namesz);
785 bp = (void *) bp + namesz;
787 memset(bp, 0, padsz);
788 bp = (void *) bp + padsz;
790 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
791 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
792 *bp++ = 0; /* owner */
793 *bp++ = 0; /* group */
794 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
795 *bp++ = 0; /* segment size */
797 afs_use_fs_server(call, fc->cbi);
798 trace_afs_make_fs_call(call, &vnode->fid);
799 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
803 * deliver reply data to an FS.RemoveFile or FS.RemoveDir
805 static int afs_deliver_fs_remove(struct afs_call *call)
807 struct afs_vnode *vnode = call->reply[0];
811 _enter("{%u}", call->unmarshall);
813 ret = afs_transfer_reply(call);
817 /* unmarshall the reply once we've received all of it */
819 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
820 &call->expected_version, NULL);
823 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
825 _leave(" = 0 [done]");
830 * FS.RemoveDir/FS.RemoveFile operation type
832 static const struct afs_call_type afs_RXFSRemoveFile = {
833 .name = "FS.RemoveFile",
834 .op = afs_FS_RemoveFile,
835 .deliver = afs_deliver_fs_remove,
836 .destructor = afs_flat_call_destructor,
839 static const struct afs_call_type afs_RXFSRemoveDir = {
840 .name = "FS.RemoveDir",
841 .op = afs_FS_RemoveDir,
842 .deliver = afs_deliver_fs_remove,
843 .destructor = afs_flat_call_destructor,
847 * remove a file or directory
849 int afs_fs_remove(struct afs_fs_cursor *fc, const char *name, bool isdir,
850 u64 current_data_version)
852 struct afs_vnode *vnode = fc->vnode;
853 struct afs_call *call;
854 struct afs_net *net = afs_v2net(vnode);
855 size_t namesz, reqsz, padsz;
860 namesz = strlen(name);
861 padsz = (4 - (namesz & 3)) & 3;
862 reqsz = (5 * 4) + namesz + padsz;
864 call = afs_alloc_flat_call(
865 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
866 reqsz, (21 + 6) * 4);
871 call->reply[0] = vnode;
872 call->expected_version = current_data_version + 1;
874 /* marshall the parameters */
876 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
877 *bp++ = htonl(vnode->fid.vid);
878 *bp++ = htonl(vnode->fid.vnode);
879 *bp++ = htonl(vnode->fid.unique);
880 *bp++ = htonl(namesz);
881 memcpy(bp, name, namesz);
882 bp = (void *) bp + namesz;
884 memset(bp, 0, padsz);
885 bp = (void *) bp + padsz;
888 afs_use_fs_server(call, fc->cbi);
889 trace_afs_make_fs_call(call, &vnode->fid);
890 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
894 * deliver reply data to an FS.Link
896 static int afs_deliver_fs_link(struct afs_call *call)
898 struct afs_vnode *dvnode = call->reply[0], *vnode = call->reply[1];
902 _enter("{%u}", call->unmarshall);
904 ret = afs_transfer_reply(call);
908 /* unmarshall the reply once we've received all of it */
910 ret = afs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
913 ret = afs_decode_status(call, &bp, &dvnode->status, dvnode,
914 &call->expected_version, NULL);
917 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
919 _leave(" = 0 [done]");
924 * FS.Link operation type
926 static const struct afs_call_type afs_RXFSLink = {
929 .deliver = afs_deliver_fs_link,
930 .destructor = afs_flat_call_destructor,
936 int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
937 const char *name, u64 current_data_version)
939 struct afs_vnode *dvnode = fc->vnode;
940 struct afs_call *call;
941 struct afs_net *net = afs_v2net(vnode);
942 size_t namesz, reqsz, padsz;
947 namesz = strlen(name);
948 padsz = (4 - (namesz & 3)) & 3;
949 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
951 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
956 call->reply[0] = dvnode;
957 call->reply[1] = vnode;
958 call->expected_version = current_data_version + 1;
960 /* marshall the parameters */
962 *bp++ = htonl(FSLINK);
963 *bp++ = htonl(dvnode->fid.vid);
964 *bp++ = htonl(dvnode->fid.vnode);
965 *bp++ = htonl(dvnode->fid.unique);
966 *bp++ = htonl(namesz);
967 memcpy(bp, name, namesz);
968 bp = (void *) bp + namesz;
970 memset(bp, 0, padsz);
971 bp = (void *) bp + padsz;
973 *bp++ = htonl(vnode->fid.vid);
974 *bp++ = htonl(vnode->fid.vnode);
975 *bp++ = htonl(vnode->fid.unique);
977 afs_use_fs_server(call, fc->cbi);
978 trace_afs_make_fs_call(call, &vnode->fid);
979 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
983 * deliver reply data to an FS.Symlink
985 static int afs_deliver_fs_symlink(struct afs_call *call)
987 struct afs_vnode *vnode = call->reply[0];
991 _enter("{%u}", call->unmarshall);
993 ret = afs_transfer_reply(call);
997 /* unmarshall the reply once we've received all of it */
999 xdr_decode_AFSFid(&bp, call->reply[1]);
1000 ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
1003 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1004 &call->expected_version, NULL);
1007 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1009 _leave(" = 0 [done]");
1014 * FS.Symlink operation type
1016 static const struct afs_call_type afs_RXFSSymlink = {
1017 .name = "FS.Symlink",
1018 .op = afs_FS_Symlink,
1019 .deliver = afs_deliver_fs_symlink,
1020 .destructor = afs_flat_call_destructor,
1024 * create a symbolic link
1026 int afs_fs_symlink(struct afs_fs_cursor *fc,
1028 const char *contents,
1029 u64 current_data_version,
1030 struct afs_fid *newfid,
1031 struct afs_file_status *newstatus)
1033 struct afs_vnode *vnode = fc->vnode;
1034 struct afs_call *call;
1035 struct afs_net *net = afs_v2net(vnode);
1036 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
1041 namesz = strlen(name);
1042 padsz = (4 - (namesz & 3)) & 3;
1044 c_namesz = strlen(contents);
1045 c_padsz = (4 - (c_namesz & 3)) & 3;
1047 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
1049 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
1050 (3 + 21 + 21 + 6) * 4);
1054 call->key = fc->key;
1055 call->reply[0] = vnode;
1056 call->reply[1] = newfid;
1057 call->reply[2] = newstatus;
1058 call->expected_version = current_data_version + 1;
1060 /* marshall the parameters */
1062 *bp++ = htonl(FSSYMLINK);
1063 *bp++ = htonl(vnode->fid.vid);
1064 *bp++ = htonl(vnode->fid.vnode);
1065 *bp++ = htonl(vnode->fid.unique);
1066 *bp++ = htonl(namesz);
1067 memcpy(bp, name, namesz);
1068 bp = (void *) bp + namesz;
1070 memset(bp, 0, padsz);
1071 bp = (void *) bp + padsz;
1073 *bp++ = htonl(c_namesz);
1074 memcpy(bp, contents, c_namesz);
1075 bp = (void *) bp + c_namesz;
1077 memset(bp, 0, c_padsz);
1078 bp = (void *) bp + c_padsz;
1080 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
1081 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1082 *bp++ = 0; /* owner */
1083 *bp++ = 0; /* group */
1084 *bp++ = htonl(S_IRWXUGO); /* unix mode */
1085 *bp++ = 0; /* segment size */
1087 afs_use_fs_server(call, fc->cbi);
1088 trace_afs_make_fs_call(call, &vnode->fid);
1089 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1093 * deliver reply data to an FS.Rename
1095 static int afs_deliver_fs_rename(struct afs_call *call)
1097 struct afs_vnode *orig_dvnode = call->reply[0], *new_dvnode = call->reply[1];
1101 _enter("{%u}", call->unmarshall);
1103 ret = afs_transfer_reply(call);
1107 /* unmarshall the reply once we've received all of it */
1109 ret = afs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1110 &call->expected_version, NULL);
1113 if (new_dvnode != orig_dvnode) {
1114 ret = afs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1115 &call->expected_version_2, NULL);
1119 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1121 _leave(" = 0 [done]");
1126 * FS.Rename operation type
1128 static const struct afs_call_type afs_RXFSRename = {
1129 .name = "FS.Rename",
1130 .op = afs_FS_Rename,
1131 .deliver = afs_deliver_fs_rename,
1132 .destructor = afs_flat_call_destructor,
1136 * create a symbolic link
1138 int afs_fs_rename(struct afs_fs_cursor *fc,
1139 const char *orig_name,
1140 struct afs_vnode *new_dvnode,
1141 const char *new_name,
1142 u64 current_orig_data_version,
1143 u64 current_new_data_version)
1145 struct afs_vnode *orig_dvnode = fc->vnode;
1146 struct afs_call *call;
1147 struct afs_net *net = afs_v2net(orig_dvnode);
1148 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1153 o_namesz = strlen(orig_name);
1154 o_padsz = (4 - (o_namesz & 3)) & 3;
1156 n_namesz = strlen(new_name);
1157 n_padsz = (4 - (n_namesz & 3)) & 3;
1160 4 + o_namesz + o_padsz +
1162 4 + n_namesz + n_padsz;
1164 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1168 call->key = fc->key;
1169 call->reply[0] = orig_dvnode;
1170 call->reply[1] = new_dvnode;
1171 call->expected_version = current_orig_data_version + 1;
1172 call->expected_version_2 = current_new_data_version + 1;
1174 /* marshall the parameters */
1176 *bp++ = htonl(FSRENAME);
1177 *bp++ = htonl(orig_dvnode->fid.vid);
1178 *bp++ = htonl(orig_dvnode->fid.vnode);
1179 *bp++ = htonl(orig_dvnode->fid.unique);
1180 *bp++ = htonl(o_namesz);
1181 memcpy(bp, orig_name, o_namesz);
1182 bp = (void *) bp + o_namesz;
1184 memset(bp, 0, o_padsz);
1185 bp = (void *) bp + o_padsz;
1188 *bp++ = htonl(new_dvnode->fid.vid);
1189 *bp++ = htonl(new_dvnode->fid.vnode);
1190 *bp++ = htonl(new_dvnode->fid.unique);
1191 *bp++ = htonl(n_namesz);
1192 memcpy(bp, new_name, n_namesz);
1193 bp = (void *) bp + n_namesz;
1195 memset(bp, 0, n_padsz);
1196 bp = (void *) bp + n_padsz;
1199 afs_use_fs_server(call, fc->cbi);
1200 trace_afs_make_fs_call(call, &orig_dvnode->fid);
1201 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1205 * deliver reply data to an FS.StoreData
1207 static int afs_deliver_fs_store_data(struct afs_call *call)
1209 struct afs_vnode *vnode = call->reply[0];
1215 ret = afs_transfer_reply(call);
1219 /* unmarshall the reply once we've received all of it */
1221 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1222 &call->expected_version, NULL);
1225 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1227 afs_pages_written_back(vnode, call);
1229 _leave(" = 0 [done]");
1234 * FS.StoreData operation type
1236 static const struct afs_call_type afs_RXFSStoreData = {
1237 .name = "FS.StoreData",
1238 .op = afs_FS_StoreData,
1239 .deliver = afs_deliver_fs_store_data,
1240 .destructor = afs_flat_call_destructor,
1243 static const struct afs_call_type afs_RXFSStoreData64 = {
1244 .name = "FS.StoreData64",
1245 .op = afs_FS_StoreData64,
1246 .deliver = afs_deliver_fs_store_data,
1247 .destructor = afs_flat_call_destructor,
1251 * store a set of pages to a very large file
1253 static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1254 struct address_space *mapping,
1255 pgoff_t first, pgoff_t last,
1256 unsigned offset, unsigned to,
1257 loff_t size, loff_t pos, loff_t i_size)
1259 struct afs_vnode *vnode = fc->vnode;
1260 struct afs_call *call;
1261 struct afs_net *net = afs_v2net(vnode);
1264 _enter(",%x,{%x:%u},,",
1265 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1267 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
1268 (4 + 6 + 3 * 2) * 4,
1273 call->key = fc->key;
1274 call->mapping = mapping;
1275 call->reply[0] = vnode;
1276 call->first = first;
1278 call->first_offset = offset;
1280 call->send_pages = true;
1281 call->expected_version = vnode->status.data_version + 1;
1283 /* marshall the parameters */
1285 *bp++ = htonl(FSSTOREDATA64);
1286 *bp++ = htonl(vnode->fid.vid);
1287 *bp++ = htonl(vnode->fid.vnode);
1288 *bp++ = htonl(vnode->fid.unique);
1290 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1291 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1292 *bp++ = 0; /* owner */
1293 *bp++ = 0; /* group */
1294 *bp++ = 0; /* unix mode */
1295 *bp++ = 0; /* segment size */
1297 *bp++ = htonl(pos >> 32);
1298 *bp++ = htonl((u32) pos);
1299 *bp++ = htonl(size >> 32);
1300 *bp++ = htonl((u32) size);
1301 *bp++ = htonl(i_size >> 32);
1302 *bp++ = htonl((u32) i_size);
1304 trace_afs_make_fs_call(call, &vnode->fid);
1305 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1309 * store a set of pages
1311 int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1312 pgoff_t first, pgoff_t last,
1313 unsigned offset, unsigned to)
1315 struct afs_vnode *vnode = fc->vnode;
1316 struct afs_call *call;
1317 struct afs_net *net = afs_v2net(vnode);
1318 loff_t size, pos, i_size;
1321 _enter(",%x,{%x:%u},,",
1322 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1324 size = (loff_t)to - (loff_t)offset;
1326 size += (loff_t)(last - first) << PAGE_SHIFT;
1327 pos = (loff_t)first << PAGE_SHIFT;
1330 i_size = i_size_read(&vnode->vfs_inode);
1331 if (pos + size > i_size)
1332 i_size = size + pos;
1334 _debug("size %llx, at %llx, i_size %llx",
1335 (unsigned long long) size, (unsigned long long) pos,
1336 (unsigned long long) i_size);
1338 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1339 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
1342 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1348 call->key = fc->key;
1349 call->mapping = mapping;
1350 call->reply[0] = vnode;
1351 call->first = first;
1353 call->first_offset = offset;
1355 call->send_pages = true;
1356 call->expected_version = vnode->status.data_version + 1;
1358 /* marshall the parameters */
1360 *bp++ = htonl(FSSTOREDATA);
1361 *bp++ = htonl(vnode->fid.vid);
1362 *bp++ = htonl(vnode->fid.vnode);
1363 *bp++ = htonl(vnode->fid.unique);
1365 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1366 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1367 *bp++ = 0; /* owner */
1368 *bp++ = 0; /* group */
1369 *bp++ = 0; /* unix mode */
1370 *bp++ = 0; /* segment size */
1373 *bp++ = htonl(size);
1374 *bp++ = htonl(i_size);
1376 afs_use_fs_server(call, fc->cbi);
1377 trace_afs_make_fs_call(call, &vnode->fid);
1378 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1382 * deliver reply data to an FS.StoreStatus
1384 static int afs_deliver_fs_store_status(struct afs_call *call)
1386 struct afs_vnode *vnode = call->reply[0];
1392 ret = afs_transfer_reply(call);
1396 /* unmarshall the reply once we've received all of it */
1398 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1399 &call->expected_version, NULL);
1402 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1404 _leave(" = 0 [done]");
1409 * FS.StoreStatus operation type
1411 static const struct afs_call_type afs_RXFSStoreStatus = {
1412 .name = "FS.StoreStatus",
1413 .op = afs_FS_StoreStatus,
1414 .deliver = afs_deliver_fs_store_status,
1415 .destructor = afs_flat_call_destructor,
1418 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1419 .name = "FS.StoreData",
1420 .op = afs_FS_StoreData,
1421 .deliver = afs_deliver_fs_store_status,
1422 .destructor = afs_flat_call_destructor,
1425 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1426 .name = "FS.StoreData64",
1427 .op = afs_FS_StoreData64,
1428 .deliver = afs_deliver_fs_store_status,
1429 .destructor = afs_flat_call_destructor,
1433 * set the attributes on a very large file, using FS.StoreData rather than
1434 * FS.StoreStatus so as to alter the file size also
1436 static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr)
1438 struct afs_vnode *vnode = fc->vnode;
1439 struct afs_call *call;
1440 struct afs_net *net = afs_v2net(vnode);
1443 _enter(",%x,{%x:%u},,",
1444 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1446 ASSERT(attr->ia_valid & ATTR_SIZE);
1448 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
1449 (4 + 6 + 3 * 2) * 4,
1454 call->key = fc->key;
1455 call->reply[0] = vnode;
1456 call->expected_version = vnode->status.data_version + 1;
1458 /* marshall the parameters */
1460 *bp++ = htonl(FSSTOREDATA64);
1461 *bp++ = htonl(vnode->fid.vid);
1462 *bp++ = htonl(vnode->fid.vnode);
1463 *bp++ = htonl(vnode->fid.unique);
1465 xdr_encode_AFS_StoreStatus(&bp, attr);
1467 *bp++ = 0; /* position of start of write */
1469 *bp++ = 0; /* size of write */
1471 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1472 *bp++ = htonl((u32) attr->ia_size);
1474 afs_use_fs_server(call, fc->cbi);
1475 trace_afs_make_fs_call(call, &vnode->fid);
1476 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1480 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1481 * so as to alter the file size also
1483 static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1485 struct afs_vnode *vnode = fc->vnode;
1486 struct afs_call *call;
1487 struct afs_net *net = afs_v2net(vnode);
1490 _enter(",%x,{%x:%u},,",
1491 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1493 ASSERT(attr->ia_valid & ATTR_SIZE);
1494 if (attr->ia_size >> 32)
1495 return afs_fs_setattr_size64(fc, attr);
1497 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1503 call->key = fc->key;
1504 call->reply[0] = vnode;
1505 call->expected_version = vnode->status.data_version + 1;
1507 /* marshall the parameters */
1509 *bp++ = htonl(FSSTOREDATA);
1510 *bp++ = htonl(vnode->fid.vid);
1511 *bp++ = htonl(vnode->fid.vnode);
1512 *bp++ = htonl(vnode->fid.unique);
1514 xdr_encode_AFS_StoreStatus(&bp, attr);
1516 *bp++ = 0; /* position of start of write */
1517 *bp++ = 0; /* size of write */
1518 *bp++ = htonl(attr->ia_size); /* new file length */
1520 afs_use_fs_server(call, fc->cbi);
1521 trace_afs_make_fs_call(call, &vnode->fid);
1522 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1526 * set the attributes on a file, using FS.StoreData if there's a change in file
1527 * size, and FS.StoreStatus otherwise
1529 int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1531 struct afs_vnode *vnode = fc->vnode;
1532 struct afs_call *call;
1533 struct afs_net *net = afs_v2net(vnode);
1536 if (attr->ia_valid & ATTR_SIZE)
1537 return afs_fs_setattr_size(fc, attr);
1539 _enter(",%x,{%x:%u},,",
1540 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1542 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1548 call->key = fc->key;
1549 call->reply[0] = vnode;
1550 call->expected_version = vnode->status.data_version;
1552 /* marshall the parameters */
1554 *bp++ = htonl(FSSTORESTATUS);
1555 *bp++ = htonl(vnode->fid.vid);
1556 *bp++ = htonl(vnode->fid.vnode);
1557 *bp++ = htonl(vnode->fid.unique);
1559 xdr_encode_AFS_StoreStatus(&bp, attr);
1561 afs_use_fs_server(call, fc->cbi);
1562 trace_afs_make_fs_call(call, &vnode->fid);
1563 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1567 * deliver reply data to an FS.GetVolumeStatus
1569 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1576 _enter("{%u}", call->unmarshall);
1578 switch (call->unmarshall) {
1581 afs_extract_to_buf(call, 12 * 4);
1583 /* extract the returned status record */
1585 _debug("extract status");
1586 ret = afs_extract_data(call, true);
1591 xdr_decode_AFSFetchVolumeStatus(&bp, call->reply[1]);
1593 afs_extract_to_tmp(call);
1595 /* extract the volume name length */
1597 ret = afs_extract_data(call, true);
1601 call->count = ntohl(call->tmp);
1602 _debug("volname length: %u", call->count);
1603 if (call->count >= AFSNAMEMAX)
1604 return afs_protocol_error(call, -EBADMSG,
1605 afs_eproto_volname_len);
1606 size = (call->count + 3) & ~3; /* It's padded */
1607 afs_extract_begin(call, call->reply[2], size);
1610 /* extract the volume name */
1612 _debug("extract volname");
1613 ret = afs_extract_data(call, true);
1619 _debug("volname '%s'", p);
1620 afs_extract_to_tmp(call);
1623 /* extract the offline message length */
1625 ret = afs_extract_data(call, true);
1629 call->count = ntohl(call->tmp);
1630 _debug("offline msg length: %u", call->count);
1631 if (call->count >= AFSNAMEMAX)
1632 return afs_protocol_error(call, -EBADMSG,
1633 afs_eproto_offline_msg_len);
1634 size = (call->count + 3) & ~3; /* It's padded */
1635 afs_extract_begin(call, call->reply[2], size);
1638 /* extract the offline message */
1640 _debug("extract offline");
1641 ret = afs_extract_data(call, true);
1647 _debug("offline '%s'", p);
1649 afs_extract_to_tmp(call);
1652 /* extract the message of the day length */
1654 ret = afs_extract_data(call, true);
1658 call->count = ntohl(call->tmp);
1659 _debug("motd length: %u", call->count);
1660 if (call->count >= AFSNAMEMAX)
1661 return afs_protocol_error(call, -EBADMSG,
1662 afs_eproto_motd_len);
1663 size = (call->count + 3) & ~3; /* It's padded */
1664 afs_extract_begin(call, call->reply[2], size);
1667 /* extract the message of the day */
1669 _debug("extract motd");
1670 ret = afs_extract_data(call, false);
1676 _debug("motd '%s'", p);
1684 _leave(" = 0 [done]");
1689 * destroy an FS.GetVolumeStatus call
1691 static void afs_get_volume_status_call_destructor(struct afs_call *call)
1693 kfree(call->reply[2]);
1694 call->reply[2] = NULL;
1695 afs_flat_call_destructor(call);
1699 * FS.GetVolumeStatus operation type
1701 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1702 .name = "FS.GetVolumeStatus",
1703 .op = afs_FS_GetVolumeStatus,
1704 .deliver = afs_deliver_fs_get_volume_status,
1705 .destructor = afs_get_volume_status_call_destructor,
1709 * fetch the status of a volume
1711 int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1712 struct afs_volume_status *vs)
1714 struct afs_vnode *vnode = fc->vnode;
1715 struct afs_call *call;
1716 struct afs_net *net = afs_v2net(vnode);
1722 tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1726 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
1732 call->key = fc->key;
1733 call->reply[0] = vnode;
1734 call->reply[1] = vs;
1735 call->reply[2] = tmpbuf;
1737 /* marshall the parameters */
1739 bp[0] = htonl(FSGETVOLUMESTATUS);
1740 bp[1] = htonl(vnode->fid.vid);
1742 afs_use_fs_server(call, fc->cbi);
1743 trace_afs_make_fs_call(call, &vnode->fid);
1744 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1748 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1750 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1755 _enter("{%u}", call->unmarshall);
1757 ret = afs_transfer_reply(call);
1761 /* unmarshall the reply once we've received all of it */
1763 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1765 _leave(" = 0 [done]");
1770 * FS.SetLock operation type
1772 static const struct afs_call_type afs_RXFSSetLock = {
1773 .name = "FS.SetLock",
1774 .op = afs_FS_SetLock,
1775 .deliver = afs_deliver_fs_xxxx_lock,
1776 .destructor = afs_flat_call_destructor,
1780 * FS.ExtendLock operation type
1782 static const struct afs_call_type afs_RXFSExtendLock = {
1783 .name = "FS.ExtendLock",
1784 .op = afs_FS_ExtendLock,
1785 .deliver = afs_deliver_fs_xxxx_lock,
1786 .destructor = afs_flat_call_destructor,
1790 * FS.ReleaseLock operation type
1792 static const struct afs_call_type afs_RXFSReleaseLock = {
1793 .name = "FS.ReleaseLock",
1794 .op = afs_FS_ReleaseLock,
1795 .deliver = afs_deliver_fs_xxxx_lock,
1796 .destructor = afs_flat_call_destructor,
1800 * Set a lock on a file
1802 int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1804 struct afs_vnode *vnode = fc->vnode;
1805 struct afs_call *call;
1806 struct afs_net *net = afs_v2net(vnode);
1811 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1815 call->key = fc->key;
1816 call->reply[0] = vnode;
1818 /* marshall the parameters */
1820 *bp++ = htonl(FSSETLOCK);
1821 *bp++ = htonl(vnode->fid.vid);
1822 *bp++ = htonl(vnode->fid.vnode);
1823 *bp++ = htonl(vnode->fid.unique);
1824 *bp++ = htonl(type);
1826 afs_use_fs_server(call, fc->cbi);
1827 trace_afs_make_fs_call(call, &vnode->fid);
1828 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1832 * extend a lock on a file
1834 int afs_fs_extend_lock(struct afs_fs_cursor *fc)
1836 struct afs_vnode *vnode = fc->vnode;
1837 struct afs_call *call;
1838 struct afs_net *net = afs_v2net(vnode);
1843 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1847 call->key = fc->key;
1848 call->reply[0] = vnode;
1850 /* marshall the parameters */
1852 *bp++ = htonl(FSEXTENDLOCK);
1853 *bp++ = htonl(vnode->fid.vid);
1854 *bp++ = htonl(vnode->fid.vnode);
1855 *bp++ = htonl(vnode->fid.unique);
1857 afs_use_fs_server(call, fc->cbi);
1858 trace_afs_make_fs_call(call, &vnode->fid);
1859 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1863 * release a lock on a file
1865 int afs_fs_release_lock(struct afs_fs_cursor *fc)
1867 struct afs_vnode *vnode = fc->vnode;
1868 struct afs_call *call;
1869 struct afs_net *net = afs_v2net(vnode);
1874 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1878 call->key = fc->key;
1879 call->reply[0] = vnode;
1881 /* marshall the parameters */
1883 *bp++ = htonl(FSRELEASELOCK);
1884 *bp++ = htonl(vnode->fid.vid);
1885 *bp++ = htonl(vnode->fid.vnode);
1886 *bp++ = htonl(vnode->fid.unique);
1888 afs_use_fs_server(call, fc->cbi);
1889 trace_afs_make_fs_call(call, &vnode->fid);
1890 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1894 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1896 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1898 return afs_transfer_reply(call);
1902 * FS.GiveUpAllCallBacks operation type
1904 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1905 .name = "FS.GiveUpAllCallBacks",
1906 .op = afs_FS_GiveUpAllCallBacks,
1907 .deliver = afs_deliver_fs_give_up_all_callbacks,
1908 .destructor = afs_flat_call_destructor,
1912 * Flush all the callbacks we have on a server.
1914 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1915 struct afs_server *server,
1916 struct afs_addr_cursor *ac,
1919 struct afs_call *call;
1924 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1930 /* marshall the parameters */
1932 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1934 /* Can't take a ref on server */
1935 return afs_make_call(ac, call, GFP_NOFS, false);
1939 * Deliver reply data to an FS.GetCapabilities operation.
1941 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1946 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
1948 switch (call->unmarshall) {
1950 afs_extract_to_tmp(call);
1953 /* Extract the capabilities word count */
1955 ret = afs_extract_data(call, true);
1959 count = ntohl(call->tmp);
1961 call->count = count;
1962 call->count2 = count;
1963 iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
1966 /* Extract capabilities words */
1968 ret = afs_extract_data(call, false);
1972 /* TODO: Examine capabilities */
1978 _leave(" = 0 [done]");
1983 * FS.GetCapabilities operation type
1985 static const struct afs_call_type afs_RXFSGetCapabilities = {
1986 .name = "FS.GetCapabilities",
1987 .op = afs_FS_GetCapabilities,
1988 .deliver = afs_deliver_fs_get_capabilities,
1989 .destructor = afs_flat_call_destructor,
1993 * Probe a fileserver for the capabilities that it supports. This can
1994 * return up to 196 words.
1996 int afs_fs_get_capabilities(struct afs_net *net,
1997 struct afs_server *server,
1998 struct afs_addr_cursor *ac,
2001 struct afs_call *call;
2006 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
2012 /* marshall the parameters */
2014 *bp++ = htonl(FSGETCAPABILITIES);
2016 /* Can't take a ref on server */
2017 trace_afs_make_fs_call(call, NULL);
2018 return afs_make_call(ac, call, GFP_NOFS, false);
2022 * Deliver reply data to an FS.FetchStatus with no vnode.
2024 static int afs_deliver_fs_fetch_status(struct afs_call *call)
2026 struct afs_file_status *status = call->reply[1];
2027 struct afs_callback *callback = call->reply[2];
2028 struct afs_volsync *volsync = call->reply[3];
2029 struct afs_vnode *vnode = call->reply[0];
2033 ret = afs_transfer_reply(call);
2037 _enter("{%x:%u}", vnode->fid.vid, vnode->fid.vnode);
2039 /* unmarshall the reply once we've received all of it */
2041 ret = afs_decode_status(call, &bp, status, vnode,
2042 &call->expected_version, NULL);
2045 callback[call->count].version = ntohl(bp[0]);
2046 callback[call->count].expiry = ntohl(bp[1]);
2047 callback[call->count].type = ntohl(bp[2]);
2049 xdr_decode_AFSCallBack(call, vnode, &bp);
2053 xdr_decode_AFSVolSync(&bp, volsync);
2055 _leave(" = 0 [done]");
2060 * FS.FetchStatus operation type
2062 static const struct afs_call_type afs_RXFSFetchStatus = {
2063 .name = "FS.FetchStatus",
2064 .op = afs_FS_FetchStatus,
2065 .deliver = afs_deliver_fs_fetch_status,
2066 .destructor = afs_flat_call_destructor,
2070 * Fetch the status information for a fid without needing a vnode handle.
2072 int afs_fs_fetch_status(struct afs_fs_cursor *fc,
2073 struct afs_net *net,
2074 struct afs_fid *fid,
2075 struct afs_file_status *status,
2076 struct afs_callback *callback,
2077 struct afs_volsync *volsync)
2079 struct afs_call *call;
2082 _enter(",%x,{%x:%u},,",
2083 key_serial(fc->key), fid->vid, fid->vnode);
2085 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
2087 fc->ac.error = -ENOMEM;
2091 call->key = fc->key;
2092 call->reply[0] = NULL; /* vnode for fid[0] */
2093 call->reply[1] = status;
2094 call->reply[2] = callback;
2095 call->reply[3] = volsync;
2096 call->expected_version = 1; /* vnode->status.data_version */
2098 /* marshall the parameters */
2100 bp[0] = htonl(FSFETCHSTATUS);
2101 bp[1] = htonl(fid->vid);
2102 bp[2] = htonl(fid->vnode);
2103 bp[3] = htonl(fid->unique);
2105 call->cb_break = fc->cb_break;
2106 afs_use_fs_server(call, fc->cbi);
2107 trace_afs_make_fs_call(call, fid);
2108 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
2112 * Deliver reply data to an FS.InlineBulkStatus call
2114 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2116 struct afs_file_status *statuses;
2117 struct afs_callback *callbacks;
2118 struct afs_vnode *vnode = call->reply[0];
2123 _enter("{%u}", call->unmarshall);
2125 switch (call->unmarshall) {
2127 afs_extract_to_tmp(call);
2130 /* Extract the file status count and array in two steps */
2132 _debug("extract status count");
2133 ret = afs_extract_data(call, true);
2137 tmp = ntohl(call->tmp);
2138 _debug("status count: %u/%u", tmp, call->count2);
2139 if (tmp != call->count2)
2140 return afs_protocol_error(call, -EBADMSG,
2141 afs_eproto_ibulkst_count);
2146 afs_extract_to_buf(call, 21 * sizeof(__be32));
2149 _debug("extract status array %u", call->count);
2150 ret = afs_extract_data(call, true);
2155 statuses = call->reply[1];
2156 ret = afs_decode_status(call, &bp, &statuses[call->count],
2157 call->count == 0 ? vnode : NULL,
2163 if (call->count < call->count2)
2168 afs_extract_to_tmp(call);
2170 /* Extract the callback count and array in two steps */
2172 _debug("extract CB count");
2173 ret = afs_extract_data(call, true);
2177 tmp = ntohl(call->tmp);
2178 _debug("CB count: %u", tmp);
2179 if (tmp != call->count2)
2180 return afs_protocol_error(call, -EBADMSG,
2181 afs_eproto_ibulkst_cb_count);
2185 afs_extract_to_buf(call, 3 * sizeof(__be32));
2188 _debug("extract CB array");
2189 ret = afs_extract_data(call, true);
2193 _debug("unmarshall CB array");
2195 callbacks = call->reply[2];
2196 callbacks[call->count].version = ntohl(bp[0]);
2197 callbacks[call->count].expiry = ntohl(bp[1]);
2198 callbacks[call->count].type = ntohl(bp[2]);
2199 statuses = call->reply[1];
2200 if (call->count == 0 && vnode && statuses[0].abort_code == 0)
2201 xdr_decode_AFSCallBack(call, vnode, &bp);
2203 if (call->count < call->count2)
2206 afs_extract_to_buf(call, 6 * sizeof(__be32));
2210 ret = afs_extract_data(call, false);
2216 xdr_decode_AFSVolSync(&bp, call->reply[3]);
2224 _leave(" = 0 [done]");
2229 * FS.InlineBulkStatus operation type
2231 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2232 .name = "FS.InlineBulkStatus",
2233 .op = afs_FS_InlineBulkStatus,
2234 .deliver = afs_deliver_fs_inline_bulk_status,
2235 .destructor = afs_flat_call_destructor,
2239 * Fetch the status information for up to 50 files
2241 int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2242 struct afs_net *net,
2243 struct afs_fid *fids,
2244 struct afs_file_status *statuses,
2245 struct afs_callback *callbacks,
2246 unsigned int nr_fids,
2247 struct afs_volsync *volsync)
2249 struct afs_call *call;
2253 _enter(",%x,{%x:%u},%u",
2254 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2256 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2257 (2 + nr_fids * 3) * 4,
2260 fc->ac.error = -ENOMEM;
2264 call->key = fc->key;
2265 call->reply[0] = NULL; /* vnode for fid[0] */
2266 call->reply[1] = statuses;
2267 call->reply[2] = callbacks;
2268 call->reply[3] = volsync;
2269 call->count2 = nr_fids;
2271 /* marshall the parameters */
2273 *bp++ = htonl(FSINLINEBULKSTATUS);
2274 *bp++ = htonl(nr_fids);
2275 for (i = 0; i < nr_fids; i++) {
2276 *bp++ = htonl(fids[i].vid);
2277 *bp++ = htonl(fids[i].vnode);
2278 *bp++ = htonl(fids[i].unique);
2281 call->cb_break = fc->cb_break;
2282 afs_use_fs_server(call, fc->cbi);
2283 trace_afs_make_fs_call(call, &fids[0]);
2284 return afs_make_call(&fc->ac, call, GFP_NOFS, false);