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->reply_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);
293 trace_afs_make_fs_call(call, &vp->fid);
294 afs_make_op_call(op, call, GFP_NOFS);
298 * deliver reply data to an FS.FetchData
300 static int afs_deliver_fs_fetch_data(struct afs_call *call)
302 struct afs_operation *op = call->op;
303 struct afs_vnode_param *vp = &op->file[0];
304 struct afs_read *req = op->fetch.req;
308 _enter("{%u,%zu,%zu/%llu}",
309 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
312 switch (call->unmarshall) {
316 if (call->operation_ID == FSFETCHDATA64) {
317 afs_extract_to_tmp64(call);
319 call->tmp_u = htonl(0);
320 afs_extract_to_tmp(call);
324 /* Extract the returned data length into
325 * ->actual_len. This may indicate more or less data than was
326 * requested will be returned.
329 _debug("extract data length");
330 ret = afs_extract_data(call, true);
334 req->actual_len = be64_to_cpu(call->tmp64);
335 _debug("DATA length: %llu", req->actual_len);
337 if (req->actual_len == 0)
340 call->iter = req->iter;
341 call->iov_len = min(req->actual_len, req->len);
345 /* extract the returned data */
347 _debug("extract data %zu/%llu",
348 iov_iter_count(call->iter), req->actual_len);
350 ret = afs_extract_data(call, true);
354 call->iter = &call->def_iter;
355 if (req->actual_len <= req->len)
358 /* Discard any excess data the server gave us */
359 afs_extract_discard(call, req->actual_len - req->len);
360 call->unmarshall = 3;
364 _debug("extract discard %zu/%llu",
365 iov_iter_count(call->iter), req->actual_len - req->len);
367 ret = afs_extract_data(call, true);
372 call->unmarshall = 4;
373 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
376 /* extract the metadata */
378 ret = afs_extract_data(call, false);
383 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
384 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
385 xdr_decode_AFSVolSync(&bp, &op->volsync);
387 req->data_version = vp->scb.status.data_version;
388 req->file_size = vp->scb.status.size;
397 _leave(" = 0 [done]");
402 * FS.FetchData operation type
404 static const struct afs_call_type afs_RXFSFetchData = {
405 .name = "FS.FetchData",
406 .op = afs_FS_FetchData,
407 .deliver = afs_deliver_fs_fetch_data,
408 .destructor = afs_flat_call_destructor,
411 static const struct afs_call_type afs_RXFSFetchData64 = {
412 .name = "FS.FetchData64",
413 .op = afs_FS_FetchData64,
414 .deliver = afs_deliver_fs_fetch_data,
415 .destructor = afs_flat_call_destructor,
419 * fetch data from a very large file
421 static void afs_fs_fetch_data64(struct afs_operation *op)
423 struct afs_vnode_param *vp = &op->file[0];
424 struct afs_read *req = op->fetch.req;
425 struct afs_call *call;
430 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
432 return afs_op_nomem(op);
434 /* marshall the parameters */
436 bp[0] = htonl(FSFETCHDATA64);
437 bp[1] = htonl(vp->fid.vid);
438 bp[2] = htonl(vp->fid.vnode);
439 bp[3] = htonl(vp->fid.unique);
440 bp[4] = htonl(upper_32_bits(req->pos));
441 bp[5] = htonl(lower_32_bits(req->pos));
443 bp[7] = htonl(lower_32_bits(req->len));
445 trace_afs_make_fs_call(call, &vp->fid);
446 afs_make_op_call(op, call, GFP_NOFS);
450 * fetch data from a file
452 void afs_fs_fetch_data(struct afs_operation *op)
454 struct afs_vnode_param *vp = &op->file[0];
455 struct afs_call *call;
456 struct afs_read *req = op->fetch.req;
459 if (upper_32_bits(req->pos) ||
460 upper_32_bits(req->len) ||
461 upper_32_bits(req->pos + req->len))
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));
481 trace_afs_make_fs_call(call, &vp->fid);
482 afs_make_op_call(op, call, GFP_NOFS);
486 * deliver reply data to an FS.CreateFile or an FS.MakeDir
488 static int afs_deliver_fs_create_vnode(struct afs_call *call)
490 struct afs_operation *op = call->op;
491 struct afs_vnode_param *dvp = &op->file[0];
492 struct afs_vnode_param *vp = &op->file[1];
496 ret = afs_transfer_reply(call);
500 /* unmarshall the reply once we've received all of it */
502 xdr_decode_AFSFid(&bp, &op->file[1].fid);
503 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
504 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
505 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
506 xdr_decode_AFSVolSync(&bp, &op->volsync);
508 _leave(" = 0 [done]");
513 * FS.CreateFile and FS.MakeDir operation type
515 static const struct afs_call_type afs_RXFSCreateFile = {
516 .name = "FS.CreateFile",
517 .op = afs_FS_CreateFile,
518 .deliver = afs_deliver_fs_create_vnode,
519 .destructor = afs_flat_call_destructor,
525 void afs_fs_create_file(struct afs_operation *op)
527 const struct qstr *name = &op->dentry->d_name;
528 struct afs_vnode_param *dvp = &op->file[0];
529 struct afs_call *call;
530 size_t namesz, reqsz, padsz;
536 padsz = (4 - (namesz & 3)) & 3;
537 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
539 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile,
540 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
542 return afs_op_nomem(op);
544 /* marshall the parameters */
546 *bp++ = htonl(FSCREATEFILE);
547 *bp++ = htonl(dvp->fid.vid);
548 *bp++ = htonl(dvp->fid.vnode);
549 *bp++ = htonl(dvp->fid.unique);
550 *bp++ = htonl(namesz);
551 memcpy(bp, name->name, namesz);
552 bp = (void *) bp + namesz;
554 memset(bp, 0, padsz);
555 bp = (void *) bp + padsz;
557 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
558 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
559 *bp++ = 0; /* owner */
560 *bp++ = 0; /* group */
561 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
562 *bp++ = 0; /* segment size */
564 trace_afs_make_fs_call1(call, &dvp->fid, name);
565 afs_make_op_call(op, call, GFP_NOFS);
568 static const struct afs_call_type afs_RXFSMakeDir = {
569 .name = "FS.MakeDir",
570 .op = afs_FS_MakeDir,
571 .deliver = afs_deliver_fs_create_vnode,
572 .destructor = afs_flat_call_destructor,
576 * Create a new directory
578 void afs_fs_make_dir(struct afs_operation *op)
580 const struct qstr *name = &op->dentry->d_name;
581 struct afs_vnode_param *dvp = &op->file[0];
582 struct afs_call *call;
583 size_t namesz, reqsz, padsz;
589 padsz = (4 - (namesz & 3)) & 3;
590 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
592 call = afs_alloc_flat_call(op->net, &afs_RXFSMakeDir,
593 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
595 return afs_op_nomem(op);
597 /* marshall the parameters */
599 *bp++ = htonl(FSMAKEDIR);
600 *bp++ = htonl(dvp->fid.vid);
601 *bp++ = htonl(dvp->fid.vnode);
602 *bp++ = htonl(dvp->fid.unique);
603 *bp++ = htonl(namesz);
604 memcpy(bp, name->name, namesz);
605 bp = (void *) bp + namesz;
607 memset(bp, 0, padsz);
608 bp = (void *) bp + padsz;
610 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
611 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
612 *bp++ = 0; /* owner */
613 *bp++ = 0; /* group */
614 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
615 *bp++ = 0; /* segment size */
617 trace_afs_make_fs_call1(call, &dvp->fid, name);
618 afs_make_op_call(op, call, GFP_NOFS);
622 * Deliver reply data to any operation that returns status and volume sync.
624 static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
626 struct afs_operation *op = call->op;
627 struct afs_vnode_param *vp = &op->file[0];
631 ret = afs_transfer_reply(call);
635 /* unmarshall the reply once we've received all of it */
637 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
638 xdr_decode_AFSVolSync(&bp, &op->volsync);
640 _leave(" = 0 [done]");
645 * FS.RemoveFile operation type
647 static const struct afs_call_type afs_RXFSRemoveFile = {
648 .name = "FS.RemoveFile",
649 .op = afs_FS_RemoveFile,
650 .deliver = afs_deliver_fs_file_status_and_vol,
651 .destructor = afs_flat_call_destructor,
657 void afs_fs_remove_file(struct afs_operation *op)
659 const struct qstr *name = &op->dentry->d_name;
660 struct afs_vnode_param *dvp = &op->file[0];
661 struct afs_call *call;
662 size_t namesz, reqsz, padsz;
668 padsz = (4 - (namesz & 3)) & 3;
669 reqsz = (5 * 4) + namesz + padsz;
671 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveFile,
672 reqsz, (21 + 6) * 4);
674 return afs_op_nomem(op);
676 /* marshall the parameters */
678 *bp++ = htonl(FSREMOVEFILE);
679 *bp++ = htonl(dvp->fid.vid);
680 *bp++ = htonl(dvp->fid.vnode);
681 *bp++ = htonl(dvp->fid.unique);
682 *bp++ = htonl(namesz);
683 memcpy(bp, name->name, namesz);
684 bp = (void *) bp + namesz;
686 memset(bp, 0, padsz);
687 bp = (void *) bp + padsz;
690 trace_afs_make_fs_call1(call, &dvp->fid, name);
691 afs_make_op_call(op, call, GFP_NOFS);
694 static const struct afs_call_type afs_RXFSRemoveDir = {
695 .name = "FS.RemoveDir",
696 .op = afs_FS_RemoveDir,
697 .deliver = afs_deliver_fs_file_status_and_vol,
698 .destructor = afs_flat_call_destructor,
702 * Remove a directory.
704 void afs_fs_remove_dir(struct afs_operation *op)
706 const struct qstr *name = &op->dentry->d_name;
707 struct afs_vnode_param *dvp = &op->file[0];
708 struct afs_call *call;
709 size_t namesz, reqsz, padsz;
715 padsz = (4 - (namesz & 3)) & 3;
716 reqsz = (5 * 4) + namesz + padsz;
718 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveDir,
719 reqsz, (21 + 6) * 4);
721 return afs_op_nomem(op);
723 /* marshall the parameters */
725 *bp++ = htonl(FSREMOVEDIR);
726 *bp++ = htonl(dvp->fid.vid);
727 *bp++ = htonl(dvp->fid.vnode);
728 *bp++ = htonl(dvp->fid.unique);
729 *bp++ = htonl(namesz);
730 memcpy(bp, name->name, namesz);
731 bp = (void *) bp + namesz;
733 memset(bp, 0, padsz);
734 bp = (void *) bp + padsz;
737 trace_afs_make_fs_call1(call, &dvp->fid, name);
738 afs_make_op_call(op, call, GFP_NOFS);
742 * deliver reply data to an FS.Link
744 static int afs_deliver_fs_link(struct afs_call *call)
746 struct afs_operation *op = call->op;
747 struct afs_vnode_param *dvp = &op->file[0];
748 struct afs_vnode_param *vp = &op->file[1];
752 _enter("{%u}", call->unmarshall);
754 ret = afs_transfer_reply(call);
758 /* unmarshall the reply once we've received all of it */
760 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
761 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
762 xdr_decode_AFSVolSync(&bp, &op->volsync);
764 _leave(" = 0 [done]");
769 * FS.Link operation type
771 static const struct afs_call_type afs_RXFSLink = {
774 .deliver = afs_deliver_fs_link,
775 .destructor = afs_flat_call_destructor,
781 void afs_fs_link(struct afs_operation *op)
783 const struct qstr *name = &op->dentry->d_name;
784 struct afs_vnode_param *dvp = &op->file[0];
785 struct afs_vnode_param *vp = &op->file[1];
786 struct afs_call *call;
787 size_t namesz, reqsz, padsz;
793 padsz = (4 - (namesz & 3)) & 3;
794 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
796 call = afs_alloc_flat_call(op->net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
798 return afs_op_nomem(op);
800 /* marshall the parameters */
802 *bp++ = htonl(FSLINK);
803 *bp++ = htonl(dvp->fid.vid);
804 *bp++ = htonl(dvp->fid.vnode);
805 *bp++ = htonl(dvp->fid.unique);
806 *bp++ = htonl(namesz);
807 memcpy(bp, name->name, namesz);
808 bp = (void *) bp + namesz;
810 memset(bp, 0, padsz);
811 bp = (void *) bp + padsz;
813 *bp++ = htonl(vp->fid.vid);
814 *bp++ = htonl(vp->fid.vnode);
815 *bp++ = htonl(vp->fid.unique);
817 trace_afs_make_fs_call1(call, &vp->fid, name);
818 afs_make_op_call(op, call, GFP_NOFS);
822 * deliver reply data to an FS.Symlink
824 static int afs_deliver_fs_symlink(struct afs_call *call)
826 struct afs_operation *op = call->op;
827 struct afs_vnode_param *dvp = &op->file[0];
828 struct afs_vnode_param *vp = &op->file[1];
832 _enter("{%u}", call->unmarshall);
834 ret = afs_transfer_reply(call);
838 /* unmarshall the reply once we've received all of it */
840 xdr_decode_AFSFid(&bp, &vp->fid);
841 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
842 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
843 xdr_decode_AFSVolSync(&bp, &op->volsync);
845 _leave(" = 0 [done]");
850 * FS.Symlink operation type
852 static const struct afs_call_type afs_RXFSSymlink = {
853 .name = "FS.Symlink",
854 .op = afs_FS_Symlink,
855 .deliver = afs_deliver_fs_symlink,
856 .destructor = afs_flat_call_destructor,
860 * create a symbolic link
862 void afs_fs_symlink(struct afs_operation *op)
864 const struct qstr *name = &op->dentry->d_name;
865 struct afs_vnode_param *dvp = &op->file[0];
866 struct afs_call *call;
867 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
873 padsz = (4 - (namesz & 3)) & 3;
875 c_namesz = strlen(op->create.symlink);
876 c_padsz = (4 - (c_namesz & 3)) & 3;
878 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
880 call = afs_alloc_flat_call(op->net, &afs_RXFSSymlink, reqsz,
881 (3 + 21 + 21 + 6) * 4);
883 return afs_op_nomem(op);
885 /* marshall the parameters */
887 *bp++ = htonl(FSSYMLINK);
888 *bp++ = htonl(dvp->fid.vid);
889 *bp++ = htonl(dvp->fid.vnode);
890 *bp++ = htonl(dvp->fid.unique);
891 *bp++ = htonl(namesz);
892 memcpy(bp, name->name, namesz);
893 bp = (void *) bp + namesz;
895 memset(bp, 0, padsz);
896 bp = (void *) bp + padsz;
898 *bp++ = htonl(c_namesz);
899 memcpy(bp, op->create.symlink, c_namesz);
900 bp = (void *) bp + c_namesz;
902 memset(bp, 0, c_padsz);
903 bp = (void *) bp + c_padsz;
905 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
906 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
907 *bp++ = 0; /* owner */
908 *bp++ = 0; /* group */
909 *bp++ = htonl(S_IRWXUGO); /* unix mode */
910 *bp++ = 0; /* segment size */
912 trace_afs_make_fs_call1(call, &dvp->fid, name);
913 afs_make_op_call(op, call, GFP_NOFS);
917 * deliver reply data to an FS.Rename
919 static int afs_deliver_fs_rename(struct afs_call *call)
921 struct afs_operation *op = call->op;
922 struct afs_vnode_param *orig_dvp = &op->file[0];
923 struct afs_vnode_param *new_dvp = &op->file[1];
927 ret = afs_transfer_reply(call);
932 /* If the two dirs are the same, we have two copies of the same status
933 * report, so we just decode it twice.
935 xdr_decode_AFSFetchStatus(&bp, call, &orig_dvp->scb);
936 xdr_decode_AFSFetchStatus(&bp, call, &new_dvp->scb);
937 xdr_decode_AFSVolSync(&bp, &op->volsync);
939 _leave(" = 0 [done]");
944 * FS.Rename operation type
946 static const struct afs_call_type afs_RXFSRename = {
949 .deliver = afs_deliver_fs_rename,
950 .destructor = afs_flat_call_destructor,
954 * Rename/move a file or directory.
956 void afs_fs_rename(struct afs_operation *op)
958 struct afs_vnode_param *orig_dvp = &op->file[0];
959 struct afs_vnode_param *new_dvp = &op->file[1];
960 const struct qstr *orig_name = &op->dentry->d_name;
961 const struct qstr *new_name = &op->dentry_2->d_name;
962 struct afs_call *call;
963 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
968 o_namesz = orig_name->len;
969 o_padsz = (4 - (o_namesz & 3)) & 3;
971 n_namesz = new_name->len;
972 n_padsz = (4 - (n_namesz & 3)) & 3;
975 4 + o_namesz + o_padsz +
977 4 + n_namesz + n_padsz;
979 call = afs_alloc_flat_call(op->net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
981 return afs_op_nomem(op);
983 /* marshall the parameters */
985 *bp++ = htonl(FSRENAME);
986 *bp++ = htonl(orig_dvp->fid.vid);
987 *bp++ = htonl(orig_dvp->fid.vnode);
988 *bp++ = htonl(orig_dvp->fid.unique);
989 *bp++ = htonl(o_namesz);
990 memcpy(bp, orig_name->name, o_namesz);
991 bp = (void *) bp + o_namesz;
993 memset(bp, 0, o_padsz);
994 bp = (void *) bp + o_padsz;
997 *bp++ = htonl(new_dvp->fid.vid);
998 *bp++ = htonl(new_dvp->fid.vnode);
999 *bp++ = htonl(new_dvp->fid.unique);
1000 *bp++ = htonl(n_namesz);
1001 memcpy(bp, new_name->name, n_namesz);
1002 bp = (void *) bp + n_namesz;
1004 memset(bp, 0, n_padsz);
1005 bp = (void *) bp + n_padsz;
1008 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1009 afs_make_op_call(op, call, GFP_NOFS);
1013 * Deliver reply data to FS.StoreData or FS.StoreStatus
1015 static int afs_deliver_fs_store_data(struct afs_call *call)
1017 struct afs_operation *op = call->op;
1018 struct afs_vnode_param *vp = &op->file[0];
1024 ret = afs_transfer_reply(call);
1028 /* unmarshall the reply once we've received all of it */
1030 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
1031 xdr_decode_AFSVolSync(&bp, &op->volsync);
1033 _leave(" = 0 [done]");
1038 * FS.StoreData operation type
1040 static const struct afs_call_type afs_RXFSStoreData = {
1041 .name = "FS.StoreData",
1042 .op = afs_FS_StoreData,
1043 .deliver = afs_deliver_fs_store_data,
1044 .destructor = afs_flat_call_destructor,
1047 static const struct afs_call_type afs_RXFSStoreData64 = {
1048 .name = "FS.StoreData64",
1049 .op = afs_FS_StoreData64,
1050 .deliver = afs_deliver_fs_store_data,
1051 .destructor = afs_flat_call_destructor,
1055 * store a set of pages to a very large file
1057 static void afs_fs_store_data64(struct afs_operation *op)
1059 struct afs_vnode_param *vp = &op->file[0];
1060 struct afs_call *call;
1063 _enter(",%x,{%llx:%llu},,",
1064 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1066 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64,
1067 (4 + 6 + 3 * 2) * 4,
1070 return afs_op_nomem(op);
1072 call->write_iter = op->store.write_iter;
1074 /* marshall the parameters */
1076 *bp++ = htonl(FSSTOREDATA64);
1077 *bp++ = htonl(vp->fid.vid);
1078 *bp++ = htonl(vp->fid.vnode);
1079 *bp++ = htonl(vp->fid.unique);
1081 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1082 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
1083 *bp++ = 0; /* owner */
1084 *bp++ = 0; /* group */
1085 *bp++ = 0; /* unix mode */
1086 *bp++ = 0; /* segment size */
1088 *bp++ = htonl(upper_32_bits(op->store.pos));
1089 *bp++ = htonl(lower_32_bits(op->store.pos));
1090 *bp++ = htonl(upper_32_bits(op->store.size));
1091 *bp++ = htonl(lower_32_bits(op->store.size));
1092 *bp++ = htonl(upper_32_bits(op->store.i_size));
1093 *bp++ = htonl(lower_32_bits(op->store.i_size));
1095 trace_afs_make_fs_call(call, &vp->fid);
1096 afs_make_op_call(op, call, GFP_NOFS);
1100 * Write data to a file on the server.
1102 void afs_fs_store_data(struct afs_operation *op)
1104 struct afs_vnode_param *vp = &op->file[0];
1105 struct afs_call *call;
1108 _enter(",%x,{%llx:%llu},,",
1109 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1111 _debug("size %llx, at %llx, i_size %llx",
1112 (unsigned long long)op->store.size,
1113 (unsigned long long)op->store.pos,
1114 (unsigned long long)op->store.i_size);
1116 if (upper_32_bits(op->store.pos) ||
1117 upper_32_bits(op->store.size) ||
1118 upper_32_bits(op->store.i_size))
1119 return afs_fs_store_data64(op);
1121 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData,
1125 return afs_op_nomem(op);
1127 call->write_iter = op->store.write_iter;
1129 /* marshall the parameters */
1131 *bp++ = htonl(FSSTOREDATA);
1132 *bp++ = htonl(vp->fid.vid);
1133 *bp++ = htonl(vp->fid.vnode);
1134 *bp++ = htonl(vp->fid.unique);
1136 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1137 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
1138 *bp++ = 0; /* owner */
1139 *bp++ = 0; /* group */
1140 *bp++ = 0; /* unix mode */
1141 *bp++ = 0; /* segment size */
1143 *bp++ = htonl(lower_32_bits(op->store.pos));
1144 *bp++ = htonl(lower_32_bits(op->store.size));
1145 *bp++ = htonl(lower_32_bits(op->store.i_size));
1147 trace_afs_make_fs_call(call, &vp->fid);
1148 afs_make_op_call(op, call, GFP_NOFS);
1152 * FS.StoreStatus operation type
1154 static const struct afs_call_type afs_RXFSStoreStatus = {
1155 .name = "FS.StoreStatus",
1156 .op = afs_FS_StoreStatus,
1157 .deliver = afs_deliver_fs_store_data,
1158 .destructor = afs_flat_call_destructor,
1161 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1162 .name = "FS.StoreData",
1163 .op = afs_FS_StoreData,
1164 .deliver = afs_deliver_fs_store_data,
1165 .destructor = afs_flat_call_destructor,
1168 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1169 .name = "FS.StoreData64",
1170 .op = afs_FS_StoreData64,
1171 .deliver = afs_deliver_fs_store_data,
1172 .destructor = afs_flat_call_destructor,
1176 * set the attributes on a very large file, using FS.StoreData rather than
1177 * FS.StoreStatus so as to alter the file size also
1179 static void afs_fs_setattr_size64(struct afs_operation *op)
1181 struct afs_vnode_param *vp = &op->file[0];
1182 struct afs_call *call;
1183 struct iattr *attr = op->setattr.attr;
1186 _enter(",%x,{%llx:%llu},,",
1187 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1189 ASSERT(attr->ia_valid & ATTR_SIZE);
1191 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64_as_Status,
1192 (4 + 6 + 3 * 2) * 4,
1195 return afs_op_nomem(op);
1197 /* marshall the parameters */
1199 *bp++ = htonl(FSSTOREDATA64);
1200 *bp++ = htonl(vp->fid.vid);
1201 *bp++ = htonl(vp->fid.vnode);
1202 *bp++ = htonl(vp->fid.unique);
1204 xdr_encode_AFS_StoreStatus(&bp, attr);
1206 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* position of start of write */
1207 *bp++ = htonl(lower_32_bits(attr->ia_size));
1208 *bp++ = 0; /* size of write */
1210 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* new file length */
1211 *bp++ = htonl(lower_32_bits(attr->ia_size));
1213 trace_afs_make_fs_call(call, &vp->fid);
1214 afs_make_op_call(op, call, GFP_NOFS);
1218 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1219 * so as to alter the file size also
1221 static void afs_fs_setattr_size(struct afs_operation *op)
1223 struct afs_vnode_param *vp = &op->file[0];
1224 struct afs_call *call;
1225 struct iattr *attr = op->setattr.attr;
1228 _enter(",%x,{%llx:%llu},,",
1229 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1231 ASSERT(attr->ia_valid & ATTR_SIZE);
1232 if (upper_32_bits(attr->ia_size))
1233 return afs_fs_setattr_size64(op);
1235 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData_as_Status,
1239 return afs_op_nomem(op);
1241 /* marshall the parameters */
1243 *bp++ = htonl(FSSTOREDATA);
1244 *bp++ = htonl(vp->fid.vid);
1245 *bp++ = htonl(vp->fid.vnode);
1246 *bp++ = htonl(vp->fid.unique);
1248 xdr_encode_AFS_StoreStatus(&bp, attr);
1250 *bp++ = htonl(attr->ia_size); /* position of start of write */
1251 *bp++ = 0; /* size of write */
1252 *bp++ = htonl(attr->ia_size); /* new file length */
1254 trace_afs_make_fs_call(call, &vp->fid);
1255 afs_make_op_call(op, call, GFP_NOFS);
1259 * set the attributes on a file, using FS.StoreData if there's a change in file
1260 * size, and FS.StoreStatus otherwise
1262 void afs_fs_setattr(struct afs_operation *op)
1264 struct afs_vnode_param *vp = &op->file[0];
1265 struct afs_call *call;
1266 struct iattr *attr = op->setattr.attr;
1269 if (attr->ia_valid & ATTR_SIZE)
1270 return afs_fs_setattr_size(op);
1272 _enter(",%x,{%llx:%llu},,",
1273 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1275 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreStatus,
1279 return afs_op_nomem(op);
1281 /* marshall the parameters */
1283 *bp++ = htonl(FSSTORESTATUS);
1284 *bp++ = htonl(vp->fid.vid);
1285 *bp++ = htonl(vp->fid.vnode);
1286 *bp++ = htonl(vp->fid.unique);
1288 xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr);
1290 trace_afs_make_fs_call(call, &vp->fid);
1291 afs_make_op_call(op, call, GFP_NOFS);
1295 * deliver reply data to an FS.GetVolumeStatus
1297 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1299 struct afs_operation *op = call->op;
1305 _enter("{%u}", call->unmarshall);
1307 switch (call->unmarshall) {
1310 afs_extract_to_buf(call, 12 * 4);
1313 /* extract the returned status record */
1315 _debug("extract status");
1316 ret = afs_extract_data(call, true);
1321 xdr_decode_AFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1323 afs_extract_to_tmp(call);
1326 /* extract the volume name length */
1328 ret = afs_extract_data(call, true);
1332 call->count = ntohl(call->tmp);
1333 _debug("volname length: %u", call->count);
1334 if (call->count >= AFSNAMEMAX)
1335 return afs_protocol_error(call, afs_eproto_volname_len);
1336 size = (call->count + 3) & ~3; /* It's padded */
1337 afs_extract_to_buf(call, size);
1341 /* extract the volume name */
1343 _debug("extract volname");
1344 ret = afs_extract_data(call, true);
1350 _debug("volname '%s'", p);
1351 afs_extract_to_tmp(call);
1355 /* extract the offline message length */
1357 ret = afs_extract_data(call, true);
1361 call->count = ntohl(call->tmp);
1362 _debug("offline msg length: %u", call->count);
1363 if (call->count >= AFSNAMEMAX)
1364 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1365 size = (call->count + 3) & ~3; /* It's padded */
1366 afs_extract_to_buf(call, size);
1370 /* extract the offline message */
1372 _debug("extract offline");
1373 ret = afs_extract_data(call, true);
1379 _debug("offline '%s'", p);
1381 afs_extract_to_tmp(call);
1385 /* extract the message of the day length */
1387 ret = afs_extract_data(call, true);
1391 call->count = ntohl(call->tmp);
1392 _debug("motd length: %u", call->count);
1393 if (call->count >= AFSNAMEMAX)
1394 return afs_protocol_error(call, afs_eproto_motd_len);
1395 size = (call->count + 3) & ~3; /* It's padded */
1396 afs_extract_to_buf(call, size);
1400 /* extract the message of the day */
1402 _debug("extract motd");
1403 ret = afs_extract_data(call, false);
1409 _debug("motd '%s'", p);
1418 _leave(" = 0 [done]");
1423 * FS.GetVolumeStatus operation type
1425 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1426 .name = "FS.GetVolumeStatus",
1427 .op = afs_FS_GetVolumeStatus,
1428 .deliver = afs_deliver_fs_get_volume_status,
1429 .destructor = afs_flat_call_destructor,
1433 * fetch the status of a volume
1435 void afs_fs_get_volume_status(struct afs_operation *op)
1437 struct afs_vnode_param *vp = &op->file[0];
1438 struct afs_call *call;
1443 call = afs_alloc_flat_call(op->net, &afs_RXFSGetVolumeStatus, 2 * 4,
1444 max(12 * 4, AFSOPAQUEMAX + 1));
1446 return afs_op_nomem(op);
1448 /* marshall the parameters */
1450 bp[0] = htonl(FSGETVOLUMESTATUS);
1451 bp[1] = htonl(vp->fid.vid);
1453 trace_afs_make_fs_call(call, &vp->fid);
1454 afs_make_op_call(op, call, GFP_NOFS);
1458 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1460 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1462 struct afs_operation *op = call->op;
1466 _enter("{%u}", call->unmarshall);
1468 ret = afs_transfer_reply(call);
1472 /* unmarshall the reply once we've received all of it */
1474 xdr_decode_AFSVolSync(&bp, &op->volsync);
1476 _leave(" = 0 [done]");
1481 * FS.SetLock operation type
1483 static const struct afs_call_type afs_RXFSSetLock = {
1484 .name = "FS.SetLock",
1485 .op = afs_FS_SetLock,
1486 .deliver = afs_deliver_fs_xxxx_lock,
1487 .done = afs_lock_op_done,
1488 .destructor = afs_flat_call_destructor,
1492 * FS.ExtendLock operation type
1494 static const struct afs_call_type afs_RXFSExtendLock = {
1495 .name = "FS.ExtendLock",
1496 .op = afs_FS_ExtendLock,
1497 .deliver = afs_deliver_fs_xxxx_lock,
1498 .done = afs_lock_op_done,
1499 .destructor = afs_flat_call_destructor,
1503 * FS.ReleaseLock operation type
1505 static const struct afs_call_type afs_RXFSReleaseLock = {
1506 .name = "FS.ReleaseLock",
1507 .op = afs_FS_ReleaseLock,
1508 .deliver = afs_deliver_fs_xxxx_lock,
1509 .destructor = afs_flat_call_destructor,
1513 * Set a lock on a file
1515 void afs_fs_set_lock(struct afs_operation *op)
1517 struct afs_vnode_param *vp = &op->file[0];
1518 struct afs_call *call;
1523 call = afs_alloc_flat_call(op->net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1525 return afs_op_nomem(op);
1527 /* marshall the parameters */
1529 *bp++ = htonl(FSSETLOCK);
1530 *bp++ = htonl(vp->fid.vid);
1531 *bp++ = htonl(vp->fid.vnode);
1532 *bp++ = htonl(vp->fid.unique);
1533 *bp++ = htonl(op->lock.type);
1535 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1536 afs_make_op_call(op, call, GFP_NOFS);
1540 * extend a lock on a file
1542 void afs_fs_extend_lock(struct afs_operation *op)
1544 struct afs_vnode_param *vp = &op->file[0];
1545 struct afs_call *call;
1550 call = afs_alloc_flat_call(op->net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1552 return afs_op_nomem(op);
1554 /* marshall the parameters */
1556 *bp++ = htonl(FSEXTENDLOCK);
1557 *bp++ = htonl(vp->fid.vid);
1558 *bp++ = htonl(vp->fid.vnode);
1559 *bp++ = htonl(vp->fid.unique);
1561 trace_afs_make_fs_call(call, &vp->fid);
1562 afs_make_op_call(op, call, GFP_NOFS);
1566 * release a lock on a file
1568 void afs_fs_release_lock(struct afs_operation *op)
1570 struct afs_vnode_param *vp = &op->file[0];
1571 struct afs_call *call;
1576 call = afs_alloc_flat_call(op->net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1578 return afs_op_nomem(op);
1580 /* marshall the parameters */
1582 *bp++ = htonl(FSRELEASELOCK);
1583 *bp++ = htonl(vp->fid.vid);
1584 *bp++ = htonl(vp->fid.vnode);
1585 *bp++ = htonl(vp->fid.unique);
1587 trace_afs_make_fs_call(call, &vp->fid);
1588 afs_make_op_call(op, call, GFP_NOFS);
1592 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1594 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1596 return afs_transfer_reply(call);
1600 * FS.GiveUpAllCallBacks operation type
1602 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1603 .name = "FS.GiveUpAllCallBacks",
1604 .op = afs_FS_GiveUpAllCallBacks,
1605 .deliver = afs_deliver_fs_give_up_all_callbacks,
1606 .destructor = afs_flat_call_destructor,
1610 * Flush all the callbacks we have on a server.
1612 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1613 struct afs_server *server,
1614 struct afs_addr_cursor *ac,
1617 struct afs_call *call;
1622 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1628 /* marshall the parameters */
1630 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1632 call->server = afs_use_server(server, afs_server_trace_give_up_cb);
1633 afs_make_call(ac, call, GFP_NOFS);
1634 return afs_wait_for_call_to_complete(call, ac);
1638 * Deliver reply data to an FS.GetCapabilities operation.
1640 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1645 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
1647 switch (call->unmarshall) {
1649 afs_extract_to_tmp(call);
1653 /* Extract the capabilities word count */
1655 ret = afs_extract_data(call, true);
1659 count = ntohl(call->tmp);
1661 call->count = count;
1662 call->count2 = count;
1663 afs_extract_discard(call, count * sizeof(__be32));
1667 /* Extract capabilities words */
1669 ret = afs_extract_data(call, false);
1673 /* TODO: Examine capabilities */
1679 _leave(" = 0 [done]");
1684 * FS.GetCapabilities operation type
1686 static const struct afs_call_type afs_RXFSGetCapabilities = {
1687 .name = "FS.GetCapabilities",
1688 .op = afs_FS_GetCapabilities,
1689 .deliver = afs_deliver_fs_get_capabilities,
1690 .done = afs_fileserver_probe_result,
1691 .destructor = afs_flat_call_destructor,
1695 * Probe a fileserver for the capabilities that it supports. This RPC can
1696 * reply with up to 196 words. The operation is asynchronous and if we managed
1697 * to allocate a call, true is returned the result is delivered through the
1698 * ->done() - otherwise we return false to indicate we didn't even try.
1700 bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
1701 struct afs_addr_cursor *ac, struct key *key)
1703 struct afs_call *call;
1708 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1713 call->server = afs_use_server(server, afs_server_trace_get_caps);
1714 call->upgrade = true;
1716 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
1718 /* marshall the parameters */
1720 *bp++ = htonl(FSGETCAPABILITIES);
1722 trace_afs_make_fs_call(call, NULL);
1723 afs_make_call(ac, call, GFP_NOFS);
1729 * Deliver reply data to an FS.InlineBulkStatus call
1731 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
1733 struct afs_operation *op = call->op;
1734 struct afs_status_cb *scb;
1739 _enter("{%u}", call->unmarshall);
1741 switch (call->unmarshall) {
1743 afs_extract_to_tmp(call);
1747 /* Extract the file status count and array in two steps */
1749 _debug("extract status count");
1750 ret = afs_extract_data(call, true);
1754 tmp = ntohl(call->tmp);
1755 _debug("status count: %u/%u", tmp, op->nr_files);
1756 if (tmp != op->nr_files)
1757 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1762 afs_extract_to_buf(call, 21 * sizeof(__be32));
1766 _debug("extract status array %u", call->count);
1767 ret = afs_extract_data(call, true);
1771 switch (call->count) {
1773 scb = &op->file[0].scb;
1776 scb = &op->file[1].scb;
1779 scb = &op->more_files[call->count - 2].scb;
1784 xdr_decode_AFSFetchStatus(&bp, call, scb);
1787 if (call->count < op->nr_files)
1792 afs_extract_to_tmp(call);
1795 /* Extract the callback count and array in two steps */
1797 _debug("extract CB count");
1798 ret = afs_extract_data(call, true);
1802 tmp = ntohl(call->tmp);
1803 _debug("CB count: %u", tmp);
1804 if (tmp != op->nr_files)
1805 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1809 afs_extract_to_buf(call, 3 * sizeof(__be32));
1813 _debug("extract CB array");
1814 ret = afs_extract_data(call, true);
1818 _debug("unmarshall CB array");
1819 switch (call->count) {
1821 scb = &op->file[0].scb;
1824 scb = &op->file[1].scb;
1827 scb = &op->more_files[call->count - 2].scb;
1832 xdr_decode_AFSCallBack(&bp, call, scb);
1834 if (call->count < op->nr_files)
1837 afs_extract_to_buf(call, 6 * sizeof(__be32));
1842 ret = afs_extract_data(call, false);
1847 xdr_decode_AFSVolSync(&bp, &op->volsync);
1856 _leave(" = 0 [done]");
1860 static void afs_done_fs_inline_bulk_status(struct afs_call *call)
1862 if (call->error == -ECONNABORTED &&
1863 call->abort_code == RX_INVALID_OPERATION) {
1864 set_bit(AFS_SERVER_FL_NO_IBULK, &call->server->flags);
1866 set_bit(AFS_VOLUME_MAYBE_NO_IBULK, &call->op->volume->flags);
1871 * FS.InlineBulkStatus operation type
1873 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
1874 .name = "FS.InlineBulkStatus",
1875 .op = afs_FS_InlineBulkStatus,
1876 .deliver = afs_deliver_fs_inline_bulk_status,
1877 .done = afs_done_fs_inline_bulk_status,
1878 .destructor = afs_flat_call_destructor,
1882 * Fetch the status information for up to 50 files
1884 void afs_fs_inline_bulk_status(struct afs_operation *op)
1886 struct afs_vnode_param *dvp = &op->file[0];
1887 struct afs_vnode_param *vp = &op->file[1];
1888 struct afs_call *call;
1892 if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) {
1893 op->error = -ENOTSUPP;
1897 _enter(",%x,{%llx:%llu},%u",
1898 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1900 call = afs_alloc_flat_call(op->net, &afs_RXFSInlineBulkStatus,
1901 (2 + op->nr_files * 3) * 4,
1904 return afs_op_nomem(op);
1906 /* marshall the parameters */
1908 *bp++ = htonl(FSINLINEBULKSTATUS);
1909 *bp++ = htonl(op->nr_files);
1910 *bp++ = htonl(dvp->fid.vid);
1911 *bp++ = htonl(dvp->fid.vnode);
1912 *bp++ = htonl(dvp->fid.unique);
1913 *bp++ = htonl(vp->fid.vid);
1914 *bp++ = htonl(vp->fid.vnode);
1915 *bp++ = htonl(vp->fid.unique);
1916 for (i = 0; i < op->nr_files - 2; i++) {
1917 *bp++ = htonl(op->more_files[i].fid.vid);
1918 *bp++ = htonl(op->more_files[i].fid.vnode);
1919 *bp++ = htonl(op->more_files[i].fid.unique);
1922 trace_afs_make_fs_call(call, &vp->fid);
1923 afs_make_op_call(op, call, GFP_NOFS);
1927 * deliver reply data to an FS.FetchACL
1929 static int afs_deliver_fs_fetch_acl(struct afs_call *call)
1931 struct afs_operation *op = call->op;
1932 struct afs_vnode_param *vp = &op->file[0];
1933 struct afs_acl *acl;
1938 _enter("{%u}", call->unmarshall);
1940 switch (call->unmarshall) {
1942 afs_extract_to_tmp(call);
1946 /* extract the returned data length */
1948 ret = afs_extract_data(call, true);
1952 size = call->count2 = ntohl(call->tmp);
1953 size = round_up(size, 4);
1955 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1959 acl->size = call->count2;
1960 afs_extract_begin(call, acl->data, size);
1964 /* extract the returned data */
1966 ret = afs_extract_data(call, true);
1970 afs_extract_to_buf(call, (21 + 6) * 4);
1974 /* extract the metadata */
1976 ret = afs_extract_data(call, false);
1981 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
1982 xdr_decode_AFSVolSync(&bp, &op->volsync);
1991 _leave(" = 0 [done]");
1996 * FS.FetchACL operation type
1998 static const struct afs_call_type afs_RXFSFetchACL = {
1999 .name = "FS.FetchACL",
2000 .op = afs_FS_FetchACL,
2001 .deliver = afs_deliver_fs_fetch_acl,
2005 * Fetch the ACL for a file.
2007 void afs_fs_fetch_acl(struct afs_operation *op)
2009 struct afs_vnode_param *vp = &op->file[0];
2010 struct afs_call *call;
2013 _enter(",%x,{%llx:%llu},,",
2014 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
2016 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2018 return afs_op_nomem(op);
2020 /* marshall the parameters */
2022 bp[0] = htonl(FSFETCHACL);
2023 bp[1] = htonl(vp->fid.vid);
2024 bp[2] = htonl(vp->fid.vnode);
2025 bp[3] = htonl(vp->fid.unique);
2027 trace_afs_make_fs_call(call, &vp->fid);
2028 afs_make_op_call(op, call, GFP_KERNEL);
2032 * FS.StoreACL operation type
2034 static const struct afs_call_type afs_RXFSStoreACL = {
2035 .name = "FS.StoreACL",
2036 .op = afs_FS_StoreACL,
2037 .deliver = afs_deliver_fs_file_status_and_vol,
2038 .destructor = afs_flat_call_destructor,
2042 * Fetch the ACL for a file.
2044 void afs_fs_store_acl(struct afs_operation *op)
2046 struct afs_vnode_param *vp = &op->file[0];
2047 struct afs_call *call;
2048 const struct afs_acl *acl = op->acl;
2052 _enter(",%x,{%llx:%llu},,",
2053 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
2055 size = round_up(acl->size, 4);
2056 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreACL,
2057 5 * 4 + size, (21 + 6) * 4);
2059 return afs_op_nomem(op);
2061 /* marshall the parameters */
2063 bp[0] = htonl(FSSTOREACL);
2064 bp[1] = htonl(vp->fid.vid);
2065 bp[2] = htonl(vp->fid.vnode);
2066 bp[3] = htonl(vp->fid.unique);
2067 bp[4] = htonl(acl->size);
2068 memcpy(&bp[5], acl->data, acl->size);
2069 if (acl->size != size)
2070 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2072 trace_afs_make_fs_call(call, &vp->fid);
2073 afs_make_op_call(op, call, GFP_KERNEL);