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.
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 int 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;
93 type = ntohl(xdr->type);
97 case AFS_FTYPE_SYMLINK:
104 status->nlink = ntohl(xdr->nlink);
105 status->author = ntohl(xdr->author);
106 status->owner = ntohl(xdr->owner);
107 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
108 status->anon_access = ntohl(xdr->anon_access);
109 status->mode = ntohl(xdr->mode) & S_IALLUGO;
110 status->group = ntohl(xdr->group);
111 status->lock_count = ntohl(xdr->lock_count);
113 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
114 status->mtime_client.tv_nsec = 0;
115 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
116 status->mtime_server.tv_nsec = 0;
118 size = (u64)ntohl(xdr->size_lo);
119 size |= (u64)ntohl(xdr->size_hi) << 32;
122 data_version = (u64)ntohl(xdr->data_version_lo);
123 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
124 status->data_version = data_version;
125 scb->have_status = true;
127 *_bp = (const void *)*_bp + sizeof(*xdr);
132 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
135 static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
137 return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
140 static void xdr_decode_AFSCallBack(const __be32 **_bp,
141 struct afs_call *call,
142 struct afs_status_cb *scb)
144 struct afs_callback *cb = &scb->callback;
145 const __be32 *bp = *_bp;
148 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
155 * decode an AFSVolSync block
157 static void xdr_decode_AFSVolSync(const __be32 **_bp,
158 struct afs_volsync *volsync)
160 const __be32 *bp = *_bp;
163 creation = ntohl(*bp++);
172 volsync->creation = creation;
176 * encode the requested attributes into an AFSStoreStatus block
178 static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
181 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
184 if (attr->ia_valid & ATTR_MTIME) {
185 mask |= AFS_SET_MTIME;
186 mtime = attr->ia_mtime.tv_sec;
189 if (attr->ia_valid & ATTR_UID) {
190 mask |= AFS_SET_OWNER;
191 owner = from_kuid(&init_user_ns, attr->ia_uid);
194 if (attr->ia_valid & ATTR_GID) {
195 mask |= AFS_SET_GROUP;
196 group = from_kgid(&init_user_ns, attr->ia_gid);
199 if (attr->ia_valid & ATTR_MODE) {
200 mask |= AFS_SET_MODE;
201 mode = attr->ia_mode & S_IALLUGO;
205 *bp++ = htonl(mtime);
206 *bp++ = htonl(owner);
207 *bp++ = htonl(group);
209 *bp++ = 0; /* segment size */
214 * decode an AFSFetchVolumeStatus block
216 static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
217 struct afs_volume_status *vs)
219 const __be32 *bp = *_bp;
221 vs->vid = ntohl(*bp++);
222 vs->parent_id = ntohl(*bp++);
223 vs->online = ntohl(*bp++);
224 vs->in_service = ntohl(*bp++);
225 vs->blessed = ntohl(*bp++);
226 vs->needs_salvage = ntohl(*bp++);
227 vs->type = ntohl(*bp++);
228 vs->min_quota = ntohl(*bp++);
229 vs->max_quota = ntohl(*bp++);
230 vs->blocks_in_use = ntohl(*bp++);
231 vs->part_blocks_avail = ntohl(*bp++);
232 vs->part_max_blocks = ntohl(*bp++);
233 vs->vol_copy_date = 0;
234 vs->vol_backup_date = 0;
239 * deliver reply data to an FS.FetchStatus
241 static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
246 ret = afs_transfer_reply(call);
250 /* unmarshall the reply once we've received all of it */
252 ret = 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) {
390 ASSERTCMP(req->remain, ==, 0);
391 if (req->actual_len <= req->len)
394 /* Discard any excess data the server gave us */
395 afs_extract_discard(call, req->actual_len - req->len);
396 call->unmarshall = 3;
400 _debug("extract discard %zu/%llu",
401 iov_iter_count(&call->iter), req->actual_len - req->len);
403 ret = afs_extract_data(call, true);
408 call->unmarshall = 4;
409 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
412 /* extract the metadata */
414 ret = afs_extract_data(call, false);
419 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
422 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
423 xdr_decode_AFSVolSync(&bp, call->out_volsync);
425 req->data_version = call->out_scb->status.data_version;
426 req->file_size = call->out_scb->status.size;
434 for (; req->index < req->nr_pages; req->index++) {
435 if (req->offset < PAGE_SIZE)
436 zero_user_segment(req->pages[req->index],
437 req->offset, PAGE_SIZE);
443 _leave(" = 0 [done]");
447 static void afs_fetch_data_destructor(struct afs_call *call)
449 struct afs_read *req = call->read_request;
452 afs_flat_call_destructor(call);
456 * FS.FetchData operation type
458 static const struct afs_call_type afs_RXFSFetchData = {
459 .name = "FS.FetchData",
460 .op = afs_FS_FetchData,
461 .deliver = afs_deliver_fs_fetch_data,
462 .destructor = afs_fetch_data_destructor,
465 static const struct afs_call_type afs_RXFSFetchData64 = {
466 .name = "FS.FetchData64",
467 .op = afs_FS_FetchData64,
468 .deliver = afs_deliver_fs_fetch_data,
469 .destructor = afs_fetch_data_destructor,
473 * fetch data from a very large file
475 static int afs_fs_fetch_data64(struct afs_fs_cursor *fc,
476 struct afs_status_cb *scb,
477 struct afs_read *req)
479 struct afs_vnode *vnode = fc->vnode;
480 struct afs_call *call;
481 struct afs_net *net = afs_v2net(vnode);
486 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
492 call->out_volsync = NULL;
493 call->read_request = req;
495 /* marshall the parameters */
497 bp[0] = htonl(FSFETCHDATA64);
498 bp[1] = htonl(vnode->fid.vid);
499 bp[2] = htonl(vnode->fid.vnode);
500 bp[3] = htonl(vnode->fid.unique);
501 bp[4] = htonl(upper_32_bits(req->pos));
502 bp[5] = htonl(lower_32_bits(req->pos));
504 bp[7] = htonl(lower_32_bits(req->len));
506 refcount_inc(&req->usage);
507 afs_use_fs_server(call, fc->cbi);
508 trace_afs_make_fs_call(call, &vnode->fid);
509 afs_set_fc_call(call, fc);
510 afs_make_call(&fc->ac, call, GFP_NOFS);
511 return afs_wait_for_call_to_complete(call, &fc->ac);
515 * fetch data from a file
517 int afs_fs_fetch_data(struct afs_fs_cursor *fc,
518 struct afs_status_cb *scb,
519 struct afs_read *req)
521 struct afs_vnode *vnode = fc->vnode;
522 struct afs_call *call;
523 struct afs_net *net = afs_v2net(vnode);
526 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
527 return yfs_fs_fetch_data(fc, scb, req);
529 if (upper_32_bits(req->pos) ||
530 upper_32_bits(req->len) ||
531 upper_32_bits(req->pos + req->len))
532 return afs_fs_fetch_data64(fc, scb, req);
536 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
542 call->out_volsync = NULL;
543 call->read_request = req;
545 /* marshall the parameters */
547 bp[0] = htonl(FSFETCHDATA);
548 bp[1] = htonl(vnode->fid.vid);
549 bp[2] = htonl(vnode->fid.vnode);
550 bp[3] = htonl(vnode->fid.unique);
551 bp[4] = htonl(lower_32_bits(req->pos));
552 bp[5] = htonl(lower_32_bits(req->len));
554 refcount_inc(&req->usage);
555 afs_use_fs_server(call, fc->cbi);
556 trace_afs_make_fs_call(call, &vnode->fid);
557 afs_set_fc_call(call, fc);
558 afs_make_call(&fc->ac, call, GFP_NOFS);
559 return afs_wait_for_call_to_complete(call, &fc->ac);
563 * deliver reply data to an FS.CreateFile or an FS.MakeDir
565 static int afs_deliver_fs_create_vnode(struct afs_call *call)
570 ret = afs_transfer_reply(call);
574 /* unmarshall the reply once we've received all of it */
576 xdr_decode_AFSFid(&bp, call->out_fid);
577 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
580 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
583 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
584 xdr_decode_AFSVolSync(&bp, call->out_volsync);
586 _leave(" = 0 [done]");
591 * FS.CreateFile and FS.MakeDir operation type
593 static const struct afs_call_type afs_RXFSCreateFile = {
594 .name = "FS.CreateFile",
595 .op = afs_FS_CreateFile,
596 .deliver = afs_deliver_fs_create_vnode,
597 .destructor = afs_flat_call_destructor,
600 static const struct afs_call_type afs_RXFSMakeDir = {
601 .name = "FS.MakeDir",
602 .op = afs_FS_MakeDir,
603 .deliver = afs_deliver_fs_create_vnode,
604 .destructor = afs_flat_call_destructor,
608 * create a file or make a directory
610 int afs_fs_create(struct afs_fs_cursor *fc,
613 struct afs_status_cb *dvnode_scb,
614 struct afs_fid *newfid,
615 struct afs_status_cb *new_scb)
617 struct afs_vnode *dvnode = fc->vnode;
618 struct afs_call *call;
619 struct afs_net *net = afs_v2net(dvnode);
620 size_t namesz, reqsz, padsz;
623 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
625 return yfs_fs_make_dir(fc, name, mode, dvnode_scb,
628 return yfs_fs_create_file(fc, name, mode, dvnode_scb,
634 namesz = strlen(name);
635 padsz = (4 - (namesz & 3)) & 3;
636 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
638 call = afs_alloc_flat_call(
639 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
640 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
645 call->out_dir_scb = dvnode_scb;
646 call->out_fid = newfid;
647 call->out_scb = new_scb;
649 /* marshall the parameters */
651 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
652 *bp++ = htonl(dvnode->fid.vid);
653 *bp++ = htonl(dvnode->fid.vnode);
654 *bp++ = htonl(dvnode->fid.unique);
655 *bp++ = htonl(namesz);
656 memcpy(bp, name, namesz);
657 bp = (void *) bp + namesz;
659 memset(bp, 0, padsz);
660 bp = (void *) bp + padsz;
662 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
663 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
664 *bp++ = 0; /* owner */
665 *bp++ = 0; /* group */
666 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
667 *bp++ = 0; /* segment size */
669 afs_use_fs_server(call, fc->cbi);
670 trace_afs_make_fs_call1(call, &dvnode->fid, name);
671 afs_set_fc_call(call, fc);
672 afs_make_call(&fc->ac, call, GFP_NOFS);
673 return afs_wait_for_call_to_complete(call, &fc->ac);
677 * Deliver reply data to any operation that returns directory status and volume
680 static int afs_deliver_fs_dir_status_and_vol(struct afs_call *call)
685 ret = afs_transfer_reply(call);
689 /* unmarshall the reply once we've received all of it */
691 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
694 xdr_decode_AFSVolSync(&bp, call->out_volsync);
696 _leave(" = 0 [done]");
701 * FS.RemoveDir/FS.RemoveFile operation type
703 static const struct afs_call_type afs_RXFSRemoveFile = {
704 .name = "FS.RemoveFile",
705 .op = afs_FS_RemoveFile,
706 .deliver = afs_deliver_fs_dir_status_and_vol,
707 .destructor = afs_flat_call_destructor,
710 static const struct afs_call_type afs_RXFSRemoveDir = {
711 .name = "FS.RemoveDir",
712 .op = afs_FS_RemoveDir,
713 .deliver = afs_deliver_fs_dir_status_and_vol,
714 .destructor = afs_flat_call_destructor,
718 * remove a file or directory
720 int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
721 const char *name, bool isdir, struct afs_status_cb *dvnode_scb)
723 struct afs_vnode *dvnode = fc->vnode;
724 struct afs_call *call;
725 struct afs_net *net = afs_v2net(dvnode);
726 size_t namesz, reqsz, padsz;
729 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
730 return yfs_fs_remove(fc, vnode, name, isdir, dvnode_scb);
734 namesz = strlen(name);
735 padsz = (4 - (namesz & 3)) & 3;
736 reqsz = (5 * 4) + namesz + padsz;
738 call = afs_alloc_flat_call(
739 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
740 reqsz, (21 + 6) * 4);
745 call->out_dir_scb = dvnode_scb;
747 /* marshall the parameters */
749 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
750 *bp++ = htonl(dvnode->fid.vid);
751 *bp++ = htonl(dvnode->fid.vnode);
752 *bp++ = htonl(dvnode->fid.unique);
753 *bp++ = htonl(namesz);
754 memcpy(bp, name, namesz);
755 bp = (void *) bp + namesz;
757 memset(bp, 0, padsz);
758 bp = (void *) bp + padsz;
761 afs_use_fs_server(call, fc->cbi);
762 trace_afs_make_fs_call1(call, &dvnode->fid, name);
763 afs_set_fc_call(call, fc);
764 afs_make_call(&fc->ac, call, GFP_NOFS);
765 return afs_wait_for_call_to_complete(call, &fc->ac);
769 * deliver reply data to an FS.Link
771 static int afs_deliver_fs_link(struct afs_call *call)
776 _enter("{%u}", call->unmarshall);
778 ret = afs_transfer_reply(call);
782 /* unmarshall the reply once we've received all of it */
784 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
787 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
790 xdr_decode_AFSVolSync(&bp, call->out_volsync);
792 _leave(" = 0 [done]");
797 * FS.Link operation type
799 static const struct afs_call_type afs_RXFSLink = {
802 .deliver = afs_deliver_fs_link,
803 .destructor = afs_flat_call_destructor,
809 int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
811 struct afs_status_cb *dvnode_scb,
812 struct afs_status_cb *vnode_scb)
814 struct afs_vnode *dvnode = fc->vnode;
815 struct afs_call *call;
816 struct afs_net *net = afs_v2net(vnode);
817 size_t namesz, reqsz, padsz;
820 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
821 return yfs_fs_link(fc, vnode, name, dvnode_scb, vnode_scb);
825 namesz = strlen(name);
826 padsz = (4 - (namesz & 3)) & 3;
827 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
829 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
834 call->out_dir_scb = dvnode_scb;
835 call->out_scb = vnode_scb;
837 /* marshall the parameters */
839 *bp++ = htonl(FSLINK);
840 *bp++ = htonl(dvnode->fid.vid);
841 *bp++ = htonl(dvnode->fid.vnode);
842 *bp++ = htonl(dvnode->fid.unique);
843 *bp++ = htonl(namesz);
844 memcpy(bp, name, namesz);
845 bp = (void *) bp + namesz;
847 memset(bp, 0, padsz);
848 bp = (void *) bp + padsz;
850 *bp++ = htonl(vnode->fid.vid);
851 *bp++ = htonl(vnode->fid.vnode);
852 *bp++ = htonl(vnode->fid.unique);
854 afs_use_fs_server(call, fc->cbi);
855 trace_afs_make_fs_call1(call, &vnode->fid, name);
856 afs_set_fc_call(call, fc);
857 afs_make_call(&fc->ac, call, GFP_NOFS);
858 return afs_wait_for_call_to_complete(call, &fc->ac);
862 * deliver reply data to an FS.Symlink
864 static int afs_deliver_fs_symlink(struct afs_call *call)
869 _enter("{%u}", call->unmarshall);
871 ret = afs_transfer_reply(call);
875 /* unmarshall the reply once we've received all of it */
877 xdr_decode_AFSFid(&bp, call->out_fid);
878 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
881 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
884 xdr_decode_AFSVolSync(&bp, call->out_volsync);
886 _leave(" = 0 [done]");
891 * FS.Symlink operation type
893 static const struct afs_call_type afs_RXFSSymlink = {
894 .name = "FS.Symlink",
895 .op = afs_FS_Symlink,
896 .deliver = afs_deliver_fs_symlink,
897 .destructor = afs_flat_call_destructor,
901 * create a symbolic link
903 int afs_fs_symlink(struct afs_fs_cursor *fc,
905 const char *contents,
906 struct afs_status_cb *dvnode_scb,
907 struct afs_fid *newfid,
908 struct afs_status_cb *new_scb)
910 struct afs_vnode *dvnode = fc->vnode;
911 struct afs_call *call;
912 struct afs_net *net = afs_v2net(dvnode);
913 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
916 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
917 return yfs_fs_symlink(fc, name, contents, dvnode_scb,
922 namesz = strlen(name);
923 padsz = (4 - (namesz & 3)) & 3;
925 c_namesz = strlen(contents);
926 c_padsz = (4 - (c_namesz & 3)) & 3;
928 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
930 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
931 (3 + 21 + 21 + 6) * 4);
936 call->out_dir_scb = dvnode_scb;
937 call->out_fid = newfid;
938 call->out_scb = new_scb;
940 /* marshall the parameters */
942 *bp++ = htonl(FSSYMLINK);
943 *bp++ = htonl(dvnode->fid.vid);
944 *bp++ = htonl(dvnode->fid.vnode);
945 *bp++ = htonl(dvnode->fid.unique);
946 *bp++ = htonl(namesz);
947 memcpy(bp, name, namesz);
948 bp = (void *) bp + namesz;
950 memset(bp, 0, padsz);
951 bp = (void *) bp + padsz;
953 *bp++ = htonl(c_namesz);
954 memcpy(bp, contents, c_namesz);
955 bp = (void *) bp + c_namesz;
957 memset(bp, 0, c_padsz);
958 bp = (void *) bp + c_padsz;
960 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
961 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
962 *bp++ = 0; /* owner */
963 *bp++ = 0; /* group */
964 *bp++ = htonl(S_IRWXUGO); /* unix mode */
965 *bp++ = 0; /* segment size */
967 afs_use_fs_server(call, fc->cbi);
968 trace_afs_make_fs_call1(call, &dvnode->fid, name);
969 afs_set_fc_call(call, fc);
970 afs_make_call(&fc->ac, call, GFP_NOFS);
971 return afs_wait_for_call_to_complete(call, &fc->ac);
975 * deliver reply data to an FS.Rename
977 static int afs_deliver_fs_rename(struct afs_call *call)
982 ret = afs_transfer_reply(call);
986 /* unmarshall the reply once we've received all of it */
988 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
991 if (call->out_dir_scb != call->out_scb) {
992 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
996 xdr_decode_AFSVolSync(&bp, call->out_volsync);
998 _leave(" = 0 [done]");
1003 * FS.Rename operation type
1005 static const struct afs_call_type afs_RXFSRename = {
1006 .name = "FS.Rename",
1007 .op = afs_FS_Rename,
1008 .deliver = afs_deliver_fs_rename,
1009 .destructor = afs_flat_call_destructor,
1013 * Rename/move a file or directory.
1015 int afs_fs_rename(struct afs_fs_cursor *fc,
1016 const char *orig_name,
1017 struct afs_vnode *new_dvnode,
1018 const char *new_name,
1019 struct afs_status_cb *orig_dvnode_scb,
1020 struct afs_status_cb *new_dvnode_scb)
1022 struct afs_vnode *orig_dvnode = fc->vnode;
1023 struct afs_call *call;
1024 struct afs_net *net = afs_v2net(orig_dvnode);
1025 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1028 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1029 return yfs_fs_rename(fc, orig_name,
1030 new_dvnode, new_name,
1036 o_namesz = strlen(orig_name);
1037 o_padsz = (4 - (o_namesz & 3)) & 3;
1039 n_namesz = strlen(new_name);
1040 n_padsz = (4 - (n_namesz & 3)) & 3;
1043 4 + o_namesz + o_padsz +
1045 4 + n_namesz + n_padsz;
1047 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1051 call->key = fc->key;
1052 call->out_dir_scb = orig_dvnode_scb;
1053 call->out_scb = new_dvnode_scb;
1055 /* marshall the parameters */
1057 *bp++ = htonl(FSRENAME);
1058 *bp++ = htonl(orig_dvnode->fid.vid);
1059 *bp++ = htonl(orig_dvnode->fid.vnode);
1060 *bp++ = htonl(orig_dvnode->fid.unique);
1061 *bp++ = htonl(o_namesz);
1062 memcpy(bp, orig_name, o_namesz);
1063 bp = (void *) bp + o_namesz;
1065 memset(bp, 0, o_padsz);
1066 bp = (void *) bp + o_padsz;
1069 *bp++ = htonl(new_dvnode->fid.vid);
1070 *bp++ = htonl(new_dvnode->fid.vnode);
1071 *bp++ = htonl(new_dvnode->fid.unique);
1072 *bp++ = htonl(n_namesz);
1073 memcpy(bp, new_name, n_namesz);
1074 bp = (void *) bp + n_namesz;
1076 memset(bp, 0, n_padsz);
1077 bp = (void *) bp + n_padsz;
1080 afs_use_fs_server(call, fc->cbi);
1081 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1082 afs_set_fc_call(call, fc);
1083 afs_make_call(&fc->ac, call, GFP_NOFS);
1084 return afs_wait_for_call_to_complete(call, &fc->ac);
1088 * deliver reply data to an FS.StoreData
1090 static int afs_deliver_fs_store_data(struct afs_call *call)
1097 ret = afs_transfer_reply(call);
1101 /* unmarshall the reply once we've received all of it */
1103 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1106 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1108 _leave(" = 0 [done]");
1113 * FS.StoreData operation type
1115 static const struct afs_call_type afs_RXFSStoreData = {
1116 .name = "FS.StoreData",
1117 .op = afs_FS_StoreData,
1118 .deliver = afs_deliver_fs_store_data,
1119 .destructor = afs_flat_call_destructor,
1122 static const struct afs_call_type afs_RXFSStoreData64 = {
1123 .name = "FS.StoreData64",
1124 .op = afs_FS_StoreData64,
1125 .deliver = afs_deliver_fs_store_data,
1126 .destructor = afs_flat_call_destructor,
1130 * store a set of pages to a very large file
1132 static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1133 struct address_space *mapping,
1134 pgoff_t first, pgoff_t last,
1135 unsigned offset, unsigned to,
1136 loff_t size, loff_t pos, loff_t i_size,
1137 struct afs_status_cb *scb)
1139 struct afs_vnode *vnode = fc->vnode;
1140 struct afs_call *call;
1141 struct afs_net *net = afs_v2net(vnode);
1144 _enter(",%x,{%llx:%llu},,",
1145 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1147 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
1148 (4 + 6 + 3 * 2) * 4,
1153 call->key = fc->key;
1154 call->mapping = mapping;
1155 call->first = first;
1157 call->first_offset = offset;
1159 call->send_pages = true;
1160 call->out_scb = scb;
1162 /* marshall the parameters */
1164 *bp++ = htonl(FSSTOREDATA64);
1165 *bp++ = htonl(vnode->fid.vid);
1166 *bp++ = htonl(vnode->fid.vnode);
1167 *bp++ = htonl(vnode->fid.unique);
1169 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1170 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1171 *bp++ = 0; /* owner */
1172 *bp++ = 0; /* group */
1173 *bp++ = 0; /* unix mode */
1174 *bp++ = 0; /* segment size */
1176 *bp++ = htonl(pos >> 32);
1177 *bp++ = htonl((u32) pos);
1178 *bp++ = htonl(size >> 32);
1179 *bp++ = htonl((u32) size);
1180 *bp++ = htonl(i_size >> 32);
1181 *bp++ = htonl((u32) i_size);
1183 trace_afs_make_fs_call(call, &vnode->fid);
1184 afs_set_fc_call(call, fc);
1185 afs_make_call(&fc->ac, call, GFP_NOFS);
1186 return afs_wait_for_call_to_complete(call, &fc->ac);
1190 * store a set of pages
1192 int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1193 pgoff_t first, pgoff_t last,
1194 unsigned offset, unsigned to,
1195 struct afs_status_cb *scb)
1197 struct afs_vnode *vnode = fc->vnode;
1198 struct afs_call *call;
1199 struct afs_net *net = afs_v2net(vnode);
1200 loff_t size, pos, i_size;
1203 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1204 return yfs_fs_store_data(fc, mapping, first, last, offset, to, scb);
1206 _enter(",%x,{%llx:%llu},,",
1207 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1209 size = (loff_t)to - (loff_t)offset;
1211 size += (loff_t)(last - first) << PAGE_SHIFT;
1212 pos = (loff_t)first << PAGE_SHIFT;
1215 i_size = i_size_read(&vnode->vfs_inode);
1216 if (pos + size > i_size)
1217 i_size = size + pos;
1219 _debug("size %llx, at %llx, i_size %llx",
1220 (unsigned long long) size, (unsigned long long) pos,
1221 (unsigned long long) i_size);
1223 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1224 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
1225 size, pos, i_size, scb);
1227 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1233 call->key = fc->key;
1234 call->mapping = mapping;
1235 call->first = first;
1237 call->first_offset = offset;
1239 call->send_pages = true;
1240 call->out_scb = scb;
1242 /* marshall the parameters */
1244 *bp++ = htonl(FSSTOREDATA);
1245 *bp++ = htonl(vnode->fid.vid);
1246 *bp++ = htonl(vnode->fid.vnode);
1247 *bp++ = htonl(vnode->fid.unique);
1249 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1250 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1251 *bp++ = 0; /* owner */
1252 *bp++ = 0; /* group */
1253 *bp++ = 0; /* unix mode */
1254 *bp++ = 0; /* segment size */
1257 *bp++ = htonl(size);
1258 *bp++ = htonl(i_size);
1260 afs_use_fs_server(call, fc->cbi);
1261 trace_afs_make_fs_call(call, &vnode->fid);
1262 afs_set_fc_call(call, fc);
1263 afs_make_call(&fc->ac, call, GFP_NOFS);
1264 return afs_wait_for_call_to_complete(call, &fc->ac);
1268 * deliver reply data to an FS.StoreStatus
1270 static int afs_deliver_fs_store_status(struct afs_call *call)
1277 ret = afs_transfer_reply(call);
1281 /* unmarshall the reply once we've received all of it */
1283 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1286 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1288 _leave(" = 0 [done]");
1293 * FS.StoreStatus operation type
1295 static const struct afs_call_type afs_RXFSStoreStatus = {
1296 .name = "FS.StoreStatus",
1297 .op = afs_FS_StoreStatus,
1298 .deliver = afs_deliver_fs_store_status,
1299 .destructor = afs_flat_call_destructor,
1302 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1303 .name = "FS.StoreData",
1304 .op = afs_FS_StoreData,
1305 .deliver = afs_deliver_fs_store_status,
1306 .destructor = afs_flat_call_destructor,
1309 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1310 .name = "FS.StoreData64",
1311 .op = afs_FS_StoreData64,
1312 .deliver = afs_deliver_fs_store_status,
1313 .destructor = afs_flat_call_destructor,
1317 * set the attributes on a very large file, using FS.StoreData rather than
1318 * FS.StoreStatus so as to alter the file size also
1320 static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr,
1321 struct afs_status_cb *scb)
1323 struct afs_vnode *vnode = fc->vnode;
1324 struct afs_call *call;
1325 struct afs_net *net = afs_v2net(vnode);
1328 _enter(",%x,{%llx:%llu},,",
1329 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1331 ASSERT(attr->ia_valid & ATTR_SIZE);
1333 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
1334 (4 + 6 + 3 * 2) * 4,
1339 call->key = fc->key;
1340 call->out_scb = scb;
1342 /* marshall the parameters */
1344 *bp++ = htonl(FSSTOREDATA64);
1345 *bp++ = htonl(vnode->fid.vid);
1346 *bp++ = htonl(vnode->fid.vnode);
1347 *bp++ = htonl(vnode->fid.unique);
1349 xdr_encode_AFS_StoreStatus(&bp, attr);
1351 *bp++ = htonl(attr->ia_size >> 32); /* position of start of write */
1352 *bp++ = htonl((u32) attr->ia_size);
1353 *bp++ = 0; /* size of write */
1355 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1356 *bp++ = htonl((u32) attr->ia_size);
1358 afs_use_fs_server(call, fc->cbi);
1359 trace_afs_make_fs_call(call, &vnode->fid);
1360 afs_set_fc_call(call, fc);
1361 afs_make_call(&fc->ac, call, GFP_NOFS);
1362 return afs_wait_for_call_to_complete(call, &fc->ac);
1366 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1367 * so as to alter the file size also
1369 static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr,
1370 struct afs_status_cb *scb)
1372 struct afs_vnode *vnode = fc->vnode;
1373 struct afs_call *call;
1374 struct afs_net *net = afs_v2net(vnode);
1377 _enter(",%x,{%llx:%llu},,",
1378 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1380 ASSERT(attr->ia_valid & ATTR_SIZE);
1381 if (attr->ia_size >> 32)
1382 return afs_fs_setattr_size64(fc, attr, scb);
1384 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1390 call->key = fc->key;
1391 call->out_scb = scb;
1393 /* marshall the parameters */
1395 *bp++ = htonl(FSSTOREDATA);
1396 *bp++ = htonl(vnode->fid.vid);
1397 *bp++ = htonl(vnode->fid.vnode);
1398 *bp++ = htonl(vnode->fid.unique);
1400 xdr_encode_AFS_StoreStatus(&bp, attr);
1402 *bp++ = htonl(attr->ia_size); /* position of start of write */
1403 *bp++ = 0; /* size of write */
1404 *bp++ = htonl(attr->ia_size); /* new file length */
1406 afs_use_fs_server(call, fc->cbi);
1407 trace_afs_make_fs_call(call, &vnode->fid);
1408 afs_set_fc_call(call, fc);
1409 afs_make_call(&fc->ac, call, GFP_NOFS);
1410 return afs_wait_for_call_to_complete(call, &fc->ac);
1414 * set the attributes on a file, using FS.StoreData if there's a change in file
1415 * size, and FS.StoreStatus otherwise
1417 int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr,
1418 struct afs_status_cb *scb)
1420 struct afs_vnode *vnode = fc->vnode;
1421 struct afs_call *call;
1422 struct afs_net *net = afs_v2net(vnode);
1425 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1426 return yfs_fs_setattr(fc, attr, scb);
1428 if (attr->ia_valid & ATTR_SIZE)
1429 return afs_fs_setattr_size(fc, attr, scb);
1431 _enter(",%x,{%llx:%llu},,",
1432 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1434 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1440 call->key = fc->key;
1441 call->out_scb = scb;
1443 /* marshall the parameters */
1445 *bp++ = htonl(FSSTORESTATUS);
1446 *bp++ = htonl(vnode->fid.vid);
1447 *bp++ = htonl(vnode->fid.vnode);
1448 *bp++ = htonl(vnode->fid.unique);
1450 xdr_encode_AFS_StoreStatus(&bp, attr);
1452 afs_use_fs_server(call, fc->cbi);
1453 trace_afs_make_fs_call(call, &vnode->fid);
1454 afs_set_fc_call(call, fc);
1455 afs_make_call(&fc->ac, call, GFP_NOFS);
1456 return afs_wait_for_call_to_complete(call, &fc->ac);
1460 * deliver reply data to an FS.GetVolumeStatus
1462 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1469 _enter("{%u}", call->unmarshall);
1471 switch (call->unmarshall) {
1474 afs_extract_to_buf(call, 12 * 4);
1477 /* extract the returned status record */
1479 _debug("extract status");
1480 ret = afs_extract_data(call, true);
1485 xdr_decode_AFSFetchVolumeStatus(&bp, call->out_volstatus);
1487 afs_extract_to_tmp(call);
1490 /* extract the volume name length */
1492 ret = afs_extract_data(call, true);
1496 call->count = ntohl(call->tmp);
1497 _debug("volname length: %u", call->count);
1498 if (call->count >= AFSNAMEMAX)
1499 return afs_protocol_error(call, -EBADMSG,
1500 afs_eproto_volname_len);
1501 size = (call->count + 3) & ~3; /* It's padded */
1502 afs_extract_to_buf(call, size);
1506 /* extract the volume name */
1508 _debug("extract volname");
1509 ret = afs_extract_data(call, true);
1515 _debug("volname '%s'", p);
1516 afs_extract_to_tmp(call);
1520 /* extract the offline message length */
1522 ret = afs_extract_data(call, true);
1526 call->count = ntohl(call->tmp);
1527 _debug("offline msg length: %u", call->count);
1528 if (call->count >= AFSNAMEMAX)
1529 return afs_protocol_error(call, -EBADMSG,
1530 afs_eproto_offline_msg_len);
1531 size = (call->count + 3) & ~3; /* It's padded */
1532 afs_extract_to_buf(call, size);
1536 /* extract the offline message */
1538 _debug("extract offline");
1539 ret = afs_extract_data(call, true);
1545 _debug("offline '%s'", p);
1547 afs_extract_to_tmp(call);
1551 /* extract the message of the day length */
1553 ret = afs_extract_data(call, true);
1557 call->count = ntohl(call->tmp);
1558 _debug("motd length: %u", call->count);
1559 if (call->count >= AFSNAMEMAX)
1560 return afs_protocol_error(call, -EBADMSG,
1561 afs_eproto_motd_len);
1562 size = (call->count + 3) & ~3; /* It's padded */
1563 afs_extract_to_buf(call, size);
1567 /* extract the message of the day */
1569 _debug("extract motd");
1570 ret = afs_extract_data(call, false);
1576 _debug("motd '%s'", p);
1584 _leave(" = 0 [done]");
1589 * FS.GetVolumeStatus operation type
1591 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1592 .name = "FS.GetVolumeStatus",
1593 .op = afs_FS_GetVolumeStatus,
1594 .deliver = afs_deliver_fs_get_volume_status,
1595 .destructor = afs_flat_call_destructor,
1599 * fetch the status of a volume
1601 int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1602 struct afs_volume_status *vs)
1604 struct afs_vnode *vnode = fc->vnode;
1605 struct afs_call *call;
1606 struct afs_net *net = afs_v2net(vnode);
1609 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1610 return yfs_fs_get_volume_status(fc, vs);
1614 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4,
1615 max(12 * 4, AFSOPAQUEMAX + 1));
1619 call->key = fc->key;
1620 call->out_volstatus = vs;
1622 /* marshall the parameters */
1624 bp[0] = htonl(FSGETVOLUMESTATUS);
1625 bp[1] = htonl(vnode->fid.vid);
1627 afs_use_fs_server(call, fc->cbi);
1628 trace_afs_make_fs_call(call, &vnode->fid);
1629 afs_set_fc_call(call, fc);
1630 afs_make_call(&fc->ac, call, GFP_NOFS);
1631 return afs_wait_for_call_to_complete(call, &fc->ac);
1635 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1637 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1642 _enter("{%u}", call->unmarshall);
1644 ret = afs_transfer_reply(call);
1648 /* unmarshall the reply once we've received all of it */
1650 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1652 _leave(" = 0 [done]");
1657 * FS.SetLock operation type
1659 static const struct afs_call_type afs_RXFSSetLock = {
1660 .name = "FS.SetLock",
1661 .op = afs_FS_SetLock,
1662 .deliver = afs_deliver_fs_xxxx_lock,
1663 .done = afs_lock_op_done,
1664 .destructor = afs_flat_call_destructor,
1668 * FS.ExtendLock operation type
1670 static const struct afs_call_type afs_RXFSExtendLock = {
1671 .name = "FS.ExtendLock",
1672 .op = afs_FS_ExtendLock,
1673 .deliver = afs_deliver_fs_xxxx_lock,
1674 .done = afs_lock_op_done,
1675 .destructor = afs_flat_call_destructor,
1679 * FS.ReleaseLock operation type
1681 static const struct afs_call_type afs_RXFSReleaseLock = {
1682 .name = "FS.ReleaseLock",
1683 .op = afs_FS_ReleaseLock,
1684 .deliver = afs_deliver_fs_xxxx_lock,
1685 .destructor = afs_flat_call_destructor,
1689 * Set a lock on a file
1691 int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type,
1692 struct afs_status_cb *scb)
1694 struct afs_vnode *vnode = fc->vnode;
1695 struct afs_call *call;
1696 struct afs_net *net = afs_v2net(vnode);
1699 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1700 return yfs_fs_set_lock(fc, type, scb);
1704 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1708 call->key = fc->key;
1709 call->lvnode = vnode;
1710 call->out_scb = scb;
1712 /* marshall the parameters */
1714 *bp++ = htonl(FSSETLOCK);
1715 *bp++ = htonl(vnode->fid.vid);
1716 *bp++ = htonl(vnode->fid.vnode);
1717 *bp++ = htonl(vnode->fid.unique);
1718 *bp++ = htonl(type);
1720 afs_use_fs_server(call, fc->cbi);
1721 trace_afs_make_fs_calli(call, &vnode->fid, type);
1722 afs_set_fc_call(call, fc);
1723 afs_make_call(&fc->ac, call, GFP_NOFS);
1724 return afs_wait_for_call_to_complete(call, &fc->ac);
1728 * extend a lock on a file
1730 int afs_fs_extend_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
1732 struct afs_vnode *vnode = fc->vnode;
1733 struct afs_call *call;
1734 struct afs_net *net = afs_v2net(vnode);
1737 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1738 return yfs_fs_extend_lock(fc, scb);
1742 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1746 call->key = fc->key;
1747 call->lvnode = vnode;
1748 call->out_scb = scb;
1750 /* marshall the parameters */
1752 *bp++ = htonl(FSEXTENDLOCK);
1753 *bp++ = htonl(vnode->fid.vid);
1754 *bp++ = htonl(vnode->fid.vnode);
1755 *bp++ = htonl(vnode->fid.unique);
1757 afs_use_fs_server(call, fc->cbi);
1758 trace_afs_make_fs_call(call, &vnode->fid);
1759 afs_set_fc_call(call, fc);
1760 afs_make_call(&fc->ac, call, GFP_NOFS);
1761 return afs_wait_for_call_to_complete(call, &fc->ac);
1765 * release a lock on a file
1767 int afs_fs_release_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
1769 struct afs_vnode *vnode = fc->vnode;
1770 struct afs_call *call;
1771 struct afs_net *net = afs_v2net(vnode);
1774 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1775 return yfs_fs_release_lock(fc, scb);
1779 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1783 call->key = fc->key;
1784 call->lvnode = vnode;
1785 call->out_scb = scb;
1787 /* marshall the parameters */
1789 *bp++ = htonl(FSRELEASELOCK);
1790 *bp++ = htonl(vnode->fid.vid);
1791 *bp++ = htonl(vnode->fid.vnode);
1792 *bp++ = htonl(vnode->fid.unique);
1794 afs_use_fs_server(call, fc->cbi);
1795 trace_afs_make_fs_call(call, &vnode->fid);
1796 afs_set_fc_call(call, fc);
1797 afs_make_call(&fc->ac, call, GFP_NOFS);
1798 return afs_wait_for_call_to_complete(call, &fc->ac);
1802 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1804 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1806 return afs_transfer_reply(call);
1810 * FS.GiveUpAllCallBacks operation type
1812 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1813 .name = "FS.GiveUpAllCallBacks",
1814 .op = afs_FS_GiveUpAllCallBacks,
1815 .deliver = afs_deliver_fs_give_up_all_callbacks,
1816 .destructor = afs_flat_call_destructor,
1820 * Flush all the callbacks we have on a server.
1822 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1823 struct afs_server *server,
1824 struct afs_addr_cursor *ac,
1827 struct afs_call *call;
1832 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1838 /* marshall the parameters */
1840 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1842 /* Can't take a ref on server */
1843 afs_make_call(ac, call, GFP_NOFS);
1844 return afs_wait_for_call_to_complete(call, ac);
1848 * Deliver reply data to an FS.GetCapabilities operation.
1850 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1855 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
1857 switch (call->unmarshall) {
1859 afs_extract_to_tmp(call);
1863 /* Extract the capabilities word count */
1865 ret = afs_extract_data(call, true);
1869 count = ntohl(call->tmp);
1871 call->count = count;
1872 call->count2 = count;
1873 afs_extract_discard(call, count * sizeof(__be32));
1877 /* Extract capabilities words */
1879 ret = afs_extract_data(call, false);
1883 /* TODO: Examine capabilities */
1889 _leave(" = 0 [done]");
1894 * FS.GetCapabilities operation type
1896 static const struct afs_call_type afs_RXFSGetCapabilities = {
1897 .name = "FS.GetCapabilities",
1898 .op = afs_FS_GetCapabilities,
1899 .deliver = afs_deliver_fs_get_capabilities,
1900 .done = afs_fileserver_probe_result,
1901 .destructor = afs_flat_call_destructor,
1905 * Probe a fileserver for the capabilities that it supports. This can
1906 * return up to 196 words.
1908 struct afs_call *afs_fs_get_capabilities(struct afs_net *net,
1909 struct afs_server *server,
1910 struct afs_addr_cursor *ac,
1912 unsigned int server_index)
1914 struct afs_call *call;
1919 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1921 return ERR_PTR(-ENOMEM);
1924 call->server = afs_get_server(server, afs_server_trace_get_caps);
1925 call->server_index = server_index;
1926 call->upgrade = true;
1928 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
1930 /* marshall the parameters */
1932 *bp++ = htonl(FSGETCAPABILITIES);
1934 /* Can't take a ref on server */
1935 trace_afs_make_fs_call(call, NULL);
1936 afs_make_call(ac, call, GFP_NOFS);
1941 * Deliver reply data to an FS.FetchStatus with no vnode.
1943 static int afs_deliver_fs_fetch_status(struct afs_call *call)
1948 ret = afs_transfer_reply(call);
1952 /* unmarshall the reply once we've received all of it */
1954 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1957 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
1958 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1960 _leave(" = 0 [done]");
1965 * FS.FetchStatus operation type
1967 static const struct afs_call_type afs_RXFSFetchStatus = {
1968 .name = "FS.FetchStatus",
1969 .op = afs_FS_FetchStatus,
1970 .deliver = afs_deliver_fs_fetch_status,
1971 .destructor = afs_flat_call_destructor,
1975 * Fetch the status information for a fid without needing a vnode handle.
1977 int afs_fs_fetch_status(struct afs_fs_cursor *fc,
1978 struct afs_net *net,
1979 struct afs_fid *fid,
1980 struct afs_status_cb *scb,
1981 struct afs_volsync *volsync)
1983 struct afs_call *call;
1986 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1987 return yfs_fs_fetch_status(fc, net, fid, scb, volsync);
1989 _enter(",%x,{%llx:%llu},,",
1990 key_serial(fc->key), fid->vid, fid->vnode);
1992 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
1994 fc->ac.error = -ENOMEM;
1998 call->key = fc->key;
1999 call->out_fid = fid;
2000 call->out_scb = scb;
2001 call->out_volsync = volsync;
2003 /* marshall the parameters */
2005 bp[0] = htonl(FSFETCHSTATUS);
2006 bp[1] = htonl(fid->vid);
2007 bp[2] = htonl(fid->vnode);
2008 bp[3] = htonl(fid->unique);
2010 afs_use_fs_server(call, fc->cbi);
2011 trace_afs_make_fs_call(call, fid);
2012 afs_set_fc_call(call, fc);
2013 afs_make_call(&fc->ac, call, GFP_NOFS);
2014 return afs_wait_for_call_to_complete(call, &fc->ac);
2018 * Deliver reply data to an FS.InlineBulkStatus call
2020 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2022 struct afs_status_cb *scb;
2027 _enter("{%u}", call->unmarshall);
2029 switch (call->unmarshall) {
2031 afs_extract_to_tmp(call);
2035 /* Extract the file status count and array in two steps */
2037 _debug("extract status count");
2038 ret = afs_extract_data(call, true);
2042 tmp = ntohl(call->tmp);
2043 _debug("status count: %u/%u", tmp, call->count2);
2044 if (tmp != call->count2)
2045 return afs_protocol_error(call, -EBADMSG,
2046 afs_eproto_ibulkst_count);
2051 afs_extract_to_buf(call, 21 * sizeof(__be32));
2055 _debug("extract status array %u", call->count);
2056 ret = afs_extract_data(call, true);
2061 scb = &call->out_scb[call->count];
2062 ret = xdr_decode_AFSFetchStatus(&bp, call, scb);
2067 if (call->count < call->count2)
2072 afs_extract_to_tmp(call);
2075 /* Extract the callback count and array in two steps */
2077 _debug("extract CB count");
2078 ret = afs_extract_data(call, true);
2082 tmp = ntohl(call->tmp);
2083 _debug("CB count: %u", tmp);
2084 if (tmp != call->count2)
2085 return afs_protocol_error(call, -EBADMSG,
2086 afs_eproto_ibulkst_cb_count);
2090 afs_extract_to_buf(call, 3 * sizeof(__be32));
2094 _debug("extract CB array");
2095 ret = afs_extract_data(call, true);
2099 _debug("unmarshall CB array");
2101 scb = &call->out_scb[call->count];
2102 xdr_decode_AFSCallBack(&bp, call, scb);
2104 if (call->count < call->count2)
2107 afs_extract_to_buf(call, 6 * sizeof(__be32));
2112 ret = afs_extract_data(call, false);
2117 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2125 _leave(" = 0 [done]");
2130 * FS.InlineBulkStatus operation type
2132 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2133 .name = "FS.InlineBulkStatus",
2134 .op = afs_FS_InlineBulkStatus,
2135 .deliver = afs_deliver_fs_inline_bulk_status,
2136 .destructor = afs_flat_call_destructor,
2140 * Fetch the status information for up to 50 files
2142 int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2143 struct afs_net *net,
2144 struct afs_fid *fids,
2145 struct afs_status_cb *statuses,
2146 unsigned int nr_fids,
2147 struct afs_volsync *volsync)
2149 struct afs_call *call;
2153 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2154 return yfs_fs_inline_bulk_status(fc, net, fids, statuses,
2157 _enter(",%x,{%llx:%llu},%u",
2158 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2160 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2161 (2 + nr_fids * 3) * 4,
2164 fc->ac.error = -ENOMEM;
2168 call->key = fc->key;
2169 call->out_scb = statuses;
2170 call->out_volsync = volsync;
2171 call->count2 = nr_fids;
2173 /* marshall the parameters */
2175 *bp++ = htonl(FSINLINEBULKSTATUS);
2176 *bp++ = htonl(nr_fids);
2177 for (i = 0; i < nr_fids; i++) {
2178 *bp++ = htonl(fids[i].vid);
2179 *bp++ = htonl(fids[i].vnode);
2180 *bp++ = htonl(fids[i].unique);
2183 afs_use_fs_server(call, fc->cbi);
2184 trace_afs_make_fs_call(call, &fids[0]);
2185 afs_set_fc_call(call, fc);
2186 afs_make_call(&fc->ac, call, GFP_NOFS);
2187 return afs_wait_for_call_to_complete(call, &fc->ac);
2191 * deliver reply data to an FS.FetchACL
2193 static int afs_deliver_fs_fetch_acl(struct afs_call *call)
2195 struct afs_acl *acl;
2200 _enter("{%u}", call->unmarshall);
2202 switch (call->unmarshall) {
2204 afs_extract_to_tmp(call);
2208 /* extract the returned data length */
2210 ret = afs_extract_data(call, true);
2214 size = call->count2 = ntohl(call->tmp);
2215 size = round_up(size, 4);
2217 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2220 call->ret_acl = acl;
2221 acl->size = call->count2;
2222 afs_extract_begin(call, acl->data, size);
2226 /* extract the returned data */
2228 ret = afs_extract_data(call, true);
2232 afs_extract_to_buf(call, (21 + 6) * 4);
2236 /* extract the metadata */
2238 ret = afs_extract_data(call, false);
2243 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
2246 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2254 _leave(" = 0 [done]");
2258 static void afs_destroy_fs_fetch_acl(struct afs_call *call)
2260 kfree(call->ret_acl);
2261 afs_flat_call_destructor(call);
2265 * FS.FetchACL operation type
2267 static const struct afs_call_type afs_RXFSFetchACL = {
2268 .name = "FS.FetchACL",
2269 .op = afs_FS_FetchACL,
2270 .deliver = afs_deliver_fs_fetch_acl,
2271 .destructor = afs_destroy_fs_fetch_acl,
2275 * Fetch the ACL for a file.
2277 struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc,
2278 struct afs_status_cb *scb)
2280 struct afs_vnode *vnode = fc->vnode;
2281 struct afs_call *call;
2282 struct afs_net *net = afs_v2net(vnode);
2285 _enter(",%x,{%llx:%llu},,",
2286 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2288 call = afs_alloc_flat_call(net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2290 fc->ac.error = -ENOMEM;
2291 return ERR_PTR(-ENOMEM);
2294 call->key = fc->key;
2295 call->ret_acl = NULL;
2296 call->out_scb = scb;
2297 call->out_volsync = NULL;
2299 /* marshall the parameters */
2301 bp[0] = htonl(FSFETCHACL);
2302 bp[1] = htonl(vnode->fid.vid);
2303 bp[2] = htonl(vnode->fid.vnode);
2304 bp[3] = htonl(vnode->fid.unique);
2306 afs_use_fs_server(call, fc->cbi);
2307 trace_afs_make_fs_call(call, &vnode->fid);
2308 afs_make_call(&fc->ac, call, GFP_KERNEL);
2309 return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2313 * Deliver reply data to any operation that returns file status and volume
2316 static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
2321 ret = afs_transfer_reply(call);
2326 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
2329 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2331 _leave(" = 0 [done]");
2336 * FS.StoreACL operation type
2338 static const struct afs_call_type afs_RXFSStoreACL = {
2339 .name = "FS.StoreACL",
2340 .op = afs_FS_StoreACL,
2341 .deliver = afs_deliver_fs_file_status_and_vol,
2342 .destructor = afs_flat_call_destructor,
2346 * Fetch the ACL for a file.
2348 int afs_fs_store_acl(struct afs_fs_cursor *fc, const struct afs_acl *acl,
2349 struct afs_status_cb *scb)
2351 struct afs_vnode *vnode = fc->vnode;
2352 struct afs_call *call;
2353 struct afs_net *net = afs_v2net(vnode);
2357 _enter(",%x,{%llx:%llu},,",
2358 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2360 size = round_up(acl->size, 4);
2361 call = afs_alloc_flat_call(net, &afs_RXFSStoreACL,
2362 5 * 4 + size, (21 + 6) * 4);
2364 fc->ac.error = -ENOMEM;
2368 call->key = fc->key;
2369 call->out_scb = scb;
2370 call->out_volsync = NULL;
2372 /* marshall the parameters */
2374 bp[0] = htonl(FSSTOREACL);
2375 bp[1] = htonl(vnode->fid.vid);
2376 bp[2] = htonl(vnode->fid.vnode);
2377 bp[3] = htonl(vnode->fid.unique);
2378 bp[4] = htonl(acl->size);
2379 memcpy(&bp[5], acl->data, acl->size);
2380 if (acl->size != size)
2381 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2383 trace_afs_make_fs_call(call, &vnode->fid);
2384 afs_make_call(&fc->ac, call, GFP_KERNEL);
2385 return afs_wait_for_call_to_complete(call, &fc->ac);