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);
471 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
475 * deliver reply data to an FS.FetchData
477 static int afs_deliver_fs_fetch_data(struct afs_call *call)
479 struct afs_vnode *vnode = call->reply[0];
480 struct afs_read *req = call->reply[2];
485 _enter("{%u,%zu/%llu}",
486 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
488 switch (call->unmarshall) {
492 req->offset = req->pos & (PAGE_SIZE - 1);
494 if (call->operation_ID == FSFETCHDATA64) {
495 afs_extract_to_tmp64(call);
497 call->tmp_u = htonl(0);
498 afs_extract_to_tmp(call);
501 /* Fall through - and extract the returned data length */
503 _debug("extract data length");
504 ret = afs_extract_data(call, true);
508 req->actual_len = be64_to_cpu(call->tmp64);
509 _debug("DATA length: %llu", req->actual_len);
510 req->remain = min(req->len, req->actual_len);
511 if (req->remain == 0)
517 ASSERTCMP(req->index, <, req->nr_pages);
518 if (req->remain > PAGE_SIZE - req->offset)
519 size = PAGE_SIZE - req->offset;
522 call->bvec[0].bv_len = size;
523 call->bvec[0].bv_offset = req->offset;
524 call->bvec[0].bv_page = req->pages[req->index];
525 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
526 ASSERTCMP(size, <=, PAGE_SIZE);
528 /* Fall through - and extract the returned data */
530 _debug("extract data %zu/%llu",
531 iov_iter_count(&call->iter), req->remain);
533 ret = afs_extract_data(call, true);
536 req->remain -= call->bvec[0].bv_len;
537 req->offset += call->bvec[0].bv_len;
538 ASSERTCMP(req->offset, <=, PAGE_SIZE);
539 if (req->offset == PAGE_SIZE) {
542 req->page_done(call, req);
548 ASSERTCMP(req->remain, ==, 0);
549 if (req->actual_len <= req->len)
552 /* Discard any excess data the server gave us */
553 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
554 call->unmarshall = 3;
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 /* Fall through - and 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 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
669 * fetch data from a file
671 int afs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
673 struct afs_vnode *vnode = fc->vnode;
674 struct afs_call *call;
675 struct afs_net *net = afs_v2net(vnode);
678 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
679 return yfs_fs_fetch_data(fc, req);
681 if (upper_32_bits(req->pos) ||
682 upper_32_bits(req->len) ||
683 upper_32_bits(req->pos + req->len))
684 return afs_fs_fetch_data64(fc, req);
688 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
693 call->reply[0] = vnode;
694 call->reply[1] = NULL; /* volsync */
695 call->reply[2] = req;
696 call->expected_version = vnode->status.data_version;
697 call->want_reply_time = true;
699 /* marshall the parameters */
701 bp[0] = htonl(FSFETCHDATA);
702 bp[1] = htonl(vnode->fid.vid);
703 bp[2] = htonl(vnode->fid.vnode);
704 bp[3] = htonl(vnode->fid.unique);
705 bp[4] = htonl(lower_32_bits(req->pos));
706 bp[5] = htonl(lower_32_bits(req->len));
708 refcount_inc(&req->usage);
709 call->cb_break = fc->cb_break;
710 afs_use_fs_server(call, fc->cbi);
711 trace_afs_make_fs_call(call, &vnode->fid);
712 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
716 * deliver reply data to an FS.CreateFile or an FS.MakeDir
718 static int afs_deliver_fs_create_vnode(struct afs_call *call)
720 struct afs_vnode *vnode = call->reply[0];
724 _enter("{%u}", call->unmarshall);
726 ret = afs_transfer_reply(call);
730 /* unmarshall the reply once we've received all of it */
732 xdr_decode_AFSFid(&bp, call->reply[1]);
733 ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
736 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
737 &call->expected_version, NULL);
740 xdr_decode_AFSCallBack_raw(call, &bp, call->reply[3]);
741 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
743 _leave(" = 0 [done]");
748 * FS.CreateFile and FS.MakeDir operation type
750 static const struct afs_call_type afs_RXFSCreateFile = {
751 .name = "FS.CreateFile",
752 .op = afs_FS_CreateFile,
753 .deliver = afs_deliver_fs_create_vnode,
754 .destructor = afs_flat_call_destructor,
757 static const struct afs_call_type afs_RXFSMakeDir = {
758 .name = "FS.MakeDir",
759 .op = afs_FS_MakeDir,
760 .deliver = afs_deliver_fs_create_vnode,
761 .destructor = afs_flat_call_destructor,
765 * create a file or make a directory
767 int afs_fs_create(struct afs_fs_cursor *fc,
770 u64 current_data_version,
771 struct afs_fid *newfid,
772 struct afs_file_status *newstatus,
773 struct afs_callback *newcb)
775 struct afs_vnode *vnode = fc->vnode;
776 struct afs_call *call;
777 struct afs_net *net = afs_v2net(vnode);
778 size_t namesz, reqsz, padsz;
781 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
783 return yfs_fs_make_dir(fc, name, mode, current_data_version,
784 newfid, newstatus, newcb);
786 return yfs_fs_create_file(fc, name, mode, current_data_version,
787 newfid, newstatus, newcb);
792 namesz = strlen(name);
793 padsz = (4 - (namesz & 3)) & 3;
794 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
796 call = afs_alloc_flat_call(
797 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
798 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
803 call->reply[0] = vnode;
804 call->reply[1] = newfid;
805 call->reply[2] = newstatus;
806 call->reply[3] = newcb;
807 call->expected_version = current_data_version + 1;
808 call->want_reply_time = true;
810 /* marshall the parameters */
812 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
813 *bp++ = htonl(vnode->fid.vid);
814 *bp++ = htonl(vnode->fid.vnode);
815 *bp++ = htonl(vnode->fid.unique);
816 *bp++ = htonl(namesz);
817 memcpy(bp, name, namesz);
818 bp = (void *) bp + namesz;
820 memset(bp, 0, padsz);
821 bp = (void *) bp + padsz;
823 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
824 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
825 *bp++ = 0; /* owner */
826 *bp++ = 0; /* group */
827 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
828 *bp++ = 0; /* segment size */
830 afs_use_fs_server(call, fc->cbi);
831 trace_afs_make_fs_call(call, &vnode->fid);
832 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
836 * deliver reply data to an FS.RemoveFile or FS.RemoveDir
838 static int afs_deliver_fs_remove(struct afs_call *call)
840 struct afs_vnode *vnode = call->reply[0];
844 _enter("{%u}", call->unmarshall);
846 ret = afs_transfer_reply(call);
850 /* unmarshall the reply once we've received all of it */
852 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
853 &call->expected_version, NULL);
856 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
858 _leave(" = 0 [done]");
863 * FS.RemoveDir/FS.RemoveFile operation type
865 static const struct afs_call_type afs_RXFSRemoveFile = {
866 .name = "FS.RemoveFile",
867 .op = afs_FS_RemoveFile,
868 .deliver = afs_deliver_fs_remove,
869 .destructor = afs_flat_call_destructor,
872 static const struct afs_call_type afs_RXFSRemoveDir = {
873 .name = "FS.RemoveDir",
874 .op = afs_FS_RemoveDir,
875 .deliver = afs_deliver_fs_remove,
876 .destructor = afs_flat_call_destructor,
880 * remove a file or directory
882 int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
883 const char *name, bool isdir, u64 current_data_version)
885 struct afs_vnode *dvnode = fc->vnode;
886 struct afs_call *call;
887 struct afs_net *net = afs_v2net(dvnode);
888 size_t namesz, reqsz, padsz;
891 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
892 return yfs_fs_remove(fc, vnode, name, isdir, current_data_version);
896 namesz = strlen(name);
897 padsz = (4 - (namesz & 3)) & 3;
898 reqsz = (5 * 4) + namesz + padsz;
900 call = afs_alloc_flat_call(
901 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
902 reqsz, (21 + 6) * 4);
907 call->reply[0] = dvnode;
908 call->reply[1] = vnode;
909 call->expected_version = current_data_version + 1;
911 /* marshall the parameters */
913 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
914 *bp++ = htonl(dvnode->fid.vid);
915 *bp++ = htonl(dvnode->fid.vnode);
916 *bp++ = htonl(dvnode->fid.unique);
917 *bp++ = htonl(namesz);
918 memcpy(bp, name, namesz);
919 bp = (void *) bp + namesz;
921 memset(bp, 0, padsz);
922 bp = (void *) bp + padsz;
925 afs_use_fs_server(call, fc->cbi);
926 trace_afs_make_fs_call(call, &dvnode->fid);
927 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
931 * deliver reply data to an FS.Link
933 static int afs_deliver_fs_link(struct afs_call *call)
935 struct afs_vnode *dvnode = call->reply[0], *vnode = call->reply[1];
939 _enter("{%u}", call->unmarshall);
941 ret = afs_transfer_reply(call);
945 /* unmarshall the reply once we've received all of it */
947 ret = afs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
950 ret = afs_decode_status(call, &bp, &dvnode->status, dvnode,
951 &call->expected_version, NULL);
954 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
956 _leave(" = 0 [done]");
961 * FS.Link operation type
963 static const struct afs_call_type afs_RXFSLink = {
966 .deliver = afs_deliver_fs_link,
967 .destructor = afs_flat_call_destructor,
973 int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
974 const char *name, u64 current_data_version)
976 struct afs_vnode *dvnode = fc->vnode;
977 struct afs_call *call;
978 struct afs_net *net = afs_v2net(vnode);
979 size_t namesz, reqsz, padsz;
982 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
983 return yfs_fs_link(fc, vnode, name, current_data_version);
987 namesz = strlen(name);
988 padsz = (4 - (namesz & 3)) & 3;
989 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
991 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
996 call->reply[0] = dvnode;
997 call->reply[1] = vnode;
998 call->expected_version = current_data_version + 1;
1000 /* marshall the parameters */
1002 *bp++ = htonl(FSLINK);
1003 *bp++ = htonl(dvnode->fid.vid);
1004 *bp++ = htonl(dvnode->fid.vnode);
1005 *bp++ = htonl(dvnode->fid.unique);
1006 *bp++ = htonl(namesz);
1007 memcpy(bp, name, namesz);
1008 bp = (void *) bp + namesz;
1010 memset(bp, 0, padsz);
1011 bp = (void *) bp + padsz;
1013 *bp++ = htonl(vnode->fid.vid);
1014 *bp++ = htonl(vnode->fid.vnode);
1015 *bp++ = htonl(vnode->fid.unique);
1017 afs_use_fs_server(call, fc->cbi);
1018 trace_afs_make_fs_call(call, &vnode->fid);
1019 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1023 * deliver reply data to an FS.Symlink
1025 static int afs_deliver_fs_symlink(struct afs_call *call)
1027 struct afs_vnode *vnode = call->reply[0];
1031 _enter("{%u}", call->unmarshall);
1033 ret = afs_transfer_reply(call);
1037 /* unmarshall the reply once we've received all of it */
1039 xdr_decode_AFSFid(&bp, call->reply[1]);
1040 ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
1043 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1044 &call->expected_version, NULL);
1047 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1049 _leave(" = 0 [done]");
1054 * FS.Symlink operation type
1056 static const struct afs_call_type afs_RXFSSymlink = {
1057 .name = "FS.Symlink",
1058 .op = afs_FS_Symlink,
1059 .deliver = afs_deliver_fs_symlink,
1060 .destructor = afs_flat_call_destructor,
1064 * create a symbolic link
1066 int afs_fs_symlink(struct afs_fs_cursor *fc,
1068 const char *contents,
1069 u64 current_data_version,
1070 struct afs_fid *newfid,
1071 struct afs_file_status *newstatus)
1073 struct afs_vnode *vnode = fc->vnode;
1074 struct afs_call *call;
1075 struct afs_net *net = afs_v2net(vnode);
1076 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
1079 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1080 return yfs_fs_symlink(fc, name, contents, current_data_version,
1085 namesz = strlen(name);
1086 padsz = (4 - (namesz & 3)) & 3;
1088 c_namesz = strlen(contents);
1089 c_padsz = (4 - (c_namesz & 3)) & 3;
1091 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
1093 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
1094 (3 + 21 + 21 + 6) * 4);
1098 call->key = fc->key;
1099 call->reply[0] = vnode;
1100 call->reply[1] = newfid;
1101 call->reply[2] = newstatus;
1102 call->expected_version = current_data_version + 1;
1104 /* marshall the parameters */
1106 *bp++ = htonl(FSSYMLINK);
1107 *bp++ = htonl(vnode->fid.vid);
1108 *bp++ = htonl(vnode->fid.vnode);
1109 *bp++ = htonl(vnode->fid.unique);
1110 *bp++ = htonl(namesz);
1111 memcpy(bp, name, namesz);
1112 bp = (void *) bp + namesz;
1114 memset(bp, 0, padsz);
1115 bp = (void *) bp + padsz;
1117 *bp++ = htonl(c_namesz);
1118 memcpy(bp, contents, c_namesz);
1119 bp = (void *) bp + c_namesz;
1121 memset(bp, 0, c_padsz);
1122 bp = (void *) bp + c_padsz;
1124 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
1125 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1126 *bp++ = 0; /* owner */
1127 *bp++ = 0; /* group */
1128 *bp++ = htonl(S_IRWXUGO); /* unix mode */
1129 *bp++ = 0; /* segment size */
1131 afs_use_fs_server(call, fc->cbi);
1132 trace_afs_make_fs_call(call, &vnode->fid);
1133 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1137 * deliver reply data to an FS.Rename
1139 static int afs_deliver_fs_rename(struct afs_call *call)
1141 struct afs_vnode *orig_dvnode = call->reply[0], *new_dvnode = call->reply[1];
1145 _enter("{%u}", call->unmarshall);
1147 ret = afs_transfer_reply(call);
1151 /* unmarshall the reply once we've received all of it */
1153 ret = afs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1154 &call->expected_version, NULL);
1157 if (new_dvnode != orig_dvnode) {
1158 ret = afs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1159 &call->expected_version_2, NULL);
1163 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1165 _leave(" = 0 [done]");
1170 * FS.Rename operation type
1172 static const struct afs_call_type afs_RXFSRename = {
1173 .name = "FS.Rename",
1174 .op = afs_FS_Rename,
1175 .deliver = afs_deliver_fs_rename,
1176 .destructor = afs_flat_call_destructor,
1180 * create a symbolic link
1182 int afs_fs_rename(struct afs_fs_cursor *fc,
1183 const char *orig_name,
1184 struct afs_vnode *new_dvnode,
1185 const char *new_name,
1186 u64 current_orig_data_version,
1187 u64 current_new_data_version)
1189 struct afs_vnode *orig_dvnode = fc->vnode;
1190 struct afs_call *call;
1191 struct afs_net *net = afs_v2net(orig_dvnode);
1192 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1195 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1196 return yfs_fs_rename(fc, orig_name,
1197 new_dvnode, new_name,
1198 current_orig_data_version,
1199 current_new_data_version);
1203 o_namesz = strlen(orig_name);
1204 o_padsz = (4 - (o_namesz & 3)) & 3;
1206 n_namesz = strlen(new_name);
1207 n_padsz = (4 - (n_namesz & 3)) & 3;
1210 4 + o_namesz + o_padsz +
1212 4 + n_namesz + n_padsz;
1214 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1218 call->key = fc->key;
1219 call->reply[0] = orig_dvnode;
1220 call->reply[1] = new_dvnode;
1221 call->expected_version = current_orig_data_version + 1;
1222 call->expected_version_2 = current_new_data_version + 1;
1224 /* marshall the parameters */
1226 *bp++ = htonl(FSRENAME);
1227 *bp++ = htonl(orig_dvnode->fid.vid);
1228 *bp++ = htonl(orig_dvnode->fid.vnode);
1229 *bp++ = htonl(orig_dvnode->fid.unique);
1230 *bp++ = htonl(o_namesz);
1231 memcpy(bp, orig_name, o_namesz);
1232 bp = (void *) bp + o_namesz;
1234 memset(bp, 0, o_padsz);
1235 bp = (void *) bp + o_padsz;
1238 *bp++ = htonl(new_dvnode->fid.vid);
1239 *bp++ = htonl(new_dvnode->fid.vnode);
1240 *bp++ = htonl(new_dvnode->fid.unique);
1241 *bp++ = htonl(n_namesz);
1242 memcpy(bp, new_name, n_namesz);
1243 bp = (void *) bp + n_namesz;
1245 memset(bp, 0, n_padsz);
1246 bp = (void *) bp + n_padsz;
1249 afs_use_fs_server(call, fc->cbi);
1250 trace_afs_make_fs_call(call, &orig_dvnode->fid);
1251 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1255 * deliver reply data to an FS.StoreData
1257 static int afs_deliver_fs_store_data(struct afs_call *call)
1259 struct afs_vnode *vnode = call->reply[0];
1265 ret = afs_transfer_reply(call);
1269 /* unmarshall the reply once we've received all of it */
1271 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1272 &call->expected_version, NULL);
1275 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1277 afs_pages_written_back(vnode, call);
1279 _leave(" = 0 [done]");
1284 * FS.StoreData operation type
1286 static const struct afs_call_type afs_RXFSStoreData = {
1287 .name = "FS.StoreData",
1288 .op = afs_FS_StoreData,
1289 .deliver = afs_deliver_fs_store_data,
1290 .destructor = afs_flat_call_destructor,
1293 static const struct afs_call_type afs_RXFSStoreData64 = {
1294 .name = "FS.StoreData64",
1295 .op = afs_FS_StoreData64,
1296 .deliver = afs_deliver_fs_store_data,
1297 .destructor = afs_flat_call_destructor,
1301 * store a set of pages to a very large file
1303 static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1304 struct address_space *mapping,
1305 pgoff_t first, pgoff_t last,
1306 unsigned offset, unsigned to,
1307 loff_t size, loff_t pos, loff_t i_size)
1309 struct afs_vnode *vnode = fc->vnode;
1310 struct afs_call *call;
1311 struct afs_net *net = afs_v2net(vnode);
1314 _enter(",%x,{%llx:%llu},,",
1315 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1317 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
1318 (4 + 6 + 3 * 2) * 4,
1323 call->key = fc->key;
1324 call->mapping = mapping;
1325 call->reply[0] = vnode;
1326 call->first = first;
1328 call->first_offset = offset;
1330 call->send_pages = true;
1331 call->expected_version = vnode->status.data_version + 1;
1333 /* marshall the parameters */
1335 *bp++ = htonl(FSSTOREDATA64);
1336 *bp++ = htonl(vnode->fid.vid);
1337 *bp++ = htonl(vnode->fid.vnode);
1338 *bp++ = htonl(vnode->fid.unique);
1340 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1341 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1342 *bp++ = 0; /* owner */
1343 *bp++ = 0; /* group */
1344 *bp++ = 0; /* unix mode */
1345 *bp++ = 0; /* segment size */
1347 *bp++ = htonl(pos >> 32);
1348 *bp++ = htonl((u32) pos);
1349 *bp++ = htonl(size >> 32);
1350 *bp++ = htonl((u32) size);
1351 *bp++ = htonl(i_size >> 32);
1352 *bp++ = htonl((u32) i_size);
1354 trace_afs_make_fs_call(call, &vnode->fid);
1355 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1359 * store a set of pages
1361 int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1362 pgoff_t first, pgoff_t last,
1363 unsigned offset, unsigned to)
1365 struct afs_vnode *vnode = fc->vnode;
1366 struct afs_call *call;
1367 struct afs_net *net = afs_v2net(vnode);
1368 loff_t size, pos, i_size;
1371 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1372 return yfs_fs_store_data(fc, mapping, first, last, offset, to);
1374 _enter(",%x,{%llx:%llu},,",
1375 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1377 size = (loff_t)to - (loff_t)offset;
1379 size += (loff_t)(last - first) << PAGE_SHIFT;
1380 pos = (loff_t)first << PAGE_SHIFT;
1383 i_size = i_size_read(&vnode->vfs_inode);
1384 if (pos + size > i_size)
1385 i_size = size + pos;
1387 _debug("size %llx, at %llx, i_size %llx",
1388 (unsigned long long) size, (unsigned long long) pos,
1389 (unsigned long long) i_size);
1391 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1392 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
1395 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1401 call->key = fc->key;
1402 call->mapping = mapping;
1403 call->reply[0] = vnode;
1404 call->first = first;
1406 call->first_offset = offset;
1408 call->send_pages = true;
1409 call->expected_version = vnode->status.data_version + 1;
1411 /* marshall the parameters */
1413 *bp++ = htonl(FSSTOREDATA);
1414 *bp++ = htonl(vnode->fid.vid);
1415 *bp++ = htonl(vnode->fid.vnode);
1416 *bp++ = htonl(vnode->fid.unique);
1418 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1419 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1420 *bp++ = 0; /* owner */
1421 *bp++ = 0; /* group */
1422 *bp++ = 0; /* unix mode */
1423 *bp++ = 0; /* segment size */
1426 *bp++ = htonl(size);
1427 *bp++ = htonl(i_size);
1429 afs_use_fs_server(call, fc->cbi);
1430 trace_afs_make_fs_call(call, &vnode->fid);
1431 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1435 * deliver reply data to an FS.StoreStatus
1437 static int afs_deliver_fs_store_status(struct afs_call *call)
1439 struct afs_vnode *vnode = call->reply[0];
1445 ret = afs_transfer_reply(call);
1449 /* unmarshall the reply once we've received all of it */
1451 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1452 &call->expected_version, NULL);
1455 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1457 _leave(" = 0 [done]");
1462 * FS.StoreStatus operation type
1464 static const struct afs_call_type afs_RXFSStoreStatus = {
1465 .name = "FS.StoreStatus",
1466 .op = afs_FS_StoreStatus,
1467 .deliver = afs_deliver_fs_store_status,
1468 .destructor = afs_flat_call_destructor,
1471 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1472 .name = "FS.StoreData",
1473 .op = afs_FS_StoreData,
1474 .deliver = afs_deliver_fs_store_status,
1475 .destructor = afs_flat_call_destructor,
1478 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1479 .name = "FS.StoreData64",
1480 .op = afs_FS_StoreData64,
1481 .deliver = afs_deliver_fs_store_status,
1482 .destructor = afs_flat_call_destructor,
1486 * set the attributes on a very large file, using FS.StoreData rather than
1487 * FS.StoreStatus so as to alter the file size also
1489 static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr)
1491 struct afs_vnode *vnode = fc->vnode;
1492 struct afs_call *call;
1493 struct afs_net *net = afs_v2net(vnode);
1496 _enter(",%x,{%llx:%llu},,",
1497 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1499 ASSERT(attr->ia_valid & ATTR_SIZE);
1501 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
1502 (4 + 6 + 3 * 2) * 4,
1507 call->key = fc->key;
1508 call->reply[0] = vnode;
1509 call->expected_version = vnode->status.data_version + 1;
1511 /* marshall the parameters */
1513 *bp++ = htonl(FSSTOREDATA64);
1514 *bp++ = htonl(vnode->fid.vid);
1515 *bp++ = htonl(vnode->fid.vnode);
1516 *bp++ = htonl(vnode->fid.unique);
1518 xdr_encode_AFS_StoreStatus(&bp, attr);
1520 *bp++ = 0; /* position of start of write */
1522 *bp++ = 0; /* size of write */
1524 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1525 *bp++ = htonl((u32) attr->ia_size);
1527 afs_use_fs_server(call, fc->cbi);
1528 trace_afs_make_fs_call(call, &vnode->fid);
1529 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1533 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1534 * so as to alter the file size also
1536 static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1538 struct afs_vnode *vnode = fc->vnode;
1539 struct afs_call *call;
1540 struct afs_net *net = afs_v2net(vnode);
1543 _enter(",%x,{%llx:%llu},,",
1544 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1546 ASSERT(attr->ia_valid & ATTR_SIZE);
1547 if (attr->ia_size >> 32)
1548 return afs_fs_setattr_size64(fc, attr);
1550 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1556 call->key = fc->key;
1557 call->reply[0] = vnode;
1558 call->expected_version = vnode->status.data_version + 1;
1560 /* marshall the parameters */
1562 *bp++ = htonl(FSSTOREDATA);
1563 *bp++ = htonl(vnode->fid.vid);
1564 *bp++ = htonl(vnode->fid.vnode);
1565 *bp++ = htonl(vnode->fid.unique);
1567 xdr_encode_AFS_StoreStatus(&bp, attr);
1569 *bp++ = 0; /* position of start of write */
1570 *bp++ = 0; /* size of write */
1571 *bp++ = htonl(attr->ia_size); /* new file length */
1573 afs_use_fs_server(call, fc->cbi);
1574 trace_afs_make_fs_call(call, &vnode->fid);
1575 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1579 * set the attributes on a file, using FS.StoreData if there's a change in file
1580 * size, and FS.StoreStatus otherwise
1582 int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1584 struct afs_vnode *vnode = fc->vnode;
1585 struct afs_call *call;
1586 struct afs_net *net = afs_v2net(vnode);
1589 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1590 return yfs_fs_setattr(fc, attr);
1592 if (attr->ia_valid & ATTR_SIZE)
1593 return afs_fs_setattr_size(fc, attr);
1595 _enter(",%x,{%llx:%llu},,",
1596 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1598 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1604 call->key = fc->key;
1605 call->reply[0] = vnode;
1606 call->expected_version = vnode->status.data_version;
1608 /* marshall the parameters */
1610 *bp++ = htonl(FSSTORESTATUS);
1611 *bp++ = htonl(vnode->fid.vid);
1612 *bp++ = htonl(vnode->fid.vnode);
1613 *bp++ = htonl(vnode->fid.unique);
1615 xdr_encode_AFS_StoreStatus(&bp, attr);
1617 afs_use_fs_server(call, fc->cbi);
1618 trace_afs_make_fs_call(call, &vnode->fid);
1619 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1623 * deliver reply data to an FS.GetVolumeStatus
1625 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1632 _enter("{%u}", call->unmarshall);
1634 switch (call->unmarshall) {
1637 afs_extract_to_buf(call, 12 * 4);
1639 /* Fall through - and extract the returned status record */
1641 _debug("extract status");
1642 ret = afs_extract_data(call, true);
1647 xdr_decode_AFSFetchVolumeStatus(&bp, call->reply[1]);
1649 afs_extract_to_tmp(call);
1651 /* Fall through - and extract the volume name length */
1653 ret = afs_extract_data(call, true);
1657 call->count = ntohl(call->tmp);
1658 _debug("volname length: %u", call->count);
1659 if (call->count >= AFSNAMEMAX)
1660 return afs_protocol_error(call, -EBADMSG,
1661 afs_eproto_volname_len);
1662 size = (call->count + 3) & ~3; /* It's padded */
1663 afs_extract_begin(call, call->reply[2], size);
1666 /* Fall through - and extract the volume name */
1668 _debug("extract volname");
1669 ret = afs_extract_data(call, true);
1675 _debug("volname '%s'", p);
1676 afs_extract_to_tmp(call);
1679 /* Fall through - and extract the offline message length */
1681 ret = afs_extract_data(call, true);
1685 call->count = ntohl(call->tmp);
1686 _debug("offline msg length: %u", call->count);
1687 if (call->count >= AFSNAMEMAX)
1688 return afs_protocol_error(call, -EBADMSG,
1689 afs_eproto_offline_msg_len);
1690 size = (call->count + 3) & ~3; /* It's padded */
1691 afs_extract_begin(call, call->reply[2], size);
1694 /* Fall through - and extract the offline message */
1696 _debug("extract offline");
1697 ret = afs_extract_data(call, true);
1703 _debug("offline '%s'", p);
1705 afs_extract_to_tmp(call);
1708 /* Fall through - and extract the message of the day length */
1710 ret = afs_extract_data(call, true);
1714 call->count = ntohl(call->tmp);
1715 _debug("motd length: %u", call->count);
1716 if (call->count >= AFSNAMEMAX)
1717 return afs_protocol_error(call, -EBADMSG,
1718 afs_eproto_motd_len);
1719 size = (call->count + 3) & ~3; /* It's padded */
1720 afs_extract_begin(call, call->reply[2], size);
1723 /* Fall through - and extract the message of the day */
1725 _debug("extract motd");
1726 ret = afs_extract_data(call, false);
1732 _debug("motd '%s'", p);
1740 _leave(" = 0 [done]");
1745 * destroy an FS.GetVolumeStatus call
1747 static void afs_get_volume_status_call_destructor(struct afs_call *call)
1749 kfree(call->reply[2]);
1750 call->reply[2] = NULL;
1751 afs_flat_call_destructor(call);
1755 * FS.GetVolumeStatus operation type
1757 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1758 .name = "FS.GetVolumeStatus",
1759 .op = afs_FS_GetVolumeStatus,
1760 .deliver = afs_deliver_fs_get_volume_status,
1761 .destructor = afs_get_volume_status_call_destructor,
1765 * fetch the status of a volume
1767 int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1768 struct afs_volume_status *vs)
1770 struct afs_vnode *vnode = fc->vnode;
1771 struct afs_call *call;
1772 struct afs_net *net = afs_v2net(vnode);
1776 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1777 return yfs_fs_get_volume_status(fc, vs);
1781 tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1785 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
1791 call->key = fc->key;
1792 call->reply[0] = vnode;
1793 call->reply[1] = vs;
1794 call->reply[2] = tmpbuf;
1796 /* marshall the parameters */
1798 bp[0] = htonl(FSGETVOLUMESTATUS);
1799 bp[1] = htonl(vnode->fid.vid);
1801 afs_use_fs_server(call, fc->cbi);
1802 trace_afs_make_fs_call(call, &vnode->fid);
1803 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1807 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1809 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1814 _enter("{%u}", call->unmarshall);
1816 ret = afs_transfer_reply(call);
1820 /* unmarshall the reply once we've received all of it */
1822 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1824 _leave(" = 0 [done]");
1829 * FS.SetLock operation type
1831 static const struct afs_call_type afs_RXFSSetLock = {
1832 .name = "FS.SetLock",
1833 .op = afs_FS_SetLock,
1834 .deliver = afs_deliver_fs_xxxx_lock,
1835 .destructor = afs_flat_call_destructor,
1839 * FS.ExtendLock operation type
1841 static const struct afs_call_type afs_RXFSExtendLock = {
1842 .name = "FS.ExtendLock",
1843 .op = afs_FS_ExtendLock,
1844 .deliver = afs_deliver_fs_xxxx_lock,
1845 .destructor = afs_flat_call_destructor,
1849 * FS.ReleaseLock operation type
1851 static const struct afs_call_type afs_RXFSReleaseLock = {
1852 .name = "FS.ReleaseLock",
1853 .op = afs_FS_ReleaseLock,
1854 .deliver = afs_deliver_fs_xxxx_lock,
1855 .destructor = afs_flat_call_destructor,
1859 * Set a lock on a file
1861 int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1863 struct afs_vnode *vnode = fc->vnode;
1864 struct afs_call *call;
1865 struct afs_net *net = afs_v2net(vnode);
1868 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1869 return yfs_fs_set_lock(fc, type);
1873 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1877 call->key = fc->key;
1878 call->reply[0] = vnode;
1880 /* marshall the parameters */
1882 *bp++ = htonl(FSSETLOCK);
1883 *bp++ = htonl(vnode->fid.vid);
1884 *bp++ = htonl(vnode->fid.vnode);
1885 *bp++ = htonl(vnode->fid.unique);
1886 *bp++ = htonl(type);
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 * extend a lock on a file
1896 int afs_fs_extend_lock(struct afs_fs_cursor *fc)
1898 struct afs_vnode *vnode = fc->vnode;
1899 struct afs_call *call;
1900 struct afs_net *net = afs_v2net(vnode);
1903 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1904 return yfs_fs_extend_lock(fc);
1908 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1912 call->key = fc->key;
1913 call->reply[0] = vnode;
1915 /* marshall the parameters */
1917 *bp++ = htonl(FSEXTENDLOCK);
1918 *bp++ = htonl(vnode->fid.vid);
1919 *bp++ = htonl(vnode->fid.vnode);
1920 *bp++ = htonl(vnode->fid.unique);
1922 afs_use_fs_server(call, fc->cbi);
1923 trace_afs_make_fs_call(call, &vnode->fid);
1924 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1928 * release a lock on a file
1930 int afs_fs_release_lock(struct afs_fs_cursor *fc)
1932 struct afs_vnode *vnode = fc->vnode;
1933 struct afs_call *call;
1934 struct afs_net *net = afs_v2net(vnode);
1937 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1938 return yfs_fs_release_lock(fc);
1942 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1946 call->key = fc->key;
1947 call->reply[0] = vnode;
1949 /* marshall the parameters */
1951 *bp++ = htonl(FSRELEASELOCK);
1952 *bp++ = htonl(vnode->fid.vid);
1953 *bp++ = htonl(vnode->fid.vnode);
1954 *bp++ = htonl(vnode->fid.unique);
1956 afs_use_fs_server(call, fc->cbi);
1957 trace_afs_make_fs_call(call, &vnode->fid);
1958 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1962 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1964 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1966 return afs_transfer_reply(call);
1970 * FS.GiveUpAllCallBacks operation type
1972 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1973 .name = "FS.GiveUpAllCallBacks",
1974 .op = afs_FS_GiveUpAllCallBacks,
1975 .deliver = afs_deliver_fs_give_up_all_callbacks,
1976 .destructor = afs_flat_call_destructor,
1980 * Flush all the callbacks we have on a server.
1982 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1983 struct afs_server *server,
1984 struct afs_addr_cursor *ac,
1987 struct afs_call *call;
1992 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1998 /* marshall the parameters */
2000 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
2002 /* Can't take a ref on server */
2003 return afs_make_call(ac, call, GFP_NOFS, false);
2007 * Deliver reply data to an FS.GetCapabilities operation.
2009 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
2014 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
2016 switch (call->unmarshall) {
2018 afs_extract_to_tmp(call);
2021 /* Fall through - and extract the capabilities word count */
2023 ret = afs_extract_data(call, true);
2027 count = ntohl(call->tmp);
2029 call->count = count;
2030 call->count2 = count;
2031 iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
2034 /* Fall through - and extract capabilities words */
2036 ret = afs_extract_data(call, false);
2040 /* TODO: Examine capabilities */
2046 _leave(" = 0 [done]");
2050 static void afs_destroy_fs_get_capabilities(struct afs_call *call)
2052 struct afs_server *server = call->reply[0];
2054 afs_put_server(call->net, server);
2055 afs_flat_call_destructor(call);
2059 * FS.GetCapabilities operation type
2061 static const struct afs_call_type afs_RXFSGetCapabilities = {
2062 .name = "FS.GetCapabilities",
2063 .op = afs_FS_GetCapabilities,
2064 .deliver = afs_deliver_fs_get_capabilities,
2065 .done = afs_fileserver_probe_result,
2066 .destructor = afs_destroy_fs_get_capabilities,
2070 * Probe a fileserver for the capabilities that it supports. This can
2071 * return up to 196 words.
2073 int afs_fs_get_capabilities(struct afs_net *net,
2074 struct afs_server *server,
2075 struct afs_addr_cursor *ac,
2077 unsigned int server_index,
2080 struct afs_call *call;
2085 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
2090 call->reply[0] = afs_get_server(server);
2091 call->reply[1] = (void *)(long)server_index;
2092 call->upgrade = true;
2093 call->want_reply_time = true;
2095 /* marshall the parameters */
2097 *bp++ = htonl(FSGETCAPABILITIES);
2099 /* Can't take a ref on server */
2100 trace_afs_make_fs_call(call, NULL);
2101 return afs_make_call(ac, call, GFP_NOFS, async);
2105 * Deliver reply data to an FS.FetchStatus with no vnode.
2107 static int afs_deliver_fs_fetch_status(struct afs_call *call)
2109 struct afs_file_status *status = call->reply[1];
2110 struct afs_callback *callback = call->reply[2];
2111 struct afs_volsync *volsync = call->reply[3];
2112 struct afs_fid *fid = call->reply[0];
2116 ret = afs_transfer_reply(call);
2120 _enter("{%llx:%llu}", fid->vid, fid->vnode);
2122 /* unmarshall the reply once we've received all of it */
2124 ret = afs_decode_status(call, &bp, status, NULL,
2125 &call->expected_version, NULL);
2128 xdr_decode_AFSCallBack_raw(call, &bp, callback);
2129 xdr_decode_AFSVolSync(&bp, volsync);
2131 _leave(" = 0 [done]");
2136 * FS.FetchStatus operation type
2138 static const struct afs_call_type afs_RXFSFetchStatus = {
2139 .name = "FS.FetchStatus",
2140 .op = afs_FS_FetchStatus,
2141 .deliver = afs_deliver_fs_fetch_status,
2142 .destructor = afs_flat_call_destructor,
2146 * Fetch the status information for a fid without needing a vnode handle.
2148 int afs_fs_fetch_status(struct afs_fs_cursor *fc,
2149 struct afs_net *net,
2150 struct afs_fid *fid,
2151 struct afs_file_status *status,
2152 struct afs_callback *callback,
2153 struct afs_volsync *volsync)
2155 struct afs_call *call;
2158 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2159 return yfs_fs_fetch_status(fc, net, fid, status, callback, volsync);
2161 _enter(",%x,{%llx:%llu},,",
2162 key_serial(fc->key), fid->vid, fid->vnode);
2164 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
2166 fc->ac.error = -ENOMEM;
2170 call->key = fc->key;
2171 call->reply[0] = fid;
2172 call->reply[1] = status;
2173 call->reply[2] = callback;
2174 call->reply[3] = volsync;
2175 call->expected_version = 1; /* vnode->status.data_version */
2176 call->want_reply_time = true;
2178 /* marshall the parameters */
2180 bp[0] = htonl(FSFETCHSTATUS);
2181 bp[1] = htonl(fid->vid);
2182 bp[2] = htonl(fid->vnode);
2183 bp[3] = htonl(fid->unique);
2185 call->cb_break = fc->cb_break;
2186 afs_use_fs_server(call, fc->cbi);
2187 trace_afs_make_fs_call(call, fid);
2188 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
2192 * Deliver reply data to an FS.InlineBulkStatus call
2194 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2196 struct afs_file_status *statuses;
2197 struct afs_callback *callbacks;
2198 struct afs_vnode *vnode = call->reply[0];
2203 _enter("{%u}", call->unmarshall);
2205 switch (call->unmarshall) {
2207 afs_extract_to_tmp(call);
2210 /* Extract the file status count and array in two steps */
2213 _debug("extract status count");
2214 ret = afs_extract_data(call, true);
2218 tmp = ntohl(call->tmp);
2219 _debug("status count: %u/%u", tmp, call->count2);
2220 if (tmp != call->count2)
2221 return afs_protocol_error(call, -EBADMSG,
2222 afs_eproto_ibulkst_count);
2227 afs_extract_to_buf(call, 21 * sizeof(__be32));
2231 _debug("extract status array %u", call->count);
2232 ret = afs_extract_data(call, true);
2237 statuses = call->reply[1];
2238 ret = afs_decode_status(call, &bp, &statuses[call->count],
2239 call->count == 0 ? vnode : NULL,
2245 if (call->count < call->count2)
2250 afs_extract_to_tmp(call);
2252 /* Extract the callback count and array in two steps */
2255 _debug("extract CB count");
2256 ret = afs_extract_data(call, true);
2260 tmp = ntohl(call->tmp);
2261 _debug("CB count: %u", tmp);
2262 if (tmp != call->count2)
2263 return afs_protocol_error(call, -EBADMSG,
2264 afs_eproto_ibulkst_cb_count);
2268 afs_extract_to_buf(call, 3 * sizeof(__be32));
2272 _debug("extract CB array");
2273 ret = afs_extract_data(call, true);
2277 _debug("unmarshall CB array");
2279 callbacks = call->reply[2];
2280 callbacks[call->count].version = ntohl(bp[0]);
2281 callbacks[call->count].expires_at = xdr_decode_expiry(call, ntohl(bp[1]));
2282 callbacks[call->count].type = ntohl(bp[2]);
2283 statuses = call->reply[1];
2284 if (call->count == 0 && vnode && statuses[0].abort_code == 0)
2285 xdr_decode_AFSCallBack(call, vnode, &bp);
2287 if (call->count < call->count2)
2290 afs_extract_to_buf(call, 6 * sizeof(__be32));
2295 ret = afs_extract_data(call, false);
2300 xdr_decode_AFSVolSync(&bp, call->reply[3]);
2308 _leave(" = 0 [done]");
2313 * FS.InlineBulkStatus operation type
2315 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2316 .name = "FS.InlineBulkStatus",
2317 .op = afs_FS_InlineBulkStatus,
2318 .deliver = afs_deliver_fs_inline_bulk_status,
2319 .destructor = afs_flat_call_destructor,
2323 * Fetch the status information for up to 50 files
2325 int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2326 struct afs_net *net,
2327 struct afs_fid *fids,
2328 struct afs_file_status *statuses,
2329 struct afs_callback *callbacks,
2330 unsigned int nr_fids,
2331 struct afs_volsync *volsync)
2333 struct afs_call *call;
2337 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2338 return yfs_fs_inline_bulk_status(fc, net, fids, statuses, callbacks,
2341 _enter(",%x,{%llx:%llu},%u",
2342 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2344 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2345 (2 + nr_fids * 3) * 4,
2348 fc->ac.error = -ENOMEM;
2352 call->key = fc->key;
2353 call->reply[0] = NULL; /* vnode for fid[0] */
2354 call->reply[1] = statuses;
2355 call->reply[2] = callbacks;
2356 call->reply[3] = volsync;
2357 call->count2 = nr_fids;
2358 call->want_reply_time = true;
2360 /* marshall the parameters */
2362 *bp++ = htonl(FSINLINEBULKSTATUS);
2363 *bp++ = htonl(nr_fids);
2364 for (i = 0; i < nr_fids; i++) {
2365 *bp++ = htonl(fids[i].vid);
2366 *bp++ = htonl(fids[i].vnode);
2367 *bp++ = htonl(fids[i].unique);
2370 call->cb_break = fc->cb_break;
2371 afs_use_fs_server(call, fc->cbi);
2372 trace_afs_make_fs_call(call, &fids[0]);
2373 return afs_make_call(&fc->ac, call, GFP_NOFS, false);