1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* AFS File Server client stubs
4 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #include <linux/init.h>
9 #include <linux/slab.h>
10 #include <linux/sched.h>
11 #include <linux/circ_buf.h>
12 #include <linux/iversion.h>
16 #include "protocol_yfs.h"
18 static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
20 call->cbi = afs_get_cb_interest(cbi);
24 * decode an AFSFid block
26 static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
28 const __be32 *bp = *_bp;
30 fid->vid = ntohl(*bp++);
31 fid->vnode = ntohl(*bp++);
32 fid->unique = ntohl(*bp++);
37 * Dump a bad file status record.
39 static void xdr_dump_bad(const __be32 *bp)
44 pr_notice("AFS XDR: Bad status record\n");
45 for (i = 0; i < 5 * 4 * 4; i += 16) {
48 pr_notice("%03x: %08x %08x %08x %08x\n",
49 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
53 pr_notice("0x50: %08x\n", ntohl(x[0]));
57 * decode an AFSFetchStatus block
59 static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
60 struct afs_call *call,
61 struct afs_status_cb *scb)
63 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
64 struct afs_file_status *status = &scb->status;
65 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
66 u64 data_version, size;
69 abort_code = ntohl(xdr->abort_code);
71 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
72 if (xdr->if_version == htonl(0) &&
75 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
76 * whereby it doesn't set the interface version in the error
79 status->abort_code = abort_code;
80 scb->have_error = true;
84 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
88 if (abort_code != 0 && inline_error) {
89 status->abort_code = abort_code;
90 scb->have_error = true;
94 type = ntohl(xdr->type);
98 case AFS_FTYPE_SYMLINK:
105 status->nlink = ntohl(xdr->nlink);
106 status->author = ntohl(xdr->author);
107 status->owner = ntohl(xdr->owner);
108 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
109 status->anon_access = ntohl(xdr->anon_access);
110 status->mode = ntohl(xdr->mode) & S_IALLUGO;
111 status->group = ntohl(xdr->group);
112 status->lock_count = ntohl(xdr->lock_count);
114 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
115 status->mtime_client.tv_nsec = 0;
116 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
117 status->mtime_server.tv_nsec = 0;
119 size = (u64)ntohl(xdr->size_lo);
120 size |= (u64)ntohl(xdr->size_hi) << 32;
123 data_version = (u64)ntohl(xdr->data_version_lo);
124 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
125 status->data_version = data_version;
126 scb->have_status = true;
128 *_bp = (const void *)*_bp + sizeof(*xdr);
133 afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
137 static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
139 return ktime_divns(call->issue_time, NSEC_PER_SEC) + expiry;
142 static void xdr_decode_AFSCallBack(const __be32 **_bp,
143 struct afs_call *call,
144 struct afs_status_cb *scb)
146 struct afs_callback *cb = &scb->callback;
147 const __be32 *bp = *_bp;
150 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
157 * decode an AFSVolSync block
159 static void xdr_decode_AFSVolSync(const __be32 **_bp,
160 struct afs_volsync *volsync)
162 const __be32 *bp = *_bp;
165 creation = ntohl(*bp++);
174 volsync->creation = creation;
178 * encode the requested attributes into an AFSStoreStatus block
180 static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
183 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
186 if (attr->ia_valid & ATTR_MTIME) {
187 mask |= AFS_SET_MTIME;
188 mtime = attr->ia_mtime.tv_sec;
191 if (attr->ia_valid & ATTR_UID) {
192 mask |= AFS_SET_OWNER;
193 owner = from_kuid(&init_user_ns, attr->ia_uid);
196 if (attr->ia_valid & ATTR_GID) {
197 mask |= AFS_SET_GROUP;
198 group = from_kgid(&init_user_ns, attr->ia_gid);
201 if (attr->ia_valid & ATTR_MODE) {
202 mask |= AFS_SET_MODE;
203 mode = attr->ia_mode & S_IALLUGO;
207 *bp++ = htonl(mtime);
208 *bp++ = htonl(owner);
209 *bp++ = htonl(group);
211 *bp++ = 0; /* segment size */
216 * decode an AFSFetchVolumeStatus block
218 static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
219 struct afs_volume_status *vs)
221 const __be32 *bp = *_bp;
223 vs->vid = ntohl(*bp++);
224 vs->parent_id = ntohl(*bp++);
225 vs->online = ntohl(*bp++);
226 vs->in_service = ntohl(*bp++);
227 vs->blessed = ntohl(*bp++);
228 vs->needs_salvage = ntohl(*bp++);
229 vs->type = ntohl(*bp++);
230 vs->min_quota = ntohl(*bp++);
231 vs->max_quota = ntohl(*bp++);
232 vs->blocks_in_use = ntohl(*bp++);
233 vs->part_blocks_avail = ntohl(*bp++);
234 vs->part_max_blocks = ntohl(*bp++);
235 vs->vol_copy_date = 0;
236 vs->vol_backup_date = 0;
241 * deliver reply data to an FS.FetchStatus
243 static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
248 ret = afs_transfer_reply(call);
252 /* unmarshall the reply once we've received all of it */
254 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
255 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
256 xdr_decode_AFSVolSync(&bp, call->out_volsync);
258 _leave(" = 0 [done]");
263 * FS.FetchStatus operation type
265 static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
266 .name = "FS.FetchStatus(vnode)",
267 .op = afs_FS_FetchStatus,
268 .deliver = afs_deliver_fs_fetch_status_vnode,
269 .destructor = afs_flat_call_destructor,
273 * fetch the status information for a file
275 int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_status_cb *scb,
276 struct afs_volsync *volsync)
278 struct afs_vnode *vnode = fc->vnode;
279 struct afs_call *call;
280 struct afs_net *net = afs_v2net(vnode);
283 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
284 return yfs_fs_fetch_file_status(fc, scb, volsync);
286 _enter(",%x,{%llx:%llu},,",
287 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
289 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
290 16, (21 + 3 + 6) * 4);
292 fc->ac.error = -ENOMEM;
298 call->out_volsync = volsync;
300 /* marshall the parameters */
302 bp[0] = htonl(FSFETCHSTATUS);
303 bp[1] = htonl(vnode->fid.vid);
304 bp[2] = htonl(vnode->fid.vnode);
305 bp[3] = htonl(vnode->fid.unique);
307 afs_use_fs_server(call, fc->cbi);
308 trace_afs_make_fs_call(call, &vnode->fid);
310 afs_set_fc_call(call, fc);
311 afs_make_call(&fc->ac, call, GFP_NOFS);
312 return afs_wait_for_call_to_complete(call, &fc->ac);
316 * deliver reply data to an FS.FetchData
318 static int afs_deliver_fs_fetch_data(struct afs_call *call)
320 struct afs_read *req = call->read_request;
325 _enter("{%u,%zu/%llu}",
326 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
328 switch (call->unmarshall) {
332 req->offset = req->pos & (PAGE_SIZE - 1);
334 if (call->operation_ID == FSFETCHDATA64) {
335 afs_extract_to_tmp64(call);
337 call->tmp_u = htonl(0);
338 afs_extract_to_tmp(call);
342 /* extract the returned data length */
344 _debug("extract data length");
345 ret = afs_extract_data(call, true);
349 req->actual_len = be64_to_cpu(call->tmp64);
350 _debug("DATA length: %llu", req->actual_len);
351 req->remain = min(req->len, req->actual_len);
352 if (req->remain == 0)
358 ASSERTCMP(req->index, <, req->nr_pages);
359 if (req->remain > PAGE_SIZE - req->offset)
360 size = PAGE_SIZE - req->offset;
363 call->bvec[0].bv_len = size;
364 call->bvec[0].bv_offset = req->offset;
365 call->bvec[0].bv_page = req->pages[req->index];
366 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
367 ASSERTCMP(size, <=, PAGE_SIZE);
370 /* extract the returned data */
372 _debug("extract data %zu/%llu",
373 iov_iter_count(&call->iter), req->remain);
375 ret = afs_extract_data(call, true);
378 req->remain -= call->bvec[0].bv_len;
379 req->offset += call->bvec[0].bv_len;
380 ASSERTCMP(req->offset, <=, PAGE_SIZE);
381 if (req->offset == PAGE_SIZE) {
388 ASSERTCMP(req->remain, ==, 0);
389 if (req->actual_len <= req->len)
392 /* Discard any excess data the server gave us */
393 afs_extract_discard(call, req->actual_len - req->len);
394 call->unmarshall = 3;
398 _debug("extract discard %zu/%llu",
399 iov_iter_count(&call->iter), req->actual_len - req->len);
401 ret = afs_extract_data(call, true);
406 call->unmarshall = 4;
407 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
410 /* extract the metadata */
412 ret = afs_extract_data(call, false);
417 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
418 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
419 xdr_decode_AFSVolSync(&bp, call->out_volsync);
421 req->data_version = call->out_scb->status.data_version;
422 req->file_size = call->out_scb->status.size;
430 for (; req->index < req->nr_pages; req->index++) {
431 if (req->offset < PAGE_SIZE)
432 zero_user_segment(req->pages[req->index],
433 req->offset, PAGE_SIZE);
438 for (req->index = 0; req->index < req->nr_pages; req->index++)
441 _leave(" = 0 [done]");
445 static void afs_fetch_data_destructor(struct afs_call *call)
447 struct afs_read *req = call->read_request;
450 afs_flat_call_destructor(call);
454 * FS.FetchData operation type
456 static const struct afs_call_type afs_RXFSFetchData = {
457 .name = "FS.FetchData",
458 .op = afs_FS_FetchData,
459 .deliver = afs_deliver_fs_fetch_data,
460 .destructor = afs_fetch_data_destructor,
463 static const struct afs_call_type afs_RXFSFetchData64 = {
464 .name = "FS.FetchData64",
465 .op = afs_FS_FetchData64,
466 .deliver = afs_deliver_fs_fetch_data,
467 .destructor = afs_fetch_data_destructor,
471 * fetch data from a very large file
473 static int afs_fs_fetch_data64(struct afs_fs_cursor *fc,
474 struct afs_status_cb *scb,
475 struct afs_read *req)
477 struct afs_vnode *vnode = fc->vnode;
478 struct afs_call *call;
479 struct afs_net *net = afs_v2net(vnode);
484 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
490 call->out_volsync = NULL;
491 call->read_request = req;
493 /* marshall the parameters */
495 bp[0] = htonl(FSFETCHDATA64);
496 bp[1] = htonl(vnode->fid.vid);
497 bp[2] = htonl(vnode->fid.vnode);
498 bp[3] = htonl(vnode->fid.unique);
499 bp[4] = htonl(upper_32_bits(req->pos));
500 bp[5] = htonl(lower_32_bits(req->pos));
502 bp[7] = htonl(lower_32_bits(req->len));
504 refcount_inc(&req->usage);
505 afs_use_fs_server(call, fc->cbi);
506 trace_afs_make_fs_call(call, &vnode->fid);
507 afs_set_fc_call(call, fc);
508 afs_make_call(&fc->ac, call, GFP_NOFS);
509 return afs_wait_for_call_to_complete(call, &fc->ac);
513 * fetch data from a file
515 int afs_fs_fetch_data(struct afs_fs_cursor *fc,
516 struct afs_status_cb *scb,
517 struct afs_read *req)
519 struct afs_vnode *vnode = fc->vnode;
520 struct afs_call *call;
521 struct afs_net *net = afs_v2net(vnode);
524 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
525 return yfs_fs_fetch_data(fc, scb, req);
527 if (upper_32_bits(req->pos) ||
528 upper_32_bits(req->len) ||
529 upper_32_bits(req->pos + req->len))
530 return afs_fs_fetch_data64(fc, scb, req);
534 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
540 call->out_volsync = NULL;
541 call->read_request = req;
543 /* marshall the parameters */
545 bp[0] = htonl(FSFETCHDATA);
546 bp[1] = htonl(vnode->fid.vid);
547 bp[2] = htonl(vnode->fid.vnode);
548 bp[3] = htonl(vnode->fid.unique);
549 bp[4] = htonl(lower_32_bits(req->pos));
550 bp[5] = htonl(lower_32_bits(req->len));
552 refcount_inc(&req->usage);
553 afs_use_fs_server(call, fc->cbi);
554 trace_afs_make_fs_call(call, &vnode->fid);
555 afs_set_fc_call(call, fc);
556 afs_make_call(&fc->ac, call, GFP_NOFS);
557 return afs_wait_for_call_to_complete(call, &fc->ac);
561 * deliver reply data to an FS.CreateFile or an FS.MakeDir
563 static int afs_deliver_fs_create_vnode(struct afs_call *call)
568 ret = afs_transfer_reply(call);
572 /* unmarshall the reply once we've received all of it */
574 xdr_decode_AFSFid(&bp, call->out_fid);
575 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
576 xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
577 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
578 xdr_decode_AFSVolSync(&bp, call->out_volsync);
580 _leave(" = 0 [done]");
585 * FS.CreateFile and FS.MakeDir operation type
587 static const struct afs_call_type afs_RXFSCreateFile = {
588 .name = "FS.CreateFile",
589 .op = afs_FS_CreateFile,
590 .deliver = afs_deliver_fs_create_vnode,
591 .destructor = afs_flat_call_destructor,
594 static const struct afs_call_type afs_RXFSMakeDir = {
595 .name = "FS.MakeDir",
596 .op = afs_FS_MakeDir,
597 .deliver = afs_deliver_fs_create_vnode,
598 .destructor = afs_flat_call_destructor,
602 * create a file or make a directory
604 int afs_fs_create(struct afs_fs_cursor *fc,
607 struct afs_status_cb *dvnode_scb,
608 struct afs_fid *newfid,
609 struct afs_status_cb *new_scb)
611 struct afs_vnode *dvnode = fc->vnode;
612 struct afs_call *call;
613 struct afs_net *net = afs_v2net(dvnode);
614 size_t namesz, reqsz, padsz;
617 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
619 return yfs_fs_make_dir(fc, name, mode, dvnode_scb,
622 return yfs_fs_create_file(fc, name, mode, dvnode_scb,
628 namesz = strlen(name);
629 padsz = (4 - (namesz & 3)) & 3;
630 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
632 call = afs_alloc_flat_call(
633 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
634 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
639 call->out_dir_scb = dvnode_scb;
640 call->out_fid = newfid;
641 call->out_scb = new_scb;
643 /* marshall the parameters */
645 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
646 *bp++ = htonl(dvnode->fid.vid);
647 *bp++ = htonl(dvnode->fid.vnode);
648 *bp++ = htonl(dvnode->fid.unique);
649 *bp++ = htonl(namesz);
650 memcpy(bp, name, namesz);
651 bp = (void *) bp + namesz;
653 memset(bp, 0, padsz);
654 bp = (void *) bp + padsz;
656 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
657 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
658 *bp++ = 0; /* owner */
659 *bp++ = 0; /* group */
660 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
661 *bp++ = 0; /* segment size */
663 afs_use_fs_server(call, fc->cbi);
664 trace_afs_make_fs_call1(call, &dvnode->fid, name);
665 afs_set_fc_call(call, fc);
666 afs_make_call(&fc->ac, call, GFP_NOFS);
667 return afs_wait_for_call_to_complete(call, &fc->ac);
671 * Deliver reply data to any operation that returns directory status and volume
674 static int afs_deliver_fs_dir_status_and_vol(struct afs_call *call)
679 ret = afs_transfer_reply(call);
683 /* unmarshall the reply once we've received all of it */
685 xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
686 xdr_decode_AFSVolSync(&bp, call->out_volsync);
688 _leave(" = 0 [done]");
693 * FS.RemoveDir/FS.RemoveFile operation type
695 static const struct afs_call_type afs_RXFSRemoveFile = {
696 .name = "FS.RemoveFile",
697 .op = afs_FS_RemoveFile,
698 .deliver = afs_deliver_fs_dir_status_and_vol,
699 .destructor = afs_flat_call_destructor,
702 static const struct afs_call_type afs_RXFSRemoveDir = {
703 .name = "FS.RemoveDir",
704 .op = afs_FS_RemoveDir,
705 .deliver = afs_deliver_fs_dir_status_and_vol,
706 .destructor = afs_flat_call_destructor,
710 * remove a file or directory
712 int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
713 const char *name, bool isdir, struct afs_status_cb *dvnode_scb)
715 struct afs_vnode *dvnode = fc->vnode;
716 struct afs_call *call;
717 struct afs_net *net = afs_v2net(dvnode);
718 size_t namesz, reqsz, padsz;
721 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
722 return yfs_fs_remove(fc, vnode, name, isdir, dvnode_scb);
726 namesz = strlen(name);
727 padsz = (4 - (namesz & 3)) & 3;
728 reqsz = (5 * 4) + namesz + padsz;
730 call = afs_alloc_flat_call(
731 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
732 reqsz, (21 + 6) * 4);
737 call->out_dir_scb = dvnode_scb;
739 /* marshall the parameters */
741 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
742 *bp++ = htonl(dvnode->fid.vid);
743 *bp++ = htonl(dvnode->fid.vnode);
744 *bp++ = htonl(dvnode->fid.unique);
745 *bp++ = htonl(namesz);
746 memcpy(bp, name, namesz);
747 bp = (void *) bp + namesz;
749 memset(bp, 0, padsz);
750 bp = (void *) bp + padsz;
753 afs_use_fs_server(call, fc->cbi);
754 trace_afs_make_fs_call1(call, &dvnode->fid, name);
755 afs_set_fc_call(call, fc);
756 afs_make_call(&fc->ac, call, GFP_NOFS);
757 return afs_wait_for_call_to_complete(call, &fc->ac);
761 * deliver reply data to an FS.Link
763 static int afs_deliver_fs_link(struct afs_call *call)
768 _enter("{%u}", call->unmarshall);
770 ret = afs_transfer_reply(call);
774 /* unmarshall the reply once we've received all of it */
776 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
777 xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
778 xdr_decode_AFSVolSync(&bp, call->out_volsync);
780 _leave(" = 0 [done]");
785 * FS.Link operation type
787 static const struct afs_call_type afs_RXFSLink = {
790 .deliver = afs_deliver_fs_link,
791 .destructor = afs_flat_call_destructor,
797 int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
799 struct afs_status_cb *dvnode_scb,
800 struct afs_status_cb *vnode_scb)
802 struct afs_vnode *dvnode = fc->vnode;
803 struct afs_call *call;
804 struct afs_net *net = afs_v2net(vnode);
805 size_t namesz, reqsz, padsz;
808 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
809 return yfs_fs_link(fc, vnode, name, dvnode_scb, vnode_scb);
813 namesz = strlen(name);
814 padsz = (4 - (namesz & 3)) & 3;
815 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
817 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
822 call->out_dir_scb = dvnode_scb;
823 call->out_scb = vnode_scb;
825 /* marshall the parameters */
827 *bp++ = htonl(FSLINK);
828 *bp++ = htonl(dvnode->fid.vid);
829 *bp++ = htonl(dvnode->fid.vnode);
830 *bp++ = htonl(dvnode->fid.unique);
831 *bp++ = htonl(namesz);
832 memcpy(bp, name, namesz);
833 bp = (void *) bp + namesz;
835 memset(bp, 0, padsz);
836 bp = (void *) bp + padsz;
838 *bp++ = htonl(vnode->fid.vid);
839 *bp++ = htonl(vnode->fid.vnode);
840 *bp++ = htonl(vnode->fid.unique);
842 afs_use_fs_server(call, fc->cbi);
843 trace_afs_make_fs_call1(call, &vnode->fid, name);
844 afs_set_fc_call(call, fc);
845 afs_make_call(&fc->ac, call, GFP_NOFS);
846 return afs_wait_for_call_to_complete(call, &fc->ac);
850 * deliver reply data to an FS.Symlink
852 static int afs_deliver_fs_symlink(struct afs_call *call)
857 _enter("{%u}", call->unmarshall);
859 ret = afs_transfer_reply(call);
863 /* unmarshall the reply once we've received all of it */
865 xdr_decode_AFSFid(&bp, call->out_fid);
866 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
867 xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
868 xdr_decode_AFSVolSync(&bp, call->out_volsync);
870 _leave(" = 0 [done]");
875 * FS.Symlink operation type
877 static const struct afs_call_type afs_RXFSSymlink = {
878 .name = "FS.Symlink",
879 .op = afs_FS_Symlink,
880 .deliver = afs_deliver_fs_symlink,
881 .destructor = afs_flat_call_destructor,
885 * create a symbolic link
887 int afs_fs_symlink(struct afs_fs_cursor *fc,
889 const char *contents,
890 struct afs_status_cb *dvnode_scb,
891 struct afs_fid *newfid,
892 struct afs_status_cb *new_scb)
894 struct afs_vnode *dvnode = fc->vnode;
895 struct afs_call *call;
896 struct afs_net *net = afs_v2net(dvnode);
897 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
900 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
901 return yfs_fs_symlink(fc, name, contents, dvnode_scb,
906 namesz = strlen(name);
907 padsz = (4 - (namesz & 3)) & 3;
909 c_namesz = strlen(contents);
910 c_padsz = (4 - (c_namesz & 3)) & 3;
912 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
914 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
915 (3 + 21 + 21 + 6) * 4);
920 call->out_dir_scb = dvnode_scb;
921 call->out_fid = newfid;
922 call->out_scb = new_scb;
924 /* marshall the parameters */
926 *bp++ = htonl(FSSYMLINK);
927 *bp++ = htonl(dvnode->fid.vid);
928 *bp++ = htonl(dvnode->fid.vnode);
929 *bp++ = htonl(dvnode->fid.unique);
930 *bp++ = htonl(namesz);
931 memcpy(bp, name, namesz);
932 bp = (void *) bp + namesz;
934 memset(bp, 0, padsz);
935 bp = (void *) bp + padsz;
937 *bp++ = htonl(c_namesz);
938 memcpy(bp, contents, c_namesz);
939 bp = (void *) bp + c_namesz;
941 memset(bp, 0, c_padsz);
942 bp = (void *) bp + c_padsz;
944 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
945 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
946 *bp++ = 0; /* owner */
947 *bp++ = 0; /* group */
948 *bp++ = htonl(S_IRWXUGO); /* unix mode */
949 *bp++ = 0; /* segment size */
951 afs_use_fs_server(call, fc->cbi);
952 trace_afs_make_fs_call1(call, &dvnode->fid, name);
953 afs_set_fc_call(call, fc);
954 afs_make_call(&fc->ac, call, GFP_NOFS);
955 return afs_wait_for_call_to_complete(call, &fc->ac);
959 * deliver reply data to an FS.Rename
961 static int afs_deliver_fs_rename(struct afs_call *call)
966 ret = afs_transfer_reply(call);
971 /* If the two dirs are the same, we have two copies of the same status
972 * report, so we just decode it twice.
974 xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
975 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
976 xdr_decode_AFSVolSync(&bp, call->out_volsync);
978 _leave(" = 0 [done]");
983 * FS.Rename operation type
985 static const struct afs_call_type afs_RXFSRename = {
988 .deliver = afs_deliver_fs_rename,
989 .destructor = afs_flat_call_destructor,
993 * Rename/move a file or directory.
995 int afs_fs_rename(struct afs_fs_cursor *fc,
996 const char *orig_name,
997 struct afs_vnode *new_dvnode,
998 const char *new_name,
999 struct afs_status_cb *orig_dvnode_scb,
1000 struct afs_status_cb *new_dvnode_scb)
1002 struct afs_vnode *orig_dvnode = fc->vnode;
1003 struct afs_call *call;
1004 struct afs_net *net = afs_v2net(orig_dvnode);
1005 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1008 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1009 return yfs_fs_rename(fc, orig_name,
1010 new_dvnode, new_name,
1016 o_namesz = strlen(orig_name);
1017 o_padsz = (4 - (o_namesz & 3)) & 3;
1019 n_namesz = strlen(new_name);
1020 n_padsz = (4 - (n_namesz & 3)) & 3;
1023 4 + o_namesz + o_padsz +
1025 4 + n_namesz + n_padsz;
1027 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1031 call->key = fc->key;
1032 call->out_dir_scb = orig_dvnode_scb;
1033 call->out_scb = new_dvnode_scb;
1035 /* marshall the parameters */
1037 *bp++ = htonl(FSRENAME);
1038 *bp++ = htonl(orig_dvnode->fid.vid);
1039 *bp++ = htonl(orig_dvnode->fid.vnode);
1040 *bp++ = htonl(orig_dvnode->fid.unique);
1041 *bp++ = htonl(o_namesz);
1042 memcpy(bp, orig_name, o_namesz);
1043 bp = (void *) bp + o_namesz;
1045 memset(bp, 0, o_padsz);
1046 bp = (void *) bp + o_padsz;
1049 *bp++ = htonl(new_dvnode->fid.vid);
1050 *bp++ = htonl(new_dvnode->fid.vnode);
1051 *bp++ = htonl(new_dvnode->fid.unique);
1052 *bp++ = htonl(n_namesz);
1053 memcpy(bp, new_name, n_namesz);
1054 bp = (void *) bp + n_namesz;
1056 memset(bp, 0, n_padsz);
1057 bp = (void *) bp + n_padsz;
1060 afs_use_fs_server(call, fc->cbi);
1061 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1062 afs_set_fc_call(call, fc);
1063 afs_make_call(&fc->ac, call, GFP_NOFS);
1064 return afs_wait_for_call_to_complete(call, &fc->ac);
1068 * deliver reply data to an FS.StoreData
1070 static int afs_deliver_fs_store_data(struct afs_call *call)
1077 ret = afs_transfer_reply(call);
1081 /* unmarshall the reply once we've received all of it */
1083 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1084 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1086 _leave(" = 0 [done]");
1091 * FS.StoreData operation type
1093 static const struct afs_call_type afs_RXFSStoreData = {
1094 .name = "FS.StoreData",
1095 .op = afs_FS_StoreData,
1096 .deliver = afs_deliver_fs_store_data,
1097 .destructor = afs_flat_call_destructor,
1100 static const struct afs_call_type afs_RXFSStoreData64 = {
1101 .name = "FS.StoreData64",
1102 .op = afs_FS_StoreData64,
1103 .deliver = afs_deliver_fs_store_data,
1104 .destructor = afs_flat_call_destructor,
1108 * store a set of pages to a very large file
1110 static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1111 struct address_space *mapping,
1112 pgoff_t first, pgoff_t last,
1113 unsigned offset, unsigned to,
1114 loff_t size, loff_t pos, loff_t i_size,
1115 struct afs_status_cb *scb)
1117 struct afs_vnode *vnode = fc->vnode;
1118 struct afs_call *call;
1119 struct afs_net *net = afs_v2net(vnode);
1122 _enter(",%x,{%llx:%llu},,",
1123 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1125 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
1126 (4 + 6 + 3 * 2) * 4,
1131 call->key = fc->key;
1132 call->mapping = mapping;
1133 call->first = first;
1135 call->first_offset = offset;
1137 call->send_pages = true;
1138 call->out_scb = scb;
1140 /* marshall the parameters */
1142 *bp++ = htonl(FSSTOREDATA64);
1143 *bp++ = htonl(vnode->fid.vid);
1144 *bp++ = htonl(vnode->fid.vnode);
1145 *bp++ = htonl(vnode->fid.unique);
1147 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1148 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1149 *bp++ = 0; /* owner */
1150 *bp++ = 0; /* group */
1151 *bp++ = 0; /* unix mode */
1152 *bp++ = 0; /* segment size */
1154 *bp++ = htonl(pos >> 32);
1155 *bp++ = htonl((u32) pos);
1156 *bp++ = htonl(size >> 32);
1157 *bp++ = htonl((u32) size);
1158 *bp++ = htonl(i_size >> 32);
1159 *bp++ = htonl((u32) i_size);
1161 trace_afs_make_fs_call(call, &vnode->fid);
1162 afs_set_fc_call(call, fc);
1163 afs_make_call(&fc->ac, call, GFP_NOFS);
1164 return afs_wait_for_call_to_complete(call, &fc->ac);
1168 * store a set of pages
1170 int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1171 pgoff_t first, pgoff_t last,
1172 unsigned offset, unsigned to,
1173 struct afs_status_cb *scb)
1175 struct afs_vnode *vnode = fc->vnode;
1176 struct afs_call *call;
1177 struct afs_net *net = afs_v2net(vnode);
1178 loff_t size, pos, i_size;
1181 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1182 return yfs_fs_store_data(fc, mapping, first, last, offset, to, scb);
1184 _enter(",%x,{%llx:%llu},,",
1185 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1187 size = (loff_t)to - (loff_t)offset;
1189 size += (loff_t)(last - first) << PAGE_SHIFT;
1190 pos = (loff_t)first << PAGE_SHIFT;
1193 i_size = i_size_read(&vnode->vfs_inode);
1194 if (pos + size > i_size)
1195 i_size = size + pos;
1197 _debug("size %llx, at %llx, i_size %llx",
1198 (unsigned long long) size, (unsigned long long) pos,
1199 (unsigned long long) i_size);
1201 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1202 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
1203 size, pos, i_size, scb);
1205 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1211 call->key = fc->key;
1212 call->mapping = mapping;
1213 call->first = first;
1215 call->first_offset = offset;
1217 call->send_pages = true;
1218 call->out_scb = scb;
1220 /* marshall the parameters */
1222 *bp++ = htonl(FSSTOREDATA);
1223 *bp++ = htonl(vnode->fid.vid);
1224 *bp++ = htonl(vnode->fid.vnode);
1225 *bp++ = htonl(vnode->fid.unique);
1227 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1228 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1229 *bp++ = 0; /* owner */
1230 *bp++ = 0; /* group */
1231 *bp++ = 0; /* unix mode */
1232 *bp++ = 0; /* segment size */
1235 *bp++ = htonl(size);
1236 *bp++ = htonl(i_size);
1238 afs_use_fs_server(call, fc->cbi);
1239 trace_afs_make_fs_call(call, &vnode->fid);
1240 afs_set_fc_call(call, fc);
1241 afs_make_call(&fc->ac, call, GFP_NOFS);
1242 return afs_wait_for_call_to_complete(call, &fc->ac);
1246 * deliver reply data to an FS.StoreStatus
1248 static int afs_deliver_fs_store_status(struct afs_call *call)
1255 ret = afs_transfer_reply(call);
1259 /* unmarshall the reply once we've received all of it */
1261 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1262 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1264 _leave(" = 0 [done]");
1269 * FS.StoreStatus operation type
1271 static const struct afs_call_type afs_RXFSStoreStatus = {
1272 .name = "FS.StoreStatus",
1273 .op = afs_FS_StoreStatus,
1274 .deliver = afs_deliver_fs_store_status,
1275 .destructor = afs_flat_call_destructor,
1278 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1279 .name = "FS.StoreData",
1280 .op = afs_FS_StoreData,
1281 .deliver = afs_deliver_fs_store_status,
1282 .destructor = afs_flat_call_destructor,
1285 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1286 .name = "FS.StoreData64",
1287 .op = afs_FS_StoreData64,
1288 .deliver = afs_deliver_fs_store_status,
1289 .destructor = afs_flat_call_destructor,
1293 * set the attributes on a very large file, using FS.StoreData rather than
1294 * FS.StoreStatus so as to alter the file size also
1296 static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr,
1297 struct afs_status_cb *scb)
1299 struct afs_vnode *vnode = fc->vnode;
1300 struct afs_call *call;
1301 struct afs_net *net = afs_v2net(vnode);
1304 _enter(",%x,{%llx:%llu},,",
1305 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1307 ASSERT(attr->ia_valid & ATTR_SIZE);
1309 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
1310 (4 + 6 + 3 * 2) * 4,
1315 call->key = fc->key;
1316 call->out_scb = scb;
1318 /* marshall the parameters */
1320 *bp++ = htonl(FSSTOREDATA64);
1321 *bp++ = htonl(vnode->fid.vid);
1322 *bp++ = htonl(vnode->fid.vnode);
1323 *bp++ = htonl(vnode->fid.unique);
1325 xdr_encode_AFS_StoreStatus(&bp, attr);
1327 *bp++ = htonl(attr->ia_size >> 32); /* position of start of write */
1328 *bp++ = htonl((u32) attr->ia_size);
1329 *bp++ = 0; /* size of write */
1331 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1332 *bp++ = htonl((u32) attr->ia_size);
1334 afs_use_fs_server(call, fc->cbi);
1335 trace_afs_make_fs_call(call, &vnode->fid);
1336 afs_set_fc_call(call, fc);
1337 afs_make_call(&fc->ac, call, GFP_NOFS);
1338 return afs_wait_for_call_to_complete(call, &fc->ac);
1342 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1343 * so as to alter the file size also
1345 static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr,
1346 struct afs_status_cb *scb)
1348 struct afs_vnode *vnode = fc->vnode;
1349 struct afs_call *call;
1350 struct afs_net *net = afs_v2net(vnode);
1353 _enter(",%x,{%llx:%llu},,",
1354 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1356 ASSERT(attr->ia_valid & ATTR_SIZE);
1357 if (attr->ia_size >> 32)
1358 return afs_fs_setattr_size64(fc, attr, scb);
1360 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1366 call->key = fc->key;
1367 call->out_scb = scb;
1369 /* marshall the parameters */
1371 *bp++ = htonl(FSSTOREDATA);
1372 *bp++ = htonl(vnode->fid.vid);
1373 *bp++ = htonl(vnode->fid.vnode);
1374 *bp++ = htonl(vnode->fid.unique);
1376 xdr_encode_AFS_StoreStatus(&bp, attr);
1378 *bp++ = htonl(attr->ia_size); /* position of start of write */
1379 *bp++ = 0; /* size of write */
1380 *bp++ = htonl(attr->ia_size); /* new file length */
1382 afs_use_fs_server(call, fc->cbi);
1383 trace_afs_make_fs_call(call, &vnode->fid);
1384 afs_set_fc_call(call, fc);
1385 afs_make_call(&fc->ac, call, GFP_NOFS);
1386 return afs_wait_for_call_to_complete(call, &fc->ac);
1390 * set the attributes on a file, using FS.StoreData if there's a change in file
1391 * size, and FS.StoreStatus otherwise
1393 int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr,
1394 struct afs_status_cb *scb)
1396 struct afs_vnode *vnode = fc->vnode;
1397 struct afs_call *call;
1398 struct afs_net *net = afs_v2net(vnode);
1401 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1402 return yfs_fs_setattr(fc, attr, scb);
1404 if (attr->ia_valid & ATTR_SIZE)
1405 return afs_fs_setattr_size(fc, attr, scb);
1407 _enter(",%x,{%llx:%llu},,",
1408 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1410 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1416 call->key = fc->key;
1417 call->out_scb = scb;
1419 /* marshall the parameters */
1421 *bp++ = htonl(FSSTORESTATUS);
1422 *bp++ = htonl(vnode->fid.vid);
1423 *bp++ = htonl(vnode->fid.vnode);
1424 *bp++ = htonl(vnode->fid.unique);
1426 xdr_encode_AFS_StoreStatus(&bp, attr);
1428 afs_use_fs_server(call, fc->cbi);
1429 trace_afs_make_fs_call(call, &vnode->fid);
1430 afs_set_fc_call(call, fc);
1431 afs_make_call(&fc->ac, call, GFP_NOFS);
1432 return afs_wait_for_call_to_complete(call, &fc->ac);
1436 * deliver reply data to an FS.GetVolumeStatus
1438 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1445 _enter("{%u}", call->unmarshall);
1447 switch (call->unmarshall) {
1450 afs_extract_to_buf(call, 12 * 4);
1453 /* extract the returned status record */
1455 _debug("extract status");
1456 ret = afs_extract_data(call, true);
1461 xdr_decode_AFSFetchVolumeStatus(&bp, call->out_volstatus);
1463 afs_extract_to_tmp(call);
1466 /* extract the volume name length */
1468 ret = afs_extract_data(call, true);
1472 call->count = ntohl(call->tmp);
1473 _debug("volname length: %u", call->count);
1474 if (call->count >= AFSNAMEMAX)
1475 return afs_protocol_error(call, -EBADMSG,
1476 afs_eproto_volname_len);
1477 size = (call->count + 3) & ~3; /* It's padded */
1478 afs_extract_to_buf(call, size);
1482 /* extract the volume name */
1484 _debug("extract volname");
1485 ret = afs_extract_data(call, true);
1491 _debug("volname '%s'", p);
1492 afs_extract_to_tmp(call);
1496 /* extract the offline message length */
1498 ret = afs_extract_data(call, true);
1502 call->count = ntohl(call->tmp);
1503 _debug("offline msg length: %u", call->count);
1504 if (call->count >= AFSNAMEMAX)
1505 return afs_protocol_error(call, -EBADMSG,
1506 afs_eproto_offline_msg_len);
1507 size = (call->count + 3) & ~3; /* It's padded */
1508 afs_extract_to_buf(call, size);
1512 /* extract the offline message */
1514 _debug("extract offline");
1515 ret = afs_extract_data(call, true);
1521 _debug("offline '%s'", p);
1523 afs_extract_to_tmp(call);
1527 /* extract the message of the day length */
1529 ret = afs_extract_data(call, true);
1533 call->count = ntohl(call->tmp);
1534 _debug("motd length: %u", call->count);
1535 if (call->count >= AFSNAMEMAX)
1536 return afs_protocol_error(call, -EBADMSG,
1537 afs_eproto_motd_len);
1538 size = (call->count + 3) & ~3; /* It's padded */
1539 afs_extract_to_buf(call, size);
1543 /* extract the message of the day */
1545 _debug("extract motd");
1546 ret = afs_extract_data(call, false);
1552 _debug("motd '%s'", p);
1560 _leave(" = 0 [done]");
1565 * FS.GetVolumeStatus operation type
1567 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1568 .name = "FS.GetVolumeStatus",
1569 .op = afs_FS_GetVolumeStatus,
1570 .deliver = afs_deliver_fs_get_volume_status,
1571 .destructor = afs_flat_call_destructor,
1575 * fetch the status of a volume
1577 int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1578 struct afs_volume_status *vs)
1580 struct afs_vnode *vnode = fc->vnode;
1581 struct afs_call *call;
1582 struct afs_net *net = afs_v2net(vnode);
1585 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1586 return yfs_fs_get_volume_status(fc, vs);
1590 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4,
1591 max(12 * 4, AFSOPAQUEMAX + 1));
1595 call->key = fc->key;
1596 call->out_volstatus = vs;
1598 /* marshall the parameters */
1600 bp[0] = htonl(FSGETVOLUMESTATUS);
1601 bp[1] = htonl(vnode->fid.vid);
1603 afs_use_fs_server(call, fc->cbi);
1604 trace_afs_make_fs_call(call, &vnode->fid);
1605 afs_set_fc_call(call, fc);
1606 afs_make_call(&fc->ac, call, GFP_NOFS);
1607 return afs_wait_for_call_to_complete(call, &fc->ac);
1611 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1613 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1618 _enter("{%u}", call->unmarshall);
1620 ret = afs_transfer_reply(call);
1624 /* unmarshall the reply once we've received all of it */
1626 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1628 _leave(" = 0 [done]");
1633 * FS.SetLock operation type
1635 static const struct afs_call_type afs_RXFSSetLock = {
1636 .name = "FS.SetLock",
1637 .op = afs_FS_SetLock,
1638 .deliver = afs_deliver_fs_xxxx_lock,
1639 .done = afs_lock_op_done,
1640 .destructor = afs_flat_call_destructor,
1644 * FS.ExtendLock operation type
1646 static const struct afs_call_type afs_RXFSExtendLock = {
1647 .name = "FS.ExtendLock",
1648 .op = afs_FS_ExtendLock,
1649 .deliver = afs_deliver_fs_xxxx_lock,
1650 .done = afs_lock_op_done,
1651 .destructor = afs_flat_call_destructor,
1655 * FS.ReleaseLock operation type
1657 static const struct afs_call_type afs_RXFSReleaseLock = {
1658 .name = "FS.ReleaseLock",
1659 .op = afs_FS_ReleaseLock,
1660 .deliver = afs_deliver_fs_xxxx_lock,
1661 .destructor = afs_flat_call_destructor,
1665 * Set a lock on a file
1667 int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type,
1668 struct afs_status_cb *scb)
1670 struct afs_vnode *vnode = fc->vnode;
1671 struct afs_call *call;
1672 struct afs_net *net = afs_v2net(vnode);
1675 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1676 return yfs_fs_set_lock(fc, type, scb);
1680 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1684 call->key = fc->key;
1685 call->lvnode = vnode;
1686 call->out_scb = scb;
1688 /* marshall the parameters */
1690 *bp++ = htonl(FSSETLOCK);
1691 *bp++ = htonl(vnode->fid.vid);
1692 *bp++ = htonl(vnode->fid.vnode);
1693 *bp++ = htonl(vnode->fid.unique);
1694 *bp++ = htonl(type);
1696 afs_use_fs_server(call, fc->cbi);
1697 trace_afs_make_fs_calli(call, &vnode->fid, type);
1698 afs_set_fc_call(call, fc);
1699 afs_make_call(&fc->ac, call, GFP_NOFS);
1700 return afs_wait_for_call_to_complete(call, &fc->ac);
1704 * extend a lock on a file
1706 int afs_fs_extend_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
1708 struct afs_vnode *vnode = fc->vnode;
1709 struct afs_call *call;
1710 struct afs_net *net = afs_v2net(vnode);
1713 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1714 return yfs_fs_extend_lock(fc, scb);
1718 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1722 call->key = fc->key;
1723 call->lvnode = vnode;
1724 call->out_scb = scb;
1726 /* marshall the parameters */
1728 *bp++ = htonl(FSEXTENDLOCK);
1729 *bp++ = htonl(vnode->fid.vid);
1730 *bp++ = htonl(vnode->fid.vnode);
1731 *bp++ = htonl(vnode->fid.unique);
1733 afs_use_fs_server(call, fc->cbi);
1734 trace_afs_make_fs_call(call, &vnode->fid);
1735 afs_set_fc_call(call, fc);
1736 afs_make_call(&fc->ac, call, GFP_NOFS);
1737 return afs_wait_for_call_to_complete(call, &fc->ac);
1741 * release a lock on a file
1743 int afs_fs_release_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
1745 struct afs_vnode *vnode = fc->vnode;
1746 struct afs_call *call;
1747 struct afs_net *net = afs_v2net(vnode);
1750 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1751 return yfs_fs_release_lock(fc, scb);
1755 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1759 call->key = fc->key;
1760 call->lvnode = vnode;
1761 call->out_scb = scb;
1763 /* marshall the parameters */
1765 *bp++ = htonl(FSRELEASELOCK);
1766 *bp++ = htonl(vnode->fid.vid);
1767 *bp++ = htonl(vnode->fid.vnode);
1768 *bp++ = htonl(vnode->fid.unique);
1770 afs_use_fs_server(call, fc->cbi);
1771 trace_afs_make_fs_call(call, &vnode->fid);
1772 afs_set_fc_call(call, fc);
1773 afs_make_call(&fc->ac, call, GFP_NOFS);
1774 return afs_wait_for_call_to_complete(call, &fc->ac);
1778 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1780 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1782 return afs_transfer_reply(call);
1786 * FS.GiveUpAllCallBacks operation type
1788 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1789 .name = "FS.GiveUpAllCallBacks",
1790 .op = afs_FS_GiveUpAllCallBacks,
1791 .deliver = afs_deliver_fs_give_up_all_callbacks,
1792 .destructor = afs_flat_call_destructor,
1796 * Flush all the callbacks we have on a server.
1798 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1799 struct afs_server *server,
1800 struct afs_addr_cursor *ac,
1803 struct afs_call *call;
1808 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1814 /* marshall the parameters */
1816 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1818 /* Can't take a ref on server */
1819 afs_make_call(ac, call, GFP_NOFS);
1820 return afs_wait_for_call_to_complete(call, ac);
1824 * Deliver reply data to an FS.GetCapabilities operation.
1826 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1831 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
1833 switch (call->unmarshall) {
1835 afs_extract_to_tmp(call);
1839 /* Extract the capabilities word count */
1841 ret = afs_extract_data(call, true);
1845 count = ntohl(call->tmp);
1847 call->count = count;
1848 call->count2 = count;
1849 afs_extract_discard(call, count * sizeof(__be32));
1853 /* Extract capabilities words */
1855 ret = afs_extract_data(call, false);
1859 /* TODO: Examine capabilities */
1865 _leave(" = 0 [done]");
1870 * FS.GetCapabilities operation type
1872 static const struct afs_call_type afs_RXFSGetCapabilities = {
1873 .name = "FS.GetCapabilities",
1874 .op = afs_FS_GetCapabilities,
1875 .deliver = afs_deliver_fs_get_capabilities,
1876 .done = afs_fileserver_probe_result,
1877 .destructor = afs_flat_call_destructor,
1881 * Probe a fileserver for the capabilities that it supports. This can
1882 * return up to 196 words.
1884 struct afs_call *afs_fs_get_capabilities(struct afs_net *net,
1885 struct afs_server *server,
1886 struct afs_addr_cursor *ac,
1888 unsigned int server_index)
1890 struct afs_call *call;
1895 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1897 return ERR_PTR(-ENOMEM);
1900 call->server = afs_get_server(server, afs_server_trace_get_caps);
1901 call->server_index = server_index;
1902 call->upgrade = true;
1904 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
1906 /* marshall the parameters */
1908 *bp++ = htonl(FSGETCAPABILITIES);
1910 /* Can't take a ref on server */
1911 trace_afs_make_fs_call(call, NULL);
1912 afs_make_call(ac, call, GFP_NOFS);
1917 * Deliver reply data to an FS.FetchStatus with no vnode.
1919 static int afs_deliver_fs_fetch_status(struct afs_call *call)
1924 ret = afs_transfer_reply(call);
1928 /* unmarshall the reply once we've received all of it */
1930 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1931 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
1932 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1934 _leave(" = 0 [done]");
1939 * FS.FetchStatus operation type
1941 static const struct afs_call_type afs_RXFSFetchStatus = {
1942 .name = "FS.FetchStatus",
1943 .op = afs_FS_FetchStatus,
1944 .deliver = afs_deliver_fs_fetch_status,
1945 .destructor = afs_flat_call_destructor,
1949 * Fetch the status information for a fid without needing a vnode handle.
1951 int afs_fs_fetch_status(struct afs_fs_cursor *fc,
1952 struct afs_net *net,
1953 struct afs_fid *fid,
1954 struct afs_status_cb *scb,
1955 struct afs_volsync *volsync)
1957 struct afs_call *call;
1960 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1961 return yfs_fs_fetch_status(fc, net, fid, scb, volsync);
1963 _enter(",%x,{%llx:%llu},,",
1964 key_serial(fc->key), fid->vid, fid->vnode);
1966 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
1968 fc->ac.error = -ENOMEM;
1972 call->key = fc->key;
1973 call->out_fid = fid;
1974 call->out_scb = scb;
1975 call->out_volsync = volsync;
1977 /* marshall the parameters */
1979 bp[0] = htonl(FSFETCHSTATUS);
1980 bp[1] = htonl(fid->vid);
1981 bp[2] = htonl(fid->vnode);
1982 bp[3] = htonl(fid->unique);
1984 afs_use_fs_server(call, fc->cbi);
1985 trace_afs_make_fs_call(call, fid);
1986 afs_set_fc_call(call, fc);
1987 afs_make_call(&fc->ac, call, GFP_NOFS);
1988 return afs_wait_for_call_to_complete(call, &fc->ac);
1992 * Deliver reply data to an FS.InlineBulkStatus call
1994 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
1996 struct afs_status_cb *scb;
2001 _enter("{%u}", call->unmarshall);
2003 switch (call->unmarshall) {
2005 afs_extract_to_tmp(call);
2009 /* Extract the file status count and array in two steps */
2011 _debug("extract status count");
2012 ret = afs_extract_data(call, true);
2016 tmp = ntohl(call->tmp);
2017 _debug("status count: %u/%u", tmp, call->count2);
2018 if (tmp != call->count2)
2019 return afs_protocol_error(call, -EBADMSG,
2020 afs_eproto_ibulkst_count);
2025 afs_extract_to_buf(call, 21 * sizeof(__be32));
2029 _debug("extract status array %u", call->count);
2030 ret = afs_extract_data(call, true);
2035 scb = &call->out_scb[call->count];
2036 xdr_decode_AFSFetchStatus(&bp, call, scb);
2038 if (call->count < call->count2)
2043 afs_extract_to_tmp(call);
2046 /* Extract the callback count and array in two steps */
2048 _debug("extract CB count");
2049 ret = afs_extract_data(call, true);
2053 tmp = ntohl(call->tmp);
2054 _debug("CB count: %u", tmp);
2055 if (tmp != call->count2)
2056 return afs_protocol_error(call, -EBADMSG,
2057 afs_eproto_ibulkst_cb_count);
2061 afs_extract_to_buf(call, 3 * sizeof(__be32));
2065 _debug("extract CB array");
2066 ret = afs_extract_data(call, true);
2070 _debug("unmarshall CB array");
2072 scb = &call->out_scb[call->count];
2073 xdr_decode_AFSCallBack(&bp, call, scb);
2075 if (call->count < call->count2)
2078 afs_extract_to_buf(call, 6 * sizeof(__be32));
2083 ret = afs_extract_data(call, false);
2088 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2096 _leave(" = 0 [done]");
2101 * FS.InlineBulkStatus operation type
2103 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2104 .name = "FS.InlineBulkStatus",
2105 .op = afs_FS_InlineBulkStatus,
2106 .deliver = afs_deliver_fs_inline_bulk_status,
2107 .destructor = afs_flat_call_destructor,
2111 * Fetch the status information for up to 50 files
2113 int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2114 struct afs_net *net,
2115 struct afs_fid *fids,
2116 struct afs_status_cb *statuses,
2117 unsigned int nr_fids,
2118 struct afs_volsync *volsync)
2120 struct afs_call *call;
2124 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2125 return yfs_fs_inline_bulk_status(fc, net, fids, statuses,
2128 _enter(",%x,{%llx:%llu},%u",
2129 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2131 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2132 (2 + nr_fids * 3) * 4,
2135 fc->ac.error = -ENOMEM;
2139 call->key = fc->key;
2140 call->out_scb = statuses;
2141 call->out_volsync = volsync;
2142 call->count2 = nr_fids;
2144 /* marshall the parameters */
2146 *bp++ = htonl(FSINLINEBULKSTATUS);
2147 *bp++ = htonl(nr_fids);
2148 for (i = 0; i < nr_fids; i++) {
2149 *bp++ = htonl(fids[i].vid);
2150 *bp++ = htonl(fids[i].vnode);
2151 *bp++ = htonl(fids[i].unique);
2154 afs_use_fs_server(call, fc->cbi);
2155 trace_afs_make_fs_call(call, &fids[0]);
2156 afs_set_fc_call(call, fc);
2157 afs_make_call(&fc->ac, call, GFP_NOFS);
2158 return afs_wait_for_call_to_complete(call, &fc->ac);
2162 * deliver reply data to an FS.FetchACL
2164 static int afs_deliver_fs_fetch_acl(struct afs_call *call)
2166 struct afs_acl *acl;
2171 _enter("{%u}", call->unmarshall);
2173 switch (call->unmarshall) {
2175 afs_extract_to_tmp(call);
2179 /* extract the returned data length */
2181 ret = afs_extract_data(call, true);
2185 size = call->count2 = ntohl(call->tmp);
2186 size = round_up(size, 4);
2188 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2191 call->ret_acl = acl;
2192 acl->size = call->count2;
2193 afs_extract_begin(call, acl->data, size);
2197 /* extract the returned data */
2199 ret = afs_extract_data(call, true);
2203 afs_extract_to_buf(call, (21 + 6) * 4);
2207 /* extract the metadata */
2209 ret = afs_extract_data(call, false);
2214 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
2215 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2223 _leave(" = 0 [done]");
2227 static void afs_destroy_fs_fetch_acl(struct afs_call *call)
2229 kfree(call->ret_acl);
2230 afs_flat_call_destructor(call);
2234 * FS.FetchACL operation type
2236 static const struct afs_call_type afs_RXFSFetchACL = {
2237 .name = "FS.FetchACL",
2238 .op = afs_FS_FetchACL,
2239 .deliver = afs_deliver_fs_fetch_acl,
2240 .destructor = afs_destroy_fs_fetch_acl,
2244 * Fetch the ACL for a file.
2246 struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc,
2247 struct afs_status_cb *scb)
2249 struct afs_vnode *vnode = fc->vnode;
2250 struct afs_call *call;
2251 struct afs_net *net = afs_v2net(vnode);
2254 _enter(",%x,{%llx:%llu},,",
2255 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2257 call = afs_alloc_flat_call(net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2259 fc->ac.error = -ENOMEM;
2260 return ERR_PTR(-ENOMEM);
2263 call->key = fc->key;
2264 call->ret_acl = NULL;
2265 call->out_scb = scb;
2266 call->out_volsync = NULL;
2268 /* marshall the parameters */
2270 bp[0] = htonl(FSFETCHACL);
2271 bp[1] = htonl(vnode->fid.vid);
2272 bp[2] = htonl(vnode->fid.vnode);
2273 bp[3] = htonl(vnode->fid.unique);
2275 afs_use_fs_server(call, fc->cbi);
2276 trace_afs_make_fs_call(call, &vnode->fid);
2277 afs_make_call(&fc->ac, call, GFP_KERNEL);
2278 return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2282 * Deliver reply data to any operation that returns file status and volume
2285 static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
2290 ret = afs_transfer_reply(call);
2295 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
2296 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2298 _leave(" = 0 [done]");
2303 * FS.StoreACL operation type
2305 static const struct afs_call_type afs_RXFSStoreACL = {
2306 .name = "FS.StoreACL",
2307 .op = afs_FS_StoreACL,
2308 .deliver = afs_deliver_fs_file_status_and_vol,
2309 .destructor = afs_flat_call_destructor,
2313 * Fetch the ACL for a file.
2315 int afs_fs_store_acl(struct afs_fs_cursor *fc, const struct afs_acl *acl,
2316 struct afs_status_cb *scb)
2318 struct afs_vnode *vnode = fc->vnode;
2319 struct afs_call *call;
2320 struct afs_net *net = afs_v2net(vnode);
2324 _enter(",%x,{%llx:%llu},,",
2325 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2327 size = round_up(acl->size, 4);
2328 call = afs_alloc_flat_call(net, &afs_RXFSStoreACL,
2329 5 * 4 + size, (21 + 6) * 4);
2331 fc->ac.error = -ENOMEM;
2335 call->key = fc->key;
2336 call->out_scb = scb;
2337 call->out_volsync = NULL;
2339 /* marshall the parameters */
2341 bp[0] = htonl(FSSTOREACL);
2342 bp[1] = htonl(vnode->fid.vid);
2343 bp[2] = htonl(vnode->fid.vnode);
2344 bp[3] = htonl(vnode->fid.unique);
2345 bp[4] = htonl(acl->size);
2346 memcpy(&bp[5], acl->data, acl->size);
2347 if (acl->size != size)
2348 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2350 trace_afs_make_fs_call(call, &vnode->fid);
2351 afs_make_call(&fc->ac, call, GFP_KERNEL);
2352 return afs_wait_for_call_to_complete(call, &fc->ac);