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->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 (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
460 return afs_fs_fetch_data64(op);
464 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
466 return afs_op_nomem(op);
468 req->call_debug_id = call->debug_id;
470 /* marshall the parameters */
472 bp[0] = htonl(FSFETCHDATA);
473 bp[1] = htonl(vp->fid.vid);
474 bp[2] = htonl(vp->fid.vnode);
475 bp[3] = htonl(vp->fid.unique);
476 bp[4] = htonl(lower_32_bits(req->pos));
477 bp[5] = htonl(lower_32_bits(req->len));
479 trace_afs_make_fs_call(call, &vp->fid);
480 afs_make_op_call(op, call, GFP_NOFS);
484 * deliver reply data to an FS.CreateFile or an FS.MakeDir
486 static int afs_deliver_fs_create_vnode(struct afs_call *call)
488 struct afs_operation *op = call->op;
489 struct afs_vnode_param *dvp = &op->file[0];
490 struct afs_vnode_param *vp = &op->file[1];
494 ret = afs_transfer_reply(call);
498 /* unmarshall the reply once we've received all of it */
500 xdr_decode_AFSFid(&bp, &op->file[1].fid);
501 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
502 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
503 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
504 xdr_decode_AFSVolSync(&bp, &op->volsync);
506 _leave(" = 0 [done]");
511 * FS.CreateFile and FS.MakeDir operation type
513 static const struct afs_call_type afs_RXFSCreateFile = {
514 .name = "FS.CreateFile",
515 .op = afs_FS_CreateFile,
516 .deliver = afs_deliver_fs_create_vnode,
517 .destructor = afs_flat_call_destructor,
523 void afs_fs_create_file(struct afs_operation *op)
525 const struct qstr *name = &op->dentry->d_name;
526 struct afs_vnode_param *dvp = &op->file[0];
527 struct afs_call *call;
528 size_t namesz, reqsz, padsz;
534 padsz = (4 - (namesz & 3)) & 3;
535 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
537 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile,
538 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
540 return afs_op_nomem(op);
542 /* marshall the parameters */
544 *bp++ = htonl(FSCREATEFILE);
545 *bp++ = htonl(dvp->fid.vid);
546 *bp++ = htonl(dvp->fid.vnode);
547 *bp++ = htonl(dvp->fid.unique);
548 *bp++ = htonl(namesz);
549 memcpy(bp, name->name, namesz);
550 bp = (void *) bp + namesz;
552 memset(bp, 0, padsz);
553 bp = (void *) bp + padsz;
555 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
556 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
557 *bp++ = 0; /* owner */
558 *bp++ = 0; /* group */
559 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
560 *bp++ = 0; /* segment size */
562 trace_afs_make_fs_call1(call, &dvp->fid, name);
563 afs_make_op_call(op, call, GFP_NOFS);
566 static const struct afs_call_type afs_RXFSMakeDir = {
567 .name = "FS.MakeDir",
568 .op = afs_FS_MakeDir,
569 .deliver = afs_deliver_fs_create_vnode,
570 .destructor = afs_flat_call_destructor,
574 * Create a new directory
576 void afs_fs_make_dir(struct afs_operation *op)
578 const struct qstr *name = &op->dentry->d_name;
579 struct afs_vnode_param *dvp = &op->file[0];
580 struct afs_call *call;
581 size_t namesz, reqsz, padsz;
587 padsz = (4 - (namesz & 3)) & 3;
588 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
590 call = afs_alloc_flat_call(op->net, &afs_RXFSMakeDir,
591 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
593 return afs_op_nomem(op);
595 /* marshall the parameters */
597 *bp++ = htonl(FSMAKEDIR);
598 *bp++ = htonl(dvp->fid.vid);
599 *bp++ = htonl(dvp->fid.vnode);
600 *bp++ = htonl(dvp->fid.unique);
601 *bp++ = htonl(namesz);
602 memcpy(bp, name->name, namesz);
603 bp = (void *) bp + namesz;
605 memset(bp, 0, padsz);
606 bp = (void *) bp + padsz;
608 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
609 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
610 *bp++ = 0; /* owner */
611 *bp++ = 0; /* group */
612 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
613 *bp++ = 0; /* segment size */
615 trace_afs_make_fs_call1(call, &dvp->fid, name);
616 afs_make_op_call(op, call, GFP_NOFS);
620 * Deliver reply data to any operation that returns status and volume sync.
622 static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
624 struct afs_operation *op = call->op;
625 struct afs_vnode_param *vp = &op->file[0];
629 ret = afs_transfer_reply(call);
633 /* unmarshall the reply once we've received all of it */
635 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
636 xdr_decode_AFSVolSync(&bp, &op->volsync);
638 _leave(" = 0 [done]");
643 * FS.RemoveFile operation type
645 static const struct afs_call_type afs_RXFSRemoveFile = {
646 .name = "FS.RemoveFile",
647 .op = afs_FS_RemoveFile,
648 .deliver = afs_deliver_fs_file_status_and_vol,
649 .destructor = afs_flat_call_destructor,
655 void afs_fs_remove_file(struct afs_operation *op)
657 const struct qstr *name = &op->dentry->d_name;
658 struct afs_vnode_param *dvp = &op->file[0];
659 struct afs_call *call;
660 size_t namesz, reqsz, padsz;
666 padsz = (4 - (namesz & 3)) & 3;
667 reqsz = (5 * 4) + namesz + padsz;
669 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveFile,
670 reqsz, (21 + 6) * 4);
672 return afs_op_nomem(op);
674 /* marshall the parameters */
676 *bp++ = htonl(FSREMOVEFILE);
677 *bp++ = htonl(dvp->fid.vid);
678 *bp++ = htonl(dvp->fid.vnode);
679 *bp++ = htonl(dvp->fid.unique);
680 *bp++ = htonl(namesz);
681 memcpy(bp, name->name, namesz);
682 bp = (void *) bp + namesz;
684 memset(bp, 0, padsz);
685 bp = (void *) bp + padsz;
688 trace_afs_make_fs_call1(call, &dvp->fid, name);
689 afs_make_op_call(op, call, GFP_NOFS);
692 static const struct afs_call_type afs_RXFSRemoveDir = {
693 .name = "FS.RemoveDir",
694 .op = afs_FS_RemoveDir,
695 .deliver = afs_deliver_fs_file_status_and_vol,
696 .destructor = afs_flat_call_destructor,
700 * Remove a directory.
702 void afs_fs_remove_dir(struct afs_operation *op)
704 const struct qstr *name = &op->dentry->d_name;
705 struct afs_vnode_param *dvp = &op->file[0];
706 struct afs_call *call;
707 size_t namesz, reqsz, padsz;
713 padsz = (4 - (namesz & 3)) & 3;
714 reqsz = (5 * 4) + namesz + padsz;
716 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveDir,
717 reqsz, (21 + 6) * 4);
719 return afs_op_nomem(op);
721 /* marshall the parameters */
723 *bp++ = htonl(FSREMOVEDIR);
724 *bp++ = htonl(dvp->fid.vid);
725 *bp++ = htonl(dvp->fid.vnode);
726 *bp++ = htonl(dvp->fid.unique);
727 *bp++ = htonl(namesz);
728 memcpy(bp, name->name, namesz);
729 bp = (void *) bp + namesz;
731 memset(bp, 0, padsz);
732 bp = (void *) bp + padsz;
735 trace_afs_make_fs_call1(call, &dvp->fid, name);
736 afs_make_op_call(op, call, GFP_NOFS);
740 * deliver reply data to an FS.Link
742 static int afs_deliver_fs_link(struct afs_call *call)
744 struct afs_operation *op = call->op;
745 struct afs_vnode_param *dvp = &op->file[0];
746 struct afs_vnode_param *vp = &op->file[1];
750 _enter("{%u}", call->unmarshall);
752 ret = afs_transfer_reply(call);
756 /* unmarshall the reply once we've received all of it */
758 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
759 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
760 xdr_decode_AFSVolSync(&bp, &op->volsync);
762 _leave(" = 0 [done]");
767 * FS.Link operation type
769 static const struct afs_call_type afs_RXFSLink = {
772 .deliver = afs_deliver_fs_link,
773 .destructor = afs_flat_call_destructor,
779 void afs_fs_link(struct afs_operation *op)
781 const struct qstr *name = &op->dentry->d_name;
782 struct afs_vnode_param *dvp = &op->file[0];
783 struct afs_vnode_param *vp = &op->file[1];
784 struct afs_call *call;
785 size_t namesz, reqsz, padsz;
791 padsz = (4 - (namesz & 3)) & 3;
792 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
794 call = afs_alloc_flat_call(op->net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
796 return afs_op_nomem(op);
798 /* marshall the parameters */
800 *bp++ = htonl(FSLINK);
801 *bp++ = htonl(dvp->fid.vid);
802 *bp++ = htonl(dvp->fid.vnode);
803 *bp++ = htonl(dvp->fid.unique);
804 *bp++ = htonl(namesz);
805 memcpy(bp, name->name, namesz);
806 bp = (void *) bp + namesz;
808 memset(bp, 0, padsz);
809 bp = (void *) bp + padsz;
811 *bp++ = htonl(vp->fid.vid);
812 *bp++ = htonl(vp->fid.vnode);
813 *bp++ = htonl(vp->fid.unique);
815 trace_afs_make_fs_call1(call, &vp->fid, name);
816 afs_make_op_call(op, call, GFP_NOFS);
820 * deliver reply data to an FS.Symlink
822 static int afs_deliver_fs_symlink(struct afs_call *call)
824 struct afs_operation *op = call->op;
825 struct afs_vnode_param *dvp = &op->file[0];
826 struct afs_vnode_param *vp = &op->file[1];
830 _enter("{%u}", call->unmarshall);
832 ret = afs_transfer_reply(call);
836 /* unmarshall the reply once we've received all of it */
838 xdr_decode_AFSFid(&bp, &vp->fid);
839 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
840 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
841 xdr_decode_AFSVolSync(&bp, &op->volsync);
843 _leave(" = 0 [done]");
848 * FS.Symlink operation type
850 static const struct afs_call_type afs_RXFSSymlink = {
851 .name = "FS.Symlink",
852 .op = afs_FS_Symlink,
853 .deliver = afs_deliver_fs_symlink,
854 .destructor = afs_flat_call_destructor,
858 * create a symbolic link
860 void afs_fs_symlink(struct afs_operation *op)
862 const struct qstr *name = &op->dentry->d_name;
863 struct afs_vnode_param *dvp = &op->file[0];
864 struct afs_call *call;
865 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
871 padsz = (4 - (namesz & 3)) & 3;
873 c_namesz = strlen(op->create.symlink);
874 c_padsz = (4 - (c_namesz & 3)) & 3;
876 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
878 call = afs_alloc_flat_call(op->net, &afs_RXFSSymlink, reqsz,
879 (3 + 21 + 21 + 6) * 4);
881 return afs_op_nomem(op);
883 /* marshall the parameters */
885 *bp++ = htonl(FSSYMLINK);
886 *bp++ = htonl(dvp->fid.vid);
887 *bp++ = htonl(dvp->fid.vnode);
888 *bp++ = htonl(dvp->fid.unique);
889 *bp++ = htonl(namesz);
890 memcpy(bp, name->name, namesz);
891 bp = (void *) bp + namesz;
893 memset(bp, 0, padsz);
894 bp = (void *) bp + padsz;
896 *bp++ = htonl(c_namesz);
897 memcpy(bp, op->create.symlink, c_namesz);
898 bp = (void *) bp + c_namesz;
900 memset(bp, 0, c_padsz);
901 bp = (void *) bp + c_padsz;
903 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
904 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
905 *bp++ = 0; /* owner */
906 *bp++ = 0; /* group */
907 *bp++ = htonl(S_IRWXUGO); /* unix mode */
908 *bp++ = 0; /* segment size */
910 trace_afs_make_fs_call1(call, &dvp->fid, name);
911 afs_make_op_call(op, call, GFP_NOFS);
915 * deliver reply data to an FS.Rename
917 static int afs_deliver_fs_rename(struct afs_call *call)
919 struct afs_operation *op = call->op;
920 struct afs_vnode_param *orig_dvp = &op->file[0];
921 struct afs_vnode_param *new_dvp = &op->file[1];
925 ret = afs_transfer_reply(call);
930 /* If the two dirs are the same, we have two copies of the same status
931 * report, so we just decode it twice.
933 xdr_decode_AFSFetchStatus(&bp, call, &orig_dvp->scb);
934 xdr_decode_AFSFetchStatus(&bp, call, &new_dvp->scb);
935 xdr_decode_AFSVolSync(&bp, &op->volsync);
937 _leave(" = 0 [done]");
942 * FS.Rename operation type
944 static const struct afs_call_type afs_RXFSRename = {
947 .deliver = afs_deliver_fs_rename,
948 .destructor = afs_flat_call_destructor,
952 * Rename/move a file or directory.
954 void afs_fs_rename(struct afs_operation *op)
956 struct afs_vnode_param *orig_dvp = &op->file[0];
957 struct afs_vnode_param *new_dvp = &op->file[1];
958 const struct qstr *orig_name = &op->dentry->d_name;
959 const struct qstr *new_name = &op->dentry_2->d_name;
960 struct afs_call *call;
961 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
966 o_namesz = orig_name->len;
967 o_padsz = (4 - (o_namesz & 3)) & 3;
969 n_namesz = new_name->len;
970 n_padsz = (4 - (n_namesz & 3)) & 3;
973 4 + o_namesz + o_padsz +
975 4 + n_namesz + n_padsz;
977 call = afs_alloc_flat_call(op->net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
979 return afs_op_nomem(op);
981 /* marshall the parameters */
983 *bp++ = htonl(FSRENAME);
984 *bp++ = htonl(orig_dvp->fid.vid);
985 *bp++ = htonl(orig_dvp->fid.vnode);
986 *bp++ = htonl(orig_dvp->fid.unique);
987 *bp++ = htonl(o_namesz);
988 memcpy(bp, orig_name->name, o_namesz);
989 bp = (void *) bp + o_namesz;
991 memset(bp, 0, o_padsz);
992 bp = (void *) bp + o_padsz;
995 *bp++ = htonl(new_dvp->fid.vid);
996 *bp++ = htonl(new_dvp->fid.vnode);
997 *bp++ = htonl(new_dvp->fid.unique);
998 *bp++ = htonl(n_namesz);
999 memcpy(bp, new_name->name, n_namesz);
1000 bp = (void *) bp + n_namesz;
1002 memset(bp, 0, n_padsz);
1003 bp = (void *) bp + n_padsz;
1006 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1007 afs_make_op_call(op, call, GFP_NOFS);
1011 * Deliver reply data to FS.StoreData or FS.StoreStatus
1013 static int afs_deliver_fs_store_data(struct afs_call *call)
1015 struct afs_operation *op = call->op;
1016 struct afs_vnode_param *vp = &op->file[0];
1022 ret = afs_transfer_reply(call);
1026 /* unmarshall the reply once we've received all of it */
1028 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
1029 xdr_decode_AFSVolSync(&bp, &op->volsync);
1031 _leave(" = 0 [done]");
1036 * FS.StoreData operation type
1038 static const struct afs_call_type afs_RXFSStoreData = {
1039 .name = "FS.StoreData",
1040 .op = afs_FS_StoreData,
1041 .deliver = afs_deliver_fs_store_data,
1042 .destructor = afs_flat_call_destructor,
1045 static const struct afs_call_type afs_RXFSStoreData64 = {
1046 .name = "FS.StoreData64",
1047 .op = afs_FS_StoreData64,
1048 .deliver = afs_deliver_fs_store_data,
1049 .destructor = afs_flat_call_destructor,
1053 * store a set of pages to a very large file
1055 static void afs_fs_store_data64(struct afs_operation *op)
1057 struct afs_vnode_param *vp = &op->file[0];
1058 struct afs_call *call;
1061 _enter(",%x,{%llx:%llu},,",
1062 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1064 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64,
1065 (4 + 6 + 3 * 2) * 4,
1068 return afs_op_nomem(op);
1070 call->write_iter = op->store.write_iter;
1072 /* marshall the parameters */
1074 *bp++ = htonl(FSSTOREDATA64);
1075 *bp++ = htonl(vp->fid.vid);
1076 *bp++ = htonl(vp->fid.vnode);
1077 *bp++ = htonl(vp->fid.unique);
1079 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1080 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
1081 *bp++ = 0; /* owner */
1082 *bp++ = 0; /* group */
1083 *bp++ = 0; /* unix mode */
1084 *bp++ = 0; /* segment size */
1086 *bp++ = htonl(upper_32_bits(op->store.pos));
1087 *bp++ = htonl(lower_32_bits(op->store.pos));
1088 *bp++ = htonl(upper_32_bits(op->store.size));
1089 *bp++ = htonl(lower_32_bits(op->store.size));
1090 *bp++ = htonl(upper_32_bits(op->store.i_size));
1091 *bp++ = htonl(lower_32_bits(op->store.i_size));
1093 trace_afs_make_fs_call(call, &vp->fid);
1094 afs_make_op_call(op, call, GFP_NOFS);
1098 * Write data to a file on the server.
1100 void afs_fs_store_data(struct afs_operation *op)
1102 struct afs_vnode_param *vp = &op->file[0];
1103 struct afs_call *call;
1106 _enter(",%x,{%llx:%llu},,",
1107 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1109 _debug("size %llx, at %llx, i_size %llx",
1110 (unsigned long long)op->store.size,
1111 (unsigned long long)op->store.pos,
1112 (unsigned long long)op->store.i_size);
1114 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
1115 return afs_fs_store_data64(op);
1117 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData,
1121 return afs_op_nomem(op);
1123 call->write_iter = op->store.write_iter;
1125 /* marshall the parameters */
1127 *bp++ = htonl(FSSTOREDATA);
1128 *bp++ = htonl(vp->fid.vid);
1129 *bp++ = htonl(vp->fid.vnode);
1130 *bp++ = htonl(vp->fid.unique);
1132 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1133 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
1134 *bp++ = 0; /* owner */
1135 *bp++ = 0; /* group */
1136 *bp++ = 0; /* unix mode */
1137 *bp++ = 0; /* segment size */
1139 *bp++ = htonl(lower_32_bits(op->store.pos));
1140 *bp++ = htonl(lower_32_bits(op->store.size));
1141 *bp++ = htonl(lower_32_bits(op->store.i_size));
1143 trace_afs_make_fs_call(call, &vp->fid);
1144 afs_make_op_call(op, call, GFP_NOFS);
1148 * FS.StoreStatus operation type
1150 static const struct afs_call_type afs_RXFSStoreStatus = {
1151 .name = "FS.StoreStatus",
1152 .op = afs_FS_StoreStatus,
1153 .deliver = afs_deliver_fs_store_data,
1154 .destructor = afs_flat_call_destructor,
1157 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1158 .name = "FS.StoreData",
1159 .op = afs_FS_StoreData,
1160 .deliver = afs_deliver_fs_store_data,
1161 .destructor = afs_flat_call_destructor,
1164 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1165 .name = "FS.StoreData64",
1166 .op = afs_FS_StoreData64,
1167 .deliver = afs_deliver_fs_store_data,
1168 .destructor = afs_flat_call_destructor,
1172 * set the attributes on a very large file, using FS.StoreData rather than
1173 * FS.StoreStatus so as to alter the file size also
1175 static void afs_fs_setattr_size64(struct afs_operation *op)
1177 struct afs_vnode_param *vp = &op->file[0];
1178 struct afs_call *call;
1179 struct iattr *attr = op->setattr.attr;
1182 _enter(",%x,{%llx:%llu},,",
1183 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1185 ASSERT(attr->ia_valid & ATTR_SIZE);
1187 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64_as_Status,
1188 (4 + 6 + 3 * 2) * 4,
1191 return afs_op_nomem(op);
1193 /* marshall the parameters */
1195 *bp++ = htonl(FSSTOREDATA64);
1196 *bp++ = htonl(vp->fid.vid);
1197 *bp++ = htonl(vp->fid.vnode);
1198 *bp++ = htonl(vp->fid.unique);
1200 xdr_encode_AFS_StoreStatus(&bp, attr);
1202 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* position of start of write */
1203 *bp++ = htonl(lower_32_bits(attr->ia_size));
1204 *bp++ = 0; /* size of write */
1206 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* new file length */
1207 *bp++ = htonl(lower_32_bits(attr->ia_size));
1209 trace_afs_make_fs_call(call, &vp->fid);
1210 afs_make_op_call(op, call, GFP_NOFS);
1214 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1215 * so as to alter the file size also
1217 static void afs_fs_setattr_size(struct afs_operation *op)
1219 struct afs_vnode_param *vp = &op->file[0];
1220 struct afs_call *call;
1221 struct iattr *attr = op->setattr.attr;
1224 _enter(",%x,{%llx:%llu},,",
1225 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1227 ASSERT(attr->ia_valid & ATTR_SIZE);
1228 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
1229 return afs_fs_setattr_size64(op);
1231 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData_as_Status,
1235 return afs_op_nomem(op);
1237 /* marshall the parameters */
1239 *bp++ = htonl(FSSTOREDATA);
1240 *bp++ = htonl(vp->fid.vid);
1241 *bp++ = htonl(vp->fid.vnode);
1242 *bp++ = htonl(vp->fid.unique);
1244 xdr_encode_AFS_StoreStatus(&bp, attr);
1246 *bp++ = htonl(attr->ia_size); /* position of start of write */
1247 *bp++ = 0; /* size of write */
1248 *bp++ = htonl(attr->ia_size); /* new file length */
1250 trace_afs_make_fs_call(call, &vp->fid);
1251 afs_make_op_call(op, call, GFP_NOFS);
1255 * set the attributes on a file, using FS.StoreData if there's a change in file
1256 * size, and FS.StoreStatus otherwise
1258 void afs_fs_setattr(struct afs_operation *op)
1260 struct afs_vnode_param *vp = &op->file[0];
1261 struct afs_call *call;
1262 struct iattr *attr = op->setattr.attr;
1265 if (attr->ia_valid & ATTR_SIZE)
1266 return afs_fs_setattr_size(op);
1268 _enter(",%x,{%llx:%llu},,",
1269 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1271 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreStatus,
1275 return afs_op_nomem(op);
1277 /* marshall the parameters */
1279 *bp++ = htonl(FSSTORESTATUS);
1280 *bp++ = htonl(vp->fid.vid);
1281 *bp++ = htonl(vp->fid.vnode);
1282 *bp++ = htonl(vp->fid.unique);
1284 xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr);
1286 trace_afs_make_fs_call(call, &vp->fid);
1287 afs_make_op_call(op, call, GFP_NOFS);
1291 * deliver reply data to an FS.GetVolumeStatus
1293 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1295 struct afs_operation *op = call->op;
1301 _enter("{%u}", call->unmarshall);
1303 switch (call->unmarshall) {
1306 afs_extract_to_buf(call, 12 * 4);
1309 /* extract the returned status record */
1311 _debug("extract status");
1312 ret = afs_extract_data(call, true);
1317 xdr_decode_AFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1319 afs_extract_to_tmp(call);
1322 /* extract the volume name length */
1324 ret = afs_extract_data(call, true);
1328 call->count = ntohl(call->tmp);
1329 _debug("volname length: %u", call->count);
1330 if (call->count >= AFSNAMEMAX)
1331 return afs_protocol_error(call, afs_eproto_volname_len);
1332 size = (call->count + 3) & ~3; /* It's padded */
1333 afs_extract_to_buf(call, size);
1337 /* extract the volume name */
1339 _debug("extract volname");
1340 ret = afs_extract_data(call, true);
1346 _debug("volname '%s'", p);
1347 afs_extract_to_tmp(call);
1351 /* extract the offline message length */
1353 ret = afs_extract_data(call, true);
1357 call->count = ntohl(call->tmp);
1358 _debug("offline msg length: %u", call->count);
1359 if (call->count >= AFSNAMEMAX)
1360 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1361 size = (call->count + 3) & ~3; /* It's padded */
1362 afs_extract_to_buf(call, size);
1366 /* extract the offline message */
1368 _debug("extract offline");
1369 ret = afs_extract_data(call, true);
1375 _debug("offline '%s'", p);
1377 afs_extract_to_tmp(call);
1381 /* extract the message of the day length */
1383 ret = afs_extract_data(call, true);
1387 call->count = ntohl(call->tmp);
1388 _debug("motd length: %u", call->count);
1389 if (call->count >= AFSNAMEMAX)
1390 return afs_protocol_error(call, afs_eproto_motd_len);
1391 size = (call->count + 3) & ~3; /* It's padded */
1392 afs_extract_to_buf(call, size);
1396 /* extract the message of the day */
1398 _debug("extract motd");
1399 ret = afs_extract_data(call, false);
1405 _debug("motd '%s'", p);
1414 _leave(" = 0 [done]");
1419 * FS.GetVolumeStatus operation type
1421 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1422 .name = "FS.GetVolumeStatus",
1423 .op = afs_FS_GetVolumeStatus,
1424 .deliver = afs_deliver_fs_get_volume_status,
1425 .destructor = afs_flat_call_destructor,
1429 * fetch the status of a volume
1431 void afs_fs_get_volume_status(struct afs_operation *op)
1433 struct afs_vnode_param *vp = &op->file[0];
1434 struct afs_call *call;
1439 call = afs_alloc_flat_call(op->net, &afs_RXFSGetVolumeStatus, 2 * 4,
1440 max(12 * 4, AFSOPAQUEMAX + 1));
1442 return afs_op_nomem(op);
1444 /* marshall the parameters */
1446 bp[0] = htonl(FSGETVOLUMESTATUS);
1447 bp[1] = htonl(vp->fid.vid);
1449 trace_afs_make_fs_call(call, &vp->fid);
1450 afs_make_op_call(op, call, GFP_NOFS);
1454 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1456 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1458 struct afs_operation *op = call->op;
1462 _enter("{%u}", call->unmarshall);
1464 ret = afs_transfer_reply(call);
1468 /* unmarshall the reply once we've received all of it */
1470 xdr_decode_AFSVolSync(&bp, &op->volsync);
1472 _leave(" = 0 [done]");
1477 * FS.SetLock operation type
1479 static const struct afs_call_type afs_RXFSSetLock = {
1480 .name = "FS.SetLock",
1481 .op = afs_FS_SetLock,
1482 .deliver = afs_deliver_fs_xxxx_lock,
1483 .done = afs_lock_op_done,
1484 .destructor = afs_flat_call_destructor,
1488 * FS.ExtendLock operation type
1490 static const struct afs_call_type afs_RXFSExtendLock = {
1491 .name = "FS.ExtendLock",
1492 .op = afs_FS_ExtendLock,
1493 .deliver = afs_deliver_fs_xxxx_lock,
1494 .done = afs_lock_op_done,
1495 .destructor = afs_flat_call_destructor,
1499 * FS.ReleaseLock operation type
1501 static const struct afs_call_type afs_RXFSReleaseLock = {
1502 .name = "FS.ReleaseLock",
1503 .op = afs_FS_ReleaseLock,
1504 .deliver = afs_deliver_fs_xxxx_lock,
1505 .destructor = afs_flat_call_destructor,
1509 * Set a lock on a file
1511 void afs_fs_set_lock(struct afs_operation *op)
1513 struct afs_vnode_param *vp = &op->file[0];
1514 struct afs_call *call;
1519 call = afs_alloc_flat_call(op->net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1521 return afs_op_nomem(op);
1523 /* marshall the parameters */
1525 *bp++ = htonl(FSSETLOCK);
1526 *bp++ = htonl(vp->fid.vid);
1527 *bp++ = htonl(vp->fid.vnode);
1528 *bp++ = htonl(vp->fid.unique);
1529 *bp++ = htonl(op->lock.type);
1531 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1532 afs_make_op_call(op, call, GFP_NOFS);
1536 * extend a lock on a file
1538 void afs_fs_extend_lock(struct afs_operation *op)
1540 struct afs_vnode_param *vp = &op->file[0];
1541 struct afs_call *call;
1546 call = afs_alloc_flat_call(op->net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1548 return afs_op_nomem(op);
1550 /* marshall the parameters */
1552 *bp++ = htonl(FSEXTENDLOCK);
1553 *bp++ = htonl(vp->fid.vid);
1554 *bp++ = htonl(vp->fid.vnode);
1555 *bp++ = htonl(vp->fid.unique);
1557 trace_afs_make_fs_call(call, &vp->fid);
1558 afs_make_op_call(op, call, GFP_NOFS);
1562 * release a lock on a file
1564 void afs_fs_release_lock(struct afs_operation *op)
1566 struct afs_vnode_param *vp = &op->file[0];
1567 struct afs_call *call;
1572 call = afs_alloc_flat_call(op->net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1574 return afs_op_nomem(op);
1576 /* marshall the parameters */
1578 *bp++ = htonl(FSRELEASELOCK);
1579 *bp++ = htonl(vp->fid.vid);
1580 *bp++ = htonl(vp->fid.vnode);
1581 *bp++ = htonl(vp->fid.unique);
1583 trace_afs_make_fs_call(call, &vp->fid);
1584 afs_make_op_call(op, call, GFP_NOFS);
1588 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1590 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1592 return afs_transfer_reply(call);
1596 * FS.GiveUpAllCallBacks operation type
1598 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1599 .name = "FS.GiveUpAllCallBacks",
1600 .op = afs_FS_GiveUpAllCallBacks,
1601 .deliver = afs_deliver_fs_give_up_all_callbacks,
1602 .destructor = afs_flat_call_destructor,
1606 * Flush all the callbacks we have on a server.
1608 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1609 struct afs_server *server,
1610 struct afs_addr_cursor *ac,
1613 struct afs_call *call;
1618 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1624 /* marshall the parameters */
1626 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1628 call->server = afs_use_server(server, afs_server_trace_give_up_cb);
1629 afs_make_call(ac, call, GFP_NOFS);
1630 return afs_wait_for_call_to_complete(call, ac);
1634 * Deliver reply data to an FS.GetCapabilities operation.
1636 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1641 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
1643 switch (call->unmarshall) {
1645 afs_extract_to_tmp(call);
1649 /* Extract the capabilities word count */
1651 ret = afs_extract_data(call, true);
1655 count = ntohl(call->tmp);
1656 call->count = count;
1657 call->count2 = count;
1659 call->unmarshall = 4;
1664 /* Extract the first word of the capabilities to call->tmp */
1665 afs_extract_to_tmp(call);
1670 ret = afs_extract_data(call, false);
1674 afs_extract_discard(call, (count - 1) * sizeof(__be32));
1678 /* Extract remaining capabilities words */
1680 ret = afs_extract_data(call, false);
1688 _leave(" = 0 [done]");
1693 * FS.GetCapabilities operation type
1695 static const struct afs_call_type afs_RXFSGetCapabilities = {
1696 .name = "FS.GetCapabilities",
1697 .op = afs_FS_GetCapabilities,
1698 .deliver = afs_deliver_fs_get_capabilities,
1699 .done = afs_fileserver_probe_result,
1700 .destructor = afs_flat_call_destructor,
1704 * Probe a fileserver for the capabilities that it supports. This RPC can
1705 * reply with up to 196 words. The operation is asynchronous and if we managed
1706 * to allocate a call, true is returned the result is delivered through the
1707 * ->done() - otherwise we return false to indicate we didn't even try.
1709 bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
1710 struct afs_addr_cursor *ac, struct key *key)
1712 struct afs_call *call;
1717 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1722 call->server = afs_use_server(server, afs_server_trace_get_caps);
1723 call->upgrade = true;
1725 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
1727 /* marshall the parameters */
1729 *bp++ = htonl(FSGETCAPABILITIES);
1731 trace_afs_make_fs_call(call, NULL);
1732 afs_make_call(ac, call, GFP_NOFS);
1738 * Deliver reply data to an FS.InlineBulkStatus call
1740 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
1742 struct afs_operation *op = call->op;
1743 struct afs_status_cb *scb;
1748 _enter("{%u}", call->unmarshall);
1750 switch (call->unmarshall) {
1752 afs_extract_to_tmp(call);
1756 /* Extract the file status count and array in two steps */
1758 _debug("extract status count");
1759 ret = afs_extract_data(call, true);
1763 tmp = ntohl(call->tmp);
1764 _debug("status count: %u/%u", tmp, op->nr_files);
1765 if (tmp != op->nr_files)
1766 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1771 afs_extract_to_buf(call, 21 * sizeof(__be32));
1775 _debug("extract status array %u", call->count);
1776 ret = afs_extract_data(call, true);
1780 switch (call->count) {
1782 scb = &op->file[0].scb;
1785 scb = &op->file[1].scb;
1788 scb = &op->more_files[call->count - 2].scb;
1793 xdr_decode_AFSFetchStatus(&bp, call, scb);
1796 if (call->count < op->nr_files)
1801 afs_extract_to_tmp(call);
1804 /* Extract the callback count and array in two steps */
1806 _debug("extract CB count");
1807 ret = afs_extract_data(call, true);
1811 tmp = ntohl(call->tmp);
1812 _debug("CB count: %u", tmp);
1813 if (tmp != op->nr_files)
1814 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1818 afs_extract_to_buf(call, 3 * sizeof(__be32));
1822 _debug("extract CB array");
1823 ret = afs_extract_data(call, true);
1827 _debug("unmarshall CB array");
1828 switch (call->count) {
1830 scb = &op->file[0].scb;
1833 scb = &op->file[1].scb;
1836 scb = &op->more_files[call->count - 2].scb;
1841 xdr_decode_AFSCallBack(&bp, call, scb);
1843 if (call->count < op->nr_files)
1846 afs_extract_to_buf(call, 6 * sizeof(__be32));
1851 ret = afs_extract_data(call, false);
1856 xdr_decode_AFSVolSync(&bp, &op->volsync);
1865 _leave(" = 0 [done]");
1869 static void afs_done_fs_inline_bulk_status(struct afs_call *call)
1871 if (call->error == -ECONNABORTED &&
1872 call->abort_code == RX_INVALID_OPERATION) {
1873 set_bit(AFS_SERVER_FL_NO_IBULK, &call->server->flags);
1875 set_bit(AFS_VOLUME_MAYBE_NO_IBULK, &call->op->volume->flags);
1880 * FS.InlineBulkStatus operation type
1882 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
1883 .name = "FS.InlineBulkStatus",
1884 .op = afs_FS_InlineBulkStatus,
1885 .deliver = afs_deliver_fs_inline_bulk_status,
1886 .done = afs_done_fs_inline_bulk_status,
1887 .destructor = afs_flat_call_destructor,
1891 * Fetch the status information for up to 50 files
1893 void afs_fs_inline_bulk_status(struct afs_operation *op)
1895 struct afs_vnode_param *dvp = &op->file[0];
1896 struct afs_vnode_param *vp = &op->file[1];
1897 struct afs_call *call;
1901 if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) {
1902 op->error = -ENOTSUPP;
1906 _enter(",%x,{%llx:%llu},%u",
1907 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1909 call = afs_alloc_flat_call(op->net, &afs_RXFSInlineBulkStatus,
1910 (2 + op->nr_files * 3) * 4,
1913 return afs_op_nomem(op);
1915 /* marshall the parameters */
1917 *bp++ = htonl(FSINLINEBULKSTATUS);
1918 *bp++ = htonl(op->nr_files);
1919 *bp++ = htonl(dvp->fid.vid);
1920 *bp++ = htonl(dvp->fid.vnode);
1921 *bp++ = htonl(dvp->fid.unique);
1922 *bp++ = htonl(vp->fid.vid);
1923 *bp++ = htonl(vp->fid.vnode);
1924 *bp++ = htonl(vp->fid.unique);
1925 for (i = 0; i < op->nr_files - 2; i++) {
1926 *bp++ = htonl(op->more_files[i].fid.vid);
1927 *bp++ = htonl(op->more_files[i].fid.vnode);
1928 *bp++ = htonl(op->more_files[i].fid.unique);
1931 trace_afs_make_fs_call(call, &vp->fid);
1932 afs_make_op_call(op, call, GFP_NOFS);
1936 * deliver reply data to an FS.FetchACL
1938 static int afs_deliver_fs_fetch_acl(struct afs_call *call)
1940 struct afs_operation *op = call->op;
1941 struct afs_vnode_param *vp = &op->file[0];
1942 struct afs_acl *acl;
1947 _enter("{%u}", call->unmarshall);
1949 switch (call->unmarshall) {
1951 afs_extract_to_tmp(call);
1955 /* extract the returned data length */
1957 ret = afs_extract_data(call, true);
1961 size = call->count2 = ntohl(call->tmp);
1962 size = round_up(size, 4);
1964 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1968 acl->size = call->count2;
1969 afs_extract_begin(call, acl->data, size);
1973 /* extract the returned data */
1975 ret = afs_extract_data(call, true);
1979 afs_extract_to_buf(call, (21 + 6) * 4);
1983 /* extract the metadata */
1985 ret = afs_extract_data(call, false);
1990 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
1991 xdr_decode_AFSVolSync(&bp, &op->volsync);
2000 _leave(" = 0 [done]");
2005 * FS.FetchACL operation type
2007 static const struct afs_call_type afs_RXFSFetchACL = {
2008 .name = "FS.FetchACL",
2009 .op = afs_FS_FetchACL,
2010 .deliver = afs_deliver_fs_fetch_acl,
2014 * Fetch the ACL for a file.
2016 void afs_fs_fetch_acl(struct afs_operation *op)
2018 struct afs_vnode_param *vp = &op->file[0];
2019 struct afs_call *call;
2022 _enter(",%x,{%llx:%llu},,",
2023 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
2025 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2027 return afs_op_nomem(op);
2029 /* marshall the parameters */
2031 bp[0] = htonl(FSFETCHACL);
2032 bp[1] = htonl(vp->fid.vid);
2033 bp[2] = htonl(vp->fid.vnode);
2034 bp[3] = htonl(vp->fid.unique);
2036 trace_afs_make_fs_call(call, &vp->fid);
2037 afs_make_op_call(op, call, GFP_KERNEL);
2041 * FS.StoreACL operation type
2043 static const struct afs_call_type afs_RXFSStoreACL = {
2044 .name = "FS.StoreACL",
2045 .op = afs_FS_StoreACL,
2046 .deliver = afs_deliver_fs_file_status_and_vol,
2047 .destructor = afs_flat_call_destructor,
2051 * Fetch the ACL for a file.
2053 void afs_fs_store_acl(struct afs_operation *op)
2055 struct afs_vnode_param *vp = &op->file[0];
2056 struct afs_call *call;
2057 const struct afs_acl *acl = op->acl;
2061 _enter(",%x,{%llx:%llu},,",
2062 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
2064 size = round_up(acl->size, 4);
2065 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreACL,
2066 5 * 4 + size, (21 + 6) * 4);
2068 return afs_op_nomem(op);
2070 /* marshall the parameters */
2072 bp[0] = htonl(FSSTOREACL);
2073 bp[1] = htonl(vp->fid.vid);
2074 bp[2] = htonl(vp->fid.vnode);
2075 bp[3] = htonl(vp->fid.unique);
2076 bp[4] = htonl(acl->size);
2077 memcpy(&bp[5], acl->data, acl->size);
2078 if (acl->size != size)
2079 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2081 trace_afs_make_fs_call(call, &vp->fid);
2082 afs_make_op_call(op, call, GFP_KERNEL);