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>
13 #include <linux/netfs.h>
19 * decode an AFSFid block
21 static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
23 const __be32 *bp = *_bp;
25 fid->vid = ntohl(*bp++);
26 fid->vnode = ntohl(*bp++);
27 fid->unique = ntohl(*bp++);
32 * Dump a bad file status record.
34 static void xdr_dump_bad(const __be32 *bp)
39 pr_notice("AFS XDR: Bad status record\n");
40 for (i = 0; i < 5 * 4 * 4; i += 16) {
43 pr_notice("%03x: %08x %08x %08x %08x\n",
44 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
48 pr_notice("0x50: %08x\n", ntohl(x[0]));
52 * decode an AFSFetchStatus block
54 static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
55 struct afs_call *call,
56 struct afs_status_cb *scb)
58 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
59 struct afs_file_status *status = &scb->status;
60 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
61 u64 data_version, size;
64 abort_code = ntohl(xdr->abort_code);
66 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
67 if (xdr->if_version == htonl(0) &&
70 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
71 * whereby it doesn't set the interface version in the error
74 status->abort_code = abort_code;
75 scb->have_error = true;
79 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
83 if (abort_code != 0 && inline_error) {
84 status->abort_code = abort_code;
85 scb->have_error = true;
89 type = ntohl(xdr->type);
93 case AFS_FTYPE_SYMLINK:
100 status->nlink = ntohl(xdr->nlink);
101 status->author = ntohl(xdr->author);
102 status->owner = ntohl(xdr->owner);
103 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
104 status->anon_access = ntohl(xdr->anon_access);
105 status->mode = ntohl(xdr->mode) & S_IALLUGO;
106 status->group = ntohl(xdr->group);
107 status->lock_count = ntohl(xdr->lock_count);
109 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
110 status->mtime_client.tv_nsec = 0;
111 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
112 status->mtime_server.tv_nsec = 0;
114 size = (u64)ntohl(xdr->size_lo);
115 size |= (u64)ntohl(xdr->size_hi) << 32;
118 data_version = (u64)ntohl(xdr->data_version_lo);
119 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
120 status->data_version = data_version;
121 scb->have_status = true;
123 *_bp = (const void *)*_bp + sizeof(*xdr);
128 afs_protocol_error(call, afs_eproto_bad_status);
132 static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
134 return ktime_divns(call->issue_time, NSEC_PER_SEC) + expiry;
137 static void xdr_decode_AFSCallBack(const __be32 **_bp,
138 struct afs_call *call,
139 struct afs_status_cb *scb)
141 struct afs_callback *cb = &scb->callback;
142 const __be32 *bp = *_bp;
145 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
152 * decode an AFSVolSync block
154 static void xdr_decode_AFSVolSync(const __be32 **_bp,
155 struct afs_volsync *volsync)
157 const __be32 *bp = *_bp;
160 creation = ntohl(*bp++);
169 volsync->creation = creation;
173 * encode the requested attributes into an AFSStoreStatus block
175 static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
178 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
181 if (attr->ia_valid & ATTR_MTIME) {
182 mask |= AFS_SET_MTIME;
183 mtime = attr->ia_mtime.tv_sec;
186 if (attr->ia_valid & ATTR_UID) {
187 mask |= AFS_SET_OWNER;
188 owner = from_kuid(&init_user_ns, attr->ia_uid);
191 if (attr->ia_valid & ATTR_GID) {
192 mask |= AFS_SET_GROUP;
193 group = from_kgid(&init_user_ns, attr->ia_gid);
196 if (attr->ia_valid & ATTR_MODE) {
197 mask |= AFS_SET_MODE;
198 mode = attr->ia_mode & S_IALLUGO;
202 *bp++ = htonl(mtime);
203 *bp++ = htonl(owner);
204 *bp++ = htonl(group);
206 *bp++ = 0; /* segment size */
211 * decode an AFSFetchVolumeStatus block
213 static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
214 struct afs_volume_status *vs)
216 const __be32 *bp = *_bp;
218 vs->vid = ntohl(*bp++);
219 vs->parent_id = ntohl(*bp++);
220 vs->online = ntohl(*bp++);
221 vs->in_service = ntohl(*bp++);
222 vs->blessed = ntohl(*bp++);
223 vs->needs_salvage = ntohl(*bp++);
224 vs->type = ntohl(*bp++);
225 vs->min_quota = ntohl(*bp++);
226 vs->max_quota = ntohl(*bp++);
227 vs->blocks_in_use = ntohl(*bp++);
228 vs->part_blocks_avail = ntohl(*bp++);
229 vs->part_max_blocks = ntohl(*bp++);
230 vs->vol_copy_date = 0;
231 vs->vol_backup_date = 0;
236 * deliver reply data to an FS.FetchStatus
238 static int afs_deliver_fs_fetch_status(struct afs_call *call)
240 struct afs_operation *op = call->op;
241 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
245 ret = afs_transfer_reply(call);
249 /* unmarshall the reply once we've received all of it */
251 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
252 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
253 xdr_decode_AFSVolSync(&bp, &op->volsync);
255 _leave(" = 0 [done]");
260 * FS.FetchStatus operation type
262 static const struct afs_call_type afs_RXFSFetchStatus = {
263 .name = "FS.FetchStatus",
264 .op = afs_FS_FetchStatus,
265 .deliver = afs_deliver_fs_fetch_status,
266 .destructor = afs_flat_call_destructor,
270 * fetch the status information for a file
272 void afs_fs_fetch_status(struct afs_operation *op)
274 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
275 struct afs_call *call;
278 _enter(",%x,{%llx:%llu},,",
279 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
281 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchStatus,
282 16, (21 + 3 + 6) * 4);
284 return afs_op_nomem(op);
286 /* marshall the parameters */
288 bp[0] = htonl(FSFETCHSTATUS);
289 bp[1] = htonl(vp->fid.vid);
290 bp[2] = htonl(vp->fid.vnode);
291 bp[3] = htonl(vp->fid.unique);
294 trace_afs_make_fs_call(call, &vp->fid);
295 afs_make_op_call(op, call, GFP_NOFS);
299 * deliver reply data to an FS.FetchData
301 static int afs_deliver_fs_fetch_data(struct afs_call *call)
303 struct afs_operation *op = call->op;
304 struct netfs_io_subrequest *subreq = op->fetch.subreq;
305 struct afs_vnode_param *vp = &op->file[0];
310 _enter("{%u,%zu,%zu/%llu}",
311 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
314 switch (call->unmarshall) {
318 if (call->operation_ID == FSFETCHDATA64) {
319 afs_extract_to_tmp64(call);
321 call->tmp_u = htonl(0);
322 afs_extract_to_tmp(call);
326 /* Extract the returned data length into ->remaining.
327 * This may indicate more or less data than was
328 * requested will be returned.
331 _debug("extract data length");
332 ret = afs_extract_data(call, true);
336 call->remaining = be64_to_cpu(call->tmp64);
337 _debug("DATA length: %llu", call->remaining);
339 if (call->remaining == 0)
342 call->iter = &subreq->io_iter;
343 call->iov_len = umin(call->remaining, subreq->len - subreq->transferred);
347 /* extract the returned data */
349 count_before = call->iov_len;
350 _debug("extract data %zu/%llu", count_before, call->remaining);
352 ret = afs_extract_data(call, true);
353 subreq->transferred += count_before - call->iov_len;
354 call->remaining -= count_before - call->iov_len;
358 call->iter = &call->def_iter;
362 /* Discard any excess data the server gave us */
363 afs_extract_discard(call, call->remaining);
364 call->unmarshall = 3;
368 _debug("extract discard %zu/%llu",
369 iov_iter_count(call->iter), call->remaining);
371 ret = afs_extract_data(call, true);
376 call->unmarshall = 4;
377 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
380 /* extract the metadata */
382 ret = afs_extract_data(call, false);
387 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
388 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
389 xdr_decode_AFSVolSync(&bp, &op->volsync);
391 if (subreq->start + subreq->transferred >= vp->scb.status.size)
392 __set_bit(NETFS_SREQ_HIT_EOF, &subreq->flags);
401 _leave(" = 0 [done]");
406 * FS.FetchData operation type
408 static const struct afs_call_type afs_RXFSFetchData = {
409 .name = "FS.FetchData",
410 .op = afs_FS_FetchData,
411 .async_rx = afs_fetch_data_async_rx,
412 .deliver = afs_deliver_fs_fetch_data,
413 .immediate_cancel = afs_fetch_data_immediate_cancel,
414 .destructor = afs_flat_call_destructor,
417 static const struct afs_call_type afs_RXFSFetchData64 = {
418 .name = "FS.FetchData64",
419 .op = afs_FS_FetchData64,
420 .async_rx = afs_fetch_data_async_rx,
421 .deliver = afs_deliver_fs_fetch_data,
422 .immediate_cancel = afs_fetch_data_immediate_cancel,
423 .destructor = afs_flat_call_destructor,
427 * fetch data from a very large file
429 static void afs_fs_fetch_data64(struct afs_operation *op)
431 struct netfs_io_subrequest *subreq = op->fetch.subreq;
432 struct afs_vnode_param *vp = &op->file[0];
433 struct afs_call *call;
438 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
440 return afs_op_nomem(op);
442 if (op->flags & AFS_OPERATION_ASYNC)
445 /* marshall the parameters */
447 bp[0] = htonl(FSFETCHDATA64);
448 bp[1] = htonl(vp->fid.vid);
449 bp[2] = htonl(vp->fid.vnode);
450 bp[3] = htonl(vp->fid.unique);
451 bp[4] = htonl(upper_32_bits(subreq->start + subreq->transferred));
452 bp[5] = htonl(lower_32_bits(subreq->start + subreq->transferred));
454 bp[7] = htonl(lower_32_bits(subreq->len - subreq->transferred));
457 trace_afs_make_fs_call(call, &vp->fid);
458 afs_make_op_call(op, call, GFP_NOFS);
462 * fetch data from a file
464 void afs_fs_fetch_data(struct afs_operation *op)
466 struct netfs_io_subrequest *subreq = op->fetch.subreq;
467 struct afs_vnode_param *vp = &op->file[0];
468 struct afs_call *call;
471 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
472 return afs_fs_fetch_data64(op);
476 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
478 return afs_op_nomem(op);
480 /* marshall the parameters */
482 bp[0] = htonl(FSFETCHDATA);
483 bp[1] = htonl(vp->fid.vid);
484 bp[2] = htonl(vp->fid.vnode);
485 bp[3] = htonl(vp->fid.unique);
486 bp[4] = htonl(lower_32_bits(subreq->start + subreq->transferred));
487 bp[5] = htonl(lower_32_bits(subreq->len + subreq->transferred));
490 trace_afs_make_fs_call(call, &vp->fid);
491 afs_make_op_call(op, call, GFP_NOFS);
495 * deliver reply data to an FS.CreateFile or an FS.MakeDir
497 static int afs_deliver_fs_create_vnode(struct afs_call *call)
499 struct afs_operation *op = call->op;
500 struct afs_vnode_param *dvp = &op->file[0];
501 struct afs_vnode_param *vp = &op->file[1];
505 ret = afs_transfer_reply(call);
509 /* unmarshall the reply once we've received all of it */
511 xdr_decode_AFSFid(&bp, &op->file[1].fid);
512 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
513 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
514 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
515 xdr_decode_AFSVolSync(&bp, &op->volsync);
517 _leave(" = 0 [done]");
522 * FS.CreateFile and FS.MakeDir operation type
524 static const struct afs_call_type afs_RXFSCreateFile = {
525 .name = "FS.CreateFile",
526 .op = afs_FS_CreateFile,
527 .deliver = afs_deliver_fs_create_vnode,
528 .destructor = afs_flat_call_destructor,
534 void afs_fs_create_file(struct afs_operation *op)
536 const struct qstr *name = &op->dentry->d_name;
537 struct afs_vnode_param *dvp = &op->file[0];
538 struct afs_call *call;
539 size_t namesz, reqsz, padsz;
545 padsz = (4 - (namesz & 3)) & 3;
546 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
548 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile,
549 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
551 return afs_op_nomem(op);
553 /* marshall the parameters */
555 *bp++ = htonl(FSCREATEFILE);
556 *bp++ = htonl(dvp->fid.vid);
557 *bp++ = htonl(dvp->fid.vnode);
558 *bp++ = htonl(dvp->fid.unique);
559 *bp++ = htonl(namesz);
560 memcpy(bp, name->name, namesz);
561 bp = (void *) bp + namesz;
563 memset(bp, 0, padsz);
564 bp = (void *) bp + padsz;
566 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
567 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
568 *bp++ = 0; /* owner */
569 *bp++ = 0; /* group */
570 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
571 *bp++ = 0; /* segment size */
573 call->fid = dvp->fid;
574 trace_afs_make_fs_call1(call, &dvp->fid, name);
575 afs_make_op_call(op, call, GFP_NOFS);
578 static const struct afs_call_type afs_RXFSMakeDir = {
579 .name = "FS.MakeDir",
580 .op = afs_FS_MakeDir,
581 .deliver = afs_deliver_fs_create_vnode,
582 .destructor = afs_flat_call_destructor,
586 * Create a new directory
588 void afs_fs_make_dir(struct afs_operation *op)
590 const struct qstr *name = &op->dentry->d_name;
591 struct afs_vnode_param *dvp = &op->file[0];
592 struct afs_call *call;
593 size_t namesz, reqsz, padsz;
599 padsz = (4 - (namesz & 3)) & 3;
600 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
602 call = afs_alloc_flat_call(op->net, &afs_RXFSMakeDir,
603 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
605 return afs_op_nomem(op);
607 /* marshall the parameters */
609 *bp++ = htonl(FSMAKEDIR);
610 *bp++ = htonl(dvp->fid.vid);
611 *bp++ = htonl(dvp->fid.vnode);
612 *bp++ = htonl(dvp->fid.unique);
613 *bp++ = htonl(namesz);
614 memcpy(bp, name->name, namesz);
615 bp = (void *) bp + namesz;
617 memset(bp, 0, padsz);
618 bp = (void *) bp + padsz;
620 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
621 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
622 *bp++ = 0; /* owner */
623 *bp++ = 0; /* group */
624 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
625 *bp++ = 0; /* segment size */
627 call->fid = dvp->fid;
628 trace_afs_make_fs_call1(call, &dvp->fid, name);
629 afs_make_op_call(op, call, GFP_NOFS);
633 * Deliver reply data to any operation that returns status and volume sync.
635 static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
637 struct afs_operation *op = call->op;
638 struct afs_vnode_param *vp = &op->file[0];
642 ret = afs_transfer_reply(call);
646 /* unmarshall the reply once we've received all of it */
648 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
649 xdr_decode_AFSVolSync(&bp, &op->volsync);
651 _leave(" = 0 [done]");
656 * FS.RemoveFile operation type
658 static const struct afs_call_type afs_RXFSRemoveFile = {
659 .name = "FS.RemoveFile",
660 .op = afs_FS_RemoveFile,
661 .deliver = afs_deliver_fs_file_status_and_vol,
662 .destructor = afs_flat_call_destructor,
668 void afs_fs_remove_file(struct afs_operation *op)
670 const struct qstr *name = &op->dentry->d_name;
671 struct afs_vnode_param *dvp = &op->file[0];
672 struct afs_call *call;
673 size_t namesz, reqsz, padsz;
679 padsz = (4 - (namesz & 3)) & 3;
680 reqsz = (5 * 4) + namesz + padsz;
682 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveFile,
683 reqsz, (21 + 6) * 4);
685 return afs_op_nomem(op);
687 /* marshall the parameters */
689 *bp++ = htonl(FSREMOVEFILE);
690 *bp++ = htonl(dvp->fid.vid);
691 *bp++ = htonl(dvp->fid.vnode);
692 *bp++ = htonl(dvp->fid.unique);
693 *bp++ = htonl(namesz);
694 memcpy(bp, name->name, namesz);
695 bp = (void *) bp + namesz;
697 memset(bp, 0, padsz);
698 bp = (void *) bp + padsz;
701 call->fid = dvp->fid;
702 trace_afs_make_fs_call1(call, &dvp->fid, name);
703 afs_make_op_call(op, call, GFP_NOFS);
706 static const struct afs_call_type afs_RXFSRemoveDir = {
707 .name = "FS.RemoveDir",
708 .op = afs_FS_RemoveDir,
709 .deliver = afs_deliver_fs_file_status_and_vol,
710 .destructor = afs_flat_call_destructor,
714 * Remove a directory.
716 void afs_fs_remove_dir(struct afs_operation *op)
718 const struct qstr *name = &op->dentry->d_name;
719 struct afs_vnode_param *dvp = &op->file[0];
720 struct afs_call *call;
721 size_t namesz, reqsz, padsz;
727 padsz = (4 - (namesz & 3)) & 3;
728 reqsz = (5 * 4) + namesz + padsz;
730 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveDir,
731 reqsz, (21 + 6) * 4);
733 return afs_op_nomem(op);
735 /* marshall the parameters */
737 *bp++ = htonl(FSREMOVEDIR);
738 *bp++ = htonl(dvp->fid.vid);
739 *bp++ = htonl(dvp->fid.vnode);
740 *bp++ = htonl(dvp->fid.unique);
741 *bp++ = htonl(namesz);
742 memcpy(bp, name->name, namesz);
743 bp = (void *) bp + namesz;
745 memset(bp, 0, padsz);
746 bp = (void *) bp + padsz;
749 call->fid = dvp->fid;
750 trace_afs_make_fs_call1(call, &dvp->fid, name);
751 afs_make_op_call(op, call, GFP_NOFS);
755 * deliver reply data to an FS.Link
757 static int afs_deliver_fs_link(struct afs_call *call)
759 struct afs_operation *op = call->op;
760 struct afs_vnode_param *dvp = &op->file[0];
761 struct afs_vnode_param *vp = &op->file[1];
765 _enter("{%u}", call->unmarshall);
767 ret = afs_transfer_reply(call);
771 /* unmarshall the reply once we've received all of it */
773 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
774 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
775 xdr_decode_AFSVolSync(&bp, &op->volsync);
777 _leave(" = 0 [done]");
782 * FS.Link operation type
784 static const struct afs_call_type afs_RXFSLink = {
787 .deliver = afs_deliver_fs_link,
788 .destructor = afs_flat_call_destructor,
794 void afs_fs_link(struct afs_operation *op)
796 const struct qstr *name = &op->dentry->d_name;
797 struct afs_vnode_param *dvp = &op->file[0];
798 struct afs_vnode_param *vp = &op->file[1];
799 struct afs_call *call;
800 size_t namesz, reqsz, padsz;
806 padsz = (4 - (namesz & 3)) & 3;
807 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
809 call = afs_alloc_flat_call(op->net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
811 return afs_op_nomem(op);
813 /* marshall the parameters */
815 *bp++ = htonl(FSLINK);
816 *bp++ = htonl(dvp->fid.vid);
817 *bp++ = htonl(dvp->fid.vnode);
818 *bp++ = htonl(dvp->fid.unique);
819 *bp++ = htonl(namesz);
820 memcpy(bp, name->name, namesz);
821 bp = (void *) bp + namesz;
823 memset(bp, 0, padsz);
824 bp = (void *) bp + padsz;
826 *bp++ = htonl(vp->fid.vid);
827 *bp++ = htonl(vp->fid.vnode);
828 *bp++ = htonl(vp->fid.unique);
831 trace_afs_make_fs_call1(call, &vp->fid, name);
832 afs_make_op_call(op, call, GFP_NOFS);
836 * deliver reply data to an FS.Symlink
838 static int afs_deliver_fs_symlink(struct afs_call *call)
840 struct afs_operation *op = call->op;
841 struct afs_vnode_param *dvp = &op->file[0];
842 struct afs_vnode_param *vp = &op->file[1];
846 _enter("{%u}", call->unmarshall);
848 ret = afs_transfer_reply(call);
852 /* unmarshall the reply once we've received all of it */
854 xdr_decode_AFSFid(&bp, &vp->fid);
855 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
856 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
857 xdr_decode_AFSVolSync(&bp, &op->volsync);
859 _leave(" = 0 [done]");
864 * FS.Symlink operation type
866 static const struct afs_call_type afs_RXFSSymlink = {
867 .name = "FS.Symlink",
868 .op = afs_FS_Symlink,
869 .deliver = afs_deliver_fs_symlink,
870 .destructor = afs_flat_call_destructor,
874 * create a symbolic link
876 void afs_fs_symlink(struct afs_operation *op)
878 const struct qstr *name = &op->dentry->d_name;
879 struct afs_vnode_param *dvp = &op->file[0];
880 struct afs_call *call;
881 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
887 padsz = (4 - (namesz & 3)) & 3;
889 c_namesz = strlen(op->create.symlink);
890 c_padsz = (4 - (c_namesz & 3)) & 3;
892 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
894 call = afs_alloc_flat_call(op->net, &afs_RXFSSymlink, reqsz,
895 (3 + 21 + 21 + 6) * 4);
897 return afs_op_nomem(op);
899 /* marshall the parameters */
901 *bp++ = htonl(FSSYMLINK);
902 *bp++ = htonl(dvp->fid.vid);
903 *bp++ = htonl(dvp->fid.vnode);
904 *bp++ = htonl(dvp->fid.unique);
905 *bp++ = htonl(namesz);
906 memcpy(bp, name->name, namesz);
907 bp = (void *) bp + namesz;
909 memset(bp, 0, padsz);
910 bp = (void *) bp + padsz;
912 *bp++ = htonl(c_namesz);
913 memcpy(bp, op->create.symlink, c_namesz);
914 bp = (void *) bp + c_namesz;
916 memset(bp, 0, c_padsz);
917 bp = (void *) bp + c_padsz;
919 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
920 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
921 *bp++ = 0; /* owner */
922 *bp++ = 0; /* group */
923 *bp++ = htonl(S_IRWXUGO); /* unix mode */
924 *bp++ = 0; /* segment size */
926 call->fid = dvp->fid;
927 trace_afs_make_fs_call1(call, &dvp->fid, name);
928 afs_make_op_call(op, call, GFP_NOFS);
932 * deliver reply data to an FS.Rename
934 static int afs_deliver_fs_rename(struct afs_call *call)
936 struct afs_operation *op = call->op;
937 struct afs_vnode_param *orig_dvp = &op->file[0];
938 struct afs_vnode_param *new_dvp = &op->file[1];
942 ret = afs_transfer_reply(call);
947 /* If the two dirs are the same, we have two copies of the same status
948 * report, so we just decode it twice.
950 xdr_decode_AFSFetchStatus(&bp, call, &orig_dvp->scb);
951 xdr_decode_AFSFetchStatus(&bp, call, &new_dvp->scb);
952 xdr_decode_AFSVolSync(&bp, &op->volsync);
954 _leave(" = 0 [done]");
959 * FS.Rename operation type
961 static const struct afs_call_type afs_RXFSRename = {
964 .deliver = afs_deliver_fs_rename,
965 .destructor = afs_flat_call_destructor,
969 * Rename/move a file or directory.
971 void afs_fs_rename(struct afs_operation *op)
973 struct afs_vnode_param *orig_dvp = &op->file[0];
974 struct afs_vnode_param *new_dvp = &op->file[1];
975 const struct qstr *orig_name = &op->dentry->d_name;
976 const struct qstr *new_name = &op->dentry_2->d_name;
977 struct afs_call *call;
978 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
983 o_namesz = orig_name->len;
984 o_padsz = (4 - (o_namesz & 3)) & 3;
986 n_namesz = new_name->len;
987 n_padsz = (4 - (n_namesz & 3)) & 3;
990 4 + o_namesz + o_padsz +
992 4 + n_namesz + n_padsz;
994 call = afs_alloc_flat_call(op->net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
996 return afs_op_nomem(op);
998 /* marshall the parameters */
1000 *bp++ = htonl(FSRENAME);
1001 *bp++ = htonl(orig_dvp->fid.vid);
1002 *bp++ = htonl(orig_dvp->fid.vnode);
1003 *bp++ = htonl(orig_dvp->fid.unique);
1004 *bp++ = htonl(o_namesz);
1005 memcpy(bp, orig_name->name, o_namesz);
1006 bp = (void *) bp + o_namesz;
1008 memset(bp, 0, o_padsz);
1009 bp = (void *) bp + o_padsz;
1012 *bp++ = htonl(new_dvp->fid.vid);
1013 *bp++ = htonl(new_dvp->fid.vnode);
1014 *bp++ = htonl(new_dvp->fid.unique);
1015 *bp++ = htonl(n_namesz);
1016 memcpy(bp, new_name->name, n_namesz);
1017 bp = (void *) bp + n_namesz;
1019 memset(bp, 0, n_padsz);
1020 bp = (void *) bp + n_padsz;
1023 call->fid = orig_dvp->fid;
1024 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1025 afs_make_op_call(op, call, GFP_NOFS);
1029 * Deliver reply data to FS.StoreData or FS.StoreStatus
1031 static int afs_deliver_fs_store_data(struct afs_call *call)
1033 struct afs_operation *op = call->op;
1034 struct afs_vnode_param *vp = &op->file[0];
1040 ret = afs_transfer_reply(call);
1044 /* unmarshall the reply once we've received all of it */
1046 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
1047 xdr_decode_AFSVolSync(&bp, &op->volsync);
1049 _leave(" = 0 [done]");
1054 * FS.StoreData operation type
1056 static const struct afs_call_type afs_RXFSStoreData = {
1057 .name = "FS.StoreData",
1058 .op = afs_FS_StoreData,
1059 .deliver = afs_deliver_fs_store_data,
1060 .destructor = afs_flat_call_destructor,
1063 static const struct afs_call_type afs_RXFSStoreData64 = {
1064 .name = "FS.StoreData64",
1065 .op = afs_FS_StoreData64,
1066 .deliver = afs_deliver_fs_store_data,
1067 .destructor = afs_flat_call_destructor,
1071 * store a set of pages to a very large file
1073 static void afs_fs_store_data64(struct afs_operation *op)
1075 struct afs_vnode_param *vp = &op->file[0];
1076 struct afs_call *call;
1079 _enter(",%x,{%llx:%llu},,",
1080 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1082 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64,
1083 (4 + 6 + 3 * 2) * 4,
1086 return afs_op_nomem(op);
1088 call->write_iter = op->store.write_iter;
1090 /* marshall the parameters */
1092 *bp++ = htonl(FSSTOREDATA64);
1093 *bp++ = htonl(vp->fid.vid);
1094 *bp++ = htonl(vp->fid.vnode);
1095 *bp++ = htonl(vp->fid.unique);
1097 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1098 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
1099 *bp++ = 0; /* owner */
1100 *bp++ = 0; /* group */
1101 *bp++ = 0; /* unix mode */
1102 *bp++ = 0; /* segment size */
1104 *bp++ = htonl(upper_32_bits(op->store.pos));
1105 *bp++ = htonl(lower_32_bits(op->store.pos));
1106 *bp++ = htonl(upper_32_bits(op->store.size));
1107 *bp++ = htonl(lower_32_bits(op->store.size));
1108 *bp++ = htonl(upper_32_bits(op->store.i_size));
1109 *bp++ = htonl(lower_32_bits(op->store.i_size));
1111 call->fid = vp->fid;
1112 trace_afs_make_fs_call(call, &vp->fid);
1113 afs_make_op_call(op, call, GFP_NOFS);
1117 * Write data to a file on the server.
1119 void afs_fs_store_data(struct afs_operation *op)
1121 struct afs_vnode_param *vp = &op->file[0];
1122 struct afs_call *call;
1125 _enter(",%x,{%llx:%llu},,",
1126 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1128 _debug("size %llx, at %llx, i_size %llx",
1129 (unsigned long long)op->store.size,
1130 (unsigned long long)op->store.pos,
1131 (unsigned long long)op->store.i_size);
1133 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
1134 return afs_fs_store_data64(op);
1136 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData,
1140 return afs_op_nomem(op);
1142 call->write_iter = op->store.write_iter;
1144 /* marshall the parameters */
1146 *bp++ = htonl(FSSTOREDATA);
1147 *bp++ = htonl(vp->fid.vid);
1148 *bp++ = htonl(vp->fid.vnode);
1149 *bp++ = htonl(vp->fid.unique);
1151 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1152 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
1153 *bp++ = 0; /* owner */
1154 *bp++ = 0; /* group */
1155 *bp++ = 0; /* unix mode */
1156 *bp++ = 0; /* segment size */
1158 *bp++ = htonl(lower_32_bits(op->store.pos));
1159 *bp++ = htonl(lower_32_bits(op->store.size));
1160 *bp++ = htonl(lower_32_bits(op->store.i_size));
1162 call->fid = vp->fid;
1163 trace_afs_make_fs_call(call, &vp->fid);
1164 afs_make_op_call(op, call, GFP_NOFS);
1168 * FS.StoreStatus operation type
1170 static const struct afs_call_type afs_RXFSStoreStatus = {
1171 .name = "FS.StoreStatus",
1172 .op = afs_FS_StoreStatus,
1173 .deliver = afs_deliver_fs_store_data,
1174 .destructor = afs_flat_call_destructor,
1177 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1178 .name = "FS.StoreData",
1179 .op = afs_FS_StoreData,
1180 .deliver = afs_deliver_fs_store_data,
1181 .destructor = afs_flat_call_destructor,
1184 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1185 .name = "FS.StoreData64",
1186 .op = afs_FS_StoreData64,
1187 .deliver = afs_deliver_fs_store_data,
1188 .destructor = afs_flat_call_destructor,
1192 * set the attributes on a very large file, using FS.StoreData rather than
1193 * FS.StoreStatus so as to alter the file size also
1195 static void afs_fs_setattr_size64(struct afs_operation *op)
1197 struct afs_vnode_param *vp = &op->file[0];
1198 struct afs_call *call;
1199 struct iattr *attr = op->setattr.attr;
1202 _enter(",%x,{%llx:%llu},,",
1203 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1205 ASSERT(attr->ia_valid & ATTR_SIZE);
1207 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64_as_Status,
1208 (4 + 6 + 3 * 2) * 4,
1211 return afs_op_nomem(op);
1213 /* marshall the parameters */
1215 *bp++ = htonl(FSSTOREDATA64);
1216 *bp++ = htonl(vp->fid.vid);
1217 *bp++ = htonl(vp->fid.vnode);
1218 *bp++ = htonl(vp->fid.unique);
1220 xdr_encode_AFS_StoreStatus(&bp, attr);
1222 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* position of start of write */
1223 *bp++ = htonl(lower_32_bits(attr->ia_size));
1224 *bp++ = 0; /* size of write */
1226 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* new file length */
1227 *bp++ = htonl(lower_32_bits(attr->ia_size));
1229 call->fid = vp->fid;
1230 trace_afs_make_fs_call(call, &vp->fid);
1231 afs_make_op_call(op, call, GFP_NOFS);
1235 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1236 * so as to alter the file size also
1238 static void afs_fs_setattr_size(struct afs_operation *op)
1240 struct afs_vnode_param *vp = &op->file[0];
1241 struct afs_call *call;
1242 struct iattr *attr = op->setattr.attr;
1245 _enter(",%x,{%llx:%llu},,",
1246 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1248 ASSERT(attr->ia_valid & ATTR_SIZE);
1249 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
1250 return afs_fs_setattr_size64(op);
1252 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData_as_Status,
1256 return afs_op_nomem(op);
1258 /* marshall the parameters */
1260 *bp++ = htonl(FSSTOREDATA);
1261 *bp++ = htonl(vp->fid.vid);
1262 *bp++ = htonl(vp->fid.vnode);
1263 *bp++ = htonl(vp->fid.unique);
1265 xdr_encode_AFS_StoreStatus(&bp, attr);
1267 *bp++ = htonl(attr->ia_size); /* position of start of write */
1268 *bp++ = 0; /* size of write */
1269 *bp++ = htonl(attr->ia_size); /* new file length */
1271 call->fid = vp->fid;
1272 trace_afs_make_fs_call(call, &vp->fid);
1273 afs_make_op_call(op, call, GFP_NOFS);
1277 * set the attributes on a file, using FS.StoreData if there's a change in file
1278 * size, and FS.StoreStatus otherwise
1280 void afs_fs_setattr(struct afs_operation *op)
1282 struct afs_vnode_param *vp = &op->file[0];
1283 struct afs_call *call;
1284 struct iattr *attr = op->setattr.attr;
1287 if (attr->ia_valid & ATTR_SIZE)
1288 return afs_fs_setattr_size(op);
1290 _enter(",%x,{%llx:%llu},,",
1291 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1293 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreStatus,
1297 return afs_op_nomem(op);
1299 /* marshall the parameters */
1301 *bp++ = htonl(FSSTORESTATUS);
1302 *bp++ = htonl(vp->fid.vid);
1303 *bp++ = htonl(vp->fid.vnode);
1304 *bp++ = htonl(vp->fid.unique);
1306 xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr);
1308 call->fid = vp->fid;
1309 trace_afs_make_fs_call(call, &vp->fid);
1310 afs_make_op_call(op, call, GFP_NOFS);
1314 * deliver reply data to an FS.GetVolumeStatus
1316 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1318 struct afs_operation *op = call->op;
1324 _enter("{%u}", call->unmarshall);
1326 switch (call->unmarshall) {
1329 afs_extract_to_buf(call, 12 * 4);
1332 /* extract the returned status record */
1334 _debug("extract status");
1335 ret = afs_extract_data(call, true);
1340 xdr_decode_AFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1342 afs_extract_to_tmp(call);
1345 /* extract the volume name length */
1347 ret = afs_extract_data(call, true);
1351 call->count = ntohl(call->tmp);
1352 _debug("volname length: %u", call->count);
1353 if (call->count >= AFSNAMEMAX)
1354 return afs_protocol_error(call, afs_eproto_volname_len);
1355 size = (call->count + 3) & ~3; /* It's padded */
1356 afs_extract_to_buf(call, size);
1360 /* extract the volume name */
1362 _debug("extract volname");
1363 ret = afs_extract_data(call, true);
1369 _debug("volname '%s'", p);
1370 afs_extract_to_tmp(call);
1374 /* extract the offline message length */
1376 ret = afs_extract_data(call, true);
1380 call->count = ntohl(call->tmp);
1381 _debug("offline msg length: %u", call->count);
1382 if (call->count >= AFSNAMEMAX)
1383 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1384 size = (call->count + 3) & ~3; /* It's padded */
1385 afs_extract_to_buf(call, size);
1389 /* extract the offline message */
1391 _debug("extract offline");
1392 ret = afs_extract_data(call, true);
1398 _debug("offline '%s'", p);
1400 afs_extract_to_tmp(call);
1404 /* extract the message of the day length */
1406 ret = afs_extract_data(call, true);
1410 call->count = ntohl(call->tmp);
1411 _debug("motd length: %u", call->count);
1412 if (call->count >= AFSNAMEMAX)
1413 return afs_protocol_error(call, afs_eproto_motd_len);
1414 size = (call->count + 3) & ~3; /* It's padded */
1415 afs_extract_to_buf(call, size);
1419 /* extract the message of the day */
1421 _debug("extract motd");
1422 ret = afs_extract_data(call, false);
1428 _debug("motd '%s'", p);
1437 _leave(" = 0 [done]");
1442 * FS.GetVolumeStatus operation type
1444 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1445 .name = "FS.GetVolumeStatus",
1446 .op = afs_FS_GetVolumeStatus,
1447 .deliver = afs_deliver_fs_get_volume_status,
1448 .destructor = afs_flat_call_destructor,
1452 * fetch the status of a volume
1454 void afs_fs_get_volume_status(struct afs_operation *op)
1456 struct afs_vnode_param *vp = &op->file[0];
1457 struct afs_call *call;
1462 call = afs_alloc_flat_call(op->net, &afs_RXFSGetVolumeStatus, 2 * 4,
1463 max(12 * 4, AFSOPAQUEMAX + 1));
1465 return afs_op_nomem(op);
1467 /* marshall the parameters */
1469 bp[0] = htonl(FSGETVOLUMESTATUS);
1470 bp[1] = htonl(vp->fid.vid);
1472 call->fid = vp->fid;
1473 trace_afs_make_fs_call(call, &vp->fid);
1474 afs_make_op_call(op, call, GFP_NOFS);
1478 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1480 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1482 struct afs_operation *op = call->op;
1486 _enter("{%u}", call->unmarshall);
1488 ret = afs_transfer_reply(call);
1492 /* unmarshall the reply once we've received all of it */
1494 xdr_decode_AFSVolSync(&bp, &op->volsync);
1496 _leave(" = 0 [done]");
1501 * FS.SetLock operation type
1503 static const struct afs_call_type afs_RXFSSetLock = {
1504 .name = "FS.SetLock",
1505 .op = afs_FS_SetLock,
1506 .deliver = afs_deliver_fs_xxxx_lock,
1507 .done = afs_lock_op_done,
1508 .destructor = afs_flat_call_destructor,
1512 * FS.ExtendLock operation type
1514 static const struct afs_call_type afs_RXFSExtendLock = {
1515 .name = "FS.ExtendLock",
1516 .op = afs_FS_ExtendLock,
1517 .deliver = afs_deliver_fs_xxxx_lock,
1518 .done = afs_lock_op_done,
1519 .destructor = afs_flat_call_destructor,
1523 * FS.ReleaseLock operation type
1525 static const struct afs_call_type afs_RXFSReleaseLock = {
1526 .name = "FS.ReleaseLock",
1527 .op = afs_FS_ReleaseLock,
1528 .deliver = afs_deliver_fs_xxxx_lock,
1529 .destructor = afs_flat_call_destructor,
1533 * Set a lock on a file
1535 void afs_fs_set_lock(struct afs_operation *op)
1537 struct afs_vnode_param *vp = &op->file[0];
1538 struct afs_call *call;
1543 call = afs_alloc_flat_call(op->net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1545 return afs_op_nomem(op);
1547 /* marshall the parameters */
1549 *bp++ = htonl(FSSETLOCK);
1550 *bp++ = htonl(vp->fid.vid);
1551 *bp++ = htonl(vp->fid.vnode);
1552 *bp++ = htonl(vp->fid.unique);
1553 *bp++ = htonl(op->lock.type);
1555 call->fid = vp->fid;
1556 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1557 afs_make_op_call(op, call, GFP_NOFS);
1561 * extend a lock on a file
1563 void afs_fs_extend_lock(struct afs_operation *op)
1565 struct afs_vnode_param *vp = &op->file[0];
1566 struct afs_call *call;
1571 call = afs_alloc_flat_call(op->net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1573 return afs_op_nomem(op);
1575 /* marshall the parameters */
1577 *bp++ = htonl(FSEXTENDLOCK);
1578 *bp++ = htonl(vp->fid.vid);
1579 *bp++ = htonl(vp->fid.vnode);
1580 *bp++ = htonl(vp->fid.unique);
1582 call->fid = vp->fid;
1583 trace_afs_make_fs_call(call, &vp->fid);
1584 afs_make_op_call(op, call, GFP_NOFS);
1588 * release a lock on a file
1590 void afs_fs_release_lock(struct afs_operation *op)
1592 struct afs_vnode_param *vp = &op->file[0];
1593 struct afs_call *call;
1598 call = afs_alloc_flat_call(op->net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1600 return afs_op_nomem(op);
1602 /* marshall the parameters */
1604 *bp++ = htonl(FSRELEASELOCK);
1605 *bp++ = htonl(vp->fid.vid);
1606 *bp++ = htonl(vp->fid.vnode);
1607 *bp++ = htonl(vp->fid.unique);
1609 call->fid = vp->fid;
1610 trace_afs_make_fs_call(call, &vp->fid);
1611 afs_make_op_call(op, call, GFP_NOFS);
1615 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1617 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1619 return afs_transfer_reply(call);
1623 * FS.GiveUpAllCallBacks operation type
1625 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1626 .name = "FS.GiveUpAllCallBacks",
1627 .op = afs_FS_GiveUpAllCallBacks,
1628 .deliver = afs_deliver_fs_give_up_all_callbacks,
1629 .destructor = afs_flat_call_destructor,
1633 * Flush all the callbacks we have on a server.
1635 int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *server,
1636 struct afs_address *addr, struct key *key)
1638 struct afs_call *call;
1644 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1649 call->peer = rxrpc_kernel_get_peer(addr->peer);
1650 call->service_id = server->service_id;
1652 /* marshall the parameters */
1654 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1656 call->server = afs_use_server(server, false, afs_server_trace_use_give_up_cb);
1657 afs_make_call(call, GFP_NOFS);
1658 afs_wait_for_call_to_complete(call);
1660 if (call->responded)
1661 set_bit(AFS_SERVER_FL_RESPONDING, &server->flags);
1667 * Deliver reply data to an FS.GetCapabilities operation.
1669 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1674 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
1676 switch (call->unmarshall) {
1678 afs_extract_to_tmp(call);
1682 /* Extract the capabilities word count */
1684 ret = afs_extract_data(call, true);
1688 count = ntohl(call->tmp);
1689 call->count = count;
1690 call->count2 = count;
1692 call->unmarshall = 4;
1697 /* Extract the first word of the capabilities to call->tmp */
1698 afs_extract_to_tmp(call);
1703 ret = afs_extract_data(call, false);
1707 afs_extract_discard(call, (count - 1) * sizeof(__be32));
1711 /* Extract remaining capabilities words */
1713 ret = afs_extract_data(call, false);
1721 _leave(" = 0 [done]");
1725 static void afs_fs_get_capabilities_destructor(struct afs_call *call)
1727 afs_put_endpoint_state(call->probe, afs_estate_trace_put_getcaps);
1728 afs_flat_call_destructor(call);
1732 * FS.GetCapabilities operation type
1734 static const struct afs_call_type afs_RXFSGetCapabilities = {
1735 .name = "FS.GetCapabilities",
1736 .op = afs_FS_GetCapabilities,
1737 .deliver = afs_deliver_fs_get_capabilities,
1738 .done = afs_fileserver_probe_result,
1739 .immediate_cancel = afs_fileserver_probe_result,
1740 .destructor = afs_fs_get_capabilities_destructor,
1744 * Probe a fileserver for the capabilities that it supports. This RPC can
1745 * reply with up to 196 words. The operation is asynchronous and if we managed
1746 * to allocate a call, true is returned the result is delivered through the
1747 * ->done() - otherwise we return false to indicate we didn't even try.
1749 bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
1750 struct afs_endpoint_state *estate, unsigned int addr_index,
1753 struct afs_call *call;
1758 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1763 call->server = afs_use_server(server, false, afs_server_trace_use_get_caps);
1764 call->peer = rxrpc_kernel_get_peer(estate->addresses->addrs[addr_index].peer);
1765 call->probe = afs_get_endpoint_state(estate, afs_estate_trace_get_getcaps);
1766 call->probe_index = addr_index;
1767 call->service_id = server->service_id;
1768 call->upgrade = true;
1770 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
1772 /* marshall the parameters */
1774 *bp++ = htonl(FSGETCAPABILITIES);
1776 trace_afs_make_fs_call(call, NULL);
1777 afs_make_call(call, GFP_NOFS);
1783 * Deliver reply data to an FS.InlineBulkStatus call
1785 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
1787 struct afs_operation *op = call->op;
1788 struct afs_status_cb *scb;
1793 _enter("{%u}", call->unmarshall);
1795 switch (call->unmarshall) {
1797 afs_extract_to_tmp(call);
1801 /* Extract the file status count and array in two steps */
1803 _debug("extract status count");
1804 ret = afs_extract_data(call, true);
1808 tmp = ntohl(call->tmp);
1809 _debug("status count: %u/%u", tmp, op->nr_files);
1810 if (tmp != op->nr_files)
1811 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1816 afs_extract_to_buf(call, 21 * sizeof(__be32));
1820 _debug("extract status array %u", call->count);
1821 ret = afs_extract_data(call, true);
1825 switch (call->count) {
1827 scb = &op->file[0].scb;
1830 scb = &op->file[1].scb;
1833 scb = &op->more_files[call->count - 2].scb;
1838 xdr_decode_AFSFetchStatus(&bp, call, scb);
1841 if (call->count < op->nr_files)
1846 afs_extract_to_tmp(call);
1849 /* Extract the callback count and array in two steps */
1851 _debug("extract CB count");
1852 ret = afs_extract_data(call, true);
1856 tmp = ntohl(call->tmp);
1857 _debug("CB count: %u", tmp);
1858 if (tmp != op->nr_files)
1859 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1863 afs_extract_to_buf(call, 3 * sizeof(__be32));
1867 _debug("extract CB array");
1868 ret = afs_extract_data(call, true);
1872 _debug("unmarshall CB array");
1873 switch (call->count) {
1875 scb = &op->file[0].scb;
1878 scb = &op->file[1].scb;
1881 scb = &op->more_files[call->count - 2].scb;
1886 xdr_decode_AFSCallBack(&bp, call, scb);
1888 if (call->count < op->nr_files)
1891 afs_extract_to_buf(call, 6 * sizeof(__be32));
1896 ret = afs_extract_data(call, false);
1901 /* Unfortunately, prior to OpenAFS-1.6, volsync here is filled
1904 xdr_decode_AFSVolSync(&bp, NULL);
1913 _leave(" = 0 [done]");
1917 static void afs_done_fs_inline_bulk_status(struct afs_call *call)
1919 if (call->error == -ECONNABORTED &&
1920 call->abort_code == RX_INVALID_OPERATION) {
1921 set_bit(AFS_SERVER_FL_NO_IBULK, &call->server->flags);
1923 set_bit(AFS_VOLUME_MAYBE_NO_IBULK, &call->op->volume->flags);
1928 * FS.InlineBulkStatus operation type
1930 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
1931 .name = "FS.InlineBulkStatus",
1932 .op = afs_FS_InlineBulkStatus,
1933 .deliver = afs_deliver_fs_inline_bulk_status,
1934 .done = afs_done_fs_inline_bulk_status,
1935 .destructor = afs_flat_call_destructor,
1939 * Fetch the status information for up to 50 files
1941 void afs_fs_inline_bulk_status(struct afs_operation *op)
1943 struct afs_vnode_param *dvp = &op->file[0];
1944 struct afs_vnode_param *vp = &op->file[1];
1945 struct afs_call *call;
1949 if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) {
1950 afs_op_set_error(op, -ENOTSUPP);
1954 _enter(",%x,{%llx:%llu},%u",
1955 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1957 call = afs_alloc_flat_call(op->net, &afs_RXFSInlineBulkStatus,
1958 (2 + op->nr_files * 3) * 4,
1961 return afs_op_nomem(op);
1963 /* marshall the parameters */
1965 *bp++ = htonl(FSINLINEBULKSTATUS);
1966 *bp++ = htonl(op->nr_files);
1967 *bp++ = htonl(dvp->fid.vid);
1968 *bp++ = htonl(dvp->fid.vnode);
1969 *bp++ = htonl(dvp->fid.unique);
1970 *bp++ = htonl(vp->fid.vid);
1971 *bp++ = htonl(vp->fid.vnode);
1972 *bp++ = htonl(vp->fid.unique);
1973 for (i = 0; i < op->nr_files - 2; i++) {
1974 *bp++ = htonl(op->more_files[i].fid.vid);
1975 *bp++ = htonl(op->more_files[i].fid.vnode);
1976 *bp++ = htonl(op->more_files[i].fid.unique);
1979 call->fid = vp->fid;
1980 trace_afs_make_fs_call(call, &vp->fid);
1981 afs_make_op_call(op, call, GFP_NOFS);
1985 * deliver reply data to an FS.FetchACL
1987 static int afs_deliver_fs_fetch_acl(struct afs_call *call)
1989 struct afs_operation *op = call->op;
1990 struct afs_vnode_param *vp = &op->file[0];
1991 struct afs_acl *acl;
1996 _enter("{%u}", call->unmarshall);
1998 switch (call->unmarshall) {
2000 afs_extract_to_tmp(call);
2004 /* extract the returned data length */
2006 ret = afs_extract_data(call, true);
2010 size = call->count2 = ntohl(call->tmp);
2011 size = round_up(size, 4);
2013 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2017 acl->size = call->count2;
2018 afs_extract_begin(call, acl->data, size);
2022 /* extract the returned data */
2024 ret = afs_extract_data(call, true);
2028 afs_extract_to_buf(call, (21 + 6) * 4);
2032 /* extract the metadata */
2034 ret = afs_extract_data(call, false);
2039 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
2040 xdr_decode_AFSVolSync(&bp, &op->volsync);
2049 _leave(" = 0 [done]");
2054 * FS.FetchACL operation type
2056 static const struct afs_call_type afs_RXFSFetchACL = {
2057 .name = "FS.FetchACL",
2058 .op = afs_FS_FetchACL,
2059 .deliver = afs_deliver_fs_fetch_acl,
2063 * Fetch the ACL for a file.
2065 void afs_fs_fetch_acl(struct afs_operation *op)
2067 struct afs_vnode_param *vp = &op->file[0];
2068 struct afs_call *call;
2071 _enter(",%x,{%llx:%llu},,",
2072 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
2074 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2076 return afs_op_nomem(op);
2078 /* marshall the parameters */
2080 bp[0] = htonl(FSFETCHACL);
2081 bp[1] = htonl(vp->fid.vid);
2082 bp[2] = htonl(vp->fid.vnode);
2083 bp[3] = htonl(vp->fid.unique);
2085 call->fid = vp->fid;
2086 trace_afs_make_fs_call(call, &vp->fid);
2087 afs_make_op_call(op, call, GFP_KERNEL);
2091 * FS.StoreACL operation type
2093 static const struct afs_call_type afs_RXFSStoreACL = {
2094 .name = "FS.StoreACL",
2095 .op = afs_FS_StoreACL,
2096 .deliver = afs_deliver_fs_file_status_and_vol,
2097 .destructor = afs_flat_call_destructor,
2101 * Fetch the ACL for a file.
2103 void afs_fs_store_acl(struct afs_operation *op)
2105 struct afs_vnode_param *vp = &op->file[0];
2106 struct afs_call *call;
2107 const struct afs_acl *acl = op->acl;
2111 _enter(",%x,{%llx:%llu},,",
2112 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
2114 size = round_up(acl->size, 4);
2115 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreACL,
2116 5 * 4 + size, (21 + 6) * 4);
2118 return afs_op_nomem(op);
2120 /* marshall the parameters */
2122 bp[0] = htonl(FSSTOREACL);
2123 bp[1] = htonl(vp->fid.vid);
2124 bp[2] = htonl(vp->fid.vnode);
2125 bp[3] = htonl(vp->fid.unique);
2126 bp[4] = htonl(acl->size);
2127 memcpy(&bp[5], acl->data, acl->size);
2128 if (acl->size != size)
2129 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2131 call->fid = vp->fid;
2132 trace_afs_make_fs_call(call, &vp->fid);
2133 afs_make_op_call(op, call, GFP_KERNEL);