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>
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 afs_vnode_param *vp = &op->file[0];
305 struct afs_read *req = op->fetch.req;
309 _enter("{%u,%zu,%zu/%llu}",
310 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
313 switch (call->unmarshall) {
317 if (call->operation_ID == FSFETCHDATA64) {
318 afs_extract_to_tmp64(call);
320 call->tmp_u = htonl(0);
321 afs_extract_to_tmp(call);
325 /* Extract the returned data length into
326 * ->actual_len. This may indicate more or less data than was
327 * requested will be returned.
330 _debug("extract data length");
331 ret = afs_extract_data(call, true);
335 req->actual_len = be64_to_cpu(call->tmp64);
336 _debug("DATA length: %llu", req->actual_len);
338 if (req->actual_len == 0)
341 call->iter = req->iter;
342 call->iov_len = min(req->actual_len, req->len);
346 /* extract the returned data */
348 _debug("extract data %zu/%llu",
349 iov_iter_count(call->iter), req->actual_len);
351 ret = afs_extract_data(call, true);
355 call->iter = &call->def_iter;
356 if (req->actual_len <= req->len)
359 /* Discard any excess data the server gave us */
360 afs_extract_discard(call, req->actual_len - req->len);
361 call->unmarshall = 3;
365 _debug("extract discard %zu/%llu",
366 iov_iter_count(call->iter), req->actual_len - req->len);
368 ret = afs_extract_data(call, true);
373 call->unmarshall = 4;
374 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
377 /* extract the metadata */
379 ret = afs_extract_data(call, false);
384 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
385 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
386 xdr_decode_AFSVolSync(&bp, &op->volsync);
388 req->data_version = vp->scb.status.data_version;
389 req->file_size = vp->scb.status.size;
398 _leave(" = 0 [done]");
403 * FS.FetchData operation type
405 static const struct afs_call_type afs_RXFSFetchData = {
406 .name = "FS.FetchData",
407 .op = afs_FS_FetchData,
408 .deliver = afs_deliver_fs_fetch_data,
409 .destructor = afs_flat_call_destructor,
412 static const struct afs_call_type afs_RXFSFetchData64 = {
413 .name = "FS.FetchData64",
414 .op = afs_FS_FetchData64,
415 .deliver = afs_deliver_fs_fetch_data,
416 .destructor = afs_flat_call_destructor,
420 * fetch data from a very large file
422 static void afs_fs_fetch_data64(struct afs_operation *op)
424 struct afs_vnode_param *vp = &op->file[0];
425 struct afs_read *req = op->fetch.req;
426 struct afs_call *call;
431 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
433 return afs_op_nomem(op);
435 /* marshall the parameters */
437 bp[0] = htonl(FSFETCHDATA64);
438 bp[1] = htonl(vp->fid.vid);
439 bp[2] = htonl(vp->fid.vnode);
440 bp[3] = htonl(vp->fid.unique);
441 bp[4] = htonl(upper_32_bits(req->pos));
442 bp[5] = htonl(lower_32_bits(req->pos));
444 bp[7] = htonl(lower_32_bits(req->len));
447 trace_afs_make_fs_call(call, &vp->fid);
448 afs_make_op_call(op, call, GFP_NOFS);
452 * fetch data from a file
454 void afs_fs_fetch_data(struct afs_operation *op)
456 struct afs_vnode_param *vp = &op->file[0];
457 struct afs_call *call;
458 struct afs_read *req = op->fetch.req;
461 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
462 return afs_fs_fetch_data64(op);
466 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
468 return afs_op_nomem(op);
470 req->call_debug_id = call->debug_id;
472 /* marshall the parameters */
474 bp[0] = htonl(FSFETCHDATA);
475 bp[1] = htonl(vp->fid.vid);
476 bp[2] = htonl(vp->fid.vnode);
477 bp[3] = htonl(vp->fid.unique);
478 bp[4] = htonl(lower_32_bits(req->pos));
479 bp[5] = htonl(lower_32_bits(req->len));
482 trace_afs_make_fs_call(call, &vp->fid);
483 afs_make_op_call(op, call, GFP_NOFS);
487 * deliver reply data to an FS.CreateFile or an FS.MakeDir
489 static int afs_deliver_fs_create_vnode(struct afs_call *call)
491 struct afs_operation *op = call->op;
492 struct afs_vnode_param *dvp = &op->file[0];
493 struct afs_vnode_param *vp = &op->file[1];
497 ret = afs_transfer_reply(call);
501 /* unmarshall the reply once we've received all of it */
503 xdr_decode_AFSFid(&bp, &op->file[1].fid);
504 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
505 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
506 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
507 xdr_decode_AFSVolSync(&bp, &op->volsync);
509 _leave(" = 0 [done]");
514 * FS.CreateFile and FS.MakeDir operation type
516 static const struct afs_call_type afs_RXFSCreateFile = {
517 .name = "FS.CreateFile",
518 .op = afs_FS_CreateFile,
519 .deliver = afs_deliver_fs_create_vnode,
520 .destructor = afs_flat_call_destructor,
526 void afs_fs_create_file(struct afs_operation *op)
528 const struct qstr *name = &op->dentry->d_name;
529 struct afs_vnode_param *dvp = &op->file[0];
530 struct afs_call *call;
531 size_t namesz, reqsz, padsz;
537 padsz = (4 - (namesz & 3)) & 3;
538 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
540 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile,
541 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
543 return afs_op_nomem(op);
545 /* marshall the parameters */
547 *bp++ = htonl(FSCREATEFILE);
548 *bp++ = htonl(dvp->fid.vid);
549 *bp++ = htonl(dvp->fid.vnode);
550 *bp++ = htonl(dvp->fid.unique);
551 *bp++ = htonl(namesz);
552 memcpy(bp, name->name, namesz);
553 bp = (void *) bp + namesz;
555 memset(bp, 0, padsz);
556 bp = (void *) bp + padsz;
558 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
559 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
560 *bp++ = 0; /* owner */
561 *bp++ = 0; /* group */
562 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
563 *bp++ = 0; /* segment size */
565 call->fid = dvp->fid;
566 trace_afs_make_fs_call1(call, &dvp->fid, name);
567 afs_make_op_call(op, call, GFP_NOFS);
570 static const struct afs_call_type afs_RXFSMakeDir = {
571 .name = "FS.MakeDir",
572 .op = afs_FS_MakeDir,
573 .deliver = afs_deliver_fs_create_vnode,
574 .destructor = afs_flat_call_destructor,
578 * Create a new directory
580 void afs_fs_make_dir(struct afs_operation *op)
582 const struct qstr *name = &op->dentry->d_name;
583 struct afs_vnode_param *dvp = &op->file[0];
584 struct afs_call *call;
585 size_t namesz, reqsz, padsz;
591 padsz = (4 - (namesz & 3)) & 3;
592 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
594 call = afs_alloc_flat_call(op->net, &afs_RXFSMakeDir,
595 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
597 return afs_op_nomem(op);
599 /* marshall the parameters */
601 *bp++ = htonl(FSMAKEDIR);
602 *bp++ = htonl(dvp->fid.vid);
603 *bp++ = htonl(dvp->fid.vnode);
604 *bp++ = htonl(dvp->fid.unique);
605 *bp++ = htonl(namesz);
606 memcpy(bp, name->name, namesz);
607 bp = (void *) bp + namesz;
609 memset(bp, 0, padsz);
610 bp = (void *) bp + padsz;
612 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
613 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
614 *bp++ = 0; /* owner */
615 *bp++ = 0; /* group */
616 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
617 *bp++ = 0; /* segment size */
619 call->fid = dvp->fid;
620 trace_afs_make_fs_call1(call, &dvp->fid, name);
621 afs_make_op_call(op, call, GFP_NOFS);
625 * Deliver reply data to any operation that returns status and volume sync.
627 static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
629 struct afs_operation *op = call->op;
630 struct afs_vnode_param *vp = &op->file[0];
634 ret = afs_transfer_reply(call);
638 /* unmarshall the reply once we've received all of it */
640 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
641 xdr_decode_AFSVolSync(&bp, &op->volsync);
643 _leave(" = 0 [done]");
648 * FS.RemoveFile operation type
650 static const struct afs_call_type afs_RXFSRemoveFile = {
651 .name = "FS.RemoveFile",
652 .op = afs_FS_RemoveFile,
653 .deliver = afs_deliver_fs_file_status_and_vol,
654 .destructor = afs_flat_call_destructor,
660 void afs_fs_remove_file(struct afs_operation *op)
662 const struct qstr *name = &op->dentry->d_name;
663 struct afs_vnode_param *dvp = &op->file[0];
664 struct afs_call *call;
665 size_t namesz, reqsz, padsz;
671 padsz = (4 - (namesz & 3)) & 3;
672 reqsz = (5 * 4) + namesz + padsz;
674 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveFile,
675 reqsz, (21 + 6) * 4);
677 return afs_op_nomem(op);
679 /* marshall the parameters */
681 *bp++ = htonl(FSREMOVEFILE);
682 *bp++ = htonl(dvp->fid.vid);
683 *bp++ = htonl(dvp->fid.vnode);
684 *bp++ = htonl(dvp->fid.unique);
685 *bp++ = htonl(namesz);
686 memcpy(bp, name->name, namesz);
687 bp = (void *) bp + namesz;
689 memset(bp, 0, padsz);
690 bp = (void *) bp + padsz;
693 call->fid = dvp->fid;
694 trace_afs_make_fs_call1(call, &dvp->fid, name);
695 afs_make_op_call(op, call, GFP_NOFS);
698 static const struct afs_call_type afs_RXFSRemoveDir = {
699 .name = "FS.RemoveDir",
700 .op = afs_FS_RemoveDir,
701 .deliver = afs_deliver_fs_file_status_and_vol,
702 .destructor = afs_flat_call_destructor,
706 * Remove a directory.
708 void afs_fs_remove_dir(struct afs_operation *op)
710 const struct qstr *name = &op->dentry->d_name;
711 struct afs_vnode_param *dvp = &op->file[0];
712 struct afs_call *call;
713 size_t namesz, reqsz, padsz;
719 padsz = (4 - (namesz & 3)) & 3;
720 reqsz = (5 * 4) + namesz + padsz;
722 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveDir,
723 reqsz, (21 + 6) * 4);
725 return afs_op_nomem(op);
727 /* marshall the parameters */
729 *bp++ = htonl(FSREMOVEDIR);
730 *bp++ = htonl(dvp->fid.vid);
731 *bp++ = htonl(dvp->fid.vnode);
732 *bp++ = htonl(dvp->fid.unique);
733 *bp++ = htonl(namesz);
734 memcpy(bp, name->name, namesz);
735 bp = (void *) bp + namesz;
737 memset(bp, 0, padsz);
738 bp = (void *) bp + padsz;
741 call->fid = dvp->fid;
742 trace_afs_make_fs_call1(call, &dvp->fid, name);
743 afs_make_op_call(op, call, GFP_NOFS);
747 * deliver reply data to an FS.Link
749 static int afs_deliver_fs_link(struct afs_call *call)
751 struct afs_operation *op = call->op;
752 struct afs_vnode_param *dvp = &op->file[0];
753 struct afs_vnode_param *vp = &op->file[1];
757 _enter("{%u}", call->unmarshall);
759 ret = afs_transfer_reply(call);
763 /* unmarshall the reply once we've received all of it */
765 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
766 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
767 xdr_decode_AFSVolSync(&bp, &op->volsync);
769 _leave(" = 0 [done]");
774 * FS.Link operation type
776 static const struct afs_call_type afs_RXFSLink = {
779 .deliver = afs_deliver_fs_link,
780 .destructor = afs_flat_call_destructor,
786 void afs_fs_link(struct afs_operation *op)
788 const struct qstr *name = &op->dentry->d_name;
789 struct afs_vnode_param *dvp = &op->file[0];
790 struct afs_vnode_param *vp = &op->file[1];
791 struct afs_call *call;
792 size_t namesz, reqsz, padsz;
798 padsz = (4 - (namesz & 3)) & 3;
799 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
801 call = afs_alloc_flat_call(op->net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
803 return afs_op_nomem(op);
805 /* marshall the parameters */
807 *bp++ = htonl(FSLINK);
808 *bp++ = htonl(dvp->fid.vid);
809 *bp++ = htonl(dvp->fid.vnode);
810 *bp++ = htonl(dvp->fid.unique);
811 *bp++ = htonl(namesz);
812 memcpy(bp, name->name, namesz);
813 bp = (void *) bp + namesz;
815 memset(bp, 0, padsz);
816 bp = (void *) bp + padsz;
818 *bp++ = htonl(vp->fid.vid);
819 *bp++ = htonl(vp->fid.vnode);
820 *bp++ = htonl(vp->fid.unique);
823 trace_afs_make_fs_call1(call, &vp->fid, name);
824 afs_make_op_call(op, call, GFP_NOFS);
828 * deliver reply data to an FS.Symlink
830 static int afs_deliver_fs_symlink(struct afs_call *call)
832 struct afs_operation *op = call->op;
833 struct afs_vnode_param *dvp = &op->file[0];
834 struct afs_vnode_param *vp = &op->file[1];
838 _enter("{%u}", call->unmarshall);
840 ret = afs_transfer_reply(call);
844 /* unmarshall the reply once we've received all of it */
846 xdr_decode_AFSFid(&bp, &vp->fid);
847 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
848 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
849 xdr_decode_AFSVolSync(&bp, &op->volsync);
851 _leave(" = 0 [done]");
856 * FS.Symlink operation type
858 static const struct afs_call_type afs_RXFSSymlink = {
859 .name = "FS.Symlink",
860 .op = afs_FS_Symlink,
861 .deliver = afs_deliver_fs_symlink,
862 .destructor = afs_flat_call_destructor,
866 * create a symbolic link
868 void afs_fs_symlink(struct afs_operation *op)
870 const struct qstr *name = &op->dentry->d_name;
871 struct afs_vnode_param *dvp = &op->file[0];
872 struct afs_call *call;
873 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
879 padsz = (4 - (namesz & 3)) & 3;
881 c_namesz = strlen(op->create.symlink);
882 c_padsz = (4 - (c_namesz & 3)) & 3;
884 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
886 call = afs_alloc_flat_call(op->net, &afs_RXFSSymlink, reqsz,
887 (3 + 21 + 21 + 6) * 4);
889 return afs_op_nomem(op);
891 /* marshall the parameters */
893 *bp++ = htonl(FSSYMLINK);
894 *bp++ = htonl(dvp->fid.vid);
895 *bp++ = htonl(dvp->fid.vnode);
896 *bp++ = htonl(dvp->fid.unique);
897 *bp++ = htonl(namesz);
898 memcpy(bp, name->name, namesz);
899 bp = (void *) bp + namesz;
901 memset(bp, 0, padsz);
902 bp = (void *) bp + padsz;
904 *bp++ = htonl(c_namesz);
905 memcpy(bp, op->create.symlink, c_namesz);
906 bp = (void *) bp + c_namesz;
908 memset(bp, 0, c_padsz);
909 bp = (void *) bp + c_padsz;
911 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
912 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
913 *bp++ = 0; /* owner */
914 *bp++ = 0; /* group */
915 *bp++ = htonl(S_IRWXUGO); /* unix mode */
916 *bp++ = 0; /* segment size */
918 call->fid = dvp->fid;
919 trace_afs_make_fs_call1(call, &dvp->fid, name);
920 afs_make_op_call(op, call, GFP_NOFS);
924 * deliver reply data to an FS.Rename
926 static int afs_deliver_fs_rename(struct afs_call *call)
928 struct afs_operation *op = call->op;
929 struct afs_vnode_param *orig_dvp = &op->file[0];
930 struct afs_vnode_param *new_dvp = &op->file[1];
934 ret = afs_transfer_reply(call);
939 /* If the two dirs are the same, we have two copies of the same status
940 * report, so we just decode it twice.
942 xdr_decode_AFSFetchStatus(&bp, call, &orig_dvp->scb);
943 xdr_decode_AFSFetchStatus(&bp, call, &new_dvp->scb);
944 xdr_decode_AFSVolSync(&bp, &op->volsync);
946 _leave(" = 0 [done]");
951 * FS.Rename operation type
953 static const struct afs_call_type afs_RXFSRename = {
956 .deliver = afs_deliver_fs_rename,
957 .destructor = afs_flat_call_destructor,
961 * Rename/move a file or directory.
963 void afs_fs_rename(struct afs_operation *op)
965 struct afs_vnode_param *orig_dvp = &op->file[0];
966 struct afs_vnode_param *new_dvp = &op->file[1];
967 const struct qstr *orig_name = &op->dentry->d_name;
968 const struct qstr *new_name = &op->dentry_2->d_name;
969 struct afs_call *call;
970 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
975 o_namesz = orig_name->len;
976 o_padsz = (4 - (o_namesz & 3)) & 3;
978 n_namesz = new_name->len;
979 n_padsz = (4 - (n_namesz & 3)) & 3;
982 4 + o_namesz + o_padsz +
984 4 + n_namesz + n_padsz;
986 call = afs_alloc_flat_call(op->net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
988 return afs_op_nomem(op);
990 /* marshall the parameters */
992 *bp++ = htonl(FSRENAME);
993 *bp++ = htonl(orig_dvp->fid.vid);
994 *bp++ = htonl(orig_dvp->fid.vnode);
995 *bp++ = htonl(orig_dvp->fid.unique);
996 *bp++ = htonl(o_namesz);
997 memcpy(bp, orig_name->name, o_namesz);
998 bp = (void *) bp + o_namesz;
1000 memset(bp, 0, o_padsz);
1001 bp = (void *) bp + o_padsz;
1004 *bp++ = htonl(new_dvp->fid.vid);
1005 *bp++ = htonl(new_dvp->fid.vnode);
1006 *bp++ = htonl(new_dvp->fid.unique);
1007 *bp++ = htonl(n_namesz);
1008 memcpy(bp, new_name->name, n_namesz);
1009 bp = (void *) bp + n_namesz;
1011 memset(bp, 0, n_padsz);
1012 bp = (void *) bp + n_padsz;
1015 call->fid = orig_dvp->fid;
1016 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1017 afs_make_op_call(op, call, GFP_NOFS);
1021 * Deliver reply data to FS.StoreData or FS.StoreStatus
1023 static int afs_deliver_fs_store_data(struct afs_call *call)
1025 struct afs_operation *op = call->op;
1026 struct afs_vnode_param *vp = &op->file[0];
1032 ret = afs_transfer_reply(call);
1036 /* unmarshall the reply once we've received all of it */
1038 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
1039 xdr_decode_AFSVolSync(&bp, &op->volsync);
1041 _leave(" = 0 [done]");
1046 * FS.StoreData operation type
1048 static const struct afs_call_type afs_RXFSStoreData = {
1049 .name = "FS.StoreData",
1050 .op = afs_FS_StoreData,
1051 .deliver = afs_deliver_fs_store_data,
1052 .destructor = afs_flat_call_destructor,
1055 static const struct afs_call_type afs_RXFSStoreData64 = {
1056 .name = "FS.StoreData64",
1057 .op = afs_FS_StoreData64,
1058 .deliver = afs_deliver_fs_store_data,
1059 .destructor = afs_flat_call_destructor,
1063 * store a set of pages to a very large file
1065 static void afs_fs_store_data64(struct afs_operation *op)
1067 struct afs_vnode_param *vp = &op->file[0];
1068 struct afs_call *call;
1071 _enter(",%x,{%llx:%llu},,",
1072 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1074 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64,
1075 (4 + 6 + 3 * 2) * 4,
1078 return afs_op_nomem(op);
1080 call->write_iter = op->store.write_iter;
1082 /* marshall the parameters */
1084 *bp++ = htonl(FSSTOREDATA64);
1085 *bp++ = htonl(vp->fid.vid);
1086 *bp++ = htonl(vp->fid.vnode);
1087 *bp++ = htonl(vp->fid.unique);
1089 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1090 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
1091 *bp++ = 0; /* owner */
1092 *bp++ = 0; /* group */
1093 *bp++ = 0; /* unix mode */
1094 *bp++ = 0; /* segment size */
1096 *bp++ = htonl(upper_32_bits(op->store.pos));
1097 *bp++ = htonl(lower_32_bits(op->store.pos));
1098 *bp++ = htonl(upper_32_bits(op->store.size));
1099 *bp++ = htonl(lower_32_bits(op->store.size));
1100 *bp++ = htonl(upper_32_bits(op->store.i_size));
1101 *bp++ = htonl(lower_32_bits(op->store.i_size));
1103 call->fid = vp->fid;
1104 trace_afs_make_fs_call(call, &vp->fid);
1105 afs_make_op_call(op, call, GFP_NOFS);
1109 * Write data to a file on the server.
1111 void afs_fs_store_data(struct afs_operation *op)
1113 struct afs_vnode_param *vp = &op->file[0];
1114 struct afs_call *call;
1117 _enter(",%x,{%llx:%llu},,",
1118 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1120 _debug("size %llx, at %llx, i_size %llx",
1121 (unsigned long long)op->store.size,
1122 (unsigned long long)op->store.pos,
1123 (unsigned long long)op->store.i_size);
1125 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
1126 return afs_fs_store_data64(op);
1128 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData,
1132 return afs_op_nomem(op);
1134 call->write_iter = op->store.write_iter;
1136 /* marshall the parameters */
1138 *bp++ = htonl(FSSTOREDATA);
1139 *bp++ = htonl(vp->fid.vid);
1140 *bp++ = htonl(vp->fid.vnode);
1141 *bp++ = htonl(vp->fid.unique);
1143 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1144 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
1145 *bp++ = 0; /* owner */
1146 *bp++ = 0; /* group */
1147 *bp++ = 0; /* unix mode */
1148 *bp++ = 0; /* segment size */
1150 *bp++ = htonl(lower_32_bits(op->store.pos));
1151 *bp++ = htonl(lower_32_bits(op->store.size));
1152 *bp++ = htonl(lower_32_bits(op->store.i_size));
1154 call->fid = vp->fid;
1155 trace_afs_make_fs_call(call, &vp->fid);
1156 afs_make_op_call(op, call, GFP_NOFS);
1160 * FS.StoreStatus operation type
1162 static const struct afs_call_type afs_RXFSStoreStatus = {
1163 .name = "FS.StoreStatus",
1164 .op = afs_FS_StoreStatus,
1165 .deliver = afs_deliver_fs_store_data,
1166 .destructor = afs_flat_call_destructor,
1169 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1170 .name = "FS.StoreData",
1171 .op = afs_FS_StoreData,
1172 .deliver = afs_deliver_fs_store_data,
1173 .destructor = afs_flat_call_destructor,
1176 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1177 .name = "FS.StoreData64",
1178 .op = afs_FS_StoreData64,
1179 .deliver = afs_deliver_fs_store_data,
1180 .destructor = afs_flat_call_destructor,
1184 * set the attributes on a very large file, using FS.StoreData rather than
1185 * FS.StoreStatus so as to alter the file size also
1187 static void afs_fs_setattr_size64(struct afs_operation *op)
1189 struct afs_vnode_param *vp = &op->file[0];
1190 struct afs_call *call;
1191 struct iattr *attr = op->setattr.attr;
1194 _enter(",%x,{%llx:%llu},,",
1195 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1197 ASSERT(attr->ia_valid & ATTR_SIZE);
1199 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64_as_Status,
1200 (4 + 6 + 3 * 2) * 4,
1203 return afs_op_nomem(op);
1205 /* marshall the parameters */
1207 *bp++ = htonl(FSSTOREDATA64);
1208 *bp++ = htonl(vp->fid.vid);
1209 *bp++ = htonl(vp->fid.vnode);
1210 *bp++ = htonl(vp->fid.unique);
1212 xdr_encode_AFS_StoreStatus(&bp, attr);
1214 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* position of start of write */
1215 *bp++ = htonl(lower_32_bits(attr->ia_size));
1216 *bp++ = 0; /* size of write */
1218 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* new file length */
1219 *bp++ = htonl(lower_32_bits(attr->ia_size));
1221 call->fid = vp->fid;
1222 trace_afs_make_fs_call(call, &vp->fid);
1223 afs_make_op_call(op, call, GFP_NOFS);
1227 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1228 * so as to alter the file size also
1230 static void afs_fs_setattr_size(struct afs_operation *op)
1232 struct afs_vnode_param *vp = &op->file[0];
1233 struct afs_call *call;
1234 struct iattr *attr = op->setattr.attr;
1237 _enter(",%x,{%llx:%llu},,",
1238 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1240 ASSERT(attr->ia_valid & ATTR_SIZE);
1241 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
1242 return afs_fs_setattr_size64(op);
1244 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData_as_Status,
1248 return afs_op_nomem(op);
1250 /* marshall the parameters */
1252 *bp++ = htonl(FSSTOREDATA);
1253 *bp++ = htonl(vp->fid.vid);
1254 *bp++ = htonl(vp->fid.vnode);
1255 *bp++ = htonl(vp->fid.unique);
1257 xdr_encode_AFS_StoreStatus(&bp, attr);
1259 *bp++ = htonl(attr->ia_size); /* position of start of write */
1260 *bp++ = 0; /* size of write */
1261 *bp++ = htonl(attr->ia_size); /* new file length */
1263 call->fid = vp->fid;
1264 trace_afs_make_fs_call(call, &vp->fid);
1265 afs_make_op_call(op, call, GFP_NOFS);
1269 * set the attributes on a file, using FS.StoreData if there's a change in file
1270 * size, and FS.StoreStatus otherwise
1272 void afs_fs_setattr(struct afs_operation *op)
1274 struct afs_vnode_param *vp = &op->file[0];
1275 struct afs_call *call;
1276 struct iattr *attr = op->setattr.attr;
1279 if (attr->ia_valid & ATTR_SIZE)
1280 return afs_fs_setattr_size(op);
1282 _enter(",%x,{%llx:%llu},,",
1283 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1285 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreStatus,
1289 return afs_op_nomem(op);
1291 /* marshall the parameters */
1293 *bp++ = htonl(FSSTORESTATUS);
1294 *bp++ = htonl(vp->fid.vid);
1295 *bp++ = htonl(vp->fid.vnode);
1296 *bp++ = htonl(vp->fid.unique);
1298 xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr);
1300 call->fid = vp->fid;
1301 trace_afs_make_fs_call(call, &vp->fid);
1302 afs_make_op_call(op, call, GFP_NOFS);
1306 * deliver reply data to an FS.GetVolumeStatus
1308 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1310 struct afs_operation *op = call->op;
1316 _enter("{%u}", call->unmarshall);
1318 switch (call->unmarshall) {
1321 afs_extract_to_buf(call, 12 * 4);
1324 /* extract the returned status record */
1326 _debug("extract status");
1327 ret = afs_extract_data(call, true);
1332 xdr_decode_AFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1334 afs_extract_to_tmp(call);
1337 /* extract the volume name length */
1339 ret = afs_extract_data(call, true);
1343 call->count = ntohl(call->tmp);
1344 _debug("volname length: %u", call->count);
1345 if (call->count >= AFSNAMEMAX)
1346 return afs_protocol_error(call, afs_eproto_volname_len);
1347 size = (call->count + 3) & ~3; /* It's padded */
1348 afs_extract_to_buf(call, size);
1352 /* extract the volume name */
1354 _debug("extract volname");
1355 ret = afs_extract_data(call, true);
1361 _debug("volname '%s'", p);
1362 afs_extract_to_tmp(call);
1366 /* extract the offline message length */
1368 ret = afs_extract_data(call, true);
1372 call->count = ntohl(call->tmp);
1373 _debug("offline msg length: %u", call->count);
1374 if (call->count >= AFSNAMEMAX)
1375 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1376 size = (call->count + 3) & ~3; /* It's padded */
1377 afs_extract_to_buf(call, size);
1381 /* extract the offline message */
1383 _debug("extract offline");
1384 ret = afs_extract_data(call, true);
1390 _debug("offline '%s'", p);
1392 afs_extract_to_tmp(call);
1396 /* extract the message of the day length */
1398 ret = afs_extract_data(call, true);
1402 call->count = ntohl(call->tmp);
1403 _debug("motd length: %u", call->count);
1404 if (call->count >= AFSNAMEMAX)
1405 return afs_protocol_error(call, afs_eproto_motd_len);
1406 size = (call->count + 3) & ~3; /* It's padded */
1407 afs_extract_to_buf(call, size);
1411 /* extract the message of the day */
1413 _debug("extract motd");
1414 ret = afs_extract_data(call, false);
1420 _debug("motd '%s'", p);
1429 _leave(" = 0 [done]");
1434 * FS.GetVolumeStatus operation type
1436 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1437 .name = "FS.GetVolumeStatus",
1438 .op = afs_FS_GetVolumeStatus,
1439 .deliver = afs_deliver_fs_get_volume_status,
1440 .destructor = afs_flat_call_destructor,
1444 * fetch the status of a volume
1446 void afs_fs_get_volume_status(struct afs_operation *op)
1448 struct afs_vnode_param *vp = &op->file[0];
1449 struct afs_call *call;
1454 call = afs_alloc_flat_call(op->net, &afs_RXFSGetVolumeStatus, 2 * 4,
1455 max(12 * 4, AFSOPAQUEMAX + 1));
1457 return afs_op_nomem(op);
1459 /* marshall the parameters */
1461 bp[0] = htonl(FSGETVOLUMESTATUS);
1462 bp[1] = htonl(vp->fid.vid);
1464 call->fid = vp->fid;
1465 trace_afs_make_fs_call(call, &vp->fid);
1466 afs_make_op_call(op, call, GFP_NOFS);
1470 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1472 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1474 struct afs_operation *op = call->op;
1478 _enter("{%u}", call->unmarshall);
1480 ret = afs_transfer_reply(call);
1484 /* unmarshall the reply once we've received all of it */
1486 xdr_decode_AFSVolSync(&bp, &op->volsync);
1488 _leave(" = 0 [done]");
1493 * FS.SetLock operation type
1495 static const struct afs_call_type afs_RXFSSetLock = {
1496 .name = "FS.SetLock",
1497 .op = afs_FS_SetLock,
1498 .deliver = afs_deliver_fs_xxxx_lock,
1499 .done = afs_lock_op_done,
1500 .destructor = afs_flat_call_destructor,
1504 * FS.ExtendLock operation type
1506 static const struct afs_call_type afs_RXFSExtendLock = {
1507 .name = "FS.ExtendLock",
1508 .op = afs_FS_ExtendLock,
1509 .deliver = afs_deliver_fs_xxxx_lock,
1510 .done = afs_lock_op_done,
1511 .destructor = afs_flat_call_destructor,
1515 * FS.ReleaseLock operation type
1517 static const struct afs_call_type afs_RXFSReleaseLock = {
1518 .name = "FS.ReleaseLock",
1519 .op = afs_FS_ReleaseLock,
1520 .deliver = afs_deliver_fs_xxxx_lock,
1521 .destructor = afs_flat_call_destructor,
1525 * Set a lock on a file
1527 void afs_fs_set_lock(struct afs_operation *op)
1529 struct afs_vnode_param *vp = &op->file[0];
1530 struct afs_call *call;
1535 call = afs_alloc_flat_call(op->net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1537 return afs_op_nomem(op);
1539 /* marshall the parameters */
1541 *bp++ = htonl(FSSETLOCK);
1542 *bp++ = htonl(vp->fid.vid);
1543 *bp++ = htonl(vp->fid.vnode);
1544 *bp++ = htonl(vp->fid.unique);
1545 *bp++ = htonl(op->lock.type);
1547 call->fid = vp->fid;
1548 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1549 afs_make_op_call(op, call, GFP_NOFS);
1553 * extend a lock on a file
1555 void afs_fs_extend_lock(struct afs_operation *op)
1557 struct afs_vnode_param *vp = &op->file[0];
1558 struct afs_call *call;
1563 call = afs_alloc_flat_call(op->net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1565 return afs_op_nomem(op);
1567 /* marshall the parameters */
1569 *bp++ = htonl(FSEXTENDLOCK);
1570 *bp++ = htonl(vp->fid.vid);
1571 *bp++ = htonl(vp->fid.vnode);
1572 *bp++ = htonl(vp->fid.unique);
1574 call->fid = vp->fid;
1575 trace_afs_make_fs_call(call, &vp->fid);
1576 afs_make_op_call(op, call, GFP_NOFS);
1580 * release a lock on a file
1582 void afs_fs_release_lock(struct afs_operation *op)
1584 struct afs_vnode_param *vp = &op->file[0];
1585 struct afs_call *call;
1590 call = afs_alloc_flat_call(op->net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1592 return afs_op_nomem(op);
1594 /* marshall the parameters */
1596 *bp++ = htonl(FSRELEASELOCK);
1597 *bp++ = htonl(vp->fid.vid);
1598 *bp++ = htonl(vp->fid.vnode);
1599 *bp++ = htonl(vp->fid.unique);
1601 call->fid = vp->fid;
1602 trace_afs_make_fs_call(call, &vp->fid);
1603 afs_make_op_call(op, call, GFP_NOFS);
1607 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1609 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1611 return afs_transfer_reply(call);
1615 * FS.GiveUpAllCallBacks operation type
1617 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1618 .name = "FS.GiveUpAllCallBacks",
1619 .op = afs_FS_GiveUpAllCallBacks,
1620 .deliver = afs_deliver_fs_give_up_all_callbacks,
1621 .destructor = afs_flat_call_destructor,
1625 * Flush all the callbacks we have on a server.
1627 int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *server,
1628 struct afs_address *addr, struct key *key)
1630 struct afs_call *call;
1636 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1641 call->peer = rxrpc_kernel_get_peer(addr->peer);
1642 call->service_id = server->service_id;
1644 /* marshall the parameters */
1646 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1648 call->server = afs_use_server(server, afs_server_trace_give_up_cb);
1649 afs_make_call(call, GFP_NOFS);
1650 afs_wait_for_call_to_complete(call);
1652 if (call->responded)
1653 set_bit(AFS_SERVER_FL_RESPONDING, &server->flags);
1659 * Deliver reply data to an FS.GetCapabilities operation.
1661 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1666 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
1668 switch (call->unmarshall) {
1670 afs_extract_to_tmp(call);
1674 /* Extract the capabilities word count */
1676 ret = afs_extract_data(call, true);
1680 count = ntohl(call->tmp);
1681 call->count = count;
1682 call->count2 = count;
1684 call->unmarshall = 4;
1689 /* Extract the first word of the capabilities to call->tmp */
1690 afs_extract_to_tmp(call);
1695 ret = afs_extract_data(call, false);
1699 afs_extract_discard(call, (count - 1) * sizeof(__be32));
1703 /* Extract remaining capabilities words */
1705 ret = afs_extract_data(call, false);
1713 _leave(" = 0 [done]");
1717 static void afs_fs_get_capabilities_destructor(struct afs_call *call)
1719 afs_put_endpoint_state(call->probe, afs_estate_trace_put_getcaps);
1720 afs_flat_call_destructor(call);
1724 * FS.GetCapabilities operation type
1726 static const struct afs_call_type afs_RXFSGetCapabilities = {
1727 .name = "FS.GetCapabilities",
1728 .op = afs_FS_GetCapabilities,
1729 .deliver = afs_deliver_fs_get_capabilities,
1730 .done = afs_fileserver_probe_result,
1731 .destructor = afs_fs_get_capabilities_destructor,
1735 * Probe a fileserver for the capabilities that it supports. This RPC can
1736 * reply with up to 196 words. The operation is asynchronous and if we managed
1737 * to allocate a call, true is returned the result is delivered through the
1738 * ->done() - otherwise we return false to indicate we didn't even try.
1740 bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
1741 struct afs_endpoint_state *estate, unsigned int addr_index,
1744 struct afs_call *call;
1749 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1754 call->server = afs_use_server(server, afs_server_trace_get_caps);
1755 call->peer = rxrpc_kernel_get_peer(estate->addresses->addrs[addr_index].peer);
1756 call->probe = afs_get_endpoint_state(estate, afs_estate_trace_get_getcaps);
1757 call->probe_index = addr_index;
1758 call->service_id = server->service_id;
1759 call->upgrade = true;
1761 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
1763 /* marshall the parameters */
1765 *bp++ = htonl(FSGETCAPABILITIES);
1767 trace_afs_make_fs_call(call, NULL);
1768 afs_make_call(call, GFP_NOFS);
1774 * Deliver reply data to an FS.InlineBulkStatus call
1776 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
1778 struct afs_operation *op = call->op;
1779 struct afs_status_cb *scb;
1784 _enter("{%u}", call->unmarshall);
1786 switch (call->unmarshall) {
1788 afs_extract_to_tmp(call);
1792 /* Extract the file status count and array in two steps */
1794 _debug("extract status count");
1795 ret = afs_extract_data(call, true);
1799 tmp = ntohl(call->tmp);
1800 _debug("status count: %u/%u", tmp, op->nr_files);
1801 if (tmp != op->nr_files)
1802 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1807 afs_extract_to_buf(call, 21 * sizeof(__be32));
1811 _debug("extract status array %u", call->count);
1812 ret = afs_extract_data(call, true);
1816 switch (call->count) {
1818 scb = &op->file[0].scb;
1821 scb = &op->file[1].scb;
1824 scb = &op->more_files[call->count - 2].scb;
1829 xdr_decode_AFSFetchStatus(&bp, call, scb);
1832 if (call->count < op->nr_files)
1837 afs_extract_to_tmp(call);
1840 /* Extract the callback count and array in two steps */
1842 _debug("extract CB count");
1843 ret = afs_extract_data(call, true);
1847 tmp = ntohl(call->tmp);
1848 _debug("CB count: %u", tmp);
1849 if (tmp != op->nr_files)
1850 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1854 afs_extract_to_buf(call, 3 * sizeof(__be32));
1858 _debug("extract CB array");
1859 ret = afs_extract_data(call, true);
1863 _debug("unmarshall CB array");
1864 switch (call->count) {
1866 scb = &op->file[0].scb;
1869 scb = &op->file[1].scb;
1872 scb = &op->more_files[call->count - 2].scb;
1877 xdr_decode_AFSCallBack(&bp, call, scb);
1879 if (call->count < op->nr_files)
1882 afs_extract_to_buf(call, 6 * sizeof(__be32));
1887 ret = afs_extract_data(call, false);
1892 /* Unfortunately, prior to OpenAFS-1.6, volsync here is filled
1895 xdr_decode_AFSVolSync(&bp, NULL);
1904 _leave(" = 0 [done]");
1908 static void afs_done_fs_inline_bulk_status(struct afs_call *call)
1910 if (call->error == -ECONNABORTED &&
1911 call->abort_code == RX_INVALID_OPERATION) {
1912 set_bit(AFS_SERVER_FL_NO_IBULK, &call->server->flags);
1914 set_bit(AFS_VOLUME_MAYBE_NO_IBULK, &call->op->volume->flags);
1919 * FS.InlineBulkStatus operation type
1921 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
1922 .name = "FS.InlineBulkStatus",
1923 .op = afs_FS_InlineBulkStatus,
1924 .deliver = afs_deliver_fs_inline_bulk_status,
1925 .done = afs_done_fs_inline_bulk_status,
1926 .destructor = afs_flat_call_destructor,
1930 * Fetch the status information for up to 50 files
1932 void afs_fs_inline_bulk_status(struct afs_operation *op)
1934 struct afs_vnode_param *dvp = &op->file[0];
1935 struct afs_vnode_param *vp = &op->file[1];
1936 struct afs_call *call;
1940 if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) {
1941 afs_op_set_error(op, -ENOTSUPP);
1945 _enter(",%x,{%llx:%llu},%u",
1946 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1948 call = afs_alloc_flat_call(op->net, &afs_RXFSInlineBulkStatus,
1949 (2 + op->nr_files * 3) * 4,
1952 return afs_op_nomem(op);
1954 /* marshall the parameters */
1956 *bp++ = htonl(FSINLINEBULKSTATUS);
1957 *bp++ = htonl(op->nr_files);
1958 *bp++ = htonl(dvp->fid.vid);
1959 *bp++ = htonl(dvp->fid.vnode);
1960 *bp++ = htonl(dvp->fid.unique);
1961 *bp++ = htonl(vp->fid.vid);
1962 *bp++ = htonl(vp->fid.vnode);
1963 *bp++ = htonl(vp->fid.unique);
1964 for (i = 0; i < op->nr_files - 2; i++) {
1965 *bp++ = htonl(op->more_files[i].fid.vid);
1966 *bp++ = htonl(op->more_files[i].fid.vnode);
1967 *bp++ = htonl(op->more_files[i].fid.unique);
1970 call->fid = vp->fid;
1971 trace_afs_make_fs_call(call, &vp->fid);
1972 afs_make_op_call(op, call, GFP_NOFS);
1976 * deliver reply data to an FS.FetchACL
1978 static int afs_deliver_fs_fetch_acl(struct afs_call *call)
1980 struct afs_operation *op = call->op;
1981 struct afs_vnode_param *vp = &op->file[0];
1982 struct afs_acl *acl;
1987 _enter("{%u}", call->unmarshall);
1989 switch (call->unmarshall) {
1991 afs_extract_to_tmp(call);
1995 /* extract the returned data length */
1997 ret = afs_extract_data(call, true);
2001 size = call->count2 = ntohl(call->tmp);
2002 size = round_up(size, 4);
2004 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2008 acl->size = call->count2;
2009 afs_extract_begin(call, acl->data, size);
2013 /* extract the returned data */
2015 ret = afs_extract_data(call, true);
2019 afs_extract_to_buf(call, (21 + 6) * 4);
2023 /* extract the metadata */
2025 ret = afs_extract_data(call, false);
2030 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
2031 xdr_decode_AFSVolSync(&bp, &op->volsync);
2040 _leave(" = 0 [done]");
2045 * FS.FetchACL operation type
2047 static const struct afs_call_type afs_RXFSFetchACL = {
2048 .name = "FS.FetchACL",
2049 .op = afs_FS_FetchACL,
2050 .deliver = afs_deliver_fs_fetch_acl,
2054 * Fetch the ACL for a file.
2056 void afs_fs_fetch_acl(struct afs_operation *op)
2058 struct afs_vnode_param *vp = &op->file[0];
2059 struct afs_call *call;
2062 _enter(",%x,{%llx:%llu},,",
2063 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
2065 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2067 return afs_op_nomem(op);
2069 /* marshall the parameters */
2071 bp[0] = htonl(FSFETCHACL);
2072 bp[1] = htonl(vp->fid.vid);
2073 bp[2] = htonl(vp->fid.vnode);
2074 bp[3] = htonl(vp->fid.unique);
2076 call->fid = vp->fid;
2077 trace_afs_make_fs_call(call, &vp->fid);
2078 afs_make_op_call(op, call, GFP_KERNEL);
2082 * FS.StoreACL operation type
2084 static const struct afs_call_type afs_RXFSStoreACL = {
2085 .name = "FS.StoreACL",
2086 .op = afs_FS_StoreACL,
2087 .deliver = afs_deliver_fs_file_status_and_vol,
2088 .destructor = afs_flat_call_destructor,
2092 * Fetch the ACL for a file.
2094 void afs_fs_store_acl(struct afs_operation *op)
2096 struct afs_vnode_param *vp = &op->file[0];
2097 struct afs_call *call;
2098 const struct afs_acl *acl = op->acl;
2102 _enter(",%x,{%llx:%llu},,",
2103 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
2105 size = round_up(acl->size, 4);
2106 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreACL,
2107 5 * 4 + size, (21 + 6) * 4);
2109 return afs_op_nomem(op);
2111 /* marshall the parameters */
2113 bp[0] = htonl(FSSTOREACL);
2114 bp[1] = htonl(vp->fid.vid);
2115 bp[2] = htonl(vp->fid.vnode);
2116 bp[3] = htonl(vp->fid.unique);
2117 bp[4] = htonl(acl->size);
2118 memcpy(&bp[5], acl->data, acl->size);
2119 if (acl->size != size)
2120 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2122 call->fid = vp->fid;
2123 trace_afs_make_fs_call(call, &vp->fid);
2124 afs_make_op_call(op, call, GFP_KERNEL);